DataCopyPad(ISASI)

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Performs unaligned data transfer from the global memory to the local memory. During the transfer, developers can customize how padding data is filled as required.

Prototype

  • dataCopyParams is of the DataCopyExtParams type. It supports a larger value range for parameters such as the operand stride compared to the DataCopyParams type.
    • Transfer path: global memory -> local memory
      1
      2
      template <typename T, PaddingMode mode = PaddingMode::Normal>
      __aicore__ inline void DataCopyPad(const LocalTensor<T>& dst, const GlobalTensor<T>& src, const DataCopyExtParams& dataCopyParams, const DataCopyPadExtParams<T>& padParams)
      
      1
      2
      template <typename T>
      __aicore__ inline void DataCopyPad(const LocalTensor<T>& dst, const GlobalTensor<T>& src, const DataCopyExtParams& dataCopyParams, const DataCopyPadExtParams<T>& padParams)
      
    • Transfer path: local memory -> global memory
      1
      2
      template <typename T, PaddingMode mode = PaddingMode::Normal>
      __aicore__ inline void DataCopyPad(const GlobalTensor<T>& dst, const LocalTensor<T>& src, const DataCopyExtParams& dataCopyParams)
      
      1
      2
      template <typename T>
      __aicore__ inline void DataCopyPad(const GlobalTensor<T>& dst, const LocalTensor<T>& src, const DataCopyExtParams& dataCopyParams)
      
    • Transfer path: local memory -> local memory. The actual transfer process goes through: VECIN or VECOUT -> global memory -> TSCM.
      1
      2
      template <typename T>
      __aicore__ inline void DataCopyPad(const LocalTensor<T>& dst, const LocalTensor<T>& src, const DataCopyExtParams& dataCopyParams, const Nd2NzParams& nd2nzParams)
      
  • dataCopyParams is of the DataCopyParams type.
    • Transfer path: global memory -> local memory
      1
      2
      template<typename T, PaddingMode mode = PaddingMode::Normal>
      __aicore__ inline void DataCopyPad(const LocalTensor<T>& dst, const GlobalTensor<T>& src, const DataCopyParams& dataCopyParams, const DataCopyPadParams& padParams)
      
      1
      2
      template<typename T>
      __aicore__ inline void DataCopyPad(const LocalTensor<T>& dst, const GlobalTensor<T>& src, const DataCopyParams& dataCopyParams, const DataCopyPadParams& padParams)
      
    • Transfer path: local memory -> global memory
      1
      2
      template<typename T, PaddingMode mode = PaddingMode::Normal>
      __aicore__ inline void DataCopyPad(const GlobalTensor<T>& dst, const LocalTensor<T>& src,const DataCopyParams& dataCopyParams)
      
      1
      2
      template<typename T>
      __aicore__ inline void DataCopyPad(const GlobalTensor<T>& dst, const LocalTensor<T>& src,const DataCopyParams& dataCopyParams)
      
    • Transfer path: local memory -> local memory. The actual transfer process goes through: VECIN or VECOUT -> global memory -> TSCM.
      1
      2
      template<typename T>
      __aicore__ inline void DataCopyPad(const LocalTensor<T>& dst, const LocalTensor<T>& src, const DataCopyParams& dataCopyParams, const Nd2NzParams& nd2nzParams)
      

Different product models support different function prototypes. Refer to the following table to select a function prototype supported by your product model.

Table 1 Function prototypes supported by different product models

Product Model

Data Transfer Path

Support for Setting Transfer Mode (Single-Transfer Alignment and Whole-Block Alignment)

Atlas 350 Accelerator Card

GM -> VECIN/VECOUT, GM -> A1/B1, GM -> TSCM, VECIN/VECOUT -> GM, A1/B1 -> GM, VECIN/VECOUT -> TSCM, GM -> VECCALC

Supported

Atlas A3 training product/Atlas A3 inference product

GM -> VECIN/VECOUT, VECIN/VECOUT -> GM, VECIN/VECOUT -> TSCM

Not supported

Atlas A2 training product/Atlas A2 inference product

GM -> VECIN/VECOUT, VECIN/VECOUT -> GM, VECIN/VECOUT -> TSCM

Not supported

Atlas 200I/500 A2 inference product

