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