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:
- Complete the initialization operation by calling InitSpmBuffer.
- Copy and temporarily store data by calling WriteSpmBuffer.
- Retrieve data by calling ReadSpmBuffer when you need to use temporarily stored data.
For the
Example
- 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));
- Temporarily stored in workspace
- 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
Parent topic: Memory Management