aclInitTensor

Function Usage

Initializes the parameters of a given tensor.

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

  • The definitions of aclDataType and aclFormat are provided by AscendCL. For details, see aclDataType and aclFormat in Application Development APIs.
  • StorageShape and ViewShape of aclTensor:
    • ViewShape indicates the logical shape of the aclTensor, which is the size of the tensor required in actual use.
    • StorageShape indicates the actual physical layout shape of the aclTensor, which is the actual size of the tensor in the memory.

    An example is as follows:

    • If StorageShape is [10, 20], the aclTensor is arranged in the memory based on [10, 20].
    • If ViewShape is [2, 5, 20], when the operator is used, the aclTensor can be considered as a data block [2, 5, 20].

Parameter

Input/Output

Description

tensor

Input

Tensor whose parameters are to be initialized. It is created by the aclCreateTensor call.

viewDims

Input

ViewShape dimension value of a tensor.

viewDimsNum

Input

ViewShape dimension number of a tensor.

dataType

Input

Data type of a tensor.

stride

Input

Stride of each dimension of the tensor view. The value cannot be a negative number.

offset

Input

Offset of the first element of the tensor relative to storage.

format

Input

Tensor format.

storageDims

Input

StorageShape dimension value of a tensor.

storageDimsNum

Input

StorageShape dimension number of a tensor.

tensorDataAddr

Input

Storage address of a tensor on the device.

Returns

0 on success; else, failure.