提交 5c9ae8ae authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Flake8 for gpuarray/opt.py

上级 8d0b398d
...@@ -10,9 +10,7 @@ except ImportError: ...@@ -10,9 +10,7 @@ except ImportError:
from theano import tensor, scalar, gof from theano import tensor, scalar, gof
from theano.compile import optdb from theano.compile import optdb
from theano.gof import (local_optimizer, EquilibriumDB, from theano.gof import (local_optimizer, EquilibriumDB,
SequenceDB, ProxyDB, SequenceDB, Optimizer, toolbox)
Optimizer, toolbox,
InconsistencyError, EquilibriumOptimizer)
from theano.scan_module import scan_utils, scan_op, scan_opt from theano.scan_module import scan_utils, scan_op, scan_opt
...@@ -28,10 +26,8 @@ from .conv import GpuConv ...@@ -28,10 +26,8 @@ from .conv import GpuConv
from .nnet import (GpuCrossentropySoftmaxArgmax1HotWithBias, from .nnet import (GpuCrossentropySoftmaxArgmax1HotWithBias,
GpuCrossentropySoftmax1HotWithBiasDx, GpuCrossentropySoftmax1HotWithBiasDx,
GpuSoftmaxWithBias, GpuSoftmax) GpuSoftmaxWithBias, GpuSoftmax)
from .elemwise import (GpuElemwise, _is_scalar, from .elemwise import (GpuElemwise, GpuDimShuffle, GpuCAReduceCuda,
GpuDimShuffle, GpuCAReduceCuda,
GpuCAReduceCPY) GpuCAReduceCPY)
from . import fp16_help
from .subtensor import (GpuIncSubtensor, GpuSubtensor, from .subtensor import (GpuIncSubtensor, GpuSubtensor,
GpuAdvancedIncSubtensor1, GpuAdvancedIncSubtensor1,
GpuAdvancedIncSubtensor1_dev20) GpuAdvancedIncSubtensor1_dev20)
...@@ -135,7 +131,7 @@ class InputToGpuOptimizer(Optimizer): ...@@ -135,7 +131,7 @@ class InputToGpuOptimizer(Optimizer):
new_input = host_from_gpu(gpu_from_host(input)) new_input = host_from_gpu(gpu_from_host(input))
fgraph.replace_validate(input, new_input, fgraph.replace_validate(input, new_input,
"InputToGpuOptimizer") "InputToGpuOptimizer")
except TypeError as e: except TypeError:
# This could fail if the inputs are not TensorTypes # This could fail if the inputs are not TensorTypes
pass pass
...@@ -200,8 +196,8 @@ def local_gpualloc_memset_0(node): ...@@ -200,8 +196,8 @@ def local_gpualloc_memset_0(node):
if isinstance(node.op, GpuAlloc) and not node.op.memset_0: if isinstance(node.op, GpuAlloc) and not node.op.memset_0:
inp = node.inputs[0] inp = node.inputs[0]
if (isinstance(inp, GpuArrayConstant) and if (isinstance(inp, GpuArrayConstant) and
inp.data.size == 1 and inp.data.size == 1 and
(numpy.asarray(inp.data) == 0).all()): (numpy.asarray(inp.data) == 0).all()):
new_out = GpuAlloc(memset_0=True)(*node.inputs) new_out = GpuAlloc(memset_0=True)(*node.inputs)
return [new_out] return [new_out]
...@@ -345,7 +341,7 @@ def local_gpua_join(node): ...@@ -345,7 +341,7 @@ def local_gpua_join(node):
def local_gpuajoin_1(node): def local_gpuajoin_1(node):
# join of a single element # join of a single element
if (isinstance(node.op, GpuJoin) and if (isinstance(node.op, GpuJoin) and
len(node.inputs) == 2): len(node.inputs) == 2):
return [node.inputs[1]] return [node.inputs[1]]
...@@ -362,13 +358,13 @@ def local_gpua_subtensor(node): ...@@ -362,13 +358,13 @@ def local_gpua_subtensor(node):
if (x.owner and isinstance(x.owner.op, HostFromGpu)): if (x.owner and isinstance(x.owner.op, HostFromGpu)):
gpu_x = x.owner.inputs[0] gpu_x = x.owner.inputs[0]
if (gpu_x.owner and if (gpu_x.owner and
isinstance(gpu_x.owner.op, GpuFromHost) and isinstance(gpu_x.owner.op, GpuFromHost) and
# And it is a shared var or an input of the graph. # And it is a shared var or an input of the graph.
not gpu_x.owner.inputs[0].owner): not gpu_x.owner.inputs[0].owner):
if len(x.clients) == 1: if len(x.clients) == 1:
if any([n == 'output' or any([isinstance(v.type, GpuArrayType) if any([n == 'output' or any([isinstance(v.type, GpuArrayType)
for v in n.inputs + n.outputs]) for v in n.inputs + n.outputs])
for n, _ in node.outputs[0].clients]): for n, _ in node.outputs[0].clients]):
return return
else: else:
return [host_from_gpu(gpu_from_host(node.outputs[0]))] return [host_from_gpu(gpu_from_host(node.outputs[0]))]
...@@ -393,7 +389,6 @@ def local_gpua_advanced_incsubtensor(node): ...@@ -393,7 +389,6 @@ def local_gpua_advanced_incsubtensor(node):
return None return None
x, y = node.inputs[0:2] x, y = node.inputs[0:2]
coords = node.inputs[2:]
set_instead_of_inc = node.op.set_instead_of_inc set_instead_of_inc = node.op.set_instead_of_inc
active_device_no = theano.sandbox.cuda.active_device_number() active_device_no = theano.sandbox.cuda.active_device_number()
device_properties = theano.sandbox.cuda.device_properties device_properties = theano.sandbox.cuda.device_properties
...@@ -431,7 +426,7 @@ def local_gpua_careduce(node): ...@@ -431,7 +426,7 @@ def local_gpua_careduce(node):
# We need to have the make node called, otherwise the mask can # We need to have the make node called, otherwise the mask can
# be None # be None
if (op is GpuCAReduceCPY or if (op is GpuCAReduceCPY or
gvar.owner.op.supports_c_code([gpu_from_host(x)])): gvar.owner.op.supports_c_code([gpu_from_host(x)])):
return greduce return greduce
else: else:
# Try to make a simpler pattern based on reshaping # Try to make a simpler pattern based on reshaping
...@@ -575,7 +570,7 @@ def local_gpu_conv(node): ...@@ -575,7 +570,7 @@ def local_gpu_conv(node):
version=op.version, version=op.version,
verbose=op.verbose, verbose=op.verbose,
imshp=op.imshp, imshp=op.imshp,
) )
if op.imshp_logical is not None: if op.imshp_logical is not None:
logical_img_hw = op.imshp_logical[1:3] logical_img_hw = op.imshp_logical[1:3]
if logical_img_hw != op.imshp[1:3]: if logical_img_hw != op.imshp[1:3]:
...@@ -635,15 +630,14 @@ def local_gpu_conv(node): ...@@ -635,15 +630,14 @@ def local_gpu_conv(node):
def local_gpu_elemwise_careduce(node): def local_gpu_elemwise_careduce(node):
""" Merge some GpuCAReduceCuda and GPUElemwise""" """ Merge some GpuCAReduceCuda and GPUElemwise"""
if (isinstance(node.op, GpuCAReduceCuda) and if (isinstance(node.op, GpuCAReduceCuda) and
node.op.pre_scalar_op is None and node.op.pre_scalar_op is None and
node.inputs[0].owner and node.inputs[0].owner and
isinstance(node.inputs[0].owner.op, GpuElemwise) and isinstance(node.inputs[0].owner.op, GpuElemwise) and
# The Op support all scalar with 1 inputs. We don't # The Op support all scalar with 1 inputs. We don't
# automatically add more case, as some like trigonometic # automatically add more case, as some like trigonometic
# operation with some reduction pattern will probably result # operation with some reduction pattern will probably result
# to slow down. # to slow down.
isinstance(node.inputs[0].owner.op.scalar_op, scalar.basic.Sqr) isinstance(node.inputs[0].owner.op.scalar_op, scalar.basic.Sqr)):
):
op = node.op op = node.op
inp = node.inputs[0].owner.inputs[0] inp = node.inputs[0].owner.inputs[0]
return [GpuCAReduceCuda(scalar_op=op.scalar_op, return [GpuCAReduceCuda(scalar_op=op.scalar_op,
......
...@@ -227,7 +227,6 @@ whitelist_flake8 = [ ...@@ -227,7 +227,6 @@ whitelist_flake8 = [
"sandbox/gpuarray/elemwise.py", "sandbox/gpuarray/elemwise.py",
"sandbox/gpuarray/type.py", "sandbox/gpuarray/type.py",
"sandbox/gpuarray/__init__.py", "sandbox/gpuarray/__init__.py",
"sandbox/gpuarray/opt.py",
"sandbox/gpuarray/blas.py", "sandbox/gpuarray/blas.py",
"sandbox/gpuarray/kernel_codegen.py", "sandbox/gpuarray/kernel_codegen.py",
"sandbox/gpuarray/conv.py", "sandbox/gpuarray/conv.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论