提交 741e24dc authored 作者: Frederic Bastien's avatar Frederic Bastien

fix bug with on how set_subtensor are moved to the gpu. They where moved to the…

fix bug with on how set_subtensor are moved to the gpu. They where moved to the gpu as a inc_subtensor.
上级 922c73d1
...@@ -342,7 +342,8 @@ def local_gpu_incsubtensor(node): ...@@ -342,7 +342,8 @@ def local_gpu_incsubtensor(node):
incsubt = host_output.owner.op incsubt = host_output.owner.op
x, y = host_output.owner.inputs[0:2] x, y = host_output.owner.inputs[0:2]
coords = host_output.owner.inputs[2:] coords = host_output.owner.inputs[2:]
return [GpuIncSubtensor(incsubt.idx_list, inplace=incsubt.inplace)( return [GpuIncSubtensor(incsubt.idx_list, inplace=incsubt.inplace,
set_instead_of_inc=incsubt.op.set_instead_of_inc)(
gpu_from_host(x), gpu_from_host(x),
gpu_from_host(y), gpu_from_host(y),
*coords)] *coords)]
...@@ -364,7 +365,8 @@ def local_gpu_incsubtensor(node): ...@@ -364,7 +365,8 @@ def local_gpu_incsubtensor(node):
gpu_y = gpu_from_host(y) gpu_y = gpu_from_host(y)
if go_gpu: if go_gpu:
return [host_from_gpu(GpuIncSubtensor( return [host_from_gpu(GpuIncSubtensor(
node.op.idx_list, inplace=node.op.inplace)( node.op.idx_list, inplace=node.op.inplace,
set_instead_of_inc=node.op.set_instead_of_inc)(
gpu_x, gpu_y, *coords))] gpu_x, gpu_y, *coords))]
return False return False
......
...@@ -716,6 +716,37 @@ def test_gpualloc_output_to_gpu(): ...@@ -716,6 +716,37 @@ def test_gpualloc_output_to_gpu():
assert numpy.allclose(numpy.ones(a.value.shape)+9,f_gpu(9)) assert numpy.allclose(numpy.ones(a.value.shape)+9,f_gpu(9))
assert numpy.allclose(f(5),f_gpu(5)) assert numpy.allclose(f(5),f_gpu(5))
def test_inc_subtensor():
shared = cuda.shared_constructor
#shared = tensor.shared
x,y = T.fmatrices('x','y')
xval = numpy.asarray([[1,2,3], [4,5,6], [7,8,9]],
dtype='float32')
yval = numpy.asarray([[10,10,10], [10,10,10], [10,10,10]],
dtype='float32')
expr = T.inc_subtensor(x[:,1:3], y[:,1:3])
f=theano.function([x,y], expr, mode=mode_with_gpu)
print f.maker.env.toposort()
assert sum([isinstance(node.op,cuda.GpuSubtensor) for node in f.maker.env.toposort() ])==1
assert sum([isinstance(node.op,cuda.GpuIncSubtensor) and node.op.set_instead_of_inc==False for node in f.maker.env.toposort() ])==1
assert numpy.allclose(f(xval,yval),[[1.,12.,13.], [4.,15.,16.], [7.,18.,19.]])
def test_set_subtensor():
shared = cuda.shared_constructor
#shared = tensor.shared
x,y = T.fmatrices('x','y')
xval = numpy.asarray([[1,2,3], [4,5,6], [7,8,9]],
dtype='float32')
yval = numpy.asarray([[10,10,10], [10,10,10], [10,10,10]],
dtype='float32')
expr = T.set_subtensor(x[:,1:3], y[:,1:3])
f=theano.function([x,y], expr, mode=mode_with_gpu)
print f.maker.env.toposort()
assert sum([isinstance(node.op,cuda.GpuSubtensor) for node in f.maker.env.toposort() ])==1
assert sum([isinstance(node.op,cuda.GpuIncSubtensor) and node.op.set_instead_of_inc==True for node in f.maker.env.toposort() ])==1
print f(xval,yval)
if __name__ == '__main__': if __name__ == '__main__':
test_gpujoin_twomatrices_joincolumns() test_gpujoin_twomatrices_joincolumns()
test_gpujoin_assert_cndas() test_gpujoin_assert_cndas()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论