目录

Transpose

Function Description

Function Prototype

Parameters

Table 1 Template parameters

Parameter Description
T

Operand data type.

Common transpose API:

For Kirin 9020, Kirin 9030, and Kirin X90 series processors, the supported data types include: half, int16_t, and uint16_t.

Enhanced transpose API:

For details, see Table 4.

Table 2 API parameters

Parameter Input/Output Description
dstLocal Output

Destination operand.

The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT.

The start address of the LocalTensor must be 32-byte aligned.

srcLocal Input

Source operand

The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT.

The start address of the LocalTensor must be 32-byte aligned.

The data type must be the same as that of dstLocal.

sharedTmpBuffer Input For the size of the shared temporary Buffer Tensor and sharedTmpBuffer, see Table 5.
transposeParams Input Data structure for controlling Transpose. The structure contains the input shape information and the transposeType parameter. For details about the definition of this data structure, see Table 3.

Table 3 Parameters in the transposeParams structure

Parameter Description
nSize Length of the n axis. Value range: m ∈ [0, 65535]. The default value is 0.
cSize Length of the c axis. Value range: m ∈ [0, 65535]. The default value is 0.
hSize Length of the h axis. Value range: m ∈ [0, 65535]. The default value is 0.
wSize Length of the w axis. Value range: m ∈ [0, 65535]. The default value is 0.
transposeType

Data layout and reshape type. The type is the TransposeType enumeration type. The options are TRANSPOSE_TYPE_NONE, TRANSPOSE_ND2ND_B16, TRANSPOSE_NCHW2NHWC, and TRANSPOSE_NHWC2NCHW.

Currently, the following reserved parameters are not supported: TRANSPOSE_NZ2ND_0213, TRANSPOSE_NZ2NZ_0213, TRANSPOSE_NZ2NZ_012_WITH_N, TRANSPOSE_NZ2ND_012_WITH_N, TRANSPOSE_NZ2ND_012_WITHOUT_N, TRANSPOSE_NZ2NZ_012_WITHOUT_N, TRANSPOSE_ND2ND_ONLY, TRANSPOSE_ND_UB_GM and TRANSPOSE_GRAD_ND_UB_GM.

Note: When transposeType is set to TRANSPOSE_ND2ND_B16, hSize and wSize must be set to 16. nSize and cSize are invalid.

Table 4 Data types supported by the enhanced transpose API

transposeType Supported Data Type
TRANSPOSE_ND2ND_B16 None
TRANSPOSE_NCHW2NHWC

Kirin X90 series processors support the following operand data types: int8_t, uint8_t, int16_t, uint16_t, half, int32_t, uint32_t, and float.

Kirin 9020 series processors support the following operand data types: int8_t, uint8_t, int16_t, uint16_t, half, int32_t, uint32_t, and float.

TRANSPOSE_NHWC2NCHW

Kirin X90 series processors support the following operand data types: int8_t, uint8_t, int16_t, uint16_t, half, int32_t, uint32_t, and float.

Kirin 9020 series processors support the following operand data types: int8_t, uint8_t, int16_t, uint16_t, half, int32_t, uint32_t, and float.

Table 5 Size required by the enhanced transpose API sharedTmpBuffer

transposeType Size of sharedTmpBuffer
TRANSPOSE_ND2ND_B16 No temporary buffer is required.
TRANSPOSE_NCHW2NHWC

The size of the temporary buffer is calculated according to the following calculation rule (pseudo code).

auto h0 = 16; // If the bit width of the data type is 8, h0 is 32. In other cases, h0 is 16.

auto w0 = 32 / sizeof(type); // type indicates the data type.

auto tmpBufferSize = (cSize + 2) * h0 * w0 * sizeof(type);

TRANSPOSE_NHWC2NCHW

The size of the temporary buffer is calculated according to the following calculation rule (pseudo code).

auto h0 = 16; // If the bit width of the data type is 8, h0 is 32. In other cases, h0 is 16.

auto w0 = 32 / sizeof(type); // type indicates the data type.

auto tmpBufferSize = (cSize * 2 + 1) * h0 * w0 * sizeof(type);

Supported Models

Kirin 9020 series processors

Kirin 9030 series processors

Kirin X90 series processors

Notes

Return Value

None

Calling Example