asc_vf_call
产品支持情况
产品 |
是否支持 |
|---|---|
Atlas 350 加速卡 |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
功能说明
在SIMD编程场景下使用。用于启动SIMD VF(Vector Function)子任务。
函数原型
1 2 | template <auto funcPtr, typename... Args> __aicore__ inline void asc_vf_call(Args &&...args) |
参数说明
参数名 |
描述 |
|---|---|
funcPtr |
用于指定SIMD入口核函数。 |
Args |
定义可变参数,用于传递实参到SIMD入口核函数。 |
参数名 |
输入/输出 |
描述 |
|---|---|---|
args |
输入 |
可变参数,用于传递实参到SIMD入口核函数。 |
返回值说明
无
约束说明
- asc_vf_call启动SIMD VF子任务时,子任务函数不能是类的成员函数,推荐使用普通函数或类静态函数,且入口函数必须使用__simd_vf__修饰宏。
- asc_vf_call启动SIMD VF子任务时,传递的参数只支持裸指针,常见基本数据类型。不支持传递结构体,数组等。
调用示例
使用SIMD VF 函数对UB数据做加法计算。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | // SIMD函数 template <typename T> __simd_vf__ inline void AddVF( __ubuf__ T* dstAddr, __ubuf__ T* src0Addr, __ubuf__ T* src1Addr, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes) { AscendC::Reg::RegTensor<T> src0Reg; AscendC::Reg::RegTensor<T> src1Reg; AscendC::Reg::RegTensor<T> dstReg; AscendC::Reg::MaskReg mask; for (uint16_t i = 0; i < repeatTimes; i++) { mask = AscendC::Reg::UpdateMask<T>(count); AscendC::Reg::LoadAlign(src0Reg, src0Addr + i * oneRepeatSize); AscendC::Reg::LoadAlign(src1Reg, src1Addr + i * oneRepeatSize); AscendC::Reg::Add(dstReg, src0Reg, src1Reg, mask); AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask); } } template <typename T> __aicore__ inline void Compute() { AscendC::LocalTensor<T> dst = outQueueZ.AllocTensor<T>(); AscendC::LocalTensor<T> src0 = inQueueX.DeQue<T>(); AscendC::LocalTensor<T> src1 = inQueueY.DeQue<T>(); constexpr uint32_t oneRepeatSize = AscendC::GetVecLen() / sizeof(T); uint32_t count = 512; // 向上取整,计算循环次数 uint16_t repeatTimes = AscendC::CeilDivision(count, oneRepeatSize); __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); __ubuf__ T* src0Addr = (__ubuf__ T*)src0.GetPhyAddr(); __ubuf__ T* src1Addr = (__ubuf__ T*)src1.GetPhyAddr(); asc_vf_call<AddVF<T>>(dstAddr, src0Addr, src1Addr, count, oneRepeatSize, repeatTimes); outQueueZ.EnQue(dst); inQueueX.FreeTensor(src0); inQueueY.FreeTensor(src1); } |
父主题: Reg矢量计算