提交 66bb1edf authored 作者: Frederic's avatar Frederic

[CRASH] during opt with Eye when k!=0

上级 1b81a00e
...@@ -2233,11 +2233,14 @@ def local_gpu_eye(node): ...@@ -2233,11 +2233,14 @@ def local_gpu_eye(node):
if (host_input.owner and if (host_input.owner and
isinstance(host_input.owner.op, tensor.Eye) and isinstance(host_input.owner.op, tensor.Eye) and
host_input.owner.op.dtype == "float32"): host_input.owner.op.dtype == "float32"):
if tensor.extract_constant(host_input.owner.inputs[2]) != 0:
return
return [gpu_eye(*host_input.owner.inputs)] return [gpu_eye(*host_input.owner.inputs)]
if isinstance(node.op, tensor.Eye) and node.op.dtype == "float32": if isinstance(node.op, tensor.Eye) and node.op.dtype == "float32":
if any([(i.owner and isinstance(i.owner.op, HostFromGpu)) if any([(i.owner and isinstance(i.owner.op, HostFromGpu))
for i in node.inputs]): for i in node.inputs]):
if tensor.extract_constant(node.inputs[2]) != 0:
return
return [host_from_gpu(gpu_eye(*node.inputs))] return [host_from_gpu(gpu_eye(*node.inputs))]
return False return False
......
...@@ -1224,7 +1224,7 @@ def test_shared_cudandarray(): ...@@ -1224,7 +1224,7 @@ def test_shared_cudandarray():
def test_gpueye(): def test_gpueye():
def check(dtype, N, M_=None): def check(dtype, N, M_=None, K=0):
# Theano does not accept None as a tensor. # Theano does not accept None as a tensor.
# So we must use a real value. # So we must use a real value.
M = M_ M = M_
...@@ -1234,22 +1234,24 @@ def test_gpueye(): ...@@ -1234,22 +1234,24 @@ def test_gpueye():
M = N M = N
N_symb = T.iscalar() N_symb = T.iscalar()
M_symb = T.iscalar() M_symb = T.iscalar()
k_symb = numpy.asarray(0) k_symb = numpy.asarray(K)
out = T.eye(N_symb, M_symb, k_symb, dtype=dtype) out = T.eye(N_symb, M_symb, k_symb, dtype=dtype)
f = theano.function([N_symb, M_symb], f = theano.function([N_symb, M_symb],
B.as_cuda_ndarray_variable(out), B.as_cuda_ndarray_variable(out),
mode=mode_with_gpu) mode=mode_with_gpu)
result = numpy.asarray(f(N, M)) result = numpy.asarray(f(N, M))
utt.assert_allclose(result, numpy.eye(N, M_, dtype=dtype)) utt.assert_allclose(result, numpy.eye(N, M_, K, dtype=dtype))
assert result.dtype == numpy.dtype(dtype) assert result.dtype == numpy.dtype(dtype)
assert any([isinstance(node.op, B.GpuEye) if K == 0:
for node in f.maker.fgraph.toposort()]) assert any([isinstance(node.op, B.GpuEye)
for node in f.maker.fgraph.toposort()])
for dtype in ['float32']: for dtype in ['float32']:
yield check, dtype, 3 yield check, dtype, 3
# M != N, k = 0 # M != N, k = 0
yield check, dtype, 3, 5 yield check, dtype, 3, 5
yield check, dtype, 5, 3 yield check, dtype, 5, 3
yield check, dtype, 5, 3, 1
class test_size(unittest.TestCase): class test_size(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论