给定一个输入张量,每一次取输入张量中的8个数填充到结果张量的8个block(32Bytes)中去,每个数对应一个block。
template <typename T> __aicore__ inline void Brcb(const LocalTensor<T>& dstLocal, const LocalTensor<T>& src0Local, const uint8_t repeatTimes, const BrcbRepeatParams& repeatParams)
参数名称 |
输入/输出 |
含义 |
---|---|---|
dstLocal |
输出 |
目的操作数,类型为LocalTensor。支持数据类型(uint16_t/uint32_t), 地址需要32bytes对齐。 |
srcLocal |
输入 |
源操作数,类型为LocalTensor。连续存储score的elements。数据类型和dst保持一致。 |
repeatTimes |
输入 |
指令迭代次数,每次迭代完成8个block的数据收集,数据范围:repeatTimes∈[0,255]。 |
repeatParams |
输入 |
指令迭代参数,类型为BrcbRepeatParams,参数说明参考表2。 |
Atlas A2训练系列产品
无
#include "kernel_operator.h" namespace AscendC { class VbrcbCase { public: __aicore__ inline VbrcbCase() {} __aicore__ inline void Init(__gm__ uint8_t *x, __gm__ uint8_t *y) { x_gm.SetGlobalBuffer(reinterpret_cast<__gm__ uint16_t *>(x)); y_gm.SetGlobalBuffer(reinterpret_cast<__gm__ uint16_t *>(y)); tpipe.InitBuffer(vecIn, 1, 16 * sizeof(uint16_t)); tpipe.InitBuffer(vecOut, 1, 256 * sizeof(uint16_t)); } __aicore__ inline void Process() { CopyIn(); Compute(); CopyOut(); } __aicore__ inline void CopyIn() { auto x_buf = vecIn.AllocTensor<uint16_t>(); AscendC::DataCopy(x_buf, x_gm, 16); vecIn.EnQue(x_buf); } __aicore__ inline void Compute() { auto x_buf = vecIn.DeQue<uint16_t>(); auto y_buf = vecOut.AllocTensor<uint16_t>(); Brcb(y_buf, x_buf, 2, {1,8}); vecOut.EnQue(y_buf); vecIn.FreeTensor(x_buf); } __aicore__ inline void CopyOut() { auto y_buf = vecOut.DeQue<uint16_t>(); AscendC::DataCopy(y_gm, y_buf, 256); vecOut.FreeTensor(y_buf); } private: GlobalTensor<uint16_t> x_gm; GlobalTensor<uint16_t> y_gm; TPipe tpipe; TQue<QuePosition::VECIN, 1> vecIn; TQue<QuePosition::VECOUT, 1> vecOut; }; } // namespace AscendC extern "C" __global__ __aicore__ void vbrcb_uint16_t_16(__gm__ uint8_t *x, __gm__ uint8_t *y) { AscendC::VbrcbCase op; op.Init(x, y); op.Process(); }
输入数据(srcGlobal): [1 2 3 ... 16] 输出数据(dstGlobal):[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16]