List of gpuarray Ops implemented

Normally you should not call directly those Ops! Theano should automatically transform cpu ops to their gpu equivalent. So this list is just useful to let people know what is implemented on the gpu.

Basic Op

class theano.gpuarray.basic_ops.CGpuKernelBase(func_files, func_name=None)[source]

Class to combine GpuKernelBase and COp.

It adds a new section type ‘kernels’ where you can define kernels with the ‘#kernel’ tag

class theano.gpuarray.basic_ops.GpuAlloc(context_name, memset_0=False)[source]

Allocate initialized memory on the GPU.

Parameters:
  • context_name (str) – The name of the context in which to allocate memory
  • memset_0 (bool) – It’s only an optimized version. True, it means the value is always 0, so the c code call memset as it is faster.
class theano.gpuarray.basic_ops.GpuAllocEmpty(dtype, context_name)[source]

Allocate uninitialized memory on the GPU.

class theano.gpuarray.basic_ops.GpuContiguous[source]

Return a C contiguous version of the input.

This may either pass the object as-is (if already C contiguous) or make a copy.

class theano.gpuarray.basic_ops.GpuEye(dtype=None, context_name=None)[source]

Eye for GPU.

class theano.gpuarray.basic_ops.GpuFromHost(context_name)[source]

Transfer data to GPU.

class theano.gpuarray.basic_ops.GpuJoin(view=-1)[source]

Join for GPU.

class theano.gpuarray.basic_ops.GpuKernelBase[source]

Base class for operations that need to compile kernels.

It is not mandatory to use this class, but it helps with a lot of the small things that you have to pay attention to.

gpu_kernels(node, name)[source]

This is the method to override. This should return an iterable of Kernel objects that describe the kernels this op will need.

kernel_version(node)[source]

If you override c_code_cache_version_apply(), call this method to have the version of the kernel support code and device.

Parameters:node (apply node) – The node that we need the cache version for.
class theano.gpuarray.basic_ops.GpuReshape(ndim, name=None)[source]

Reshape for GPU variables.

class theano.gpuarray.basic_ops.GpuSplit(len_splits)[source]

Split for GPU.

class theano.gpuarray.basic_ops.GpuToGpu(context_name)[source]

Transfer data between GPUs.

class theano.gpuarray.basic_ops.HostFromGpu[source]

Transfer data to CPU.

class theano.gpuarray.basic_ops.Kernel(code, params, name, flags, codevar=None, binvar=None, objvar=None, fname=None, sname=None)[source]

This class groups together all the attributes of a gpu kernel.

params should contain the data type for each argument. Buffer arguments should use the GpuArray class as the data type and scalar should use their equivalent numpy dtype. For ga_size and ga_ssize, use gpuarray.SIZE and gpuarray.SSIZE.

If the ctypes flags is set to True then it should be a C string which represent the typecode to use.

flags can contain the following keys whose values are booleans:

have_double
the kernel uses double-typed variables somewhere
have_small
the kernel uses variables whose type takes less than 4 bytes somewhere
have_complex
the kernel uses complex values somewhere
have_half
the kernel uses half-floats somewhere
ctypes
the params list consists of C typecodes

It can also have the key cflags which is a string of C flag values like this “GA_USE_DOUBLE|GA_USE_CLUDA”.

Parameters:
  • code (str) – The source code of the kernel.
  • params (list) – list of parameter types.
  • name (str) – the name of the kernel function in the source.
  • flags (dict) – dictionary of flags
  • codevar (str) – the name of the variable for the code object. (defaults to kcode_ + name)
  • binvar (str) – the name of the variable for the binary object. (defaults to kbin_ + name)
  • objvar (str) – the name of the variable for the kernel object. (defaults to k_ + name)
  • fname (str) – the name of the function wrapper. (defaults to name + _call)
  • sname (str) – the name of the scheduled call function (defaults to name _ _scall)
theano.gpuarray.basic_ops.as_gpuarray_variable(x, context_name)[source]

This will attempt to convert x into a variable on the GPU.

It can take either a value of another variable. If x is already suitable, it will be returned as-is.

Parameters:
  • x – Object to convert
  • context_name (str or None) – target context name for the result
theano.gpuarray.basic_ops.infer_context_name(*vars)[source]

