SetCmpMask(ISASI)
产 品 支 持 情 况
功 能 说 明
头 文 件 路 径 为:"basic_api/kernel_operator_vec_cmpsel_intf.h"。
设 置 比 较 寄 存 器 的 值,配 合 不 传 入mask参 数 的Select接 口 使 用,根 据 不 同 的selMode传 入 不 同 的 数 据。
模 式0(SELMODE::VSEL_CMPMASK_SPR)
SetCmpMask中 传 入selMask LocalTensor。
模 式1(SELMODE::VSEL_TENSOR_SCALAR_MODE)
SetCmpMask中 传 入src1 LocalTensor。
模 式2(SELMODE::VSEL_TENSOR_TENSOR_MODE)
SetCmpMask中 传 入LocalTensor,LocalTensor中 存 放 的 是selMask的 地 址。
函 数 原 型
C++
template <typename T>
__aicore__ inline void SetCmpMask(const LocalTensor<T>& src)
参 数 说 明
表 1 模 板 参 数 说 明
| 参 数 名 | 描 述 |
|---|---|
| T | 操 作 数 的 数 据 类 型。 |
表 2 参 数 说 明
| 参 数 名 | 输 入/输 出 | 描 述 |
|---|---|---|
| src | 输 入 | 类 型 为LocalTensor,支 持 的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的 起 始 地 址 需 要16字 节 对 齐。 |
数 据 类 型
支 持 数 据 类 型 为:b8、b16、b32、b64。
返 回 值 说 明
无
约 束 说 明
无
调 用 示 例
当selMode为 模 式0或 模 式2时:
C++uint32_t dataSize = 256; uint32_t selDataSize = 8; TPipe pipe; TQue<TPosition::VECIN, 1> inQueueX; TQue<TPosition::VECIN, 1> inQueueY; TQue<TPosition::VECIN, 1> inQueueSel; TQue<TPosition::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::LocalTensor<float> dst = outQueue.AllocTensor<float>(); AscendC::LocalTensor<uint8_t> sel = inQueueSel.AllocTensor<uint8_t>(); AscendC::LocalTensor<float> src0 = inQueueX.AllocTensor<float>(); AscendC::LocalTensor<float> src1 = inQueueY.AllocTensor<float>(); uint8_t repeat = 4; uint32_t mask = 64; AscendC::BinaryRepeatParams repeatParams = { 1, 1, 1, 8, 8, 8 }; // selMode为 模 式0(SELMODE::VSEL_CMPMASK_SPR) AscendC::SetCmpMask(sel); AscendC::PipeBarrier<PIPE_V>(); AscendC::SetVectorMask<float>(mask); AscendC::Select<float, AscendC::SELMODE::VSEL_CMPMASK_SPR>(dst, src0, src1, repeat, repeatParams); // selMode为 模 式2(SELMODE::VSEL_TENSOR_TENSOR_MODE) AscendC::LocalTensor<int32_t> tempBuf; #if defined(ASCENDC_CPU_DEBUG) && (ASCENDC_CPU_DEBUG == 1) // cpu调 试 tempBuf.ReinterpretCast<int64_t>().SetValue(0, reinterpret_cast<int64_t>(reinterpret_cast<__ubuf__ int64_t*>(sel.GetPhyAddr()))); event_t eventIdSToV = static_cast<event_t>(AscendC::GetTPipePtr()->FetchEventID(AscendC::HardEvent::S_V)); AscendC::SetFlag<AscendC::HardEvent::S_V>(eventIdSToV); AscendC::WaitFlag<AscendC::HardEvent::S_V>(eventIdSToV); #else // npu调 试 uint32_t selAddr = static_cast<uint32_t>(reinterpret_cast<int64_t>(reinterpret_cast<__ubuf__ int64_t*>(sel.GetPhyAddr()))); AscendC::SetVectorMask<uint32_t>(32); AscendC::Duplicate<uint32_t, false>(tempBuf.ReinterpretCast<uint32_t>(), selAddr, AscendC::MASK_PLACEHOLDER, 1, 1, 8); AscendC::PipeBarrier<PIPE_V>(); #endif AscendC::SetCmpMask<int64_t>(tempBuf.ReinterpretCast<int64_t>()); AscendC::PipeBarrier<PIPE_V>(); AscendC::SetVectorMask<float>(mask); AscendC::Select<float, AscendC::SELMODE::VSEL_TENSOR_TENSOR_MODE>(dst, src0, src1, repeat, repeatParams);当selMode为 模 式1时:
C++uint32_t dataSize = 256; uint32_t selDataSize = 8; TPipe pipe; TQue<TPosition::VECIN, 1> inQueueX; TQue<TPosition::VECIN, 1> inQueueY; TQue<TPosition::VECIN, 1> inQueueSel; TQue<TPosition::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::LocalTensor<float> dst = outQueue.AllocTensor<float>(); AscendC::LocalTensor<uint8_t> sel = inQueueSel.AllocTensor<uint8_t>(); AscendC::LocalTensor<float> src0 = inQueueX.AllocTensor<float>(); AscendC::LocalTensor<float> tmpScalar = inQueueY.AllocTensor<float>(); uint8_t repeat = 4; uint32_t mask = 64; AscendC::BinaryRepeatParams repeatParams = { 1, 1, 1, 8, 8, 8 }; // selMode为 模 式1(SELMODE::VSEL_TENSOR_SCALAR_MODE) AscendC::SetVectorMask<uint32_t>(32); AscendC::Duplicate<float, false>(tmpScalar, static_cast<float>(1.0), AscendC::MASK_PLACEHOLDER, 1, 1, 8); AscendC::PipeBarrier<PIPE_V>(); AscendC::SetCmpMask(tmpScalar); AscendC::PipeBarrier<PIPE_V>(); AscendC::SetVectorMask<float>(mask); AscendC::Select(dst, sel, src0, repeat, repeatParams);