TCMP¶
指令示意图¶
简介¶
比较两个 Tile 并写入一个打包的谓词掩码。
数学语义¶
Conceptually, for each element (i, j) in the valid region, define a predicate:
\[ p_{i,j} = \left(\mathrm{src0}_{i,j}\ \mathrm{cmpMode}\ \mathrm{src1}_{i,j}\right) \]
The predicate mask is stored in dst using an implementation-defined packed layout.
汇编语法¶
PTO-AS 形式:参见 PTO-AS Specification.
同步形式:
%dst = tcmp %src0, %src1 {cmpMode = #pto.cmp<EQ>} : !pto.tile<...> -> !pto.tile<...>
AS Level 1 (SSA)¶
%dst = pto.tcmp %src0, %src1{cmpMode = #pto<cmp xx>}: (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
AS Level 2 (DPS)¶
pto.tcmp ins(%src0, %src1{cmpMode = #pto<cmp xx>}: !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
AS Level 1(SSA)¶
%dst = pto.tcmp %src0, %src1{cmpMode = #pto<cmp xx>}: (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
AS Level 2(DPS)¶
pto.tcmp ins(%src0, %src1{cmpMode = #pto<cmp xx>}: !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++ 内建接口¶
声明于 include/pto/common/pto_instr.hpp and include/pto/common/type.hpp:
template <typename TileDataDst, typename TileDataSrc, typename... WaitEvents>
PTO_INST RecordEvent TCMP(TileDataDst &dst, TileDataSrc &src0, TileDataSrc &src1, CmpMode cmpMode, WaitEvents &... events);
约束¶
- 实现检查 (A2A3):
- Input type must be one of:
int32_t,half,float. - Output type must be
uint8_t. src0/src1/dsttile location must beTileType::Vec.- Static valid bounds:
TileDataSrc::ValidRow <= TileDataSrc::RowsandTileDataSrc::ValidCol <= TileDataSrc::Cols. - Runtime:
src0.GetValidRow() == dst.GetValidRow()andsrc0.GetValidCol() == dst.GetValidCol(). - Note:
src1shape/valid is not validated by explicit runtime assertions in this implementation. - For
TileDataSrc::DType == int32_t, the implementation uses theEQcompare path regardless ofcmpMode.
- Input type must be one of:
- 实现检查 (A5):
- Input type must be one of:
uint32_t,int32_t,uint16_t,int16_t,uint8_t,int8_t,float,half. - Output type must be
uint32_t. - Implemented (see
include/pto/npu/a5/TCmp.hpp). - The A5 implementation uses
dst.GetValidRow()/dst.GetValidCol()as the iteration domain and writes a packed predicate mask intodst(target-defined packing).
- Input type must be one of:
- Mask encoding:
- The mask tile is interpreted as packed predicate bits in a target-defined layout.
示例¶
自动(Auto)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using SrcT = Tile<TileType::Vec, float, 16, 16>;
using MaskT = Tile<TileType::Vec, uint8_t, 16, 32, BLayout::RowMajor, -1, -1>;
SrcT src0, src1;
MaskT mask(16, 2);
TCMP(mask, src0, src1, CmpMode::GT);
}
手动(Manual)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using SrcT = Tile<TileType::Vec, float, 16, 16>;
using MaskT = Tile<TileType::Vec, uint8_t, 16, 32, BLayout::RowMajor, -1, -1>;
SrcT src0, src1;
MaskT mask(16, 2);
TASSIGN(src0, 0x1000);
TASSIGN(src1, 0x2000);
TASSIGN(mask, 0x3000);
TCMP(mask, src0, src1, CmpMode::GT);
}