WriteSpmBuffer

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

x

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

Function Usage

Copies the data to be overflowed and temporarily stored to the SPM buffer.

Prototype

  • Applicable to continuous and discontinuous temporary data storage:
    1
    2
    template <typename T>
    __aicore__ inline void WriteSpmBuffer(const LocalTensor<T>& writeBuffer, const DataCopyParams& copyParams, int32_t writeOffset = 0)
    
  • Applicable to continuous temporary data storage:
    1
    2
    template <typename T>
    __aicore__ inline void WriteSpmBuffer(const LocalTensor<T>& writeBuffer, const int32_t writeSize, int32_t writeOffset = 0)
    

Parameters

Table 1 API parameters

Parameter

Input/Output

Meaning

writeBuffer

Input

Local memory to be overflowed and temporarily stored.

copyParams

Input

Movement parameter, DataCopyParams type. For details about the structure definition of DataCopyParams, see Table 2.

writeSize

Input

Number of copied elements.

writeOffset

Input

Offset copied to the SPM buffer, in bytes.

Table 2 Parameters in the DataCopyParams structure

Parameter

Description

blockCount

Number of data chunks to be transferred, which is of the uint16_t type. The value range is [1, 4095].

blockLen

Length of each data chunk to be transferred, in the unit of a data block (32 bytes). The value is of the uint16_t type. The value range is [1, 65535].

Notes:

  • When dst is located in C2PIPE2GM, the unit is 128 bytes.
  • Generally, dst in C2 indicates the length of a data chunk in the source operand. The unit is 64 bytes. For the Atlas 350 Accelerator Card, dst in C2 indicates the length of a data chunk in the source operand. The unit is 32 bytes.

srcGap

Gap between adjacent data chunks of the source operand (the distance from the tail of one data chunk to the head of the next). The unit is a data block (32 bytes). The value is of the uint16_t type and must not exceed the value range of this data type.

In the scenario of L1 Buffer -> Fixpipe Buffer, srcGap refers to the gap between adjacent data chunks of the source operand (the distance from the head of one data chunk to the head of the next). The unit is a data block (32 bytes). The value is of the uint16_t type and must not exceed the value range of this data type.

dstGap

Gap between adjacent data chunks of the destination operand (the distance from the tail of one data chunk to the head of the next). The unit is a data block (32 bytes). The value is of the uint16_t type and must not exceed the value range of this data type.

Notes:

  • When dst is located in C2PIPE2GM, the unit is 128 bytes.
  • Generally, dst in C2 indicates the length of a data chunk in the source operand. The unit is 64 bytes. For the Atlas 350 Accelerator Card, dst in C2 indicates the length of a data chunk in the source operand. The unit is 32 bytes.

In the scenario of L1 Buffer -> Fixpipe Buffer, dstGap refers to the gap between adjacent data chunks of the source operand (the distance from the head of one data chunk to the head of the next). The unit is a data block (32 bytes). The value is of the uint16_t type and must not exceed the value range of this data type.

Constraints

  • Ensure that writeSize and writeOffset are 32-byte aligned when the data is temporarily stored and copied to L1.
  • The size of the copied memory cannot exceed the size of the initialized SPM buffer. Otherwise, problems such as overflow violation may occur.

Returns

None

Example

  • Using DataCopyParams for transfer
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    AscendC::TPipe pipe;
    int dataSize = 32; // Assume that T is of the half type. Allocate the buffer of 32 × sizeof(half) bytes from Unified Buffer.
    int offset = 32; // The offset is 32 bytes when data is copied to spmBuffer.
    AscendC::DataCopyParams copyParams{1, 2, 0, 0}; // Transfer a data chunk from Unified Buffer. The length of the data chunk is two data blocks, and the length of a data block is 32 bytes.
    // writeLocal is a LocalTensor of the half type in the SPM buffer.
    pipe.WriteSpmBuffer(writeLocal, copyParams, offset); // Transfer the data chunk from Unified Buffer to the SPM buffer.
    pipe.ReadSpmBuffer(writeLocal, copyParams, offset); // Read the data temporarily stored in the SPM buffer back to the local data.
    ...
    // When Unified Buffer has sufficient memory, transfer the data chunk temporarily stored in the SPM buffer back to the global memory. dstGlobal is a GlobalTensor of the half type.
    AscendC::DataCopy(dstGlobal, writeLocal, copyParams);
    
  • Using writeSize for consecutive transfer
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    AscendC::TPipe pipe;
    int dataSize = 32; // Assume that T is of the half type. Allocate the buffer of 32 × sizeof(half) bytes from Unified Buffer.
    int offset = 32; // The offset is 32 bytes when data is copied to spmBuffer.
    ;
    // writeLocal is a LocalTensor of the half type in the SPM buffer.
    pipe.WriteSpmBuffer(writeLocal, dataSize, offset); // Transfer the data chunk from Unified Buffer to the SPM buffer.
    pipe.ReadSpmBuffer(writeLocal, dataSize, offset); // Read the data temporarily stored in the SPM buffer back to the local data.
    ...
    // When Unified Buffer has sufficient memory, transfer the data chunk temporarily stored in the SPM buffer back to the global memory. dstGlobal is a GlobalTensor of the half type.
    AscendC::DataCopy(dstGlobal, writeLocal, dataSize);