Tensor Constructor
Description
Constructs a specified tensor object. The Tensor class is used to describe the information and behavior of a tensor object, including the shape, format, datatype, and tensor data.
Prototype
Tensor() //Default constructor
Tensor (const StorageShape &storage_shape, const StorageFormat &storage_format, const TensorPlacement placement, const ge::DataType data_type, TensorAddress addr)
Tensor(const StorageShape &storage_shape, const StorageFormat &storage_format, ge::DataType data_type)
Tensor(const StorageShape &storage_shape, const StorageFormat &storage_format, const TensorPlacement placement, const ge::DataType data_type, TensorAddress addr, TensorAddrManager manager)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
storage_shape |
Input |
Shape information of a specified tensor. |
storage_format |
Input |
Format information of a specified tensor. |
placement |
Input |
Location of the device where the actual tensor data is stored. |
data_type |
Input |
Data type of a specified tensor. |
addr |
Input |
Memory address that stores the actual tensor data. |
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. using TensorAddrManager = ge::graphStatus (*)(TensorAddress addr, TensorOperateType operate_type, void **out);
enum TensorOperateType {
kGetTensorAddress, ///< Obtain the tensor address.
kFreeTensor, ///< Free the tensor.
kPlusShareCount, ///< Share the tensor.
kTensorOperateType
};
|
Returns
An initialized tensor object
Restrictions
The values of the members (such as format and shape) in the tensor must be displayed. Otherwise, the values are undefined.
Example
Tensor 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};