CANN/asc-devkit SetCmpMask API文档
SetCmpMask(ISASI)产品支持情况产品是否支持Ascend 950PR/Ascend 950DT√Atlas A3 训练系列产品 / Atlas A3 推理系列产品√Atlas A2 训练系列产品 / Atlas A2 推理系列产品√功能说明为Select不传入mask参数的接口设置比较寄存器。配合不同的selMode传入不同的数据。模式0SELMODE::VSEL_CMPMASK_SPRSetCmpMask中传入selMask LocalTensor。模式1SELMODE::VSEL_TENSOR_SCALAR_MODESetCmpMask中传入src1 LocalTensor。模式2SELMODE::VSEL_TENSOR_TENSOR_MODESetCmpMask中传入LocalTensorLocalTensor中存放的是selMask的地址。函数原型template typename T __aicore__ inline void SetCmpMask(const LocalTensorT src)参数说明表 1模板参数说明参数名描述T操作数的数据类型。表 2参数说明参数名输入/输出描述src输入类型为LocalTensor支持的TPosition为VECIN/VECCALC/VECOUT。LocalTensor的起始地址需要16字节对齐。返回值说明无约束说明无调用示例当selMode为模式0或模式2时uint32_t dataSize 256; uint32_t selDataSize 8; TPipe pipe; TQueTPosition::VECIN, 1 inQueueX; TQueTPosition::VECIN, 1 inQueueY; TQueTPosition::VECIN, 1 inQueueSel; TQueTPosition::VECOUT, 1 outQueue; pipe.InitBuffer(inQueueX, 1, dataSize * sizeof(float)); pipe.InitBuffer(inQueueY, 1, dataSize * sizeof(float)); pipe.InitBuffer(inQueueSel, 1, selDataSize * sizeof(uint8_t)); pipe.InitBuffer(outQueue, 1, dataSize * sizeof(float)); AscendC::LocalTensorfloat dst outQueue.AllocTensorfloat(); AscendC::LocalTensoruint8_t sel inQueueSel.AllocTensoruint8_t(); AscendC::LocalTensorfloat src0 inQueueX.AllocTensorfloat(); AscendC::LocalTensorfloat src1 inQueueY.AllocTensorfloat(); uint8_t repeat 4; uint32_t mask 64; AscendC::BinaryRepeatParams repeatParams { 1, 1, 1, 8, 8, 8 }; // selMode为模式0SELMODE::VSEL_CMPMASK_SPR AscendC::SetCmpMask(sel); AscendC::PipeBarrierPIPE_V(); AscendC::SetVectorMaskfloat(mask); AscendC::Selectfloat, AscendC::SELMODE::VSEL_CMPMASK_SPR(dst, src0, src1, repeat, repeatParams); // selMode为模式2SELMODE::VSEL_TENSOR_TENSOR_MODE AscendC::LocalTensorint32_t tempBuf; #if defined(ASCENDC_CPU_DEBUG) (ASCENDC_CPU_DEBUG 1) // cpu调试 tempBuf.ReinterpretCastint64_t().SetValue(0, reinterpret_castint64_t(reinterpret_cast__ubuf__ int64_t*(sel.GetPhyAddr()))); event_t eventIdSToV static_castevent_t(AscendC::GetTPipePtr()-FetchEventID(AscendC::HardEvent::S_V)); AscendC::SetFlagAscendC::HardEvent::S_V(eventIdSToV); AscendC::WaitFlagAscendC::HardEvent::S_V(eventIdSToV); #else // npu调试 uint32_t selAddr static_castuint32_t(reinterpret_castint64_t(reinterpret_cast__ubuf__ int64_t*(sel.GetPhyAddr()))); AscendC::SetVectorMaskuint32_t(32); AscendC::Duplicateuint32_t, false(tempBuf.ReinterpretCastuint32_t(), selAddr, AscendC::MASK_PLACEHOLDER, 1, 1, 8); AscendC::PipeBarrierPIPE_V(); #endif AscendC::SetCmpMaskint64_t(tempBuf.ReinterpretCastint64_t()); AscendC::PipeBarrierPIPE_V(); AscendC::SetVectorMaskfloat(mask); AscendC::Selectfloat, AscendC::SELMODE::VSEL_TENSOR_TENSOR_MODE(dst, src0, src1, repeat, repeatParams);当selMode为模式1时uint32_t dataSize 256; uint32_t selDataSize 8; TPipe pipe; TQueTPosition::VECIN, 1 inQueueX; TQueTPosition::VECIN, 1 inQueueY; TQueTPosition::VECIN, 1 inQueueSel; TQueTPosition::VECOUT, 1 outQueue; pipe.InitBuffer(inQueueX, 1, dataSize * sizeof(float)); pipe.InitBuffer(inQueueY, 1, dataSize * sizeof(float)); pipe.InitBuffer(inQueueSel, 1, selDataSize * sizeof(uint8_t)); pipe.InitBuffer(outQueue, 1, dataSize * sizeof(float)); AscendC::LocalTensorfloat dst outQueue.AllocTensorfloat(); AscendC::LocalTensoruint8_t sel inQueueSel.AllocTensoruint8_t(); AscendC::LocalTensorfloat src0 inQueueX.AllocTensorfloat(); AscendC::LocalTensorfloat tmpScalar inQueueY.AllocTensorfloat(); uint8_t repeat 4; uint32_t mask 64; AscendC::BinaryRepeatParams repeatParams { 1, 1, 1, 8, 8, 8 }; // selMode为模式1SELMODE::VSEL_TENSOR_SCALAR_MODE AscendC::SetVectorMaskuint32_t(32); AscendC::Duplicatefloat, false(tmpScalar, static_castfloat(1.0), MASK_PLACEHOLDER, 1, 1, 8); AscendC::PipeBarrierPIPE_V(); AscendC::SetCmpMask(tmpScalar); AscendC::PipeBarrierPIPE_V(); AscendC::SetVectorMaskfloat(mask); AscendC::Select(dst, sel, src0, repeat, repeatParams);创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考