ReadSpmBuffer
Applicability
Product |
Supported |
|---|---|
√ |
|
√ |
|
x |
|
√ |
|
x |
|
√ |
Function
Reads data from the SPM buffer back to the local data.
Prototype
- Applicable to continuous and discontinuous data readback:
1 2
template <typename T> __aicore__ inline void ReadSpmBuffer(const LocalTensor<T>& readBuffer, const DataCopyParams& copyParams, int32_t readOffset = 0)
- Applicable to continuous temporary data readback:
1 2
template <typename T> __aicore__ inline void ReadSpmBuffer(const LocalTensor<T>& readBuffer, const int32_t readSize, int32_t readOffset = 0)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
readBuffer |
Input |
Readback target local memory. |
copyParams |
Input |
Movement parameter, DataCopyParams type. For details about the structure definition of DataCopyParams, see Table 2. |
readSize |
Input |
Number of read elements. |
readOffset |
Input |
Offset of the SPM buffer, in bytes. |
Parameter |
Description |
|---|---|
blockCount |
Number of contiguous data blocks to be transferred, which is of the uint16_t type. The value range is [1, 4095]. |
blockLen |
Length of each contiguous data block to be transferred, in the unit of DataBlock (32 bytes). The value is of the uint16_t type. The value range is [1, 65535]. For dst in C2PIPE2GM, the unit is 128 bytes. For dst in C2, it indicates the length of contiguous data blocks for source operand transfer, with the unit being 64 bytes. |
srcGap |
Interval between adjacent contiguous data blocks of the source operand (the interval between the end of the preceding block and the start of the next block). The unit is DataBlock (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 interval between adjacent contiguous data blocks of the source operand (the interval between the start of the preceding block and the start of the next block). The unit is DataBlock (32 bytes). The value is of the uint16_t type and must not exceed the value range of this data type. |
dstGap |
Interval between adjacent contiguous data blocks of the destination operand (the interval between the end of the preceding block and the start of the next block). The unit is DataBlock (32 bytes). The value is of the uint16_t type and must not exceed the value range of this data type. For dstLocal in C2PIPE2GM, the unit is 128 bytes. For dstLocal in C2, the unit is 64 bytes. In the scenario of L1 Buffer -> Fixpipe Buffer, dstGap refers to the interval between adjacent contiguous data blocks of the source operand (the interval between the start of the preceding block and the start of the next block). The unit is DataBlock (32 bytes). The value is of the uint16_t type and must not exceed the value range of this data type. |
Restrictions
None
Returns
None
Example
1 2 3 4 5 6 7 8 | AscendC::TPipe pipe; AscendC::TQue<AscendC::TPosition::VECIN, 1> inQueueSrcVecIn; int dataSize = 32; // Assume that T is of the half type. Allocate a buffer from UB (32 × sizeof(half) bytes). int offset = 32; // 32 bytes offset on spmBuffer when read back pipe.InitBuffer(inQueueSrcVecIn, 1, dataSize * sizeof(half)); AscendC::LocalTensor<half> writeLocal = inQueueSrcVecIn.AllocTensor<half>(); AscendC::DataCopyParams copyParams{1, 2, 0, 0};// Move a data chunk. The length of the data chunk is two data blocks, and the length of a data block is 32 bytes. pipe.ReadSpmBuffer(writeLocal, copyParams, offset); |
1 2 3 4 5 6 7 | AscendC::TPipe pipe; AscendC::TQue<AscendC::TPosition::VECIN, 1> inQueueSrcVecIn; int dataSize = 64; // Allocate a buffer from UB (64 × sizeof(half) bytes). int offset = 32; // 32 bytes offset on spmBuffer when read back pipe.InitBuffer(inQueueSrcVecIn, 1, dataSize * sizeof(half)); AscendC::LocalTensor<half> writeLocal = inQueueSrcVecIn.AllocTensor<half>(); pipe.ReadSpmBuffer(writeLocal, dataSize, offset); |