TensorBase

Function Usage

TensorBase constructor, which is used to create a TensorBase object. Different constructors can be selected based on the input parameters.

If an exception indicating that the constructor fails to be executed due to memory exhaustion occurs, do not call subsequent member functions.

Prototype

TensorBase();
TensorBase(const MemoryData &memoryData, const bool &isBorrowed, const std::vector<uint32_t> &shape, const TensorDataType &type);
TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type, const MemoryData::MemoryType &bufferType, const int32_t &deviceId);
TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type, const int32_t &deviceId);
TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type);
TensorBase(const std::vector<uint32_t> &shape);
TensorBase(const TensorBase& tensor) = default;

Parameter Description

  • The prototypes 2, 3, 4, and 5 only preset the shape, but do not allocate the memory space. You need to call TensorBaseMalloc to allocate the corresponding memory space.
  • To use the prototype 1, allocate the external memory space, and then directly use the allocated memory to construct the tensor object. Ensure that the space size is the same as the shape of the tensor object and determine whether the externally allocated space is destroyed by the tensor object or by the user.

Parameter

Input/Output

Description

memoryData

Input

Memory management structure, which is used to construct the TensorBase object. For details, see MemoryData.

isBorrowed

Input

Whether the input memory data needs to be proactively destroyed by the tensor.

  • If the value is true, it indicates that the data is destroyed by the user.
  • If the value is false, it indicates that the data is destroyed during tensor destruction.

shape

Input

Tensor shape, which is used to construct the TensorBase object.

type

Input

Tensor data type, which is used to construct the TensorBase object. For details, see the enumerations of TensorDataType.

bufferType

Input

Memory type of the tensor data, which is used to construct the TensorBase object.

deviceId

Input

Device ID of the int type, which is used to construct the TensorBase object.

tensor

Input

TensorBase object, which is used to receive the constructed TensorBase object.