提交 9d34bee4 authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix an opt that could convert a AdvancedSubtensor to a GpuAdvancedIncsubtensor(check the Inc!)

This probably didn't happen due to the order of optimization. But as they are in a dictionnary we can't be sure it won't change with
上级 eeaed67a
...@@ -594,7 +594,7 @@ def local_gpu_advanced_incsubtensor1(node): ...@@ -594,7 +594,7 @@ def local_gpu_advanced_incsubtensor1(node):
gpu_from_host(y), *coords)] gpu_from_host(y), *coords)]
# Should not execute for GpuAdvancedIncSubtensor1 # Should not execute for GpuAdvancedIncSubtensor1
if node.op.__class__ is tensor.AdvancedSubtensor1 and node.inputs[0].dtype=="float32": if node.op.__class__ is tensor.AdvancedIncSubtensor1 and node.inputs[0].dtype=="float32":
x, y = node.inputs[0:2] x, y = node.inputs[0:2]
coords = node.inputs[2:] coords = node.inputs[2:]
go_gpu = False go_gpu = False
......
...@@ -806,6 +806,22 @@ class T_subtensor(theano.tensor.tests.test_basic.T_subtensor): ...@@ -806,6 +806,22 @@ class T_subtensor(theano.tensor.tests.test_basic.T_subtensor):
def __init__(self, name): def __init__(self, name):
return super(theano.tensor.tests.test_basic.T_subtensor, self).__init__(name) return super(theano.tensor.tests.test_basic.T_subtensor, self).__init__(name)
def test_advinc_subtensor1():
""" Test the second case in the opt local_gpu_advanced_incsubtensor1 """
shared = cuda.shared_constructor
#shared = tensor.shared
xval = numpy.asarray([[1,2,3], [4,5,6], [7,8,9]],
dtype='float32')
yval = numpy.asarray([[10,10,10], [10,10,10]],
dtype='float32')
x = shared(xval, name = 'x')
y = T.fmatrices('y')
expr = T.advanced_inc_subtensor1(x,y,[0,2])
f=theano.function([y], expr, mode=mode_with_gpu)
assert sum([isinstance(node.op,cuda.GpuAdvancedIncSubtensor1) for node in f.maker.env.toposort() ])==1
assert numpy.allclose(f(yval),[[11.,12.,13.], [4.,5.,6.], [17.,18.,19.]])
def test_inc_subtensor(): def test_inc_subtensor():
shared = cuda.shared_constructor shared = cuda.shared_constructor
#shared = tensor.shared #shared = tensor.shared
...@@ -832,7 +848,6 @@ def test_set_subtensor(): ...@@ -832,7 +848,6 @@ def test_set_subtensor():
dtype='float32') dtype='float32')
expr = T.set_subtensor(x[:,1:3], y[:,1:3]) expr = T.set_subtensor(x[:,1:3], y[:,1:3])
f=theano.function([x,y], expr, mode=mode_with_gpu) 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.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 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) print f(xval,yval)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论