asc_vf_call
产品支持情况
- Ascend 950PR/Ascend 950DT:支持
- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
- Atlas 200I/500 A2 推理产品:不支持
- Atlas 推理系列产品AI Core:不支持
- Atlas 推理系列产品Vector Core:不支持
- Atlas 训练系列产品:不支持
功能说明
在SIMD编程场景下使用。用于启动SIMD VF(Vector Function)子任务。
函数原型
C++
template <auto funcPtr, typename... Args>
__aicore__ inline void asc_vf_call(Args &&...args)
参数说明
表1 模板参数说明
| 参数名 | 描述 |
|---|---|
| funcPtr | 用于指定SIMD入口核函数。 |
| Args | 定义可变参数,用于传递实参到SIMD入口核函数。 |
表2 参数说明
| 参数名 | 输入/输出 | 描述 |
|---|---|---|
| args | 输入 | 可变参数,用于传递实参到SIMD入口核函数。 |
返回值说明
无
约束说明
- asc_vf_call启动SIMD VF子任务时,子任务函数不能是类的成员函数,推荐使用普通函数或类静态函数,且入口函数必须使用__simd_vf__修饰宏。
- asc_vf_call启动SIMD VF子任务时,入参仅支持Ascend C的内置数据类型(half、int32_t、uint32_t、float等)及其组成的指针、数组、结构体类型,且指针类型必须指向UB内存。
调用示例
使用SIMD VF函数对UB数据做加法计算。
C++
// SIMD函数
template <typename T>
__simd_vf__ inline void AddVF(
__ubuf__ T* dstAddr, __ubuf__ T* src0Addr, __ubuf__ T* src1Addr, uint32_t count, uint16_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 uint16_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);
}