提交 74464805 authored 作者: abergeron's avatar abergeron

Merge pull request #2957 from nouiz/tests

Fix tests errors in the buildbot
...@@ -99,6 +99,8 @@ gpu_dot22 = GpuDot22() ...@@ -99,6 +99,8 @@ gpu_dot22 = GpuDot22()
class GpuDot22Scalar(GpuOp): class GpuDot22Scalar(GpuOp):
""" """
Implement dot(2d, 2d) * scalar on the gpu. Implement dot(2d, 2d) * scalar on the gpu.
:note: Not used anymore. Keep to allow unpickle of old graph.
""" """
def __str__(self): def __str__(self):
return 'GpuDot22Scalar' return 'GpuDot22Scalar'
......
...@@ -2296,10 +2296,12 @@ def gpuScanOptimization(node): ...@@ -2296,10 +2296,12 @@ def gpuScanOptimization(node):
@local_optimizer([tensor.AllocEmpty, gpu_from_host]) @local_optimizer([tensor.AllocEmpty, gpu_from_host])
def local_gpu_allocempty(node): def local_gpu_allocempty(node):
if (isinstance(node.op, tensor.AllocEmpty) and if (isinstance(node.op, tensor.AllocEmpty) and
node.op.dtype=="float32"): node.op.dtype == "float32"):
return [host_from_gpu(GpuAllocEmpty()(*node.inputs))] ret = host_from_gpu(GpuAllocEmpty()(*node.inputs))
# Keep the check that we don't care about the value.
ret.tag.values_eq_approx = node.outputs[0].tag.values_eq_approx
return [ret]
return False return False
optdb.register('gpu_scanOp_make_inplace', optdb.register('gpu_scanOp_make_inplace',
scan_opt.ScanInplaceOptimizer(typeConstructor=typeConstructor, scan_opt.ScanInplaceOptimizer(typeConstructor=typeConstructor,
......
...@@ -90,15 +90,23 @@ def test_dot22scalar(): ...@@ -90,15 +90,23 @@ def test_dot22scalar():
[a, b], [a, b],
tensor.dot(a, b) * numpy.asarray(4, 'float32')) tensor.dot(a, b) * numpy.asarray(4, 'float32'))
t = f.maker.fgraph.toposort() t = f.maker.fgraph.toposort()
assert len(t) == 4, t assert any([isinstance(n.op, tcn.blas.GpuGemm) for n in t])
assert isinstance(t[0].op, tcn.GpuFromHost) assert any([isinstance(n.op, tcn.basic_ops.GpuAllocEmpty)
assert isinstance(t[1].op, tcn.GpuFromHost) for n in t])
assert isinstance(t[2].op, tcn.blas.GpuDot22Scalar)
assert isinstance(t[3].op, tcn.HostFromGpu)
assert numpy.allclose(f(av, bv), f2(av, bv)) assert numpy.allclose(f(av, bv), f2(av, bv))
f = theano.function([a, b, scalar], tensor.dot(a, b) * scalar, f = theano.function([a, b, scalar], tensor.dot(a, b) * scalar,
mode=mode_with_gpu) mode=mode_with_gpu)
f2 = theano.function([a, b, scalar], tensor.dot(a, b) * scalar)
t = f.maker.fgraph.toposort()
assert any([isinstance(n.op, tcn.blas.GpuGemm) for n in t])
assert any([isinstance(n.op, tcn.basic_ops.GpuAllocEmpty)
for n in t])
assert numpy.allclose(f(av, bv, 0.5), f2(av, bv, 0.5))
f = theano.function([a, b, scalar],
tensor.blas._dot22scalar(a, b, scalar),
mode=mode_with_gpu)
f2 = theano.function([a, b, scalar], tensor.dot(a, b) * scalar) f2 = theano.function([a, b, scalar], tensor.dot(a, b) * scalar)
t = f.maker.fgraph.toposort() t = f.maker.fgraph.toposort()
assert len(t) == 4 assert len(t) == 4
...@@ -107,7 +115,6 @@ def test_dot22scalar(): ...@@ -107,7 +115,6 @@ def test_dot22scalar():
assert isinstance(t[2].op, tcn.blas.GpuDot22Scalar) assert isinstance(t[2].op, tcn.blas.GpuDot22Scalar)
assert isinstance(t[3].op, tcn.HostFromGpu) assert isinstance(t[3].op, tcn.HostFromGpu)
assert numpy.allclose(f(av, bv, 0.5), f2(av, bv, 0.5)) assert numpy.allclose(f(av, bv, 0.5), f2(av, bv, 0.5))
cmp((3, 4), (4, 5)) cmp((3, 4), (4, 5))
cmp((0, 4), (4, 5)) cmp((0, 4), (4, 5))
cmp((3, 4), (4, 0)) cmp((3, 4), (4, 0))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论