提交 8e7abaf4 authored 作者: Frederic Bastien's avatar Frederic Bastien

Move the test to the GPU directory and mimic device=cuda in another test…

Move the test to the GPU directory and mimic device=cuda in another test following the current change.
上级 79582f25
......@@ -310,8 +310,9 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
def local_gpua_mrg_graph(op, context_name, inputs, outputs):
if (type(op) == mrg_uniform and
isinstance(inputs[0].type, GpuArrayType) and
not isinstance(inputs[0].owner.op, GpuFromHost)
):
(inputs[0].owner is None or
not isinstance(inputs[0].owner.op,
GpuFromHost))):
outs = GPUA_mrg_uniform.new(inputs[0],
op.output_type.ndim,
op.output_type.dtype,
......
......@@ -12,6 +12,7 @@ from theano.sandbox.tests.test_rng_mrg import test_f16_nonzero as cpu_f16_nonzer
from theano.tests import unittest_tools as utt
from .config import mode_with_gpu as mode
from .config import test_ctx_name
from ..type import gpuarray_shared_constructor
from ..rng_mrg import GPUA_mrg_uniform
......@@ -165,4 +166,25 @@ def test_validate_input_types_gpuarray_backend():
def test_f16_nonzero():
try:
# To have theano.shared(x
theano.compile.shared_constructor(gpuarray_shared_constructor)
cpu_f16_nonzero(mode=mode, op_to_check=GPUA_mrg_uniform)
finally:
theano.compile.shared_constructor(gpuarray_shared_constructor,
remove=True)
def test_cpu_target_with_shared_variable():
srng = MRG_RandomStreams()
s = np.random.rand(2, 3).astype('float32')
x = gpuarray_shared_constructor(s, name='x')
y = srng.uniform(x.shape, target='cpu')
y.name = 'y'
z = (x * y).sum()
z.name = 'z'
fz = theano.function([], z, mode=mode)
nodes = fz.maker.fgraph.toposort()
assert not any([isinstance(node.op, GPUA_mrg_uniform) for node in nodes])
......@@ -11,7 +11,7 @@ from six.moves import xrange
import theano
from theano import change_flags, config, tensor
from theano.sandbox import rng_mrg
from theano.sandbox.rng_mrg import MRG_RandomStreams, mrg_uniform
from theano.sandbox.rng_mrg import MRG_RandomStreams
from theano.tests import unittest_tools as utt
from theano.tests.unittest_tools import attr
......@@ -740,7 +740,8 @@ def test_f16_nonzero(mode=None, op_to_check=rng_mrg.mrg_uniform):
m = srng.uniform(size=(1000, 1000), dtype='float16')
assert m.dtype == 'float16', m.type
f = theano.function([], m, mode=mode)
assert any(isinstance(n.op, op_to_check) for n in f.maker.fgraph.apply_nodes)
assert any(isinstance(n.op, op_to_check)
for n in f.maker.fgraph.apply_nodes)
m_val = f()
assert np.all((0 < m_val) & (m_val < 1))
......@@ -760,21 +761,6 @@ def test_target_parameter():
basic_target_parameter_test(srng.multinomial_wo_replacement(pvals=pvals.astype('float32'), target='cpu'))
def test_cpu_target_with_shared_variable():
srng = MRG_RandomStreams()
x = theano.shared(np.random.rand(2,3).astype('float32'), name='x')
y = srng.uniform(x.shape, target='cpu')
y.name = 'y'
z = (x * y).sum()
z.name = 'z'
fz = theano.function([], z)
nodes = fz.maker.fgraph.toposort()
assert any([isinstance(node.op, mrg_uniform) for node in nodes])
if __name__ == "__main__":
rng = MRG_RandomStreams(np.random.randint(2147462579))
print(theano.__file__)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论