aclInitTensor
Function Usage
Initializes the parameters of a specified aclTensor created by calling aclCreateTensor.
If you want to reuse an existing aclTensor, you can call this API to reset the aclTensor attributes.
Prototype
aclnnStatus aclInitTensor(aclTensor *tensor, const int64_t *viewDims, uint64_t viewDimsNum, aclDataType dataType, const int64_t *stride, int64_t offset, aclFormat format, const int64_t *storageDims, uint64_t storageDimsNum, void *tensorDataAddr)
Parameters
- aclDataType is an enumeration class of data types defined by the framework. For details, see "aclDataType".
- aclFormat is an enumeration class of data formats defined by the framework. For details, see "aclFormat".
- StorageShape and ViewShape of aclTensor:
- ViewShape indicates the logical shape of the tensor, which is the size of the tensor required for actual use.
- StorageShape indicates the actual physical layout shape of the tensor, which is the actual size of the tensor in the memory.
Examples:
- If StorageShape is [10, 20], the tensor is arranged in the memory based on [10, 20].
- If ViewShape is [2, 5, 20], the tensor can be considered as a data block [2, 5, 20] for operator use.
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
tensor |
Input |
aclTensor whose parameters are to be initialized. |
|
viewDims |
Input |
ViewShape dimension value of a tensor, which is a non-negative integer. |
|
viewDimsNum |
Input |
Number of ViewShape dimensions of the tensor. |
|
dataType |
Input |
Data type of the tensor. |
|
stride |
Input |
Access stride of elements in each dimension of the tensor, which is a non-negative integer. |
|
offset |
Input |
Offset of the first element of the tensor relative to storage, which is a non-negative integer. |
|
format |
Input |
Tensor format. |
|
storageDims |
Input |
StorageShape dimension value of the tensor, which is a non-negative integer. |
|
storageDimsNum |
Input |
Number of StorageShape dimensions of the tensor. |
|
tensorDataAddr |
Input |
Storage address of the tensor on the device. |
Returns
0 on success; else, failure. For details about the return codes, see Common APIs and Return Codes.
Constraints
None
Examples
The following code examples are for reference only and are not intended for direct copying and execution:
1 2 3 4 5 6 |
std::vector<int64_t> viewDims = {2, 4}; std::vector<int64_t> stride = {4, 1}; std::vector<int64_t> storageDims = {2, 4}; // The created aclTensor is reused as a tensor. // deviceAddr indicates the storage address of the tensor on the device. auto ret = aclInitTensor(tensor, viewDims.data(), viewDims.size(), ACL_FLOAT16, stride.data(), 0, aclFormat::ACL_FORMAT_ND, storageDims.data(), storageDims.size(), deviceAddr); |