Tensor Class Reference

Tensor Class Reference#

6 min read time

Applies to Linux

rocCV: roccv::Tensor Class Reference

#include <tensor.hpp>

Public Types

using Requirements = TensorRequirements
 

Public Member Functions

const eDeviceType device () const
 Returns the location (device or host) of the tensor data. More...
 
const DataTypedtype () const
 Returns the data type of the tensor. More...
 
TensorData exportData () const
 Exports the tensor data of the tensor. More...
 
template<typename DerivedTensorData >
DerivedTensorData exportData () const
 Exports tensor data and casts it to a specified tensor data object. More...
 
const TensorLayoutlayout () const
 Returns the layout of the tensor. More...
 
Tensoroperator= (const Tensor &other)
 
int rank () const
 Returns the rank of the tensor (i.e. the number of dimensions) More...
 
Tensor reshape (const TensorShape &new_shape) const
 Creates a view of this tensor with a new shape and layout. More...
 
Tensor reshape (const TensorShape &new_shape, const DataType &new_dtype) const
 Creates a vew of this tensor with a new shape, layout, and data type. The number of bytes allocated must match the original tensor. More...
 
const TensorShapeshape () const
 Returns the shape of the tensor. More...
 
const int64_t shape (int d) const &
 Retrieves a specific dimension size from the tensor shape. More...
 
 Tensor (const Tensor &other)=delete
 
 Tensor (const TensorRequirements &reqs)
 Constructs a Tensor object given a list of requirements. Creating a tensor through this constructor will automatically allocate the required amount of space on either the device or host. More...
 
 Tensor (const TensorRequirements &reqs, std::shared_ptr< TensorStorage > data)
 Constructs a Tensor object given a list of requirements and the underlying data as a TensorStorage pointer. This constructor will not automatically allocate data. More...
 
 Tensor (const TensorShape &shape, DataType dtype, const eDeviceType device=eDeviceType::GPU)
 Constructs a tensor object and allocates the appropriate amount of memory on the specified device. More...
 
 Tensor (int num_images, Size2D image_size, ImageFormat fmt, eDeviceType device=eDeviceType::GPU)
 Constructs a tensor using image-based requirements and allocates the appropriate amount of memory on the specified device. More...
 
 Tensor (Tensor &&other)
 

Static Public Member Functions

static Requirements CalcRequirements (const TensorShape &shape, DataType dtype, const eDeviceType device=eDeviceType::GPU)
 Calculates tensor requirements. This essentially wraps the provided parameters into a TensorRequirements object. More...
 
static Requirements CalcRequirements (int num_images, Size2D image_size, ImageFormat fmt, eDeviceType device=eDeviceType::GPU)
 Calculates tensor requirements using image-based parameters. More...
 

Member Typedef Documentation

◆ Requirements

Constructor & Destructor Documentation

◆ Tensor() [1/6]

roccv::Tensor::Tensor ( const TensorRequirements reqs)
explicit

Constructs a Tensor object given a list of requirements. Creating a tensor through this constructor will automatically allocate the required amount of space on either the device or host.

Parameters
[in]reqsAn object representing the requirements for this tensor.

◆ Tensor() [2/6]

roccv::Tensor::Tensor ( const TensorRequirements reqs,
std::shared_ptr< TensorStorage data 
)
explicit

Constructs a Tensor object given a list of requirements and the underlying data as a TensorStorage pointer. This constructor will not automatically allocate data.

Parameters
[in]reqsAn object representing the requirements for this tensor.
[in]dataA TensorStorage object for the tensor's underlying data.

◆ Tensor() [3/6]

roccv::Tensor::Tensor ( const TensorShape shape,
DataType  dtype,
const eDeviceType  device = eDeviceType::GPU 
)
explicit

Constructs a tensor object and allocates the appropriate amount of memory on the specified device.

Parameters
[in]shapeThe shape describing the tensor.
[in]dtypeThe underlying datatype of the tensor.
[in]deviceThe device the tensor should be allocated on.

◆ Tensor() [4/6]

