提交 a14dcfad authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Move test of optimization into test_opt.py

上级 42ffa21a
......@@ -474,48 +474,3 @@ def test_Gpujoin_inplace():
f = theano.function([s], theano.Out(c, borrow=True))
assert x.get_value(borrow=True, return_internal_type=True) is f(0)
assert np.allclose(f(0), [3, 4, 5])
def test_many_arg_elemwise():
# this test checks whether the + and * elemwise ops can handle
# extremely large numbers of arguments on gpu
rng = np.random.RandomState([1, 2, 3])
for num_args in [75]:
for op_to_test in [theano.tensor.add, theano.tensor.mul]:
for nb_dim in [2, 3, 4, 5, 7]:
shapes = [rng.randint(1, 5) for i in range(nb_dim)]
args = [np.cast['float32'](rng.randn(*shapes))
for arg in range(0, num_args)]
symb_args = [theano.tensor.TensorType('float32',
(False,) * nb_dim)()
for arg in range(0, num_args)]
outputs = []
for mode in [mode_with_gpu, mode_without_gpu]:
# test the optijmization local_gpu_elemwise_0
f = theano.function(
symb_args, op_to_test(*symb_args),
mode=mode.excluding("local_gpu_elemwise_1"))
outputs.append(f(*args))
# assert that the test was done on the gpu.
if mode is mode_with_gpu:
assert any([isinstance(node.op, GpuElemwise)
for node in f.maker.fgraph.apply_nodes])
# test the optijmization local_gpu_elemwise_1
f = theano.function(
symb_args,
GpuFromHost(test_ctx_name)(op_to_test(*symb_args)),
mode=mode.excluding("local_gpu_elemwise_0"))
out = f(*args)
# assert that the test was done on the gpu.
if mode is mode_with_gpu:
assert any([isinstance(node.op, GpuElemwise)
for node in f.maker.fgraph.apply_nodes])
utt.assert_allclose(out, outputs[-1])
results_gpu, results_cpu = outputs
utt.assert_allclose(results_gpu, results_cpu)
......@@ -18,7 +18,7 @@ from ..type import GpuArrayType, get_context
from pygpu import ndgpuarray as gpuarray
# This is acutally a test for GpuElemwise
# This is actually a test for GpuElemwise
class test_gpu_Broadcast(test_elemwise.test_Broadcast):
cop = GpuElemwise
ctype = GpuArrayType
......
......@@ -19,7 +19,7 @@ from ..elemwise import GpuCAReduceCuda, GpuCAReduceCPY, GpuElemwise
from ..subtensor import GpuSubtensor
from ..linalg import GpuCusolverSolve, cusolver_available
from .config import mode_with_gpu, test_ctx_name, SkipTest
from .config import mode_with_gpu, mode_without_gpu, test_ctx_name, SkipTest
def test_local_assert():
......@@ -448,6 +448,51 @@ def test_local_gpu_elemwise():
utt.assert_allclose(out[1], a_v[::2] * c_v[::2])
def test_many_arg_elemwise():
# this test checks whether the + and * elemwise ops can handle
# extremely large numbers of arguments on gpu
rng = np.random.RandomState([1, 2, 3])
for num_args in [75]:
for op_to_test in [theano.tensor.add, theano.tensor.mul]:
for nb_dim in [2, 3, 4, 5, 7]:
shapes = [rng.randint(1, 5) for i in range(nb_dim)]
args = [np.cast['float32'](rng.randn(*shapes))
for arg in range(0, num_args)]
symb_args = [theano.tensor.TensorType('float32',
(False,) * nb_dim)()
for arg in range(0, num_args)]
outputs = []
for mode in [mode_with_gpu, mode_without_gpu]:
# test the optijmization local_gpu_elemwise_0
f = theano.function(
symb_args, op_to_test(*symb_args),
mode=mode.excluding("local_gpu_elemwise_1"))
outputs.append(f(*args))
# assert that the test was done on the gpu.
if mode is mode_with_gpu:
assert any([isinstance(node.op, GpuElemwise)
for node in f.maker.fgraph.apply_nodes])
# test the optijmization local_gpu_elemwise_1
f = theano.function(
symb_args,
GpuFromHost(test_ctx_name)(op_to_test(*symb_args)),
mode=mode.excluding("local_gpu_elemwise_0"))
out = f(*args)
# assert that the test was done on the gpu.
if mode is mode_with_gpu:
assert any([isinstance(node.op, GpuElemwise)
for node in f.maker.fgraph.apply_nodes])
utt.assert_allclose(out, outputs[-1])
results_gpu, results_cpu = outputs
utt.assert_allclose(results_gpu, results_cpu)
def test_local_lift_abstractconv_gpu_shape():
prev = theano.config.on_opt_error
try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论