提交 dd478b4e authored 作者: Frederic's avatar Frederic

Fix gpu lazy opt warning

上级 51368a6b
...@@ -497,12 +497,19 @@ def local_gpu_lazy_ifelse(node): ...@@ -497,12 +497,19 @@ def local_gpu_lazy_ifelse(node):
# Should not happen, but just in case # Should not happen, but just in case
if isinstance(c.type, CudaNdarrayType): if isinstance(c.type, CudaNdarrayType):
c = host_from_gpu(c) c = host_from_gpu(c)
if all([isinstance(o.type, CudaNdarrayType) or o.dtype != 'float32'
for o in outs]):
return
for i in range(len(outs)): for i in range(len(outs)):
if not isinstance(outs[i], CudaNdarrayType): if (not isinstance(outs[i].type, CudaNdarrayType) and
outs[i].dtype == 'float32'):
outs[i] = gpu_from_host(outs[i]) outs[i] = gpu_from_host(outs[i])
return [host_from_gpu(out) for out in outs = gpu_ifelse(c, *outs, return_list=True)
gpu_ifelse.make_node(c, *outs).outputs] for i in range(len(outs)):
if isinstance(outs[i].type, CudaNdarrayType):
outs[i] = host_from_gpu(outs[i])
return outs
if isinstance(node.op, GpuFromHost): if isinstance(node.op, GpuFromHost):
host_input = node.inputs[0] host_input = node.inputs[0]
...@@ -522,11 +529,14 @@ def local_gpu_lazy_ifelse(node): ...@@ -522,11 +529,14 @@ def local_gpu_lazy_ifelse(node):
# Should not happen, but just in case # Should not happen, but just in case
if isinstance(c.type, CudaNdarrayType): if isinstance(c.type, CudaNdarrayType):
c = host_from_gpu(c) c = host_from_gpu(c)
if all([isinstance(o.type, CudaNdarrayType) or o.dtype != 'float32'
for o in outs]):
return
for i in range(len(outs)): for i in range(len(outs)):
if not isinstance(outs[i], CudaNdarrayType): if (not isinstance(outs[i].type, CudaNdarrayType) and
outs[i].dtype == 'float32'):
outs[i] = gpu_from_host(outs[i]) outs[i] = gpu_from_host(outs[i])
outs = gpu_ifelse.make_node(c, *outs).outputs outs = gpu_ifelse.make_node(c, *outs).outputs
return outs return outs
......
...@@ -51,6 +51,33 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -51,6 +51,33 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
assert numpy.allclose(vx, f(1, vx, vy)) assert numpy.allclose(vx, f(1, vx, vy))
assert numpy.allclose(vy, f(0, vx, vy)) assert numpy.allclose(vy, f(0, vx, vy))
def test_mixed_dtype(self):
x1 = tensor.vector('x1', dtype='int32')
x2 = tensor.vector('x2', dtype=self.dtype)
y1 = tensor.vector('y1', dtype='int32')
y2 = tensor.vector('y2', dtype=self.dtype)
c = tensor.iscalar('c')
f = theano.function([c, x1, x2, y1, y2],
ifelse(c, (x1, x2), (y1, y2)), mode=self.mode)
self.assertFunctionContains1(f, self.get_ifelse(2))
rng = numpy.random.RandomState(utt.fetch_seed())
xlen = rng.randint(200)
ylen = rng.randint(200)
vx1 = numpy.asarray(rng.uniform(size=(xlen,))*3, 'int32')
vx2 = numpy.asarray(rng.uniform(size=(xlen,)), self.dtype)
vy1 = numpy.asarray(rng.uniform(size=(ylen,))*3, 'int32')
vy2 = numpy.asarray(rng.uniform(size=(ylen,)), self.dtype)
o1, o2 = f(1, vx1, vx2, vy1, vy2)
assert numpy.allclose(vx1, o1)
assert numpy.allclose(vx2, o2)
o1, o2 = f(0, vx1, vx2, vy1, vy2)
assert numpy.allclose(vy1, o1)
assert numpy.allclose(vy2, o2)
def test_lazy_if_on_generics(self): def test_lazy_if_on_generics(self):
x = theano.generic() x = theano.generic()
y = theano.generic() y = theano.generic()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论