提交 57da13ea authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix ifelse lifter when GraphToGPU don't encore the same type for corresponding inputs.

上级 c275a1af
......@@ -931,11 +931,20 @@ def local_gpua_lazy_ifelse(op, context_name, inputs, outputs):
return
c = inputs[0]
inps = []
for v in inputs[1:]:
if isinstance(v.type, tensor.TensorType) and move_to_gpu(v):
inps.append(as_gpuarray_variable(v, context_name))
falses = []
# ifelse need corresponding true/false inputs variables to be of the same type.
# But we can't rely on inputs to respect that, as GraphToGPU don't enforce that.
# So we need to take care of this here.
for v1, v2 in zip(inputs[1:1+op.n_outs], inputs[1+op.n_outs:]):
if ((isinstance(v1.type, tensor.TensorType) and move_to_gpu(v1)) or
isinstance(v1.type, GpuArrayType) or
isinstance(v2.type, GpuArrayType)):
inps.append(as_gpuarray_variable(v1, context_name))
falses.append(as_gpuarray_variable(v2, context_name))
else:
inps.append(v)
inps.append(v1)
falses.append(v2)
inps.extend(falses)
return IfElse(op.n_outs, gpu=True)(c, *inps, return_list=True)
......
......@@ -267,6 +267,16 @@ class test_gpu_ifelse(test_ifelse.test_ifelse):
mode=mode_with_gpu)
assert f(np.float32([1, 2, 3]), 0) == 6
def test_lifter_with_shared_var(self):
x = tensor.lscalar('x')
y = gpuarray_shared_constructor(np.asarray(1, dtype='float32'),
target=test_ctx_name)
z = tensor.constant(2.)
a = theano.ifelse.ifelse(x, y, z)
with theano.configparser.change_flags(on_opt_error='raise'):
f = theano.function([x], [a], mode=mode_with_gpu)
def test_print_op():
""" Test that print ops don't block gpu optimization"""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论