roccv::Tensor::Tensor ( int  num_images,
Size2D  image_size,
ImageFormat  fmt,
eDeviceType  device = eDeviceType::GPU 
)
explicit

Constructs a tensor using image-based requirements and allocates the appropriate amount of memory on the specified device.

Parameters
[in]num_imagesThe number of images in the batch.
[in]image_sizeThe size for images in the batch.
[in]fmtThe format of the underlying image data.
[in]deviceThe device the tensor should be allocated on.

◆ Tensor() [5/6]

roccv::Tensor::Tensor ( const Tensor other)
delete

◆ Tensor() [6/6]

roccv::Tensor::Tensor ( Tensor &&  other)

Member Function Documentation

◆ CalcRequirements() [1/2]

static Requirements roccv::Tensor::CalcRequirements ( const TensorShape shape,
DataType  dtype,
const eDeviceType  device = eDeviceType::GPU 
)
static

Calculates tensor requirements. This essentially wraps the provided parameters into a TensorRequirements object.

Parameters
[in]shapeThe desired shape of the tensor.
[in]dtypeThe desired data type of the tensor's raw data.
[in]deviceThe deivce the tensor data should belong to.
Returns
A TensorRequirements object representing this tensor's requirements.

◆ CalcRequirements() [2/2]

static Requirements roccv::Tensor::CalcRequirements ( int  num_images,
Size2D  image_size,
ImageFormat  fmt,
eDeviceType  device = eDeviceType::GPU 
)
static

Calculates tensor requirements using image-based parameters.

Parameters
[in]num_imagesThe number of images in the batch.
[in]image_sizeThe size for images in the batch.
[in]fmtThe format of the underlying image data.
[in]deviceThe deivce the tensor data should belong to.
Returns
A TensorRequirements object representing the tensor's requirements.

◆ device()

const eDeviceType roccv::Tensor::device ( ) const

Returns the location (device or host) of the tensor data.

Returns
The location of the tensor data.

◆ dtype()

const DataType& roccv::Tensor::dtype ( ) const

Returns the data type of the tensor.

Returns
Data type of the tensor

◆ exportData() [1/2]

TensorData roccv::Tensor::exportData ( ) const

Exports the tensor data of the tensor.

Returns
Tensor data of the tensor

◆ exportData() [2/2]

template<typename DerivedTensorData >
DerivedTensorData roccv::Tensor::exportData ( ) const
inline

Exports tensor data and casts it to a specified tensor data object.

Template Parameters
Thetensor data object to cast this tensor's data to
Returns
The tensor data casted to the tensor data object specified

◆ layout()

const TensorLayout& roccv::Tensor::layout ( ) const

Returns the layout of the tensor.

Returns
Layout of the tensor

◆ operator=()

Tensor& roccv::Tensor::operator= ( const Tensor other)

◆ rank()

int roccv::Tensor::rank ( ) const

Returns the rank of the tensor (i.e. the number of dimensions)

Returns
An integer representing the rank of the tensor

◆ reshape() [1/2]

Tensor roccv::Tensor::reshape ( const TensorShape new_shape) const

Creates a view of this tensor with a new shape and layout.

Parameters
[in]new_shapethe new shape of the tensor
Returns
Tensor

◆ reshape() [2/2]

Tensor roccv::Tensor::reshape ( const TensorShape new_shape,
const DataType new_dtype 
) const

Creates a vew of this tensor with a new shape, layout, and data type. The number of bytes allocated must match the original tensor.

Parameters
new_shapeThe new tensor shape.
new_dtypeThe new data type of the underlying tensor data.
Returns
Tensor

◆ shape() [1/2]

const TensorShape& roccv::Tensor::shape ( ) const

Returns the shape of the tensor.

Returns
Shape of the tensor

◆ shape() [2/2]

const int64_t roccv::Tensor::shape ( int  d) const &

Retrieves a specific dimension size from the tensor shape.

Parameters
[in]dThe index of the dimension.
Returns
The size of the specified dimension.

The documentation for this class was generated from the following file:
  • /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/core/tensor.hpp