提交 890b9af0 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

pep8 fixes

上级 2b1d70cc
......@@ -30,6 +30,7 @@ from type import (GpuArrayType, GpuArrayVariable, GpuArrayConstant,
GpuArraySharedVariable, gpuarray_shared_constructor)
import opt
def init_dev(dev):
global pygpu_activated
context = pygpu.init(dev)
......
......@@ -19,6 +19,7 @@ except ImportError:
from type import GpuArrayType
def as_gpuarray_variable(x):
if hasattr(x, '_as_GpuArrayVariable'):
return x._as_GpuArrayVariable()
......@@ -30,6 +31,7 @@ def as_gpuarray_variable(x):
def as_gpuarray(x):
return gpuarray.array(x, copy=False)
class HideC(object):
def __hide(*args):
raise MethodNotDefined()
......@@ -116,7 +118,7 @@ class HostFromGpu(Op):
%(fail)s
}
""" % {'name': name, 'fail': sub['fail'], 'inp': inputs[0],
'out': outputs[0]}
'out': outputs[0]}
def c_code_cache_version(self):
return (1,)
......@@ -124,7 +126,7 @@ class HostFromGpu(Op):
def grad(self, inputs, grads):
gz, = grads
return [gpu_from_host(gz)]
def R_op(self, inputs, eval_points):
ev, = eval_points
if isinstance(ev, tensor.TensorType):
......@@ -320,7 +322,7 @@ class GpuFromCuda(Op):
if (%(out)s == NULL) {
%(fail)s
}
""" % {'name':name, 'in': inputs[0], 'out': outputs[0],
""" % {'name': name, 'in': inputs[0], 'out': outputs[0],
'fail': sub['fail']}
def c_code_cache_version(self):
......@@ -508,7 +510,7 @@ class GpuAlloc(HideC, Alloc):
""" % dict(name=name, ndim=ndim, zz=zz, vv=vv, fail=sub['fail'])
if config.gpuarray.sync:
code += "GpuArray_sync(&%(zz)s->ga);" % dict(zz=zz);
code += "GpuArray_sync(&%(zz)s->ga);" % dict(zz=zz)
return code
......
......@@ -10,6 +10,7 @@ except ImportError, e:
# To make sure theano is importable
pass
class BlasOp(HideC):
def c_headers(self):
return ['<blas_api.h>']
......@@ -20,6 +21,7 @@ class BlasOp(HideC):
def c_init_code(self):
return ['import_pygpu__blas();']
class GpuGemv(BlasOp, Gemv):
def make_node(self, y, alpha, A, x, beta):
res = Gemv.make_node(self, y, alpha, A, x, beta)
......@@ -71,6 +73,7 @@ class GpuGemv(BlasOp, Gemv):
gpugemv_no_inplace = GpuGemv(inplace=False)
gpugemv_inplace = GpuGemv(inplace=True)
class GpuGemm(BlasOp, Gemm):
def make_node(self, C, alpha, A, B, beta):
res = Gemm.make_node(self, C, alpha, A, B, beta)
......@@ -127,11 +130,13 @@ from theano.compile import optdb
from theano.gof import local_optimizer, LocalOptGroup
from theano.tensor.opt import in2out
@local_optimizer([gpugemv_no_inplace])
def local_inplace_gpuagemv(node):
if node.op == gpugemv_no_inplace:
return [gpugemv_inplace(*node.inputs)]
@local_optimizer([gpugemm_no_inplace])
def local_inplace_gpuagemm(node):
if node.op == gpugemm_no_inplace:
......
......@@ -18,15 +18,18 @@ from theano.sandbox.gpuarray.type import GpuArrayType
from theano.gof.utils import MethodNotDefined
def _is_scalar(v):
False
def make_argument(v, name):
if _is_scalar(v):
return ScalarArg(numpy.dtype(v.type.dtype), name)
else:
return ArrayArg(numpy.dtype(v.type.dtype), name)
def ensure_allocated(storage, shape, dtype):
odat = storage[0]
if odat is not None:
......@@ -39,10 +42,12 @@ def ensure_allocated(storage, shape, dtype):
storage[0] = odat
return odat
def as_C_string_const(s):
return '\n'.join('"%s\\n"' % (l.replace('"', '\\"'))
for l in s.split('\n'))
class GpuElemwise(HideC, Elemwise):
nin = property(lambda self: self.scalar_op.nin)
nout = property(lambda self: self.scalar_op.nout)
......
import copy
import theano, numpy
import theano
import numpy
from theano import tensor, scalar
from theano.compile import optdb
from theano.gof import (local_optimizer, EquilibriumDB, SequenceDB, ProxyDB,
......@@ -31,6 +32,7 @@ optdb.register('gpuarray_opt', gpu_seqopt,
optdb.__position__.get('add_destroy_handler', 49.5) - 1,
'gpuarray')
def register_opt(*tags, **kwargs):
def f(local_opt):
name = (kwargs and kwargs.pop('name')) or local_opt.__name__
......@@ -40,6 +42,7 @@ def register_opt(*tags, **kwargs):
register_opt()(theano.tensor.opt.local_track_shape_i)
def op_lifter(OP):
"""
OP(..., host_from_gpu(), ...) -> host_from_gpu(GpuOP(...))
......@@ -65,6 +68,7 @@ def op_lifter(OP):
return local_optimizer([OP])(local_opt)
return f
class InputToGpuOptimizer(Optimizer):
"Transfer the input to the gpu to start the rolling wave."
......@@ -93,6 +97,7 @@ class InputToGpuOptimizer(Optimizer):
gpu_seqopt.register('InputToGpuArrayOptimizer', InputToGpuOptimizer(),
0, 'fast_run', 'fast_compile', 'merge')
@local_optimizer([])
def local_cut_gpu_host_gpu(node):
if tensor.opt.opt.check_chain(node, gpu_from_host, host_from_gpu):
......@@ -108,11 +113,13 @@ gpu_cut_copies.register('cut_gpua_constant_transfers',
optdb['canonicalize'].register('local_cut_gpua_host_gpua',
local_cut_gpu_host_gpu, 'fast_run', 'gpuarray')
@register_opt()
@op_lifter(tensor.Alloc)
def local_gpualloc(node):
return gpu_alloc
@register_opt()
@op_lifter(tensor.Elemwise)
def local_gpu_elemwise(node):
......@@ -125,6 +132,7 @@ def local_gpu_elemwise(node):
nfunc_spec=op.nfunc_spec)
return res
def max_inputs_to_GpuElemwise(node):
ptr_size = 8
int_size = 4
......@@ -173,6 +181,7 @@ def local_gpua_specifyShape(node):
def local_gpua_subtensor(node):
return GpuSubtensor(node.op.idx_list)
@register_opt()
@op_lifter(tensor.CAReduce)
def local_gpua_careduce(node):
......
......@@ -17,6 +17,7 @@ except ImportError:
from theano.sandbox.gpuarray.type import GpuArrayType
from theano.sandbox.gpuarray.basic_ops import as_gpuarray_variable, HideC
class GpuSubtensor(HideC, Subtensor):
def make_node(self, x, *inputs):
rval = tensor.Subtensor.make_node(self, x, *inputs)
......@@ -31,13 +32,13 @@ class GpuSubtensor(HideC, Subtensor):
if self.perform_cache_cdata is not None:
out[0] = x.__getitem__(self.perform_cache_cdata)
return
cdata = get_idx_list(inputs, self.idx_list)
if len(cdata) == 1:
cdata = cdata[0]
if len(inputs) == 1:
self.perform_cache_cdata = cdata
out[0] = x.__getitem__(cdata)
def c_support_code(self):
......
......@@ -107,8 +107,8 @@ class GpuArrayType(Type):
return GpuArrayType.values_eq(a, b)
else:
res = elemwise2(a, '', b, a, odtype=numpy.dtype('bool'),
op_tmpl="res[i] = ((%(a)s - %(b)s) <" \
"(1e-8 + 1e-5 * fabs(%(b)s)))")
op_tmpl="res[i] = ((%(a)s - %(b)s) <"
"(1e-8 + 1e-5 * fabs(%(b)s)))")
return numpy.asarray(res).all()
def value_zeros(self, shape):
......@@ -163,7 +163,7 @@ class GpuArrayType(Type):
""" % {'name': name, 'fail': sub['fail']}
def c_cleanup(self, name, sub):
return "Py_XDECREF(%(name)s); %(name)s = NULL;" % {'name': name }
return "Py_XDECREF(%(name)s); %(name)s = NULL;" % {'name': name}
def c_sync(self, name, sub):
return """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论