TensorWrap classes

group NVCV_CPP_CUDATOOLS_TENSORWRAP

Typedefs

template<typename T, int64_t... Strides>
using TensorWrap = TensorWrapT<T, int64_t, Strides...>
template<typename T, int32_t... Strides>
using TensorWrap32 = TensorWrapT<T, int32_t, Strides...>
template<typename T, typename StrideT, StrideT... Strides>
class TensorWrapT
#include <TensorWrap.hpp>

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

TensorWrap is a wrapper of a multi-dimensional tensor that can have one or more of its N dimension strides, or pitches, defined either at compile-time or at run-time. Each pitch in Strides represents the offset in bytes as a compile-time template parameter that will be applied from the first (slowest changing) dimension to the last (fastest changing) dimension of the tensor, in that order. Each dimension with run-time pitch is specified as -1 in the Strides template parameter.

Template arguments:

  • T type of the values inside the tensor

  • StrideT type of the stride used in the byte offset calculation

  • Strides sequence of compile- or run-time pitches (-1 indicates run-time)

    • Y compile-time pitches

    • X run-time pitches

    • N dimensions, where N = X + Y

For example, in the code below a wrap is defined for an NHWC 4D tensor where each sample image in N has a run-time image pitch (first -1 in template argument), and each row in H has a run-time row pitch (second -1), a pixel in W has a compile-time constant pitch as the size of the pixel type and a channel in C has also a compile-time constant pitch as the size of the channel type.

using DataType = ...;
using ChannelType = BaseType<DataType>;
using TensorWrap = TensorWrap<ChannelType, -1, -1, sizeof(DataType), sizeof(ChannelType)>;
std::byte *imageData = ...;
int imgStride = ...;
int rowStride = ...;
TensorWrap tensorWrap(imageData, imgStride, rowStride);
// Elements may be accessed via operator[] using an int4 argument.  They can also be accessed via pointer using
// the ptr method with up to 4 integer arguments.

Tensor wrapper class specialized for non-constant value type.

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

  • Strides – Each compile-time (use -1 for run-time) pitch in bytes from first to last dimension.

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

  • Strides – Each compile-time (use -1 for run-time) pitch in bytes from first to last dimension.

template<typename T, typename StrideT, StrideT... Strides>
class TensorWrapT<const T, StrideT, Strides...>
#include <TensorWrap.hpp>