Infer the context name to use from the inputs given

Blas Op

class theano.gpuarray.blas.BaseGpuCorr3dMM(border_mode='valid', subsample=(1, 1, 1), filter_dilation=(1, 1, 1))[source]

Base class for GpuCorr3dMM, GpuCorr3dMM_gradWeights and GpuCorr3dMM_gradInputs. Cannot be used directly.

Parameters:
  • border_mode ({'valid', 'full', 'half'}) – Additionally, the padding size could be directly specified by an integer or a pair of integers
  • subsample – Perform subsampling of the output (default: (1, 1, 1)).
  • filter_dilation – Perform subsampling of the input, also known as dilation (default: (1, 1, 1)).
c_code_helper(bottom, weights, top, direction, sub, height=None, width=None, depth=None)[source]

This generates the C code for GpuCorr3dMM (direction=”forward”), GpuCorr3dMM_gradWeights (direction=”backprop weights”), and GpuCorr3dMM_gradInputs (direction=”backprop inputs”). Depending on the direction, one of bottom, weights, top will receive the output, while the other two serve as inputs.

Parameters:
  • bottom – Variable name of the input images in the forward pass, or the gradient of the input images in backprop wrt. inputs
  • weights – Variable name of the filters in the forward pass, or the gradient of the filters in backprop wrt. weights
  • top – Variable name of the output images / feature maps in the forward pass, or the gradient of the outputs in the backprop passes
  • direction ({'forward', 'backprop weights', 'backprop inputs'}) – “forward” to correlate bottom with weights and store results in top, “backprop weights” to do a valid convolution of bottom with top (swapping the first two dimensions) and store results in weights, and “backprop inputs” to do a full convolution of top with weights (swapping the first two dimensions) and store results in bottom.
  • sub – Dictionary of substitutions useable to help generating the C code.
  • height – Required if self.subsample[0] != 1, a variable giving the height of the filters for direction=”backprop weights” or the height of the input images for direction=”backprop inputs”. Required if self.border_mode == ‘half’, a variable giving the height of the filters for direction=”backprop weights”. Not required otherwise, but if a value is given this will be checked.
  • width – Required if self.subsample[1] != 1, a variable giving the width of the filters for direction=”backprop weights” or the width of the input images for direction=”backprop inputs”. Required if self.border_mode == ‘half’, a variable giving the width of the filters for direction=”backprop weights”. Not required otherwise, but if a value is given this will be checked.
  • depth – Required if self.subsample[2] != 1, a variable giving the depth of the filters for direction=”backprop weights” or the depth of the input images for direction=”backprop inputs”. Required if self.border_mode == ‘half’, a variable giving the depth of the filters for direction=”backprop weights”. Not required otherwise, but if a value is given this will be checked.
flops(inp, outp)[source]

Useful with the hack in profilemode to print the MFlops.

class theano.gpuarray.blas.BaseGpuCorrMM(border_mode='valid', subsample=(1, 1), filter_dilation=(1, 1))[source]

Base class for GpuCorrMM, GpuCorrMM_gradWeights and GpuCorrMM_gradInputs. Cannot be used directly.

Parameters:
  • border_mode ({'valid', 'full', 'half'}) – Additionally, the padding size could be directly specified by an integer or a pair of integers
  • subsample – Perform subsampling of the output (default: (1, 1)).
  • filter_dilation – Perform subsampling of the input, also known as dilation (default: (1, 1)).
c_code_helper(bottom, weights, top, direction, sub, height=None, width=None)[source]

This generates the C code for GpuCorrMM (direction=”forward”), GpuCorrMM_gradWeights (direction=”backprop weights”), and GpuCorrMM_gradInputs (direction=”backprop inputs”). Depending on the direction, one of bottom, weights, top will receive the output, while the other two serve as inputs.

