TRSQRT¶
指令示意图¶
简介¶
逐元素倒数平方根。
数学语义¶
对每个元素 (i, j) 在有效区域内:
\[ \mathrm{dst}_{i,j} = \frac{1}{\sqrt{\mathrm{src}_{i,j}}} \]
汇编语法¶
PTO-AS 形式:参见 PTO-AS Specification.
同步形式:
%dst = trsqrt %src : !pto.tile<...>
AS Level 1 (SSA)¶
%dst = pto.trsqrt %src : !pto.tile<...> -> !pto.tile<...>
AS Level 2 (DPS)¶
pto.trsqrt ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
AS Level 1(SSA)¶
%dst = pto.trsqrt %src : !pto.tile<...> -> !pto.tile<...>
AS Level 2(DPS)¶
pto.trsqrt ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++ 内建接口¶
声明于 include/pto/common/pto_instr.hpp:
template <typename TileDataDst, typename TileDataSrc, typename... WaitEvents>
PTO_INST RecordEvent TRSQRT(TileDataDst &dst, TileDataSrc &src, WaitEvents &... events);
template <typename TileDataDst, typename TileDataSrc, typename TileDataTmp, typename... WaitEvents>
PTO_INST RecordEvent TRSQRT(TileDataDst &dst, TileDataSrc &src, TileDataTmp &tmp, WaitEvents &... events);
约束¶
- 实现检查 (NPU):
- The
tmpbuffer must be at least 32 bytes. When tmp is provided, the high-precision version is executed. TileData::DTypemust be one of:floatorhalf;- Tile location must be vector (
TileData::Loc == TileType::Vec); - Static valid bounds:
TileData::ValidRow <= TileData::RowsandTileData::ValidCol <= TileData::Cols; - Runtime:
src.GetValidRow() == dst.GetValidRow()andsrc.GetValidCol() == dst.GetValidCol(); - Tile 布局 must be row-major (
TileData::isRowMajor).
- The
- 有效区域:
- The op uses
dst.GetValidRow()/dst.GetValidCol()as the iteration domain.
- The op uses
- Domain / NaN:
- Behavior is target-defined (e.g., for
src == 0or negative inputs).
- Behavior is target-defined (e.g., for
示例¶
自动(Auto)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
TileT src, dst;
TRSQRT(dst, src);
}
手动(Manual)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
TileT src, dst;
TASSIGN(src, 0x1000);
TASSIGN(dst, 0x2000);
TRSQRT(dst, src);
}