SPM Buffer

Overview

The spill memory (SPM) buffer supports temporary storage of Unified Buffer. If Unified Buffer overflows, the Unified Buffer data can be copied to the SPM buffer for temporary storage and then retrieved as required.

The methods are as follows:

  1. Complete the initialization operation by calling InitSpmBuffer.
  2. Copy and temporarily store data by calling WriteSpmBuffer.
  3. Retrieve data by calling ReadSpmBuffer when you need to use temporarily stored data.

For the Atlas Training Series Product , data can be temporarily stored in workspace or L1 Buffer.

Example

  1. Initialization operations
    • Temporarily stored in workspace
      AscendC::TPipe pipe;
      int len = 1024;
      AscendC::GlobalTensor<half> workspace_gm;
      auto usrWorkspace = AscendC::GetUserWorkspace(workspace);
      // usrWorkspace is a user-defined workspace, which is of the half type and has a number of len elements.
      workspace_gm.SetGlobalBuffer((__gm__ half *)usrWorkspace, len);
      auto gm = workspace_gm[AscendC::GetBlockIdx() * len];
      pipe.InitSpmBuffer(gm, len * sizeof(half));
    • Temporarily stored in L1 Buffer
      TPipe pipe;
      int len = 1024; // Set the SPM buffer to 1024 pieces of data of the T type.
      pipe.InitSpmBuffer(len * sizeof(T));
  2. Temporary storage and retrieve operations
    TQue<QuePosition::VECIN, 1> inQueueSrcVecIn;
    int dataSize = 32; // Assume that T is of the half type. Allocate a memory block from the UB (32 x sizeof(half) bytes).
    int offset = 32; // 32 bytes offset when copied to the SPM buffer
    pipe.InitBuffer(inQueueSrcVecIn, 1, dataSize);
    LocalTensor<half> writeLocal = inQueueSrcVecIn.AllocTensor<half>();
    DataCopyParams copyParams{1, 2, 0, 0}; // Move a piece of data with a length of two data blocks from the UB. Each data block is 32-byte.
    pipe.WriteSpmBuffer(writeLocal, copyParams, offset);
    pipe.ReadSpmBuffer(writeLocal, copyParams, offset);

Constraints

None