Tensor Class Reference#
6 min read time
#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 DataType & | dtype () 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 TensorLayout & | layout () const |
Returns the layout of the tensor. More... | |
Tensor & | operator= (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 TensorShape & | shape () 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]
|
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] reqs An object representing the requirements for this tensor.
◆ Tensor() [2/6]
|
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] reqs An object representing the requirements for this tensor. [in] data A TensorStorage object for the tensor's underlying data.
◆ Tensor() [3/6]
|
explicit |
Constructs a tensor object and allocates the appropriate amount of memory on the specified device.
- Parameters
-
[in] shape The shape describing the tensor. [in] dtype The underlying datatype of the tensor. [in] device The device the tensor should be allocated on.
◆ Tensor() [4/6]
|
explicit |
Constructs a tensor using image-based requirements and allocates the appropriate amount of memory on the specified device.
- Parameters
-
[in] num_images The number of images in the batch. [in] image_size The size for images in the batch. [in] fmt The format of the underlying image data. [in] device The device the tensor should be allocated on.
◆ Tensor() [5/6]
|
delete |
◆ Tensor() [6/6]
roccv::Tensor::Tensor | ( | Tensor && | other | ) |
Member Function Documentation
◆ CalcRequirements() [1/2]
|
static |
Calculates tensor requirements. This essentially wraps the provided parameters into a TensorRequirements object.
- Parameters
-
[in] shape The desired shape of the tensor. [in] dtype The desired data type of the tensor's raw data. [in] device The deivce the tensor data should belong to.
- Returns
- A TensorRequirements object representing this tensor's requirements.
◆ CalcRequirements() [2/2]
|
static |
Calculates tensor requirements using image-based parameters.
- Parameters
-
[in] num_images The number of images in the batch. [in] image_size The size for images in the batch. [in] fmt The format of the underlying image data. [in] device The 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]
|
inline |
Exports tensor data and casts it to a specified tensor data object.
- Template Parameters
-
The tensor 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=()
◆ 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_shape the 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_shape The new tensor shape. new_dtype The 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] d The 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