Template Class FullTensorWrap

Class Documentation

template<typename T, int N>
class FullTensorWrap

FullTensorWrap class is a non-owning wrap of a N-D tensor used for easy access of its elements in CUDA device.

FullTensorWrap is a wrapper of a multi-dimensional tensor that holds all information related to it, i.e. N strides and N shapes, where N is its number of dimensions.

Template arguments:

  • T type of the values inside the tensor

  • N dimensions

FullTensor wrapper class specialized for non-constant value type.

Template Parameters:
  • T – Type (it can be const) of each element (or value) inside the tensor wrapper.

  • N – dimensions.

  • T – Type (non-const) of each element inside the tensor wrapper.

  • N – Number of dimensions.

Public Types

using ValueType = T

Public Functions

FullTensorWrap() = default
template<typename DataType> inline explicit __host__ __device__ FullTensorWrap (DataType *data, const int(&strides)[N], const int(&shapes)[N])

Constructs a FullTensorWrap by wrapping a data pointer argument.

Parameters:
  • data[in] Pointer to the data that will be wrapped

  • strides[in] Array of strides in bytes from first to last dimension.

  • shapes[in] Array of shapes (number of elements) from first to last dimension.

Template Parameters:

DataType – Type of (inferred from) the data pointer argument.

inline __host__ FullTensorWrap(const TensorDataStridedCuda &tensor)

Constructs a FullTensorWrap by wrapping a tensor argument.

Parameters:

tensor[in] Tensor reference to the tensor that will be wrapped.

template<typename DimType> inline __host__ __device__ T & operator[] (DimType c) const

Subscript operator for read-and-write access.

Parameters:

c[in] N-D coordinate (from last to first dimension) to be accessed.

Returns:

Accessed reference.

template<typename... Args> inline __host__ __device__ T * ptr (Args... c) const

Get a read-and-write proxy (as pointer) at the Dth dimension.

Parameters:

c0..D[in] Each coordinate from first to last dimension

Returns:

The pointer to the beginning of the Dth dimension

inline __host__ __device__ const int * strides () const

Get strides in bytes for read-only access.

Returns:

The const array (as a pointer) containing the strides in bytes.

inline __host__ __device__ const int * shapes () const

Get shapes for read-only access.

Returns:

The const array (as a pointer) containing the shapes.

Public Static Attributes

static constexpr int kConstantStrides
static constexpr int kNumDimensions
static constexpr int kVariableStrides

Protected Functions

template<typename... Args> inline __host__ __device__ T * doGetPtr (Args... c) const