提交 0aee4085 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

made c_code_cache_version work with GpuCAReduce

上级 0478beb3
...@@ -1501,9 +1501,16 @@ class GpuCAReduce(GpuOp): ...@@ -1501,9 +1501,16 @@ class GpuCAReduce(GpuOp):
""" % locals() """ % locals()
def c_code_cache_version(self): def c_code_cache_version(self):
# TODO: make this act like tensor.elemwise.CAReduce op_version = self.scalar_op.cuda_assign_reduce_code_cache_version()
# needs to include scalar op's cache version in the returned tuple if op_version:
return () # our version is 0
rval = [0]
rval.extend(op_version)
rval = tuple(rval)
return rval
else:
# we can't support caching if the op doesn't
return ()
def _op_guard(self): def _op_guard(self):
""" Raises NotImplementedError if op is not Add """ """ Raises NotImplementedError if op is not Add """
......
...@@ -823,6 +823,12 @@ class ScalarOp(Op): ...@@ -823,6 +823,12 @@ class ScalarOp(Op):
raise NotImplementedError( raise NotImplementedError(
str(self)+" does not implement cuda_assign_reduce") str(self)+" does not implement cuda_assign_reduce")
def cuda_assign_reduce_code_cache_version(self):
""" Returns a tuple of integers representing the version of the
scalar op's cuda_assign_reduce method. Must be unique across ops.
An empty tuple means not to use code caching for this op"""
return ()
def c_code_cache_version(self): def c_code_cache_version(self):
return (4,) return (4,)
...@@ -1169,6 +1175,10 @@ class Maximum(BinaryScalarOp): ...@@ -1169,6 +1175,10 @@ class Maximum(BinaryScalarOp):
def cuda_assign_reduce(self, left, right): def cuda_assign_reduce(self, left, right):
return left + ' = max(' + left + ', '+ right + ');' return left + ' = max(' + left + ', '+ right + ');'
def cuda_assign_reduce_code_cache_version(self):
# Maximum's unique identifier is 0
# Version 0 of its code
return (0,0)
maximum = Maximum(upcast_out, name='maximum') maximum = Maximum(upcast_out, name='maximum')
...@@ -1235,6 +1245,11 @@ class Add(ScalarOp): ...@@ -1235,6 +1245,11 @@ class Add(ScalarOp):
def cuda_assign_reduce(self, left, right): def cuda_assign_reduce(self, left, right):
return left + ' += ' + right + ';' return left + ' += ' + right + ';'
def cuda_assign_reduce_code_cache_version(self):
# Add's unique identifier is 1
# Version 0 of its code
return (1,0)
add = Add(upcast_out, name='add') add = Add(upcast_out, name='add')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论