提交 d0d006f4 authored 作者: sentient07's avatar sentient07

Added _props_dict() to all the GPU ops in cuda/opt.py

上级 9e2eb687
...@@ -185,6 +185,8 @@ class GpuElemwise(GpuOp): ...@@ -185,6 +185,8 @@ class GpuElemwise(GpuOp):
""" """
__props__ = ("scalar_op", )
nin = property(lambda self: self.scalar_op.nin) nin = property(lambda self: self.scalar_op.nin)
nout = property(lambda self: self.scalar_op.nout) nout = property(lambda self: self.scalar_op.nout)
...@@ -568,6 +570,8 @@ class GpuCAReduce(GpuOp): ...@@ -568,6 +570,8 @@ class GpuCAReduce(GpuOp):
""" """
__props__ = ("reduce_mask", "scalar_op", )
def __init__(self, reduce_mask, scalar_op, pre_scalar_op=None): def __init__(self, reduce_mask, scalar_op, pre_scalar_op=None):
self.reduce_mask = tuple(reduce_mask) self.reduce_mask = tuple(reduce_mask)
self.scalar_op = scalar_op self.scalar_op = scalar_op
......
...@@ -288,7 +288,7 @@ def local_gpu_elemwise_0(node): ...@@ -288,7 +288,7 @@ def local_gpu_elemwise_0(node):
new_op = GpuElemwise(erfcx_gpu) new_op = GpuElemwise(erfcx_gpu)
else: else:
try: try:
new_op = GpuElemwise(node.op.scalar_op) new_op = GpuElemwise(**node.op._props_dict())
except SupportCodeError: except SupportCodeError:
# This happens when scalar_op requires support code # This happens when scalar_op requires support code
return False return False
...@@ -398,16 +398,14 @@ def local_gpu_dimshuffle_0(node): ...@@ -398,16 +398,14 @@ def local_gpu_dimshuffle_0(node):
input, = node.inputs input, = node.inputs
if input.owner and isinstance(input.owner.op, HostFromGpu): if input.owner and isinstance(input.owner.op, HostFromGpu):
# move the add to a GpuAdd # move the add to a GpuAdd
new_op = GpuDimShuffle(node.op.input_broadcastable, new_op = GpuDimShuffle(**node.op._props_dict())
node.op.new_order)
return [host_from_gpu(new_op(as_cuda_ndarray_variable(input)))] return [host_from_gpu(new_op(as_cuda_ndarray_variable(input)))]
if isinstance(node.op, GpuFromHost): if isinstance(node.op, GpuFromHost):
host_input = node.inputs[0] host_input = node.inputs[0]
if host_input.owner and isinstance(host_input.owner.op, if host_input.owner and isinstance(host_input.owner.op,
tensor.DimShuffle): tensor.DimShuffle):
dimshuffle_node = host_input.owner dimshuffle_node = host_input.owner
new_op = GpuDimShuffle(dimshuffle_node.op.input_broadcastable, new_op = GpuDimShuffle(**dimshuffle_node.op._props_dict())
dimshuffle_node.op.new_order)
return [new_op( return [new_op(
as_cuda_ndarray_variable(dimshuffle_node.inputs[0]))] as_cuda_ndarray_variable(dimshuffle_node.inputs[0]))]
return False return False
...@@ -995,9 +993,8 @@ def local_gpu_reshape(node): ...@@ -995,9 +993,8 @@ def local_gpu_reshape(node):
host_input = node.inputs[0] host_input = node.inputs[0]
if host_input.owner and \ if host_input.owner and \
isinstance(host_input.owner.op, tensor.Reshape): isinstance(host_input.owner.op, tensor.Reshape):
rshp = host_input.owner.op
x, shp = host_input.owner.inputs x, shp = host_input.owner.inputs
gpu_reshape = GpuReshape(rshp.ndim)(as_cuda_ndarray_variable(x), gpu_reshape = GpuReshape(**host_input.owner.op._props_dict())(as_cuda_ndarray_variable(x),
shp) shp)
if gpu_reshape.broadcastable != node.outputs[0].broadcastable: if gpu_reshape.broadcastable != node.outputs[0].broadcastable:
# this can happen as we always return False for all broadcast # this can happen as we always return False for all broadcast
...@@ -1011,7 +1008,7 @@ def local_gpu_reshape(node): ...@@ -1011,7 +1008,7 @@ def local_gpu_reshape(node):
x, shp = node.inputs x, shp = node.inputs
if x.owner and isinstance(x.owner.op, HostFromGpu): if x.owner and isinstance(x.owner.op, HostFromGpu):
gpu_x, = x.owner.inputs gpu_x, = x.owner.inputs
gpu_reshape = GpuReshape(node.op.ndim)(gpu_x, shp) gpu_reshape = GpuReshape(**node.op._props_dict())(gpu_x, shp)
if gpu_reshape.broadcastable != node.outputs[0].broadcastable: if gpu_reshape.broadcastable != node.outputs[0].broadcastable:
# this can happen as we always return False for all broadcast # this can happen as we always return False for all broadcast
# dim in GpuReshape but not for Reshape # dim in GpuReshape but not for Reshape
...@@ -1082,7 +1079,7 @@ def local_gpu_subtensor(node): ...@@ -1082,7 +1079,7 @@ def local_gpu_subtensor(node):
gpu_x, = x.owner.inputs gpu_x, = x.owner.inputs
coords = node.inputs[1:] coords = node.inputs[1:]
return [host_from_gpu(GpuSubtensor( return [host_from_gpu(GpuSubtensor(
node.op.idx_list)(gpu_x, *coords))] **node.op._props_dict())(gpu_x, *coords))]
return False return False
...@@ -1171,11 +1168,9 @@ def local_gpu_advanced_incsubtensor1(node): ...@@ -1171,11 +1168,9 @@ def local_gpu_advanced_incsubtensor1(node):
active_device_no = theano.sandbox.cuda.active_device_number() active_device_no = theano.sandbox.cuda.active_device_number()
compute_capability = device_properties(active_device_no)['major'] compute_capability = device_properties(active_device_no)['major']
if (compute_capability < 2 or y.ndim != 2 or x.ndim != 2): if (compute_capability < 2 or y.ndim != 2 or x.ndim != 2):
gpu_op = GpuAdvancedIncSubtensor1( gpu_op = GpuAdvancedIncSubtensor1(**node.op._props_dict())
set_instead_of_inc=set_instead_of_inc)
else: else:
gpu_op = GpuAdvancedIncSubtensor1_dev20( gpu_op = GpuAdvancedIncSubtensor1_dev20(**node.op._props_dict())
set_instead_of_inc=set_instead_of_inc)
return [host_from_gpu(gpu_op(gpu_x, gpu_y, *coords))] return [host_from_gpu(gpu_op(gpu_x, gpu_y, *coords))]
return False return False
...@@ -1229,9 +1224,7 @@ def local_gpu_incsubtensor(node): ...@@ -1229,9 +1224,7 @@ def local_gpu_incsubtensor(node):
y = tensor.cast(y, 'float32') y = tensor.cast(y, 'float32')
gpu_y = as_cuda_ndarray_variable(y) gpu_y = as_cuda_ndarray_variable(y)
if go_gpu: if go_gpu:
ret = GpuIncSubtensor( ret = GpuIncSubtensor(**node.op._props_dict())(
node.op.idx_list, inplace=node.op.inplace,
set_instead_of_inc=node.op.set_instead_of_inc)(
gpu_x, gpu_y, *coords) gpu_x, gpu_y, *coords)
val = getattr(node.outputs[0].tag, 'nan_guard_mode_check', True) val = getattr(node.outputs[0].tag, 'nan_guard_mode_check', True)
...@@ -1597,7 +1590,7 @@ def local_conv_gemm(node): ...@@ -1597,7 +1590,7 @@ def local_conv_gemm(node):
# need to flip the kernel for valid convolution # need to flip the kernel for valid convolution
kern = kern[:, :, ::-1, ::-1] kern = kern[:, :, ::-1, ::-1]
# By default use GpuCorrMM # By default use GpuCorrMM
rval = GpuCorrMM(border_mode, subsample)( rval = GpuCorrMM(**node.op._props_dict())(
gpu_contiguous(img), gpu_contiguous(kern)) gpu_contiguous(img), gpu_contiguous(kern))
# call GpuCorrMM_gradWeights if good # call GpuCorrMM_gradWeights if good
...@@ -1928,7 +1921,7 @@ def local_gpu_downsample_factor_max(node): ...@@ -1928,7 +1921,7 @@ def local_gpu_downsample_factor_max(node):
if (pad) != (0, 0) or node.op.mode != 'max' or stride != ws: if (pad) != (0, 0) or node.op.mode != 'max' or stride != ws:
return return
if (x.owner and isinstance(x.owner.op, HostFromGpu)): if (x.owner and isinstance(x.owner.op, HostFromGpu)):
gpu_ds = GpuDownsampleFactorMax(ws, node.op.ignore_border) gpu_ds = GpuDownsampleFactorMax(**node.op._props_dict())
return [host_from_gpu(gpu_ds(x.owner.inputs[0]))] return [host_from_gpu(gpu_ds(x.owner.inputs[0]))]
......
...@@ -134,6 +134,7 @@ class DimShuffle(Op): ...@@ -134,6 +134,7 @@ class DimShuffle(Op):
_f16_ok = True _f16_ok = True
check_input = False check_input = False
__props__ = ("input_broadcastable", "new_order")
def __init__(self, input_broadcastable, new_order, inplace=False): def __init__(self, input_broadcastable, new_order, inplace=False):
input_broadcastable = tuple(input_broadcastable) input_broadcastable = tuple(input_broadcastable)
...@@ -503,6 +504,8 @@ second dimension ...@@ -503,6 +504,8 @@ second dimension
""" """
__props__ = ("scalar_op",)
def __init__(self, scalar_op, inplace_pattern=None, name=None, def __init__(self, scalar_op, inplace_pattern=None, name=None,
nfunc_spec=None, openmp=None): nfunc_spec=None, openmp=None):
if inplace_pattern is None: if inplace_pattern is None:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论