TensorBase
Function Usage
Functions as the TensorBase constructor, which is used to create TensorBase objects. Different constructors can be selected based on the passed parameters.
If an exception indicating that the constructor fails to be executed due to memory exhaustion occurs, do not call subsequent member functions.
Prototype
Prototype 1:
1 | TensorBase::TensorBase(); |
Prototype 2:
1 | TensorBase::TensorBase(const MemoryData &memoryData, const bool &isBorrowed, const std::vector<uint32_t> &shape, const TensorDataType &type); |
Prototype 3:
TensorBase::TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type, const MemoryData::MemoryType &bufferType, const int32_t &deviceId);
Prototype 4:
1 | TensorBase::TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type, const int32_t &deviceId); |
Prototype 5:
1 | TensorBase::TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type); |
Prototype 6:
1 | TensorBase::TensorBase(const std::vector<uint32_t> &shape); |
Prototype 7:
1 | TensorBase::TensorBase(const TensorBase& tensor) = default; |
Parameters
- The prototypes 3, 4, 5, and 6 only preset the shapes, but do not allocate the memory spaces. You need to call TensorBaseMalloc to allocate the corresponding memory space.
- To use the prototype 2, 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, a parameter 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.
|
shape |
Input |
Tensor shape, a parameter used to construct the TensorBase object. |
type |
Input |
Tensor data type, a parameter used to construct the TensorBase object. For details, see the enumerations of TensorDataType. |
bufferType |
Input |
Memory type of the tensor data, a parameter used to construct the TensorBase object. |
deviceId |
Input |
Device ID of the int type, a parameter used to construct the TensorBase object. |
tensor |
Input |
TensorBase object, a parameter used to construct the TensorBase object. |