提交 722802b5 authored 作者: James Bergstra's avatar James Bergstra

GpuElemwise - added self.sync to eq and hash, removed sync from code version

上级 5dbb6809
...@@ -97,10 +97,11 @@ class GpuElemwise(Op): ...@@ -97,10 +97,11 @@ class GpuElemwise(Op):
self.ufunc = numpy.frompyfunc(scalar_op.impl, scalar_op.nin, scalar_op.nout) self.ufunc = numpy.frompyfunc(scalar_op.impl, scalar_op.nin, scalar_op.nout)
else: else:
self.ufunc = None self.ufunc = None
self.sync = sync
self._rehash() self._rehash()
self.src_generator = NaiveAlgo(self.scalar_op, sync=sync) self.src_generator = NaiveAlgo(self.scalar_op, sync=sync)
self.sync = sync
def __getstate__(self): def __getstate__(self):
d = copy.copy(self.__dict__) d = copy.copy(self.__dict__)
...@@ -111,6 +112,7 @@ class GpuElemwise(Op): ...@@ -111,6 +112,7 @@ class GpuElemwise(Op):
def __setstate__(self, d): def __setstate__(self, d):
self.__dict__.update(d) self.__dict__.update(d)
self.sync = d.get('sync', True) #old objects defaulted to sync behaviour
if self.scalar_op.nin > 0: if self.scalar_op.nin > 0:
self.ufunc = numpy.frompyfunc(self.scalar_op.impl, self.scalar_op.nin, self.scalar_op.nout) self.ufunc = numpy.frompyfunc(self.scalar_op.impl, self.scalar_op.nin, self.scalar_op.nout)
else: else:
...@@ -119,7 +121,8 @@ class GpuElemwise(Op): ...@@ -119,7 +121,8 @@ class GpuElemwise(Op):
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) and (self.scalar_op == other.scalar_op) \ return type(self) == type(other) and (self.scalar_op == other.scalar_op) \
and self.inplace_pattern == other.inplace_pattern and self.inplace_pattern == other.inplace_pattern \
and self.sync == other.sync
def _rehash(self): def _rehash(self):
items = self.inplace_pattern.items() items = self.inplace_pattern.items()
...@@ -130,7 +133,7 @@ class GpuElemwise(Op): ...@@ -130,7 +133,7 @@ class GpuElemwise(Op):
tuple_items+=[tuple(v)] tuple_items+=[tuple(v)]
else: tuple_items+=[v] else: tuple_items+=[v]
tuple_items = tuple(tuple_items) tuple_items = tuple(tuple_items)
h = hash(type(self)) ^ hash(self.scalar_op) ^ hash(tuple_items) h = hash(type(self)) ^ hash(self.scalar_op) ^ hash(tuple_items) ^ hash(self.sync)
# don't change a code that has already been computed for this object # don't change a code that has already been computed for this object
assert h == getattr(self,'_hashval', h) assert h == getattr(self,'_hashval', h)
self._hashval = h self._hashval = h
......
...@@ -218,8 +218,8 @@ class RecAlgo(object): ...@@ -218,8 +218,8 @@ class RecAlgo(object):
class NaiveAlgo(object): class NaiveAlgo(object):
verbose = 0 # 1, 2 or 3 for more verbose output. verbose = 0 # 1, 2 or 3 for more verbose output.
cache_version = ()
cache_version = ('debug', 7, verbose) cache_version = ('debug', 7, verbose)
cache_version = ()
def __init__(self, scalar_op, sync=True): def __init__(self, scalar_op, sync=True):
""" """
...@@ -228,8 +228,6 @@ class NaiveAlgo(object): ...@@ -228,8 +228,6 @@ class NaiveAlgo(object):
""" """
self.scalar_op = scalar_op self.scalar_op = scalar_op
self.sync = sync self.sync = sync
if not self.sync:
self.cache_version+=('nosync',)
def c_src_kernel(self, node, nodename, nd): def c_src_kernel(self, node, nodename, nd):
sio = StringIO.StringIO() sio = StringIO.StringIO()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论