GM -> VECIN/VECOUT, VECIN/VECOUT -> GM

Not supported

Parameters

Table 2 Template parameters

Parameter

Description

T

Data type of the operand and paddingValue (data value to be padded).

For the Atlas 350 Accelerator Card, the supported data types are bool, int8_t, uint8_t, int16_t, uint16_t, half, bfloat16_t, int32_t, uint32_t, float, complex32, int64_t, uint64_t, double, and complex64.

For the Atlas A3 training product/Atlas A3 inference product, the supported data types are half, bfloat16_t, int16_t, uint16_t, float, int32_t, uint32_t, int8_t, uint8_t, int64_t, uint64_t, and double.

For the Atlas A2 training product/Atlas A2 inference product, the supported data types are half, bfloat16_t, int16_t, uint16_t, float, int32_t, uint32_t, int8_t, uint8_t, int64_t, uint64_t, and double.

For the Atlas 200I/500 A2 inference product, the supported data types are int8_t, uint8_t, half, bfloat16_t, int16_t, uint16_t, float, int32_t, and uint32_t.

mode

Sets the data transfer mode. It is of the PaddingMode type, which is defined as follows:

1
2
3
4
enum class PaddingMode : uint8_t {
    Normal = 0,  // Default mode, which keeps the same data transfer format as the original. Data is padded to 32 bytes during each data transfer.
    Compact,     // Compact mode, which allows unaligned data during a single transfer. The entire data block is padded at the end to achieve 32-byte alignment.
};
Table 3 API parameters

Parameter

Input/Output

Description

dst

Output

Destination operand, which is of the LocalTensor or GlobalTensor type.

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

The start address of GlobalTensor does not require alignment.

src

Input

Source operand, which is of the LocalTensor or GlobalTensor type.

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

The start address of GlobalTensor does not require alignment.

dataCopyParams

Input

Data transfer parameters.

  • DataCopyExtParams type. For details about the parameters, see Table 4.
  • DataCopyParams type. For details about the parameters, see Table 5.

padParams

Input

When moving data from the global memory to the local memory, you can pad data on the left or right as required. padParams is used to control the data padding process.

  • DataCopyPadExtParams type. For details about the parameters, see Table 6.
  • DataCopyPadParams type. For details about the parameters, see Table 7.

nd2nzParams

Input

When moving data from VECIN/VECOUT to TSCM, you can convert the data format from ND to NZ. nd2nzParams is used to control data format conversion. It is of the Nd2NzParams type and is defined as follows. For details about the parameters, see Table 3.

Note: ndNum in Nd2NzParams can only be set to 1.

For details about the structure parameters listed in the following table, see ${INSTALL_DIR}/include/ascendc/basic_api/interface/kernel_struct_data_copy.h. Replace ${INSTALL_DIR} with the actual CANN component directory.

Table 4 Parameters in the DataCopyExtParams structure

Parameter

Description

blockCount

Number of data chunks. The data type is uint16_t, and blockCount ∈ [1, 4095].

blockLen

Length of each data chunk, in byte, which supports non-aligned movement. The data type is uint32_t. Value range: blockLen ∈ [1, 2097151].

srcStride

Stride between adjacent data chunks of the source operand (the stride between the tail of one data chunk and the head of the next).

If the logical position of the source operand is VECIN or VECOUT, the unit is a data block (32 bytes). If the logical position is GM, the unit is byte.

The data type is uint32_t. The value of srcStride cannot exceed the value range of this data type.

Supported models:

Atlas 350 Accelerator Card

The data type is int64_t. If the logical position of the source operand is VECIN or VECOUT, the value range is [0, 65535]. If the logical position is GM, the value range is [–blockLen, 240 – 1].

dstStride

Stride between adjacent data chunks of the destination operand (the stride between the tail of one data chunk and the head of the next).

If the logical position of the destination operand is VECIN or VECOUT, the unit is a data block (32 bytes). If the logical position is GM, the unit is byte.

The data type is uint32_t. The value of dstStride cannot exceed the value range of this data type.

Supported models:

Atlas 350 Accelerator Card

The data type is int64_t. If the logical position of the destination operand is VECIN or VECOUT, the value range is [0, 65535]. If the logical position is GM, the value range is [0, 240 – 1].

rsv

Reserved

Table 5 Parameters in the DataCopyParams structure

