Load2D
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function Usage
Supports data transfer over the following paths:
GM -> A1; GM -> B1; GM -> A2; GM -> B2;
A1 -> A2; B1 -> B2.
Prototype
- Load2D API
1 2 3 4
template <typename T> __aicore__ inline void LoadData(const LocalTensor<T>& dst, const LocalTensor<T>& src, const LoadData2DParams& loadDataParams) template <typename T> __aicore__ inline void LoadData(const LocalTensor<T>& dst, const GlobalTensor<T>& src, const LoadData2DParams& loadDataParams)
- Load2Dv2 API
1 2 3 4
template <typename T> __aicore__ inline void LoadData(const LocalTensor<T>& dst, const LocalTensor<T>& src,const LoadData2DParamsV2& loadDataParam) template <typename T> __aicore__ inline void LoadData(const LocalTensor<T>& dst, const GlobalTensor<T>& src,const LoadData2DParamsV2& loadDataParam)
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
dst |
Output |
Destination operand, which is of the LocalTensor type. The sequential arrangement of data is determined by TPosition of the destination operand. The constraints are as follows:
|
|
src |
Input |
Source operand, which is of the LocalTensor or GlobalTensor type. Its data type must be the same as that of dst. |
|
loadDataParams |
Input |
LoadData parameter structure. Supported types are as follows: For details, see ${INSTALL_DIR}/include/ascendc/basic_api/interface/kernel_struct_mm.h. Replace ${INSTALL_DIR} with the actual path for storing files after the CANN software is installed. |
|
Parameter |
Description |
|---|---|
|
startIndex |
Fractal matrix ID. It specifies from which fractal matrix in the source operand the data transfer begins. If it is set to 0, the transfer starts from the first fractal matrix of the source operand. Value range: startIndex ∈ [0, 65535]. Unit: 512 bytes. Default value: 0. |
|
repeatTimes |
Number of iterations. 512-byte data can be processed in each iteration. Value range: repeatTimes ∈ [1, 255]. |
|
srcStride |
In adjacent iterations, the interval between the start addresses of consecutive fractal matrices in the source operand. It is measured in units of 512 bytes. Value range: srcStride ∈ [0, 65535]. Default value: 0. |
|
sid |
Reserved parameter. Set it to 0. |
|
dstGap |
In adjacent iterations, the interval between the end address of one fractal matrix and the start address of the next fractal matrix in the destination operand. It is measured in units of 512 bytes. Value range: dstGap ∈ [0, 65535]. Default value: 0. Note: For the |
|
ifTranspose |
Whether to enable the transpose function for each fractal matrix. The default value is false.
Note: When loading data from A1 to A2 or from B1 to B2, the transpose function can be enabled. When the transpose function is enabled, the source and destination operands support only the b16 data type. |
|
addrMode |
Address update mode. Default value: false.
|
|
Parameter |
Description |
|---|---|
|
mStartPosition |
For an M × K matrix, this parameter specifies the start position along the M-axis of the source matrix, measured in units of 16 elements. |
|
kStartPosition |
For an M × K matrix, this parameter specifies the start position along the K-axis of the source matrix, measured in units of 32 bytes. |
|
mStep |
For an M × K matrix, this parameter specifies the transfer length along the M-axis of the source matrix, measured in units of 16 elements. Value range: mStep ∈ [0, 255]. When the transpose function is enabled by setting ifTranspose, mStep must meet the following additional constraints in addition to the value range of [0, 255]:
|
|
kStep |
For an M × K matrix, this parameter specifies the transfer length along the K-axis of the source matrix, measured in units of 32 bytes. Value range: kStep ∈ [0, 255]. When the transpose function is enabled by setting ifTranspose, kStep must meet the following additional constraints in addition to the value range of [0, 255]:
|
|
srcStride |
For an M × K matrix, this parameter specifies the interval between the start addresses of consecutive fractal matrices along the K-axis of the source matrix, measured in units of 512 bytes. |
|
dstStride |
For an M × K matrix, this parameter specifies the interval between the start address of one fractal matrix and the start address of the next fractal matrix along the K-axis of the destination matrix. The unit is 512 bytes. |
|
ifTranspose |
Whether to enable the transpose function for each fractal matrix. The default value is false.
Note: The transpose function can be enabled only when data is transferred from A1 to A2 or from B1 to B2. When the transpose function is enabled, the restrictions on the supported data types are as follows: For the Atlas 350 Accelerator Card, the source and destination operands support the b4, b8, b16, and b32 data types. |
|
sid |
Reserved parameter. Set it to 0. |
Restrictions
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- For the
Atlas inference product AI Core, when the Mmad API is used and the data type of matrix B is S4, if the transpose function is enabled by setting ifTranspose, only 64 × 64 fractal blocks are supported.
Returns
None
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
uint16_t C1 = 2; uint16_t H = 4, W = 4; uint8_t Kh = 2, Kw = 2; uint16_t Cout = 16; uint16_t C0 = 16; uint8_t dilationH = 2, dilationW = 2; uint8_t padTop = 1, padBottom = 1, padLeft = 1, padRight = 1; uint8_t strideH = 1, strideW = 1; uint16_t coutBlocks, ho, wo, howo, howoRound; uint32_t featureMapA1Size, weightA1Size, featureMapA2Size, weightB2Size, dstSize, dstCO1Size; uint8_t padList[4] = {padLeft, padRight, padTop, padBottom}; featureMapA2Size = howoRound * (C1 * Kh * Kw * C0); fmRepeat = featureMapA2Size / (16 * C0); AscendC::LocalTensor<half> featureMapA1 = inQueueFmA1.DeQue<half>(); AscendC::LocalTensor<half> featureMapA2 = inQueueFmA2.AllocTensor<half>(); AscendC::LoadData<A2, A1, half>(featureMapA2, featureMapA1, { padList, H, W, 0, 0, 0, -1, -1, strideW, strideH, Kw, Kh, dilationW, dilationH, 1, 0, fmRepeat, 0, (half)(0)}); LoadData2DParamsV2 param = { padList, H, W, 0, 0, 0, -1, -1, strideW, strideH, Kw, Kh, dilationW, dilationH, 1, 0, fmRepeat, 0, (half)(0)}; Load2DBitModeParam paramBitMode(param); AscendC::LoadData<A2, A1, half>(featureMapA2, featureMapA1, paramBitMode); |