提交 f75f6149 authored 作者: Frederic Bastien's avatar Frederic Bastien

added test for gpu gemm no inplace

上级 c5f98527
...@@ -79,6 +79,7 @@ def test_gemm(): ...@@ -79,6 +79,7 @@ def test_gemm():
c = tensor.fmatrix('c') c = tensor.fmatrix('c')
f = pfunc([b,c], [], updates=[(a, tensor.dot(a,b) + tensor.exp(c))], mode=mode_with_gpu) f = pfunc([b,c], [], updates=[(a, tensor.dot(a,b) + tensor.exp(c))], mode=mode_with_gpu)
assert any([node.op == tcn.blas.gpu_gemm_inplace for node in f.maker.env.toposort()])
a0 = a.value * 1.0 a0 = a.value * 1.0
print a0 print a0
...@@ -91,6 +92,30 @@ def test_gemm(): ...@@ -91,6 +92,30 @@ def test_gemm():
assert numpy.allclose(numpy.dot(a0, bval)+numpy.exp(cval), a.value) assert numpy.allclose(numpy.dot(a0, bval)+numpy.exp(cval), a.value)
def test_gemm_no_inplace():
a = tcn.shared_constructor(my_rand(4,4), 'a')
cval = my_rand(4,4)
c = tcn.shared_constructor(cval.copy(), 'c')
b = tcn.fmatrix('b')
b2 = tcn.fmatrix('b2')
f = pfunc([b,b2], [tensor.dot(a,b2) + c], updates=[(a, tensor.dot(a,b) + c)], mode=mode_with_gpu)
a0 = a.value * 1.0
#print a0
for i, node in enumerate(f.maker.env.toposort()):
print i, node
assert any([node.op == tcn.blas.gpu_gemm_no_inplace for node in f.maker.env.toposort()])
bval = my_rand(4,4)
bval2 = my_rand(4,4)
rval = f(bval,bval2)
#print a.value
assert numpy.allclose(numpy.dot(a0, bval)+cval, a.value)
assert numpy.allclose(numpy.dot(a0, bval2)+cval, rval)
if 0: if 0:
# This is commented out because it doesn't make sense... # This is commented out because it doesn't make sense...
# tcn.blas has no op called DownsampleFactorMax # tcn.blas has no op called DownsampleFactorMax
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论