Parameter

Description

blockCount

Number of data chunks. The data type is uint16_t, and blockCount ∈ [1, 4095].

blockLen

Length of each data chunk, in byte, which supports non-aligned movement. The data type is uint16_t. The value of blockLen cannot exceed the value range of this data type.

srcStride

Stride between adjacent data chunks of the source operand (the stride between the tail of one data chunk and the head of the next). If the logical position of the source operand is VECIN or VECOUT, the unit is a data block (32 bytes). If the logical position is GM, the unit is byte. The data type is uint16_t. The value of srcStride cannot exceed the value range of this data type.

dstStride

Stride between adjacent data chunks of the destination operand (the stride between the tail of one data chunk and the head of the next). If the logical position of the destination operand is VECIN or VECOUT, the unit is a data block (32 bytes). If the logical position is GM, the unit is byte. The data type is uint16_t. The value of dstStride cannot exceed the value range of this data type.

Table 6 Parameters in the DataCopyPadExtParams<T> structure

Parameter

Description

isPad

Whether to pad custom data. The options are as follows:

true: Set a padding value.

false: No padding value is specified, and a random value is used.

leftPadding

Range of the data to be padded on the left of the data chunk. The unit is the number of elements.

For both leftPadding and rightPadding, the total number of bytes occupied must not exceed 32 bytes.

rightPadding

Range of the data to be padded on the right of the data chunk. The unit is the number of elements.

For both leftPadding and rightPadding, the total number of bytes occupied must not exceed 32 bytes.

paddingValue

Values of the data to be padded on the left and right. The values must be within the byte range occupied by the data.

The data type must be the same as that of the source operand. The data type is T.

When the data type length is 64 bits, this parameter can only be set to 0.

Table 7 Parameters in the DataCopyPadParams structure

Parameter

Description

isPad

Whether to pad custom data. The options are as follows:

true: Set a padding value.

false: No padding value is specified, and a random value is used.

leftPadding

Range of the data to be padded on the left of the data chunk. The unit is the number of elements.

For both leftPadding and rightPadding, the total number of bytes occupied must not exceed 32 bytes.

rightPadding

Range of the data to be padded on the right of the data chunk. The unit is the number of elements.

For both leftPadding and rightPadding, the total number of bytes occupied must not exceed 32 bytes.

paddingValue

Values of the data to be padded on the left and right. The values must be within the byte range occupied by the data.

It is of the uint64_t type. The source operand must be of the uint64_t type, and this parameter can only be set to 0.