Parameters:
  • bottom – Variable name of the input images in the forward pass, or the gradient of the input images in backprop wrt. inputs
  • weights – Variable name of the filters in the forward pass, or the gradient of the filters in backprop wrt. weights
  • top – Variable name of the output images / feature maps in the forward pass, or the gradient of the outputs in the backprop passes
  • direction ({'forward', 'backprop weights', 'backprop inputs'}) – “forward” to correlate bottom with weights and store results in top, “backprop weights” to do a valid convolution of bottom with top (swapping the first two dimensions) and store results in weights, and “backprop inputs” to do a full convolution of top with weights (swapping the first two dimensions) and store results in bottom.
  • sub – Dictionary of substitutions useable to help generating the C code.
  • height – Required if self.subsample[0] != 1, a variable giving the height of the filters for direction=”backprop weights” or the height of the input images for direction=”backprop inputs”. Required if self.border_mode == ‘half’, a variable giving the height of the filters for direction=”backprop weights”. Not required otherwise, but if a value is given this will be checked.
  • width – Required if self.subsample[1] != 1, a variable giving the width of the filters for direction=”backprop weights” or the width of the input images for direction=”backprop inputs”. Required if self.border_mode == ‘half’, a variable giving the width of the filters for direction=”backprop weights”. Not required otherwise, but if a value is given this will be checked.
flops(inp, outp)[source]

Useful with the hack in profilemode to print the MFlops.

class theano.gpuarray.blas.GpuCorr3dMM(border_mode='valid', subsample=(1, 1, 1), filter_dilation=(1, 1, 1))[source]

GPU correlation implementation using Matrix Multiplication.

