提交 88599bc3 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Apply isort to theano.gpuarray and remove circular references

Two new modules were made in order to remove the circular references: `theano.gpuarray.dnn_opt` (i.e. optimizations specific to `theano.gpuarray.dnn`) and `theano.gpuarray.optdb` (i.e. optimization databases for gpuarray `Op`s).
上级 b4fbaa2e
import sys
import os
import logging import logging
import os
import sys
import warnings import warnings
import theano import theano
from theano import config from theano import config
from theano.compile import optdb from theano.compile import optdb
from theano.tensor.basic import register_transfer from theano.tensor.basic import register_transfer
_logger_name = "theano.gpuarray" _logger_name = "theano.gpuarray"
_logger = logging.getLogger(_logger_name) _logger = logging.getLogger(_logger_name)
...@@ -24,19 +24,20 @@ try: ...@@ -24,19 +24,20 @@ try:
except ImportError: except ImportError:
pygpu = None pygpu = None
from . import ctc, dnn, extra_ops, fft, multinomial, opt, reduction, rng_mrg, sort
from .basic_ops import as_gpuarray_variable
# This is for documentation not to depend on the availability of pygpu # This is for documentation not to depend on the availability of pygpu
from .type import ( from .type import (
GpuArrayType, ContextNotDefined,
GpuArrayVariable,
GpuArrayConstant, GpuArrayConstant,
GpuArraySharedVariable, GpuArraySharedVariable,
GpuArrayType,
GpuArrayVariable,
get_context,
gpuarray_shared_constructor, gpuarray_shared_constructor,
reg_context, reg_context,
get_context,
ContextNotDefined,
) )
from .basic_ops import as_gpuarray_variable
from . import fft, dnn, opt, extra_ops, multinomial, reduction, sort, rng_mrg, ctc
def transfer(x, target): def transfer(x, target):
...@@ -292,7 +293,7 @@ if pygpu: ...@@ -292,7 +293,7 @@ if pygpu:
host_from_gpu, host_from_gpu,
) )
from .elemwise import GpuElemwise from .elemwise import GpuElemwise
from .subtensor import GpuSubtensor, GpuIncSubtensor, GpuAdvancedIncSubtensor1 from .subtensor import GpuAdvancedIncSubtensor1, GpuIncSubtensor, GpuSubtensor
else: else:
if ( if (
......
import os
import copy import copy
import os
import re import re
import numpy as np
import theano
from collections import deque from collections import deque
import numpy as np
from six import string_types from six import string_types
from theano import Op, Apply, Type, Variable import theano
from theano import tensor, config from theano import Apply, Op, Type, Variable, config, tensor
from theano.gof import COp, HideC, ParamsType
from theano.gof.opt import copy_stack_trace
from theano.gof.utils import MethodNotDefined
from theano.gradient import grad_undefined from theano.gradient import grad_undefined
from theano.scalar import bool as bool_t, int32 as int32_t from theano.scalar import bool as bool_t
from theano.tensor.basic import Alloc, AllocEmpty, alloc_validate_shape, Join, Split from theano.scalar import int32 as int32_t
from theano.tensor.basic import Alloc, AllocEmpty, Join, Split, alloc_validate_shape
from theano.gof import HideC, COp, ParamsType
from theano.gof.utils import MethodNotDefined
from theano.gof.opt import copy_stack_trace
try: try:
import pygpu import pygpu
...@@ -26,15 +23,15 @@ try: ...@@ -26,15 +23,15 @@ try:
except ImportError: except ImportError:
pass pass
from .fp16_help import write_w
from .type import ( from .type import (
GpuArrayType, EQ_MAP,
ContextNotDefined,
GpuArrayConstant, GpuArrayConstant,
gpu_context_type, GpuArrayType,
get_context, get_context,
ContextNotDefined, gpu_context_type,
EQ_MAP,
) )
from .fp16_help import write_w
def as_gpuarray_variable(x, context_name): def as_gpuarray_variable(x, context_name):
...@@ -1000,7 +997,7 @@ class GpuAlloc(HideC, Alloc): ...@@ -1000,7 +997,7 @@ class GpuAlloc(HideC, Alloc):
return (4,) return (4,)
def do_constant_folding(self, node): def do_constant_folding(self, node):
from . import subtensor, blas from . import blas, subtensor
for client in node.outputs[0].clients: for client in node.outputs[0].clients:
if client[0] == "output": if client[0] == "output":
......
...@@ -2,7 +2,6 @@ from six import integer_types ...@@ -2,7 +2,6 @@ from six import integer_types
import theano import theano
from theano import Apply, Op from theano import Apply, Op
from theano.compile import optdb from theano.compile import optdb
from theano.gof import LocalOptGroup, ParamsType from theano.gof import LocalOptGroup, ParamsType
from theano.scalar import bool as bool_t from theano.scalar import bool as bool_t
...@@ -10,15 +9,16 @@ from theano.tensor.basic import as_tensor_variable ...@@ -10,15 +9,16 @@ from theano.tensor.basic import as_tensor_variable
from theano.tensor.opt import in2out from theano.tensor.opt import in2out
from .basic_ops import ( from .basic_ops import (
GpuArrayType,
CGpuKernelBase, CGpuKernelBase,
GpuArrayType,
as_gpuarray_variable, as_gpuarray_variable,
gpu_contiguous, gpu_contiguous,
infer_context_name,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name,
) )
from .opt_util import inplace_allocempty from .opt_util import inplace_allocempty
try: try:
import pygpu import pygpu
from pygpu import blas from pygpu import blas
......
import logging import logging
import numpy as np import numpy as np
from theano import Apply, tensor from theano import Apply, tensor
from theano.gof import COp, ParamsType from theano.gof import COp, ParamsType
from theano.tensor import discrete_dtypes, as_tensor_variable
from theano.scalar import bool as bool_t
from theano.gradient import grad_undefined from theano.gradient import grad_undefined
from theano.scalar import bool as bool_t
from theano.tensor import as_tensor_variable, discrete_dtypes
from .basic_ops import as_gpuarray_variable, gpuarray_helper_inc_dir, infer_context_name
from .type import gpu_context_type from .type import gpu_context_type
from .basic_ops import as_gpuarray_variable, infer_context_name, gpuarray_helper_inc_dir
_logger = logging.getLogger("theano.gpuarray.blocksparse") _logger = logging.getLogger("theano.gpuarray.blocksparse")
......
...@@ -4,22 +4,20 @@ import sys ...@@ -4,22 +4,20 @@ import sys
import theano import theano
import theano.tensor as tt import theano.tensor as tt
import theano.tensor.nnet.ctc import theano.tensor.nnet.ctc
from theano import config, gof from theano import config, gof
from theano.gof import local_optimizer
from theano.gpuarray import pygpu
from theano.gpuarray.basic_ops import ( from theano.gpuarray.basic_ops import (
gpu_contiguous,
as_gpuarray_variable, as_gpuarray_variable,
infer_context_name, gpu_contiguous,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name,
) )
from theano.gpuarray.type import GpuArrayType, gpu_context_type
from theano.gpuarray.elemwise import GpuDimShuffle from theano.gpuarray.elemwise import GpuDimShuffle
from theano.gpuarray.type import GpuArrayType, gpu_context_type
from theano.gradient import grad_undefined from theano.gradient import grad_undefined
from theano.gof import local_optimizer
from theano.tensor.opt import register_canonicalize
from theano.tensor.nnet.ctc import ctc_available from theano.tensor.nnet.ctc import ctc_available
from theano.tensor.opt import register_canonicalize
from theano.gpuarray import pygpu
class GpuConnectionistTemporalClassification(gof.COp): class GpuConnectionistTemporalClassification(gof.COp):
......
...@@ -18,6 +18,7 @@ Currently supported cuDNN APIs: ...@@ -18,6 +18,7 @@ Currently supported cuDNN APIs:
from theano.gof import CEnumType from theano.gof import CEnumType
HALF, FLOAT, DOUBLE = ("float16", "float32", "float64") HALF, FLOAT, DOUBLE = ("float16", "float32", "float64")
TRUE_HALF_CONFIG = (HALF, HALF) TRUE_HALF_CONFIG = (HALF, HALF)
PSEUDO_HALF_CONFIG = (HALF, FLOAT) PSEUDO_HALF_CONFIG = (HALF, FLOAT)
......
差异被折叠。
差异被折叠。
import copy import copy
import numpy as np import numpy as np
import theano
from six.moves import StringIO from six.moves import StringIO
from theano import Apply, scalar, Op import theano
from theano import Apply, Op, scalar
from theano.gof.utils import MethodNotDefined from theano.gof.utils import MethodNotDefined
from theano.scalar import Scalar, Composite from theano.scalar import Composite, Scalar
from theano.tensor.elemwise import Elemwise, DimShuffle, CAReduceDtype from theano.scalar.basic import complex_types, upgrade_to_float_no_complex
from theano.scalar.basic_scipy import Erfinv, Erfcinv from theano.scalar.basic_scipy import Erfcinv, Erfinv
from theano.scalar.basic import upgrade_to_float_no_complex, complex_types from theano.tensor.elemwise import CAReduceDtype, DimShuffle, Elemwise
try: try:
import pygpu import pygpu
from pygpu import gpuarray from pygpu import gpuarray
from pygpu.tools import ArrayArg
from pygpu.reduction import ReductionKernel
from pygpu.gpuarray import dtype_to_typecode from pygpu.gpuarray import dtype_to_typecode
from pygpu.reduction import ReductionKernel
from pygpu.tools import ArrayArg
except ImportError: except ImportError:
pass pass
from .basic_ops import ( from .basic_ops import (
as_gpuarray_variable,
HideC,
GpuKernelBase, GpuKernelBase,
HideC,
Kernel, Kernel,
as_gpuarray_variable,
infer_context_name, infer_context_name,
) )
from .type import GpuArrayType, gpu_context_type
from .fp16_help import load_w, write_w from .fp16_help import load_w, write_w
from .type import GpuArrayType, gpu_context_type
def make_argument(v, name): def make_argument(v, name):
......
from theano import Apply, Op from theano import Apply, Op
from theano.tensor.extra_ops import CumOp from theano.tensor.extra_ops import CumOp
try: try:
from pygpu import gpuarray from pygpu import gpuarray
except ImportError: except ImportError:
pass pass
import theano.scalar as scalar
from theano.gof import ParamsType
from .basic_ops import ( from .basic_ops import (
as_gpuarray_variable,
GpuKernelBase, GpuKernelBase,
Kernel,
GpuReshape, GpuReshape,
infer_context_name, Kernel,
as_gpuarray_variable,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name,
) )
from .opt import register_opt, op_lifter, register_opt2 from .opt import op_lifter, register_opt, register_opt2
from .type import gpu_context_type from .type import gpu_context_type
from theano.gof import ParamsType
import theano.scalar as scalar
class GpuCumOp(GpuKernelBase, Op): class GpuCumOp(GpuKernelBase, Op):
......
...@@ -2,18 +2,17 @@ import numpy as np ...@@ -2,18 +2,17 @@ import numpy as np
import theano import theano
import theano.tensor as tt import theano.tensor as tt
from theano import Op from theano import Op
from theano.gradient import DisconnectedType
from theano.gpuarray.basic_ops import ( from theano.gpuarray.basic_ops import (
gpu_contiguous,
as_gpuarray_variable, as_gpuarray_variable,
gpu_contiguous,
infer_context_name, infer_context_name,
) )
from theano.gpuarray.opt import op_lifter, register_opt, register_opt2
from theano.gpuarray.type import GpuArrayType from theano.gpuarray.type import GpuArrayType
from theano.gradient import DisconnectedType
from theano.tensor.fft import IRFFTOp from theano.tensor.fft import IRFFTOp
from theano.gpuarray.opt import register_opt, op_lifter, register_opt2
try: try:
import pygpu import pygpu
......
import warnings import warnings
import pkg_resources
import numpy as np import numpy as np
import pkg_resources
from numpy.linalg.linalg import LinAlgError from numpy.linalg.linalg import LinAlgError
import theano import theano
from theano import Op, config, tensor from theano import Op, config, tensor
from theano.scalar import bool as bool_t
from theano.gof import COp, ParamsType from theano.gof import COp, ParamsType
from theano.gpuarray import GpuArrayType from theano.gpuarray.basic_ops import (
from .basic_ops import (
CGpuKernelBase, CGpuKernelBase,
as_gpuarray_variable, as_gpuarray_variable,
gpu_contiguous, gpu_contiguous,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name, infer_context_name,
) )
from .type import gpu_context_type from theano.gpuarray.type import GpuArrayType, gpu_context_type
from theano.scalar import bool as bool_t
try: try:
import pygpu import pygpu
from pygpu.basic import triu, tril from pygpu.basic import tril, triu
pygpu_available = True pygpu_available = True
except ImportError: except ImportError:
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import warnings import warnings
try: try:
import pygpu import pygpu
except ImportError: except ImportError:
...@@ -11,20 +12,20 @@ import theano ...@@ -11,20 +12,20 @@ import theano
import theano.sandbox.multinomial import theano.sandbox.multinomial
from theano import Apply from theano import Apply
from theano.gof import Op from theano.gof import Op
from theano.scalar import as_scalar
from theano.tensor import NotScalarConstantError, get_scalar_constant_value from theano.tensor import NotScalarConstantError, get_scalar_constant_value
from .basic_ops import ( from .basic_ops import (
as_gpuarray_variable,
infer_context_name,
GpuKernelBase, GpuKernelBase,
Kernel, Kernel,
as_gpuarray_variable,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name,
) )
from .opt import register_opt, op_lifter, register_opt2
from .type import GpuArrayType
from .elemwise import GpuDimShuffle from .elemwise import GpuDimShuffle
from theano.scalar import as_scalar from .fp16_help import load_w, work_dtype, write_w
from .fp16_help import write_w, load_w, work_dtype from .opt import op_lifter, register_opt, register_opt2
from .type import GpuArrayType
class GPUAMultinomialFromUniform(GpuKernelBase, Op): class GPUAMultinomialFromUniform(GpuKernelBase, Op):
......
import theano.tensor as tt import theano.tensor as tt
from theano import Apply, Op
from theano import Op, Apply
from theano.gof import ParamsType from theano.gof import ParamsType
from theano.tensor.nnet.neighbours import Images2Neibs from theano.tensor.nnet.neighbours import Images2Neibs
try: try:
from pygpu import gpuarray from pygpu import gpuarray
except ImportError: except ImportError:
pass pass
from theano.gpuarray.basic_ops import ( from theano.gpuarray.basic_ops import (
as_gpuarray_variable,
GpuKernelBase, GpuKernelBase,
Kernel, Kernel,
as_gpuarray_variable,
infer_context_name, infer_context_name,
) )
from theano.gpuarray.type import GpuArrayType, gpu_context_type from theano.gpuarray.type import GpuArrayType, gpu_context_type
......
import numpy as np import numpy as np
from theano import Op, Apply
from six import StringIO from six import StringIO
from theano import Apply, Op
try: try:
import pygpu import pygpu
from pygpu import gpuarray from pygpu import gpuarray
...@@ -10,14 +11,14 @@ except ImportError: ...@@ -10,14 +11,14 @@ except ImportError:
pass pass
from .basic_ops import ( from .basic_ops import (
as_gpuarray_variable,
GpuKernelBase, GpuKernelBase,
Kernel, Kernel,
as_gpuarray_variable,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name, infer_context_name,
) )
from .fp16_help import load_w, work_dtype, write_w
from .type import GpuArrayType from .type import GpuArrayType
from .fp16_help import work_dtype, load_w, write_w
class GpuCrossentropySoftmaxArgmax1HotWithBias(GpuKernelBase, Op): class GpuCrossentropySoftmaxArgmax1HotWithBias(GpuKernelBase, Op):
......
差异被折叠。
...@@ -2,13 +2,38 @@ from functools import wraps ...@@ -2,13 +2,38 @@ from functools import wraps
import numpy as np import numpy as np
from theano import tensor, scalar as scal, Constant from theano import Constant
from theano import scalar as scal
from theano import tensor
from theano.gof import local_optimizer from theano.gof import local_optimizer
from theano.gof.opt import inherit_stack_trace from theano.gof.op import Op
from theano.tensor import DimShuffle, get_scalar_constant_value, NotScalarConstantError from theano.gof.opt import copy_stack_trace, inherit_stack_trace
from theano.gpuarray.basic_ops import (
GpuAllocEmpty,
GpuFromHost,
GpuReshape,
HostFromGpu,
host_from_gpu,
)
from theano.gpuarray.elemwise import GpuDimShuffle, GpuElemwise
from theano.gpuarray.type import GpuArrayType, get_context, move_to_gpu
from theano.tensor import DimShuffle, NotScalarConstantError, get_scalar_constant_value
# Define a few operations to use in optimizations,
# in order to avoid introducin new CPU Ops, or useless ones.
def safe_to_gpu(x, ctx_name):
if isinstance(x.type, tensor.TensorType):
return GpuFromHost(ctx_name)(x)
else:
return x
from .basic_ops import GpuFromHost, HostFromGpu, GpuAllocEmpty, GpuReshape def safe_to_cpu(x):
from .elemwise import GpuDimShuffle, GpuElemwise if isinstance(x.type, GpuArrayType):
return x.transfer("cpu")
else:
return x
def grab_cpu_scalar(v, nd): def grab_cpu_scalar(v, nd):
...@@ -420,3 +445,84 @@ def unpad_dims(output, input, leftdims, rightdims): ...@@ -420,3 +445,84 @@ def unpad_dims(output, input, leftdims, rightdims):
# restore the output to the original shape # restore the output to the original shape
outshp = tensor.join(0, input.shape[:-rightdims], output.shape[-rightdims:]) outshp = tensor.join(0, input.shape[:-rightdims], output.shape[-rightdims:])
return GpuReshape(input.ndim)(output, outshp) return GpuReshape(input.ndim)(output, outshp)
def op_lifter(OP, cuda_only=False):
"""
OP(..., host_from_gpu(), ...) -> host_from_gpu(GpuOP(...))
gpu_from_host(OP(inp0, ...)) -> GpuOP(inp0, ...)
"""
def f(maker):
def local_opt(node):
if type(node.op) in OP:
# Either one of our inputs is on the gpu or
# all of our clients are on the gpu
replace = False
# TODO: Maybe set context_name with infer_context_name()?
context_name = None
# We replace if any input is a host_from_gpu
for i in node.inputs:
if i.owner and i.owner.op == host_from_gpu and move_to_gpu(i):
context_name = i.owner.inputs[0].type.context_name
replace = True
break
if not replace:
# We replace if *all* clients are on the GPU
clients = [c for o in node.outputs for c in o.clients]
replace = len(clients) != 0
for c, idx in clients:
if c == "output" or not isinstance(c.op, GpuFromHost):
replace = False
# TODO: check that the clients want the same context?
if replace:
# All clients are GpuFromHost and we have at least one
context_name = clients[0][0].op.context_name
# Check if we should replace
if (
not replace
or (cuda_only and get_context(context_name).kind != b"cuda")
or any(["complex" in getattr(i, "dtype", "") for i in node.inputs])
):
return False
# tag the inputs with the context in case
# the context was derived from the outputs
for i in node.inputs:
i.tag.context_name = context_name
new_op = maker(node.op, context_name, node.inputs, node.outputs)
# This is needed as sometimes new_op inherits from OP.
if new_op and new_op != node.op:
if isinstance(new_op, Op):
new_outputs = new_op(*node.inputs, return_list=True)
to_cpu_fn = safe_to_cpu
elif isinstance(new_op, (tuple, list)):
new_outputs = new_op
to_cpu_fn = safe_to_cpu
else: # suppose it is a variable on the GPU
new_outputs = [new_op]
def to_cpu_fn(x):
return x.transfer("cpu")
# copy stack traces onto gpu outputs
# also copy the stack traces onto HostFromGpu outputs
on_cpu = []
for old_output, new_output in zip(node.outputs, new_outputs):
copy_stack_trace(old_output, new_output)
cpu = to_cpu_fn(new_output)
on_cpu.append(cpu)
copy_stack_trace(old_output, cpu)
return on_cpu
return False
local_opt.__name__ = maker.__name__
return local_optimizer(OP)(local_opt)
return f
from theano.compile import optdb
from theano.gof.opt import GraphToGPULocalOptGroup, TopoOptimizer, local_optimizer
from theano.gof.optdb import DB, EquilibriumDB, LocalGroupDB, SequenceDB
gpu_optimizer = EquilibriumDB()
gpu_cut_copies = EquilibriumDB()
# Not used for an EquilibriumOptimizer. It has the "tracks" that we need for GraphToGPUDB.
gpu_optimizer2 = EquilibriumDB()
gpu_seqopt = SequenceDB()
# do not add 'fast_run' to these two as this would always enable gpuarray mode
optdb.register(
"gpuarray_opt",
gpu_seqopt,
optdb.__position__.get("add_destroy_handler", 49.5) - 1,
"gpuarray",
)
pool_db = LocalGroupDB()
pool_db2 = LocalGroupDB(local_opt=GraphToGPULocalOptGroup)
pool_db2.__name__ = "pool_db2"
matrix_ops_db = LocalGroupDB()
matrix_ops_db2 = LocalGroupDB(local_opt=GraphToGPULocalOptGroup)
matrix_ops_db2.__name__ = "matrix_ops_db2"
abstract_batch_norm_db = LocalGroupDB()
abstract_batch_norm_db2 = LocalGroupDB(local_opt=GraphToGPULocalOptGroup)
abstract_batch_norm_db2.__name__ = "abstract_batch_norm_db2"
abstract_batch_norm_groupopt = LocalGroupDB()
abstract_batch_norm_groupopt.__name__ = "gpuarray_batchnorm_opts"
def register_opt(*tags, **kwargs):
def f(local_opt):
name = (kwargs and kwargs.pop("name")) or local_opt.__name__
gpu_optimizer.register(name, local_opt, "fast_run", "gpuarray", *tags)
return local_opt
return f
def register_opt2(tracks, *tags, **kwargs):
"""
Decorator for the new GraphToGPU optimizer.
Takes an extra parameter(Op) compared to register_opt decorator.
Parameters
----------
tracks : List of Op class Or Op instance or None
The Node's Op to which optimization is being applied.
tags : String
The optimization tag to which the optimizer will be registered.
"""
def f(local_opt):
name = (kwargs and kwargs.pop("name")) or local_opt.__name__
if isinstance(local_opt, DB):
opt = local_opt
else:
opt = local_optimizer(tracks)(local_opt)
gpu_optimizer2.register(name, opt, "fast_run", "gpuarray", *tags)
return local_opt
return f
def register_inplace(*tags, **kwargs):
def f(local_opt):
name = (kwargs and kwargs.pop("name")) or local_opt.__name__
optdb.register(
name,
TopoOptimizer(local_opt, failure_callback=TopoOptimizer.warn_inplace),
60,
"fast_run",
"inplace",
"gpuarray",
*tags,
)
return local_opt
return f
# Register GPU convolution implementation
# They are tried in a specific order so we can control
# which ones take precedence over others.
abstractconv_groupopt = LocalGroupDB()
abstractconv_groupopt.__name__ = "gpuarray_abstractconv_opts"
register_opt("fast_compile")(abstractconv_groupopt)
class GraphToGPUDB(DB):
"""
Retrieves the list local optimizers based on the optimizer flag's value
from EquilibriumOptimizer by calling the method query.
"""
def query(self, *tags, **kwtags):
from theano.gpuarray.opt import GraphToGPU
opt = gpu_optimizer2.query(*tags, **kwtags)
return GraphToGPU(opt.local_optimizers_all, opt.local_optimizers_map)
...@@ -5,14 +5,15 @@ from theano.scalar import bool as bool_t ...@@ -5,14 +5,15 @@ from theano.scalar import bool as bool_t
from theano.tensor.basic import as_tensor_variable from theano.tensor.basic import as_tensor_variable
from theano.tensor.signal.pool import Pool, PoolingMode_t from theano.tensor.signal.pool import Pool, PoolingMode_t
from .type import gpu_context_type
from .basic_ops import ( from .basic_ops import (
CGpuKernelBase, CGpuKernelBase,
infer_context_name,
gpuarray_helper_inc_dir,
as_gpuarray_variable, as_gpuarray_variable,
gpu_contiguous, gpu_contiguous,
gpuarray_helper_inc_dir,
infer_context_name,
) )
from .type import gpu_context_type
try: try:
import pygpu import pygpu
......
from theano.gof import Op, Apply from theano.gof import Apply, Op
from theano.gof.type import Generic from theano.gof.type import Generic
from .basic_ops import infer_context_name, as_gpuarray_variable, gpuarray_helper_inc_dir from .basic_ops import as_gpuarray_variable, gpuarray_helper_inc_dir, infer_context_name
from .type import GpuArrayType from .type import GpuArrayType
try: try:
import pygpu import pygpu
except ImportError: except ImportError:
......
...@@ -9,21 +9,21 @@ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html ...@@ -9,21 +9,21 @@ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html
from theano import Apply, tensor from theano import Apply, tensor
from theano.gof import local_optimizer from theano.gof import local_optimizer
from theano.sandbox.rng_mrg import mrg_uniform_base, mrg_uniform from theano.sandbox.rng_mrg import mrg_uniform, mrg_uniform_base
from theano.tensor import as_tensor_variable, get_vector_length
from theano.scalar import int32 as int_t from theano.scalar import int32 as int_t
from theano.tensor import as_tensor_variable, get_vector_length
from .basic_ops import ( from .basic_ops import (
GpuFromHost,
GpuKernelBase, GpuKernelBase,
Kernel, Kernel,
infer_context_name,
GpuFromHost,
host_from_gpu,
as_gpuarray_variable, as_gpuarray_variable,
host_from_gpu,
infer_context_name,
) )
from .type import GpuArrayType, gpu_context_type
from .fp16_help import write_w from .fp16_help import write_w
from .opt import register_opt, register_opt2 from .opt import register_opt, register_opt2
from .type import GpuArrayType, gpu_context_type
class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base): class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
......
...@@ -11,13 +11,14 @@ from theano.tensor.sort import TopKOp ...@@ -11,13 +11,14 @@ from theano.tensor.sort import TopKOp
from .basic_ops import ( from .basic_ops import (
GpuKernelBase, GpuKernelBase,
Kernel, Kernel,
infer_context_name,
as_gpuarray_variable, as_gpuarray_variable,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name,
) )
from .opt import register_opt, op_lifter, register_opt2 from .opt import op_lifter, register_opt, register_opt2
from .type import GpuArrayType from .type import GpuArrayType
try: try:
import pygpu import pygpu
import pygpu.gpuarray as ga import pygpu.gpuarray as ga
......
import numpy as np import numpy as np
import theano.tensor as tt
from six import integer_types from six import integer_types
from six.moves import StringIO from six.moves import StringIO
from theano import gof, Op import theano.tensor as tt
from theano import Op, gof
from theano.gof import ParamsType from theano.gof import ParamsType
from theano.gradient import grad_not_implemented from theano.gradient import grad_not_implemented
from theano.scalar import bool as bool_t
from theano.scalar import int32 as int_t
from theano.scalar import uint32 as size_t
from theano.tensor import AllocDiag from theano.tensor import AllocDiag
from theano.tensor.subtensor import ( from theano.tensor.subtensor import (
IncSubtensor,
AdvancedSubtensor,
Subtensor,
AdvancedIncSubtensor, AdvancedIncSubtensor,
AdvancedSubtensor,
AdvancedSubtensor1, AdvancedSubtensor1,
IncSubtensor,
Subtensor,
get_idx_list, get_idx_list,
) )
from theano.scalar import bool as bool_t, int32 as int_t, uint32 as size_t
try: try:
import pygpu import pygpu
...@@ -25,16 +26,17 @@ try: ...@@ -25,16 +26,17 @@ try:
except ImportError: except ImportError:
pass pass
from theano.gpuarray.type import GpuArrayType, gpu_context_type
from theano.gpuarray.basic_ops import ( from theano.gpuarray.basic_ops import (
as_gpuarray_variable,
HideC,
GpuKernelBase, GpuKernelBase,
HideC,
Kernel, Kernel,
as_gpuarray_variable,
gpu_contiguous,
gpuarray_helper_inc_dir, gpuarray_helper_inc_dir,
infer_context_name, infer_context_name,
gpu_contiguous,
) )
from theano.gpuarray.type import GpuArrayType, gpu_context_type
iadd_reg = {} iadd_reg = {}
......
import sys
import os import os
import sys
import warnings import warnings
import six.moves.copyreg as copyreg
import numpy as np import numpy as np
import six.moves.copyreg as copyreg
import theano import theano
from theano import Constant, Type, Variable, config, scalar, tensor
from theano.compile import SharedVariable
from theano.tensor.type import TensorType from theano.tensor.type import TensorType
from theano.tensor.var import _tensor_py_operators from theano.tensor.var import _tensor_py_operators
from theano import Type, Variable, Constant, tensor, config, scalar
from theano.compile import SharedVariable
# Make sure this is importable even if pygpu is absent # Make sure this is importable even if pygpu is absent
# (it will not work though) # (it will not work though)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论