The following provides configuration examples for different scenarios:

  • GM -> VECIN or VECOUT
  • VECIN or VECOUT -> GM
  • VECIN or VECOUT -> TSCM
  • Configuration example of the transfer mode
  • GM -> VECIN or VECOUT
    • Description
      • When blockLen + leftPadding + rightPadding is 32-byte aligned and isPad is false, the values used for left and right padding will default to random values; otherwise, they will be set to paddingValue.
      • When blockLen + leftPadding + rightPadding is not 32-byte aligned, the framework pads some dummy data to ensure the 32-byte alignment. When both leftPadding and rightPadding are 0, the dummy value fills with the first element of the data chunk being transferred by default. When leftPadding or rightPadding is not 0, if isPad is set to false, the data values padded on the left and right sides and dummy values are random numbers; if not, the data values padded on the left and right sides and dummy values are configured padding values.
    • Configuration example 1
      • blockLen = 64 indicates that each data chunk contains 64 bytes.

        srcStride = 1 indicates that the stride between adjacent data chunks of the source operand is 1 byte. The logical position of the source operand is GM, and the unit of srcStride is byte.

        dstStride = 1 indicates that the stride between adjacent data chunks of the destination operand is one data block. The logical position of the destination operand is VECIN or VECOUT, and the unit of dstStride is the number of data blocks (32 bytes per data block).

      • When blockLen + leftPadding + rightPadding is 32-byte aligned, if isPad is set to false, the data values padded on the left and right sides are random numbers by default; if not, the data values padded on the left and right sides are configured padding values. In this example, both leftPadding and rightPadding are 0, indicating that padding is not performed.
      • When blockLen + leftPadding + rightPadding is not 32-byte aligned, the framework pads some dummy data to ensure the 32-byte alignment. When leftPadding or rightPadding is not 0, if isPad is set to false, the data values padded on the left and right sides and dummy values are random numbers; if not, the data values padded on the left and right sides are configured padding values.

    • Configuration example 2
      • blockLen = 47 indicates that each data chunk contains 47 bytes.

        srcStride = 1 indicates that the stride between adjacent data chunks of the source operand is 1 byte.

        dstStride = 1 indicates that the stride between adjacent data chunks of the destination operand is one data block.

      • When blockLen + leftPadding + rightPadding is not 32-byte aligned, and both leftPadding and rightPadding are 0, the dummy value fills with the first element of the data chunk being transferred by default.
      • When blockLen + leftPadding + rightPadding is not 32-byte aligned, and leftPadding or rightPadding is not 0, if isPad is set to false, the data values padded on the left and right sides and dummy values are random numbers; if not, the data values padded on the left and right sides and dummy values are configured padding values.

    • Configuration example 3
      • blockLen = 48 indicates that each data chunk contains 48 bytes.

        srcStride = –48 indicates that the stride between adjacent data chunks of the source operand is –48 bytes. This means that the data chunks transferred each time are the same.

        dstStride = 1 indicates that the stride between adjacent data chunks of the destination operand is one data block.

      • When blockLen + leftPadding + rightPadding is not 32-byte aligned, and both leftPadding and rightPadding are 0, the dummy value fills with the first element of the data chunk being transferred by default.
      • When blockLen + leftPadding + rightPadding is not 32-byte aligned, and leftPadding or rightPadding is not 0, if isPad is set to false, the data values padded on the left and right sides and dummy values are random numbers; if not, the data values padded on the left and right sides and dummy values are configured padding values.

  • VECIN or VECOUT -> GM
    • When blockLen of each data chunk is 32-byte aligned, an example of DataCopyParams to be input is shown in the following figure.

      The value of blockLen is 64, meaning each data chunk contains 64 bytes.

      The value of srcStride is 1. Because the logical position of the source operand is VECIN or VECOUT and the unit of srcStride is a 32-byte data block, there is one data block between adjacent data chunks of the source operand.

      The value of dstStride is 1. Because the logical position of the destination operand is GM and the unit of dstStride is byte, there is 1-byte interval between adjacent data chunks of the destination operand.

    • The Unified Buffer requires 32-byte alignment, but blockLen of each data chunk does not meet the requirement. In this case, when the data chunk is moved out, the framework automatically pads some dummy data to ensure alignment. When the data chunk is moved to GM, the dummy data is automatically deprecated. The following figure shows an example of DataCopyParams to be input in this scenario and the principle of padding dummy data. The value of blockLen is 47, meaning each data chunk contains 47 bytes, which is not 32-byte aligned. The value of srcStride is 1, indicating that there is an interval of one data block between adjacent data chunks of the source operand. The value of dstStride is 1, indicating that there is a 1-byte interval between adjacent data chunks of the destination operand. When data is moved out, the framework automatically pads 17-byte dummy data to ensure alignment. When data is moved to GM, the padded dummy data is automatically deprecated.

  • VECIN/VECOUT->TSCM

    Note: The internal implementation involves the communication between the AIC and AIV, and the actual transfer path is VECIN/VECOUT -> GM -> TSCM. Sending communication messages causes overheads and affects the performance.

    Figure 1 illustrates the process of transferring data from VECIN or VECOUT to GM and then to TSCM. In the example, the data type is half, with a single data block (32 bytes) containing 16 half elements, and A1 to A6, B1 to B6, and C1 to C6 in the source operand indicate the data to be transferred.

    • During the transfer from VECIN or VECOUT to GM, the data storage format remains unchanged as ND.
      • blockCount indicates the number of data chunks. Set it to 3.
      • blockLen indicates the size (in bytes) of a data chunk. Set it to 192 (which is 6 × 32).
      • srcStride indicates the interval between adjacent data chunks of the source operand (the interval between the tail of one data chunk and the head of the next). The logical position of the source operand is VECIN or VECOUT, the unit is a data block, and two data chunks (A1 to A6 and B1 to B6) are separated by A7. Therefore, set srcStride to 1.
      • dstStride indicates the interval between adjacent data chunks of the destination operand (the interval between the tail of one data chunk and the head of the next). The logical position of the destination operand is GM, the unit is byte, and two data chunks (A1 to A6 and B1 to B6) are separated by two empty data blocks. Therefore, set dstStride to 64 bytes.
    • During the transfer from GM to TSCM, the data storage format is converted from ND to NZ.
      • ndNum is fixed to 1. That is, A1 to A6, B1 to B6, and C1 to C6 are considered as an entire ND matrix.
      • nValue indicates the number of rows in the ND matrix, that is, 3.
      • dValue indicates the number of elements in a row of the ND matrix, that is, 96 (which is 6 × 16).
      • srcNdMatrixStride indicates the distance between adjacent ND matrices. Because only one ND matrix is involved, srcNdMatrixStride can be set to 0.
      • srcDValue indicates a quantity of elements between the xth row and the (x+1)th row of the ND matrix. For example, the distance between A1 and B1 is eight data blocks, and there are 128 (which is 8 × 16) elements.
      • dstNzC0Stride indicates the number of data blocks between adjacent data blocks in the same row of src in the NZ matrix, for example, the distance between A1 and A2, that is, seven data blocks (A1 + blank + B1 + blank + C1 + blank × 2).
      • dstNzNStride indicates the number of data blocks between adjacent rows of the ndMatrix in src in the NZ matrix, for example, the distance between A1 and B1, that is, two data blocks (A1 + blank).
      • dstNzMatrixStride indicates the number of elements between adjacent NZ matrices. Because only one NZ matrix is involved, dstNzMatrixStride can be set to 1.
    Figure 1 VECIN/VECOUT -> TSCM data transfer
  • Configuration example of the transfer mode
    • Normal mode

      blockLen = 48 indicates that each data chunk contains 48 bytes.

      srcStride = 0 indicates that there is no stride between adjacent data chunks of the source operand. The logical position of the source operand is GM, and the unit of srcStride is byte.

      dstStride = 0 indicates that there is no stride between adjacent data chunks of the destination operand. The logical position of the destination operand is VECIN or VECOUT, and the unit of dstStride is the number of data blocks (32 bytes per data block).

      Note that the data chunks contain leftPadding and rightPadding data.

      If blockLen + leftPadding + rightPadding is 32-byte aligned and isPad is set to false, the values used for left and right padding will default to random values; otherwise, they will be set to paddingValue. In this example, leftPadding is 0, and rightPadding is 16. Each data chunk is padded with 16 bytes on the right. The total length of the destination operand is 192 bytes.

    • Compact mode

      blockLen = 48 indicates that each data chunk contains 48 bytes.

      srcStride = 0 indicates that there is no stride between adjacent data chunks of the source operand. The logical position of the source operand is GM, and the unit of srcStride is byte.

      dstStride = 0 indicates that there is no stride between adjacent data chunks of the destination operand. The logical position of the destination operand is VECIN or VECOUT, and the unit of dstStride is the number of data blocks (32 bytes per data block).

      If blockLen × blockCount + leftPadding + rightPadding is 32-byte aligned and isPad is set to false, the values used for left and right padding will default to random values; otherwise, they will be set to paddingValue. In this example, leftPadding is 0, and rightPadding is 16. 16 bytes are padded to the right of the last data chunk. The total length of the destination operand is 160 bytes.

Returns

None

Restrictions

  • For both leftPadding and rightPadding, the total number of bytes occupied must not exceed 32 bytes.
  • For the Atlas 350 Accelerator Card, the following data types are supported for data transfer from VECIN or VECOUT to TSCM: half, bfloat16_t, int16_t, uint16_t, float, int32_t, uint32_t, int8_t, uint8_t, int64_t, uint64_t, and double.

Examples

This example implements the non-aligned data transfer process of GM -> VECIN -> GM.
1
2
3
4
AscendC::DataCopyExtParams copyParams{1, 20 * sizeof(half), 0, 0, 0}; 
AscendC::DataCopyPadExtParams<half> padParams{true, 0, 2, 0};
// Transfer 40 bytes from GM to VECIN.
AscendC::DataCopyPad(dstGlobal, src0Global, copyParams, padParams); 
Result example:
Input (src0Global): [1 2 3 ... 32]
Output (dstGlobal): [1 2 3 ... 20]