Parameters:
  • border_mode – The width of a border of implicit zeros to pad the input with. Must be a tuple with 3 elements giving the width of the padding on each side, or a single integer to pad the same on all sides, or a string shortcut setting the padding at runtime: 'valid' for (0, 0, 0) (valid convolution, no padding), 'full' for (kernel_rows - 1, kernel_columns - 1, kernel_depth - 1) (full convolution), 'half' for (kernel_rows // 2, kernel_columns // 2, kernel_depth // 2) (same convolution for odd-sized kernels). Note that the three widths are each applied twice, once per side (left and right, top and bottom, front and back).
  • subsample – The subsample operation applied to each output image. Should be a tuple with 3 elements. (sv, sh, sl) is equivalent to GpuCorrMM(...)(...)[:,:,::sv, ::sh, ::sl], but faster. Set to (1, 1, 1) to disable subsampling.
  • filter_dilation – The filter dilation operation applied to each input image. Should be a tuple with 3 elements. Set to (1, 1, 1) to disable filter dilation.

Notes

Currently, the Op requires the inputs, filters and outputs to be C-contiguous. Use gpu_contiguous on these arguments if needed.

You can either enable the Theano flag optimizer_including=conv_gemm to automatically replace all convolution operations with GpuCorr3dMM or one of its gradients, or you can use it as a replacement for conv2d, called as GpuCorr3dMM(subsample=...)(image, filters). The latter is currently faster, but note that it computes a correlation – if you need to compute a convolution, flip the filters as filters[:,:,::-1,::-1,::-1].

class theano.gpuarray.blas.GpuCorr3dMM_gradInputs(border_mode='valid', subsample=(1, 1, 1), filter_dilation=(1, 1, 1))[source]

Gradient wrt. inputs for GpuCorr3dMM.

Notes

You will not want to use this directly, but rely on Theano’s automatic differentiation or graph optimization to use it as needed.

class theano.gpuarray.blas.GpuCorr3dMM_gradWeights(border_mode='valid', subsample=(1, 1, 1), filter_dilation=(1, 1, 1))[source]

Gradient wrt. filters for GpuCorr3dMM.

Notes

You will not want to use this directly, but rely on Theano’s automatic differentiation or graph optimization to use it as needed.

class theano.gpuarray.blas.GpuCorrMM(border_mode='valid', subsample=(1, 1), filter_dilation=(1, 1))[source]

GPU correlation implementation using Matrix Multiplication.

Parameters:
  • border_mode – The width of a border of implicit zeros to pad the input with. Must be a tuple with 2 elements giving the numbers of rows and columns to pad on each side, or a single integer to pad the same on all sides, or a string shortcut setting the padding at runtime: 'valid' for (0, 0) (valid convolution, no padding), 'full' for (kernel_rows - 1, kernel_columns - 1) (full convolution), 'half' for (kernel_rows // 2, kernel_columns // 2) (same convolution for odd-sized kernels). Note that the two widths are each applied twice, once per side (left and right, top and bottom).
  • subsample – The subsample operation applied to each output image. Should be a tuple with 2 elements. (sv, sh) is equivalent to GpuCorrMM(...)(...)[:,:,::sv, ::sh], but faster. Set to (1, 1) to disable subsampling.
  • filter_dilation – The filter dilation operation applied to each input image. Should be a tuple with 2 elements. Set to (1, 1) to disable filter dilation.

Notes

Currently, the Op requires the inputs, filters and outputs to be C-contiguous. Use gpu_contiguous on these arguments if needed.

You can either enable the Theano flag optimizer_including=conv_gemm to automatically replace all convolution operations with GpuCorrMM or one of its gradients, or you can use it as a replacement for conv2d, called as GpuCorrMM(subsample=...)(image, filters). The latter is currently faster, but note that it computes a correlation – if you need to compute a convolution, flip the filters as filters[:,:,::-1,::-1].

class theano.gpuarray.blas.GpuCorrMM_gradInputs(border_mode='valid', subsample=(1, 1), filter_dilation=(1, 1))[source]

Gradient wrt. inputs for GpuCorrMM.

Notes

You will not want to use this directly, but rely on Theano’s automatic differentiation or graph optimization to use it as needed.

class theano.gpuarray.blas.GpuCorrMM_gradWeights(border_mode='valid', subsample=(1, 1), filter_dilation=(1, 1))[source]

Gradient wrt. filters for GpuCorrMM.

Notes

You will not want to use this directly, but rely on Theano’s automatic differentiation or graph optimization to use it as needed.

class theano.gpuarray.blas.GpuDot22[source]

Dot22 on the GPU.

class theano.gpuarray.blas.GpuGemm(inplace=False)[source]

Gemm on the GPU.

class theano.gpuarray.blas.GpuGemv(inplace=False)[source]

Gemv on the GPU.

class theano.gpuarray.blas.GpuGer(inplace=False)[source]

Ger on the GPU.

class theano.gpuarray.nerv.Gemm16(relu=False, inplace=False)[source]

Gemm for float16 using the nervena kernels.

Elemwise Op

theano.gpuarray.elemwise.GpuCAReduce[source]

alias of GpuCAReduceCPY

class theano.gpuarray.elemwise.GpuCAReduceCPY(scalar_op, axis=None, dtype=None, acc_dtype=None)[source]

CAReduce that reuse the python code from gpuarray.

class theano.gpuarray.elemwise.GpuCAReduceCuda(scalar_op, axis=None, reduce_mask=None, dtype=None, acc_dtype=None, pre_scalar_op=None)[source]

GpuCAReduceCuda is a Reduction along some dimensions by a scalar op.

Parameters:
  • reduce_mask – The dimensions along which to reduce. The reduce_mask is a tuple of booleans (actually integers 0 or 1) that specify for each input dimension, whether to reduce it (1) or not (0).
  • pre_scalar_op – If present, must be a scalar op with only 1 input. We will execute it on the input value before reduction.

Examples

When scalar_op is a theano.scalar.basic.Add instance:

  • reduce_mask == (1,) sums a vector to a scalar
  • reduce_mask == (1,0) computes the sum of each column in a matrix
  • reduce_mask == (0,1) computes the sum of each row in a matrix
  • reduce_mask == (1,1,1) computes the sum of all elements in a 3-tensor.

Notes

Any reduce_mask of all zeros is a sort of ‘copy’, and may be removed during graph optimization.

This Op is a work in progress.

This op was recently upgraded from just GpuSum a general CAReduce. Not many code cases are supported for scalar_op being anything other than scalar.Add instances yet.

Important note: if you implement new cases for this op, be sure to benchmark them and make sure that they actually result in a speedup. GPUs are not especially well-suited to reduction operations so it is quite possible that the GPU might be slower for some cases.

c_code_reduce_01X(sio, node, name, x, z, fail, N)[source]
Parameters:N – The number of 1 in the pattern N=1 -> 01, N=2 -> 011 N=3 ->0111 Work for N=1,2,3.
supports_c_code(inputs)[source]

Returns True if the current op and reduce pattern has functioning C code.

class theano.gpuarray.elemwise.GpuDimShuffle(input_broadcastable, new_order, inplace=True)[source]

DimShuffle on the GPU.

class theano.gpuarray.elemwise.GpuElemwise(scalar_op, inplace_pattern=None, name=None, nfunc_spec=None, openmp=None)[source]

Elemwise on the GPU.

perform(node, inputs, output_storage, params=None)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
  • node (Apply instance) – Contains the symbolic inputs and outputs.
  • inputs (list) – Sequence of inputs (immutable).
  • output_storage (list) – List of mutable 1-element lists (do not change the length of these lists)

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

Raises:MethodNotDefined – The subclass does not override this method.
class theano.gpuarray.elemwise.GpuErfcinv(output_types_preference=None, name=None)[source]

Inverse complementary error function for GPU.

class theano.gpuarray.elemwise.GpuErfinv(output_types_preference=None, name=None)[source]

Inverse error function for GPU.

exception theano.gpuarray.elemwise.SupportCodeError[source]

We do not support certain things (such as the C++ complex struct).

theano.gpuarray.elemwise.max_inputs_to_GpuElemwise(node_or_outputs)[source]

Compute the maximum number of inputs that fit in a kernel call.

Subtensor Op

class theano.gpuarray.subtensor.GpuAdvancedIncSubtensor1(inplace=False, set_instead_of_inc=False)[source]

Implement AdvancedIncSubtensor1 on the gpu.

class theano.gpuarray.subtensor.GpuAdvancedIncSubtensor1_dev20(inplace=False, set_instead_of_inc=False)[source]

Implement AdvancedIncSubtensor1 on the gpu, but use function only avail on compute capability 2.0 and more recent.

make_node(x, y, ilist)[source]

It differs from GpuAdvancedIncSubtensor1 in that it makes sure the indexes are of type long.

class theano.gpuarray.subtensor.GpuAdvancedSubtensor[source]

AdvancedSubtensor On the GPU.

class theano.gpuarray.subtensor.GpuAdvancedSubtensor1(sparse_grad=False)[source]

AdvancedSubrensor1 on the GPU.

class theano.gpuarray.subtensor.GpuIncSubtensor(idx_list, inplace=False, set_instead_of_inc=False, destroyhandler_tolerate_aliased=None)[source]

Implement IncSubtensor on the gpu.

Notes

The optimization to make this inplace is in tensor/opt. The same optimization handles IncSubtensor and GpuIncSubtensor. This Op has c_code too; it inherits tensor.IncSubtensor’s c_code. The helper methods like do_type_checking(), copy_of_x(), etc. specialize the c_code for this Op.

copy_into(view, source)[source]
Parameters:
  • view (string) – C code expression for an array.
  • source (string) – C code expression for an array.
Returns:

C code expression to copy source into view, and 0 on success.

Return type:

str

copy_of_x(x)[source]
Parameters:x – A string giving the name of a C variable pointing to an array.
Returns:C code expression to make a copy of x.
Return type:str

Notes

Base class uses PyArrayObject *, subclasses may override for different types of arrays.

do_type_checking(node)[source]

Should raise NotImplementedError if c_code does not support the types involved in this node.

get_helper_c_code_args()[source]

Return a dictionary of arguments to use with helper_c_code.

make_view_array(x, view_ndim)[source]

//TODO

Parameters:
  • x – A string identifying an array to be viewed.
  • view_ndim – A string specifying the number of dimensions to have in the view. This doesn’t need to actually set up the view with the right indexing; we’ll do that manually later.
class theano.gpuarray.subtensor.GpuSubtensor(idx_list)[source]

Subtensor on the GPU.

Nnet Op

class theano.gpuarray.nnet.GpuCrossentropySoftmax1HotWithBiasDx[source]

Implement CrossentropySoftmax1HotWithBiasDx on the gpu.

Gradient wrt x of the CrossentropySoftmax1Hot Op.

class theano.gpuarray.nnet.GpuCrossentropySoftmaxArgmax1HotWithBias[source]

Implement CrossentropySoftmaxArgmax1HotWithBias on the gpu.

class theano.gpuarray.nnet.GpuSoftmax[source]

Implement Softmax on the gpu.

class theano.gpuarray.nnet.GpuSoftmaxWithBias[source]

Implement SoftmaxWithBias on the gpu.

class theano.gpuarray.neighbours.GpuImages2Neibs(mode='valid')[source]

Images2Neibs for the GPU.