neon.backends.nervanagpu.GPUTensor

class neon.backends.nervanagpu.GPUTensor(backend, shape=None, dtype=<class 'numpy.float32'>, name=None, persist_values=True, allocator=<Boost.Python.function object at 0x2db4ca0>, base=None, gpudata=None, strides=None, take_array=None, is_trans=False, rounding=0)[source]

Bases: neon.backends.backend.Tensor

The n-dimensional array data structure that resides in GPU memory, and is meant to be manipulated on the GPU.

Parameters:
  • dtype (numpy.ndtype, optional) – Underlying data type of the elements.
  • allocator (function, optional) – Memory allocator.
  • base (GPUTensor, optional) – The base of the tensor. A tensor can have different views, this keep tracks of the original tensor.
  • gpudata (pycuda._driver.DeviceAllocation, optional) – The actual gpu memory that stores the tensor.
  • strides (tuple, optional) – Tuple of bytes to step in each dimension when traversing an array.
  • take_array – The indices of the values to extract.
  • is_trans (bool, optional) – Whether the tensor is transposed or not.
  • rounding (int, optional) – Set to desired number of mantissa bits to stochasicaly round, to set to zero to disable stochastic rouding.

See also

NervanaGPU class

Notes

Unlike numpy, in this implementation we never collapse dimensions, and the minimal number of dimensions will be _min_dims (currently set to 2 to match cudanet GPU implementation). So a wrapped scalar will have dimension 1x1.

__init__(backend, shape=None, dtype=<class 'numpy.float32'>, name=None, persist_values=True, allocator=<Boost.Python.function object at 0x2db4ca0>, base=None, gpudata=None, strides=None, take_array=None, is_trans=False, rounding=0)[source]

Methods

__init__(backend[, shape, dtype, name, …])
asbuffer() Returns buffer interface to gpu data.
asnumpyarray() Deprecated.
copy(a) Construct and return a deep copy of the Tensor passed.
copy_from(a) Alias of copy.
dimension_reorder(new_order) Re-orders dimensions of a tensor without preserving data
fill(value) Assign specified value to each element of this GPUTensor.
get([stream]) Copy device array to host.
hist(tag) Compute a histogram of the current tensor values.
raw() Access the raw buffer.
reshape(*shape) Return a reshaped view.
set(ary) Copy host array to device.
share(shape[, dtype, name]) Return a view: ary, where ary.size <= self.size.
take(indices, axis[, out]) Take elements from an array along an axis.
transpose([out]) Return a transposed view of the data.
T

Return a transposed view.

asbuffer()[source]

Returns buffer interface to gpu data.

asnumpyarray()[source]

Deprecated. Scheduled to be removed in 2.0. Use get() instead.

copy(a)[source]

Construct and return a deep copy of the Tensor passed.

Arguments:
a (Tensor): the object to copy
Returns:updated view of the data.
Return type:GPUTensor
copy_from(a)[source]

Alias of copy.

Parameters:a (Tensor) – the object to copy
Returns:updated view of the data.
Return type:GPUTensor
dimension_reorder(new_order)

Re-orders dimensions of a tensor without preserving data

Parameters:new_order (list) – new order of dimensions
fill(value)[source]

Assign specified value to each element of this GPUTensor.

Parameters:value (numeric) – The value to be assigned to each element.
Returns:updated view of the data.
Return type:GPUTensor
get(stream=None)[source]

Copy device array to host.

Returns:A host numpy array
Return type:numpy.ndarray
hist(tag)[source]

Compute a histogram of the current tensor values.

Parameters:tag (string) – Tag to identify the current state of the tensor, useful for disambiguating multiple histograms of the same tensor at different points in time.
Returns:Tensor containing the histogram data.
is_contiguous

Returns whether the memory of the tensor is contiguous.

Return
bool: Whether the memory of the tensor is contiguous.
ptr

Returns an integer representation of the underlying gpu memory buffer.

Returns:The int representation
Return type:int
raw()[source]

Access the raw buffer.

Returns:A device specific pointer
Return type:pointer
reshape(*shape)[source]

Return a reshaped view.

set(ary)[source]

Copy host array to device.

Parameters:ary – host array, needs to be contiguous
Returns:self
Return type:GPUTensor
share(shape, dtype=None, name=None)[source]

Return a view: ary, where ary.size <= self.size. Allows easy sharing of temporary memory

take(indices, axis, out=None)[source]

Take elements from an array along an axis.

Parameters:
  • indices (Tensor, numpy ndarray) – indicies of elements to select
  • axis (int) – axis across which to select the values
  • out (Tensor) – Output Tensor to fill with selected values
transpose(out=None)[source]

Return a transposed view of the data. Alias of .T property needed for MOP compatibility.