ReadSpmBuffer
产品支持情况
功能说明
从SPM Buffer读回到local数据中。
函数原型
-
适用于连续和不连续的数据回读:
template <typename T> __aicore__ inline void ReadSpmBuffer(const LocalTensor<T>& readBuffer, const DataCopyParams& copyParams, int32_t readOffset = 0) -
适用于连续的数据回读:
template <typename T> __aicore__ inline void ReadSpmBuffer(const LocalTensor<T>& readBuffer, const int32_t readSize, int32_t readOffset = 0)
参数说明
表 1 接口参数说明
搬运参数,DataCopyParams类型,DataCopyParams结构定义请参考表2。 |
||
表 2 DataCopyParams结构体参数定义
约束说明
无
返回值说明
无
调用示例
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};// 搬运一个连续传输数据块,连续传输数据块的长度为2个datablock,一个datablock32字节
pipe.ReadSpmBuffer(writeLocal, copyParams, offset);
AscendC::TPipe pipe;
AscendC::TQue<AscendC::TPosition::VECIN, 1> inQueueSrcVecIn;
int dataSize = 64; // 从UB上申请一块内存64*sizeof(half)字节
int offset = 32; // 读回时在spmBuffer上偏移32字节
pipe.InitBuffer(inQueueSrcVecIn, 1, dataSize * sizeof(half));
AscendC::LocalTensor<half> writeLocal = inQueueSrcVecIn.AllocTensor<half>();
pipe.ReadSpmBuffer(writeLocal, dataSize, offset);