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

More test fixes

上级 00b55dc2
......@@ -28,9 +28,9 @@ except ImportError:
try:
import skcuda
from skcuda import fft
scikits_cuda_available = True
skcuda_available = True
except (ImportError, Exception):
scikits_cuda_available = False
skcuda_available = False
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 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")
if not pygpu_available:
......@@ -175,7 +175,7 @@ class CuIRFFTOp(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.
if not scikits_cuda_available:
if not skcuda_available:
raise RuntimeError("skcuda is needed for CuIFFTOp")
if not pygpu_available:
......@@ -370,7 +370,7 @@ def _unitary(norm):
"'no norm'" % norm)
return norm
if scikits_cuda_available:
if skcuda_available:
@register_opt('fast_compile')
@op_lifter([theano.tensor.fft.RFFTOp])
@register_opt2([theano.tensor.fft.RFFTOp], 'fast_compile')
......
......@@ -9,22 +9,36 @@ from __future__ import absolute_import, print_function, division
import numpy
from theano import Apply, tensor
from theano.gof import local_optimizer
from theano.sandbox.rng_mrg import mrg_uniform_base, mrg_uniform
from theano.tensor import as_tensor_variable, get_vector_length
from theano.gpuarray.basic_ops import GpuKernelBase, Kernel, infer_context_name
from theano.gpuarray.type import GpuArrayType
from theano.gpuarray.fp16_help import write_w
from theano.gpuarray.opt import (register_opt as register_gpua,
register_opt2,
host_from_gpu as host_from_gpua)
from .basic_ops import (GpuKernelBase, Kernel, infer_context_name,
host_from_gpu, as_gpuarray_variable)
from .type import GpuArrayType
from .fp16_help import write_w
from .opt import register_opt, register_opt2
class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
# GpuArray version
_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):
return node.inputs[0].type.context
......@@ -283,10 +297,10 @@ def local_gpua_mrg_graph(op, context_name, inputs, outputs):
op.output_type.ndim,
op.output_type.dtype,
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])
def local_gpua_mrg(node):
context_name = infer_context_name(*node.inputs)
......
......@@ -12,11 +12,11 @@ from .config import mode_with_gpu
# Skip tests if pygpu is not available.
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
raise SkipTest('Optional package pygpu not available')
if not scikits_cuda_available: # noqa
raise SkipTest('Optional package scikits.cuda not available')
if not skcuda_available: # noqa
raise SkipTest('Optional package scikit-cuda not available')
if not pycuda_available: # noqa
raise SkipTest('Optional package pycuda not available')
......
......@@ -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.tests import unittest_tools as utt
from theano.gpuarray.tests.config import mode_with_gpu as mode
from theano.gpuarray.type import gpuarray_shared_constructor
from .config import mode_with_gpu as mode
from ..type import gpuarray_shared_constructor
from ..rng_mrg import GPUA_mrg_uniform
utt.seed_rng()
......@@ -36,7 +37,7 @@ def test_consistency_GPUA_serial():
# Transfer to device
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,
dtype='float32',
size=(1,))
......@@ -84,7 +85,7 @@ def test_consistency_GPUA_parallel():
rstate = np.asarray(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',
size=(n_substreams,))
rstate.default_update = new_rstate
......@@ -125,7 +126,7 @@ def test_GPUA_full_fill():
f_cpu = theano.function([], uni)
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',
size=size)
rstate_gpu.default_update = new_rstate
......@@ -146,7 +147,7 @@ def test_overflow_gpu_new_backend():
rstate.append(rng_mrg.ff_2p72(rstate[-1]))
rstate = np.asarray(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')
# should raise error as the size overflows
sizes = [(2**31, ), (2**32, ), (2**15, 2**16,), (2, 2**15, 2**15)]
......
......@@ -209,7 +209,7 @@ class PersistentGpuArrayID(PersistentNdarrayID):
isinstance(obj, pygpu.gpuarray.GpuArray)):
if id(obj) not in self.seen:
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))
name = self._resolve_name(obj)
zipadd(write_array, self.zip_file, name)
......@@ -285,6 +285,7 @@ class PersistentNdarrayLoad(object):
def __call__(self, persid):
from theano.gpuarray.type import get_context
from theano.gpuarray import pygpu
array_type, name = persid.split('.')
if name in self.cache:
......
......@@ -665,7 +665,6 @@ def rng_mrg_overflow(sizes, fct, mode, should_raise_error):
for size in sizes:
y = fct(size=size)
f = theano.function([], y, mode=mode)
theano.printing.debugprint(f)
if should_raise_error:
assert_raises(ValueError, f)
else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论