提交 c229fa84 authored 作者: Simon Lefrancois's avatar Simon Lefrancois 提交者: GitHub

Merge pull request #5288 from chinnadhurai/ccw_4916

fix crash in MRG_RandomStreams with the new backend
......@@ -24,7 +24,8 @@ from . import multinomial
import theano.sandbox.cuda
from theano.sandbox.cuda import GpuOp
from theano.gpuarray.basic_ops import GpuKernelBase, Kernel, infer_context_name
from theano.sandbox.cuda.basic_ops import as_cuda_ndarray_variable
from theano.gpuarray.basic_ops import GpuKernelBase, Kernel, infer_context_name, as_gpuarray_variable
from theano.gpuarray.type import GpuArrayType
from theano.gpuarray.fp16_help import write_w
from theano.gpuarray.opt import (register_opt as register_gpua,
......@@ -312,19 +313,6 @@ class mrg_uniform_base(Op):
s = "no_inplace"
return self.__class__.__name__ + "{%s,%s}" % (self.output_type, s)
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)()
return Apply(self,
[rstate, size],
[rstate.type(), output_type])
def grad(self, inputs, ograd):
return [gradient.grad_undefined(self, k, inp,
'No gradient defined through '
......@@ -338,6 +326,20 @@ class mrg_uniform_base(Op):
class mrg_uniform(mrg_uniform_base):
# CPU VERSION
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_tensor_variable(rstate)
return Apply(self,
[rstate, size],
[rstate.type(), output_type])
@classmethod
def new(cls, rstate, ndim, dtype, size):
v_size = as_tensor_variable(size)
......@@ -564,6 +566,20 @@ class mrg_uniform(mrg_uniform_base):
class GPU_mrg_uniform(mrg_uniform_base, GpuOp):
# GPU VERSION
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_cuda_ndarray_variable(rstate)
return Apply(self,
[rstate, size],
[rstate.type(), output_type])
@classmethod
def new(cls, rstate, ndim, dtype, size):
v_size = as_tensor_variable(size)
......@@ -809,6 +825,20 @@ 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
......
......@@ -18,6 +18,7 @@ from theano.sandbox.rng_mrg import MRG_RandomStreams
from theano.sandbox.cuda import cuda_available
from theano.tests import unittest_tools as utt
from theano.tests.unittest_tools import attr
import theano.gpuarray.tests.config
if cuda_available:
from theano.sandbox.cuda import float32_shared_constructor
......@@ -1178,6 +1179,16 @@ def test_overflow_gpu_new_backend():
rng_mrg_overflow(sizes, fct, mode, should_raise_error=False)
def test_validate_input_types_gpuarray_backend():
from theano.sandbox.rng_mrg import mrg_uniform
from theano.gpuarray.type import gpuarray_shared_constructor
from theano.configparser import change_flags
with change_flags(compute_test_value="raise"):
rstate = numpy.zeros((7, 6), dtype="int32")
rstate = gpuarray_shared_constructor(rstate)
mrg_uniform.new(rstate, ndim=None, dtype="float32", size=(3,))
if __name__ == "__main__":
rng = MRG_RandomStreams(numpy.random.randint(2147462579))
print(theano.__file__)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论