提交 df97d8e6 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

More test fixes

上级 00b55dc2
...@@ -28,9 +28,9 @@ except ImportError: ...@@ -28,9 +28,9 @@ except ImportError:
try: try:
import skcuda import skcuda
from skcuda import fft from skcuda import fft
scikits_cuda_available = True skcuda_available = True
except (ImportError, Exception): except (ImportError, Exception):
scikits_cuda_available = False skcuda_available = False
class CuRFFTOp(Op): class CuRFFTOp(Op):
...@@ -51,7 +51,7 @@ class CuRFFTOp(Op): ...@@ -51,7 +51,7 @@ class CuRFFTOp(Op):
# the shape given to the plan, so padding will have to be done in the op. # the shape given to the plan, so padding will have to be done in the op.
# The effect of padding on gradients has yet to be investigated. # The effect of padding on gradients has yet to be investigated.
if not scikits_cuda_available: if not skcuda_available:
raise RuntimeError("skcuda is needed for CuFFTOp") raise RuntimeError("skcuda is needed for CuFFTOp")
if not pygpu_available: if not pygpu_available:
...@@ -175,7 +175,7 @@ class CuIRFFTOp(Op): ...@@ -175,7 +175,7 @@ class CuIRFFTOp(Op):
# the shape given to the plan, so padding will have to be done in the op. # the shape given to the plan, so padding will have to be done in the op.
# The effect of padding on gradients has yet to be investigated. # The effect of padding on gradients has yet to be investigated.
if not scikits_cuda_available: if not skcuda_available:
raise RuntimeError("skcuda is needed for CuIFFTOp") raise RuntimeError("skcuda is needed for CuIFFTOp")
if not pygpu_available: if not pygpu_available:
...@@ -370,7 +370,7 @@ def _unitary(norm): ...@@ -370,7 +370,7 @@ def _unitary(norm):
"'no norm'" % norm) "'no norm'" % norm)
return norm return norm
if scikits_cuda_available: if skcuda_available:
@register_opt('fast_compile') @register_opt('fast_compile')
@op_lifter([theano.tensor.fft.RFFTOp]) @op_lifter([theano.tensor.fft.RFFTOp])
@register_opt2([theano.tensor.fft.RFFTOp], 'fast_compile') @register_opt2([theano.tensor.fft.RFFTOp], 'fast_compile')
......
...@@ -9,22 +9,36 @@ from __future__ import absolute_import, print_function, division ...@@ -9,22 +9,36 @@ from __future__ import absolute_import, print_function, division
import numpy import numpy
from theano import Apply, tensor
from theano.gof import local_optimizer from theano.gof import local_optimizer
from theano.sandbox.rng_mrg import mrg_uniform_base, mrg_uniform from theano.sandbox.rng_mrg import mrg_uniform_base, mrg_uniform
from theano.tensor import as_tensor_variable, get_vector_length from theano.tensor import as_tensor_variable, get_vector_length
from theano.gpuarray.basic_ops import GpuKernelBase, Kernel, infer_context_name from .basic_ops import (GpuKernelBase, Kernel, infer_context_name,
from theano.gpuarray.type import GpuArrayType host_from_gpu, as_gpuarray_variable)
from theano.gpuarray.fp16_help import write_w from .type import GpuArrayType
from theano.gpuarray.opt import (register_opt as register_gpua, from .fp16_help import write_w
register_opt2, from .opt import register_opt, register_opt2
host_from_gpu as host_from_gpua)
class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base): class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
# GpuArray version # GpuArray version
_f16_ok = True _f16_ok = True
def make_node(self, rstate, size):
# error checking slightly redundant here, since
# this op should not be called directly.
#
# call through MRG_RandomStreams instead.
broad = []
for i in range(self.output_type.ndim):
broad.append(tensor.extract_constant(size[i]) == 1)
output_type = self.output_type.clone(broadcastable=broad)()
rstate = as_gpuarray_variable(rstate, infer_context_name(rstate))
return Apply(self,
[rstate, size],
[rstate.type(), output_type])
def get_params(self, node): def get_params(self, node):
return node.inputs[0].type.context return node.inputs[0].type.context
...@@ -283,10 +297,10 @@ def local_gpua_mrg_graph(op, context_name, inputs, outputs): ...@@ -283,10 +297,10 @@ def local_gpua_mrg_graph(op, context_name, inputs, outputs):
op.output_type.ndim, op.output_type.ndim,
op.output_type.dtype, op.output_type.dtype,
inputs[1]) inputs[1])
return [outs[0], host_from_gpua(outs[1])] return [outs[0], host_from_gpu(outs[1])]
@register_gpua('fast_compile') @register_opt('fast_compile')
@local_optimizer([mrg_uniform]) @local_optimizer([mrg_uniform])
def local_gpua_mrg(node): def local_gpua_mrg(node):
context_name = infer_context_name(*node.inputs) context_name = infer_context_name(*node.inputs)
......
...@@ -12,11 +12,11 @@ from .config import mode_with_gpu ...@@ -12,11 +12,11 @@ from .config import mode_with_gpu
# Skip tests if pygpu is not available. # Skip tests if pygpu is not available.
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from theano.gpuarray.fft import pygpu_available, scikits_cuda_available, pycuda_available from theano.gpuarray.fft import pygpu_available, skcuda_available, pycuda_available
if not pygpu_available: # noqa if not pygpu_available: # noqa
raise SkipTest('Optional package pygpu not available') raise SkipTest('Optional package pygpu not available')
if not scikits_cuda_available: # noqa if not skcuda_available: # noqa
raise SkipTest('Optional package scikits.cuda not available') raise SkipTest('Optional package scikit-cuda not available')
if not pycuda_available: # noqa if not pycuda_available: # noqa
raise SkipTest('Optional package pycuda not available') raise SkipTest('Optional package pycuda not available')
......
...@@ -10,8 +10,9 @@ from theano.sandbox.rng_mrg import MRG_RandomStreams ...@@ -10,8 +10,9 @@ from theano.sandbox.rng_mrg import MRG_RandomStreams
from theano.sandbox.tests.test_rng_mrg import java_samples, rng_mrg_overflow from theano.sandbox.tests.test_rng_mrg import java_samples, rng_mrg_overflow
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.gpuarray.tests.config import mode_with_gpu as mode from .config import mode_with_gpu as mode
from theano.gpuarray.type import gpuarray_shared_constructor from ..type import gpuarray_shared_constructor
from ..rng_mrg import GPUA_mrg_uniform
utt.seed_rng() utt.seed_rng()
...@@ -36,10 +37,10 @@ def test_consistency_GPUA_serial(): ...@@ -36,10 +37,10 @@ def test_consistency_GPUA_serial():
# Transfer to device # Transfer to device
rstate = gpuarray_shared_constructor(substream_rstate) rstate = gpuarray_shared_constructor(substream_rstate)
new_rstate, sample = rng_mrg.GPUA_mrg_uniform.new(rstate, new_rstate, sample = GPUA_mrg_uniform.new(rstate,
ndim=None, ndim=None,
dtype='float32', dtype='float32',
size=(1,)) size=(1,))
rstate.default_update = new_rstate rstate.default_update = new_rstate
# Not really necessary, just mimicking # Not really necessary, just mimicking
...@@ -84,9 +85,9 @@ def test_consistency_GPUA_parallel(): ...@@ -84,9 +85,9 @@ def test_consistency_GPUA_parallel():
rstate = np.asarray(rstate) rstate = np.asarray(rstate)
rstate = gpuarray_shared_constructor(rstate) rstate = gpuarray_shared_constructor(rstate)
new_rstate, sample = rng_mrg.GPUA_mrg_uniform.new(rstate, ndim=None, new_rstate, sample = GPUA_mrg_uniform.new(rstate, ndim=None,
dtype='float32', dtype='float32',
size=(n_substreams,)) size=(n_substreams,))
rstate.default_update = new_rstate rstate.default_update = new_rstate
# Not really necessary, just mimicking # Not really necessary, just mimicking
...@@ -125,9 +126,9 @@ def test_GPUA_full_fill(): ...@@ -125,9 +126,9 @@ def test_GPUA_full_fill():
f_cpu = theano.function([], uni) f_cpu = theano.function([], uni)
rstate_gpu = gpuarray_shared_constructor(R.state_updates[-1][0].get_value()) rstate_gpu = gpuarray_shared_constructor(R.state_updates[-1][0].get_value())
new_rstate, sample = rng_mrg.GPUA_mrg_uniform.new(rstate_gpu, ndim=None, new_rstate, sample = GPUA_mrg_uniform.new(rstate_gpu, ndim=None,
dtype='float32', dtype='float32',
size=size) size=size)
rstate_gpu.default_update = new_rstate rstate_gpu.default_update = new_rstate
f_gpu = theano.function([], sample) f_gpu = theano.function([], sample)
...@@ -146,7 +147,7 @@ def test_overflow_gpu_new_backend(): ...@@ -146,7 +147,7 @@ def test_overflow_gpu_new_backend():
rstate.append(rng_mrg.ff_2p72(rstate[-1])) rstate.append(rng_mrg.ff_2p72(rstate[-1]))
rstate = np.asarray(rstate) rstate = np.asarray(rstate)
rstate = gpuarray_shared_constructor(rstate) rstate = gpuarray_shared_constructor(rstate)
fct = functools.partial(rng_mrg.GPUA_mrg_uniform.new, rstate, fct = functools.partial(GPUA_mrg_uniform.new, rstate,
ndim=None, dtype='float32') ndim=None, dtype='float32')
# should raise error as the size overflows # should raise error as the size overflows
sizes = [(2**31, ), (2**32, ), (2**15, 2**16,), (2, 2**15, 2**15)] sizes = [(2**31, ), (2**32, ), (2**15, 2**16,), (2, 2**15, 2**15)]
......
...@@ -209,7 +209,7 @@ class PersistentGpuArrayID(PersistentNdarrayID): ...@@ -209,7 +209,7 @@ class PersistentGpuArrayID(PersistentNdarrayID):
isinstance(obj, pygpu.gpuarray.GpuArray)): isinstance(obj, pygpu.gpuarray.GpuArray)):
if id(obj) not in self.seen: if id(obj) not in self.seen:
def write_array(f): def write_array(f):
pickle.dump(f, _name_for_ctx(obj.context), 2) pickle.dump(_name_for_ctx(obj.context), f, 2)
np.lib.format.write_array(f, np.asarray(obj)) np.lib.format.write_array(f, np.asarray(obj))
name = self._resolve_name(obj) name = self._resolve_name(obj)
zipadd(write_array, self.zip_file, name) zipadd(write_array, self.zip_file, name)
...@@ -285,6 +285,7 @@ class PersistentNdarrayLoad(object): ...@@ -285,6 +285,7 @@ class PersistentNdarrayLoad(object):
def __call__(self, persid): def __call__(self, persid):
from theano.gpuarray.type import get_context from theano.gpuarray.type import get_context
from theano.gpuarray import pygpu
array_type, name = persid.split('.') array_type, name = persid.split('.')
if name in self.cache: if name in self.cache:
......
...@@ -72,7 +72,7 @@ def test_consistency_randomstreams(): ...@@ -72,7 +72,7 @@ def test_consistency_randomstreams():
stream_samples.append(s) stream_samples.append(s)
stream_samples = np.array(stream_samples) stream_samples = np.array(stream_samples)
stream_samples = stream_samples.T.flatten() stream_samples = stream_samples.T.flatten()
samples.append(stream_samples) samples.append(stream_samples)
samples = np.array(samples).flatten() samples = np.array(samples).flatten()
assert(np.allclose(samples, java_samples)) assert(np.allclose(samples, java_samples))
...@@ -665,7 +665,6 @@ def rng_mrg_overflow(sizes, fct, mode, should_raise_error): ...@@ -665,7 +665,6 @@ def rng_mrg_overflow(sizes, fct, mode, should_raise_error):
for size in sizes: for size in sizes:
y = fct(size=size) y = fct(size=size)
f = theano.function([], y, mode=mode) f = theano.function([], y, mode=mode)
theano.printing.debugprint(f)
if should_raise_error: if should_raise_error:
assert_raises(ValueError, f) assert_raises(ValueError, f)
else: else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论