Constructor
Function Usage
Constructs a specified tensor object. The TensorV2 class is used to describe the information and behavior of a tensor object, including the shape, data format, data type, step, offset, and tensor data.
Prototype
1 2 3 4 5 | TensorV2() //Default constructor TensorV2 (const StorageShape &storage_shape, const StorageFormat &storage_format, const TensorPlacement placement, const ge::DataType data_type, TensorAddress addr) TensorV2(const StorageShape &storage_shape, const StorageFormat &storage_format, ge::DataType data_type) TensorV2(const StorageShape &storage_shape, const StorageFormat &storage_format, const TensorPlacement placement, const ge::DataType data_type, TensorAddress addr, TensorAddrManager manager) TensorV2(const StorageShape &storage_shape, const StorageFormat &storage_format, const TensorPlacement placement, const ge::DataType data_type, TensorAddress addr, TensorAddrManager manager, const Stride &stride, const int64_t offset) |
Parameters
Parameter |
Input/Output |
Description |
||
|---|---|---|---|---|
storage_shape |
Input |
Shape of a specified tensor. It is of the StorageShape type. |
||
storage_format |
Input |
Data format of a specified tensor. It is of the StorageFormat type. |
||
placement |
Input |
Location of the device where the actual tensor data is stored. It is of the TensorPlacement type. |
||
data_type |
Input |
Data type of a specified tensor. It is of the ge::DataType. |
||
addr |
Input |
Memory address that stores the actual tensor data. It is of the TensorAddress type, which is defined as follows:
|
||
manager |
Input |
Management function of the tensor data. If the value of manager is empty, addr is considered as the tensor data address and the data does not need to be deallocated.
|
||
stride |
Input |
Step of a specified tensor. It is of the Stride type. |
||
offset |
Input |
Offset of a specified tensor. It is of the int64_t type. |
Returns
An initialized tensor object
Constraints
The values of the members (such as format, shape, stride, and offset) in the tensor must be configured explicitly. Otherwise, the values are undefined.
The TensorV2 class cannot be integrated into a graph.
After a TensorV2 pointer is converted into a Tensor pointer, the tensor member function can be called.
Before converting a Tensor pointer to a TensorV2 pointer, you need to call GetVersion() to obtain the version. Only kTensorV2 supports the conversion.
Examples
1 2 3 4 5 | TensorV2 tensor{{{8, 3, 224, 224}, {16, 3, 224, 224}}, // shape {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, // format kFollowing, // placement ge::DT_FLOAT16, //dt nullptr}; |