A data format is used to describe the service semantics of the axes of a multi-dimensional tensor, indicating the physical layout format of data, such as 1D, 2D, 3D, 4D, and 5D. Generally, the specific formats need to be described in the convolutional neural network (CNN) APIs.
For details about the full data formats supported by aclTensor, see "Data Types and Operation APIs > aclFormat" in .
For details about the data format layout principles, see "Concepts, Principles, and Glossary" > "Neural Networks and Operators" > "Data Layout Format" in the .
Currently, most operator APIs support the ND data format. For example, aclnnAdd supports the ND format (that is, N-dimensional tensor, with contiguous layout in low dimensions first). For aclnnConvolution, which is a CNN API, the input aclTensor must be set to a format with service semantics, instead of the ND format. Operators of this type can perform computation only when the service semantics of the tensor are known. For example, in 2D convolution, the mapping between NCHW and tensor dimensions should be known.
[object Object]
When creating an aclTensor by calling the aclCreateTensor API, you need to set the data format based on the API service requirements. Currently, the supported data formats are as follows:
ACL_FORMAT_ND, ACL_FORMAT_NCHW, ACL_FORMAT_NHWC, ACL_FORMAT_HWCN, ACL_FORMAT_NDHWC, ACL_FORMAT_NCDHW, ACL_FORMAT_NC, ACL_FORMAT_NCL
For a non-ND tensor, the dimension requirements of the tensor are the same as those of format. See the following examples:
- 5D tensor: Must be ACL_FORMAT_NCDHW, ACL_FORMAT_NDHWC, or ACL_FORMAT_ND. (If the API parameter description does not specify that the ND format is supported, an error will be reported during API verification if ND is set.)
- 4D tensor: Must be ACL_FORMAT_NCHW, ACL_FORMAT_NHWC, ACL_FORMAT_HWCN, or ACL_FORMAT_ND.
- 3D tensor: Must be ACL_FORMAT_NCL or ACL_FORMAT_ND.
- 2D tensor: Must be ACL_FORMAT_NC or ACL_FORMAT_ND.
- Other tensors: Must be ACL_FORMAT_ND.
Besides the previously mentioned common data formats, additional formats are available, such as ACL_FORMAT_NC1HWC0, ACL_FORMAT_FRACTAL_Z, ACL_FORMAT_NC1HWC0_C04, ACL_FORMAT_FRACTAL_NZ, ACL_FORMAT_NDC1HWC0, and ACL_FORMAT_FRACTAL_Z_3D.
These are private formats of the NPU, and they are now not supported by most aclnn APIs. If an API declares its supported data formats, follow the actual description of the API.