def test_gpualloc_output_to_gpu():
a_val = numpy.asarray(numpy.random.rand(4, 5), dtype='float32')
a = tcn.shared_constructor(a_val)
b = T.fscalar()
f = theano.function([b], T.ones_like(a) + b, mode=mode_without_gpu)
f_gpu = theano.function([b], B.gpu_from_host(T.ones_like(a)) + b,
mode=mode_with_gpu)
f(2)
f_gpu(2)
assert sum([node.op == T.alloc for node in f.maker.fgraph.toposort()]) == 1
assert sum([node.op == B.gpu_alloc
for node in f_gpu.maker.fgraph.toposort()]) == 1
assert numpy.allclose(numpy.ones(a.get_value(borrow=True).shape) + 9,
f_gpu(9))
assert numpy.allclose(f(5), f_gpu(5))
评论列表
文章目录