提交 46f56a7d authored 作者: Frederic's avatar Frederic

Run cpu Join test on gpu and transform cpu join to gpu join when input are constant.

上级 724df23d
...@@ -881,8 +881,8 @@ def local_gpu_join(node): ...@@ -881,8 +881,8 @@ def local_gpu_join(node):
#print "OPT: axis_and_tensors=", axis_and_tensors #print "OPT: axis_and_tensors=", axis_and_tensors
matches = [not t.owner is None and t.owner.op == host_from_gpu for t in axis_and_tensors[1:]] matches = [(not t.owner is None and t.owner.op == host_from_gpu) or
isinstance(t, gof.Constant) for t in axis_and_tensors[1:]]
#print "OPT: matches =", matches #print "OPT: matches =", matches
# if all input tensors are host_from_gpu'ified # if all input tensors are host_from_gpu'ified
......
...@@ -792,6 +792,20 @@ def test_gpualloc_output_to_gpu(): ...@@ -792,6 +792,20 @@ def test_gpualloc_output_to_gpu():
assert numpy.allclose(f(5),f_gpu(5)) assert numpy.allclose(f(5),f_gpu(5))
import theano.tensor.tests.test_basic import theano.tensor.tests.test_basic
class T_Join_and_Split(theano.tensor.tests.test_basic.T_Join_and_Split):
def setUp(self):
utt.seed_rng()
self.mode = mode_with_gpu.excluding('constant_folding')
self.join_op = cuda.GpuJoin
self.split_op = tensor.Split
# No Make vector on the gpu, Join used instead
self.make_vector_op = cuda.GpuJoin
self.floatX = "float32"
# In FAST_COMPILE mode, we force the FAST_RUN mode for optimization.
self.hide_error = not theano.config.mode in ['DebugMode', 'DEBUG_MODE']
self.shared = cuda.shared_constructor
# This is to don't duplicate test. # This is to don't duplicate test.
class T_subtensor(theano.tensor.tests.test_basic.T_subtensor): class T_subtensor(theano.tensor.tests.test_basic.T_subtensor):
shared=staticmethod(cuda.shared_constructor) shared=staticmethod(cuda.shared_constructor)
......
...@@ -2539,11 +2539,11 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2539,11 +2539,11 @@ class T_Join_and_Split(unittest.TestCase):
self.mode = theano.compile.get_default_mode().excluding('constant_folding') self.mode = theano.compile.get_default_mode().excluding('constant_folding')
self.join_op = Join self.join_op = Join
self.split_op = Split self.split_op = Split
self.make_vector_op = opt.MakeVector
self.floatX = config.floatX self.floatX = config.floatX
self.hide_error = not theano.config.mode in ['DebugMode', 'DEBUG_MODE', 'FAST_COMPILE'] self.hide_error = not theano.config.mode in ['DebugMode', 'DEBUG_MODE', 'FAST_COMPILE']
self.shared = shared self.shared = shared
def eval_outputs_and_check_join(self, outputs): def eval_outputs_and_check_join(self, outputs):
f = theano.function([], outputs, self.mode) f = theano.function([], outputs, self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
...@@ -2553,10 +2553,13 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2553,10 +2553,13 @@ class T_Join_and_Split(unittest.TestCase):
return variables[0] return variables[0]
return variables return variables
def eval_outputs_and_check_vector(self, outputs): def eval_outputs_and_check_vector(self, outputs,
make_vector_op = None):
if make_vector_op is None:
make_vector_op = self.make_vector_op
f = theano.function([], outputs, self.mode) f = theano.function([], outputs, self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
assert [True for node in topo if isinstance(node.op, opt.MakeVector)] assert [True for node in topo if isinstance(node.op, make_vector_op)]
variables = f() variables = f()
if isinstance(variables,(tuple,list)) and len(variables) == 1: if isinstance(variables,(tuple,list)) and len(variables) == 1:
return variables[0] return variables[0]
...@@ -2572,14 +2575,15 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2572,14 +2575,15 @@ class T_Join_and_Split(unittest.TestCase):
self.fail() self.fail()
def test_stack_mixed_type_constants(self): def test_stack_mixed_type_constants(self):
# tested only on cpu as gpu support only float32
a = as_tensor_variable(1) a = as_tensor_variable(1)
b = as_tensor_variable(2.0) b = as_tensor_variable(2.0)
c = shared(numpy.asarray(3.0)) c = shared(numpy.asarray(3.0).astype(self.floatX))
s = stack(a, b, c) s = stack(a, b, c)
want = numpy.array([1, 2, 3]) want = numpy.array([1, 2, 3])
out = self.eval_outputs_and_check_vector([s]) out = self.eval_outputs_and_check_vector([s], opt.MakeVector)
self.assertTrue((out == want).all()) self.assertTrue((out == want).all())
def test_stack_scalar(self): def test_stack_scalar(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论