CANN/asc-devkit特殊寄存器访问API文档 GetSpr【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit产品支持情况Ascend 950PR/Ascend 950DT支持Atlas A3 训练系列产品/Atlas A3 推理系列产品不支持Atlas A2 训练系列产品/Atlas A2 推理系列产品不支持Atlas 200I/500 A2 推理产品不支持Atlas 推理系列产品AI Core不支持Atlas 推理系列产品Vector Core不支持Atlas 训练系列产品不支持功能说明头文件路径为basic_api/kernel_operator_sys_var_intf.h。获取指定特殊寄存器的值。当前支持表SpecialPurposeReg模板参数说明。函数原型template SpecialPurposeReg spr __aicore__ inline int64_t GetSpr()参数说明表1模板参数说明参数名描述spr特殊寄存器类型为SpecialPurposeReg枚举类具体的取值请参考表SpecialPurposeReg模板参数说明。表2SpecialPurposeReg模板参数说明取值含义AR通常配合SqueezeReg矢量计算API一起使用SqueezeReg矢量计算API会存储有效元素的总字节数到AR特殊寄存器。数据类型接口返回数据类型为int64_t。返回值说明返回int64_t类型的特殊寄存器中的数值。约束说明本接口只能在VF函数外调用命名空间为AscendC函数标记符为__aicore__。调用示例如下示例中SqueezeReg矢量计算API会存储有效元素的总字节数到AR寄存器中宏函数结束后通过GetSpr获取AR寄存器的值单位为字节。template typename T __simd_vf__ inline void SqueezeVF(__ubuf__ T* xAddr, __ubuf__ T* yAddr, uint32_t repeatTimes, uint32_t oneRepeatSize) { AscendC::Reg::MaskReg mask AscendC::Reg::CreateMaskT, AscendC::Reg::MaskPattern::M4(); AscendC::Reg::RegTensorT xReg; AscendC::Reg::RegTensorT yReg; AscendC::Reg::UnalignRegForStore ureg; AscendC::Reg::ClearSprAscendC::SpecialPurposeReg::AR(); for (uint16_t i 0; i repeatTimes; i) { AscendC::Reg::LoadAlignT, AscendC::Reg::PostLiteral::POST_MODE_UPDATE(xReg, xAddr, oneRepeatSize); AscendC::Reg::SqueezeT, AscendC::Reg::GatherMaskMode::STORE_REG(yReg, xReg, mask); AscendC::Reg::StoreUnAlignT, AscendC::Reg::PostLiteral::POST_MODE_UPDATE(yAddr, yReg, ureg); } AscendC::Reg::StoreUnAlignPost(yAddr, ureg); } __aicore__ inline void Process() { AscendC::LocalMemAllocatorAscendC::Hardware::UB ubAllocator; AscendC::LocalTensorfloat xLocal ubAllocator.Allocfloat, 256(); AscendC::LocalTensorfloat yLocal ubAllocator.Allocfloat, 64(); AscendC::DataCopy(xLocal, xGm, 256); AscendC::SetFlagAscendC::HardEvent::MTE2_V(EVENT_ID0); AscendC::WaitFlagAscendC::HardEvent::MTE2_V(EVENT_ID0); __ubuf__ float* xAddr reinterpret_cast__ubuf__ float*(xLocal.GetPhyAddr()); __ubuf__ float* yAddr reinterpret_cast__ubuf__ float*(yLocal.GetPhyAddr()); constexpr uint32_t oneRepeatSize AscendC::GetVecLen() / sizeof(float); uint16_t repeatTimes DivCeil(256, oneRepeatSize); asc_vf_callSqueezeVFfloat(xAddr, yAddr, repeatTimes, oneRepeatSize); AscendC::SetFlagAscendC::HardEvent::V_S(EVENT_ID0); AscendC::WaitFlagAscendC::HardEvent::V_S(EVENT_ID0); int64_t arNum AscendC::GetSprAscendC::SpecialPurposeReg::AR(); // 可通过printf打印 AscendC::printf(arNum的值为:%lld\n, arNum); AscendC::SetFlagAscendC::HardEvent::S_MTE3(EVENT_ID0); AscendC::WaitFlagAscendC::HardEvent::S_MTE3(EVENT_ID0); AscendC::DataCopy(yGm, yLocal, 64); }结果示例如下输入256个float的数据(xLocal): [1.0 1.0 1.0 ... ] // 数据为全1.0的数 输入64个float的数据(yLocal): [1.0 1.0 1.0 ... ] // 数据为全1.0的数 arNum的值为:256【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考