WriteSpmBuffer
产品支持情况
功能说明
将需要溢出暂存的数据拷贝到SPM Buffer中。
函数原型
-
适用于连续和不连续的数据暂存:
template <typename T> __aicore__ inline void WriteSpmBuffer(const LocalTensor<T>& writeBuffer, const DataCopyParams& copyParams, int32_t writeOffset = 0) -
适用于连续的数据暂存:
template <typename T> __aicore__ inline void WriteSpmBuffer(const LocalTensor<T>& writeBuffer, const int32_t writeSize, int32_t writeOffset = 0)
参数说明
表 1 接口参数说明
搬运参数,DataCopyParams类型,DataCopyParams结构定义请参考表2。 |
||
表 2 DataCopyParams结构体参数定义
约束说明
- 暂存拷贝到L1时注意writeSize和writeOffset保证32字节对齐
- 拷贝的内存不要超出初始化的SPM Buffer大小,否则会存在溢出踩踏等问题。
返回值说明
无
调用示例
AscendC::TPipe pipe;
AscendC::TQue<AscendC::TPosition::VECIN, 1> inQueueSrcVecIn;
int dataSize = 32; // 假设T为half类型,从ub上申请一块内存32 * sizeof(half)字节
int offset = 32; // 拷贝到spmBuffer时偏移32字节
pipe.InitBuffer(inQueueSrcVecIn, 1, dataSize * sizeof(half));
AscendC::LocalTensor<half> writeLocal = inQueueSrcVecIn.AllocTensor<half>();
AscendC::DataCopyParams copyParams{1, 2, 0, 0}; // 从ub上搬运一个连续传输数据块,一个数据块的长度为2个datablock,一个datablock为32bytes
pipe.WriteSpmBuffer(writeLocal, copyParams, offset);
AscendC::TPipe pipe;
AscendC::TQue<AscendC::TPosition::VECIN, 1> inQueueSrcVecIn;
int dataSize = 32; // 假设T为half类型,从ub上申请一块内存32 * sizeof(half)字节
int offset = 32; // 拷贝到spmBuffer时偏移32字节
pipe.InitBuffer(inQueueSrcVecIn, 1, dataSize * sizeof(half));
AscendC::LocalTensor<half> writeLocal = inQueueSrcVecIn.AllocTensor<half>();
pipe.WriteSpmBuffer(writeLocal, dataSize, offset);