提交 3c1d5bc0 authored 作者: Frederic's avatar Frederic

[CRASH] fix crash on the GPU with {inc,set}_subtensor and broadcasting the value

上级 c85d1953
......@@ -2888,7 +2888,9 @@ class GpuIncSubtensor(tensor.IncSubtensor, GpuOp):
returns a C code expression to copy source into view, and
return 0 on success
"""
return """CudaNdarray_CopyFromCudaNdarray(%(view)s, %(source)s)""" % locals()
# On the CPU it unbroadcast based on the run time shapes. We
# need the same behavior on the GPU.
return """CudaNdarray_CopyFromCudaNdarray(%(view)s, %(source)s, 1)""" % locals()
def add_to_zview(self, name, x, fail):
......@@ -2910,7 +2912,7 @@ class GpuIncSubtensor(tensor.IncSubtensor, GpuOp):
def c_code_cache_version(self):
parent_version = super(GpuIncSubtensor, self).c_code_cache_version()
if parent_version:
return parent_version + (0,)
return parent_version + (1,)
return ()
......
......@@ -863,7 +863,25 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
inc_slice(2, 1),
(numpy.asarray([[0, 1], [2, 3], [4, 5.]]), numpy.asarray(9.),))
def test_advanced_inc_and_set(self):
def test_inc_and_set_subtensor(self):
"""
Test increment and set with broadcast
"""
X = tensor.matrix(dtype=self.dtype)
y = set_subtensor(X[1::, 1::], 0)
f = self.function([X], [y],
op=self.inc_sub,
N=1)
x_ = numpy.ones((9, 9))
out = f(x_.astype('float32'))
res = x_.copy()
res[1::, 1::] = 0
assert numpy.allclose(out, res)
def test_advanced1_inc_and_set(self):
"""
Test advanced increment and set.
"""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论