目录

TransDataTo5HD

Function Description

Converts the NCHW format to the NC1HWC0 format. It can also be used for transposing a two-dimensional matrix data block. Compared with the Transpose API, the Transpose API supports only the transposition of 16 x 16 matrices. This API can process 512 bytes (16 data blocks) per repeat. It supports matrix transposition for various shapes depending on the data type. For example, a 16 x 16 matrix can be transposed within one repeat when the data type is half. Multiple repeat operations are also supported.

The conversion rules in a single repeat are as follows:

Based on the preceding conversion rules, this API is used to convert the NC1HWC0 format or transpose a matrix. The NC1HWC0 format conversion is complex. The following describes how to convert the format:

When the NCHW format is converted to the NC1HWC0 format, if the data type is float, int32_t, uint32_t, int16_t, uint16_t, or half, C0 is 16; if the data type is uint8_t or int8_t, C0 is 32. The following figure uses C0 = 16 as an example.

Figure 4 Conversion rule for converting the NCHW format to the NC1HWC0 format

Function Prototype

An array consisting of dstLocalList and srcLocalList of type LocalTensor:

// The value of NCHW_CONV_ADDR_LIST_SIZE is 16.
template <typename T> 
 __aicore__ inline void TransDataTo5HD(const LocalTensor<T> (&dstLocalList)[NCHW_CONV_ADDR_LIST_SIZE], const LocalTensor<T> (&srcLocalList)[NCHW_CONV_ADDR_LIST_SIZE], const TransDataTo5HDParams& nchwconvParams)

Parameters

Table 1 Template parameters

Parameter Description
T Operand data type.

Table 2 Parameters

Parameter Input/Output Description
dstLocalList/dstList Output

Address sequence of the destination operand.

The type is LocalTensor or the address value of the LocalTensor. The TPosition supported by the LocalTensor is VECIN, VECCALC, or VECOUT. The start address of the LocalTensor must be 32-byte aligned. For details about the supported data types, see Table 1.

srcLocalList/srcList Input

Address sequence of the source operand.

The type is LocalTensor or the address value of the LocalTensor. The TPosition supported by the LocalTensor is VECIN, VECCALC, or VECOUT. The start address of the LocalTensor must be 32-byte aligned. For details about the supported data types, see Table 1.

The data type must be the same as that of dstLocalList/dstList.

dstLocal Output

Destination operand.

The type is LocalTensor. The address value of the corresponding LocalTensor is stored continuously. The TPosition supported by the LocalTensor is VECIN/VECCALC/VECOUT. The start address of the LocalTensor must be 32-byte aligned.

srcLocal Input

Source operand.

The type is LocalTensor. The address value of the corresponding LocalTensor is stored continuously. The TPosition supported by the LocalTensor is VECIN/VECCALC/VECOUT. The start address of the LocalTensor must be 32-byte aligned.

nchwconvParams Input Data structure for controlling TransDataTo5HD. The structure contains parameters such as the control parameters of the read and write positions, number of iterations, and address stride between adjacent iterations. For details about the definition of this data structure, see Table 3.

Table 3 Parameters in the TransDataTo5HDParams structure

Parameter Type Description
dstHighHalf Input

A bool specifying whether to store the data of dstLocalList to the upper or lower half of the data block. Only the int8_t or uint8_t type is supported.

The supported data type is bool. The options are as follows:

- True: upper half

- False: lower half

srcHighHalf Input

A bool specifying whether to read the data of srcLocalList from the upper or lower half of the data block. Only the int8_t or uint8_t type is supported.

The supported data type is bool. The options are as follows:

- True: Data is read from the upper half of a data block.

- False: Data is read from the lower half of a data block.

Supported Models

Kirin 9020 series processors

Kirin 9030 series processors

Kirin X90 series processors

Precautions

Return Value

None

Calling Example