TRSQRT¶
Tile Operation Diagram¶
Introduction¶
Elementwise reciprocal square root.
Math Interpretation¶
For each element (i, j) in the valid region:
\[ \mathrm{dst}_{i,j} = \frac{1}{\sqrt{\mathrm{src}_{i,j}}} \]
Assembly Syntax¶
Synchronous form:
%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<...>)
C++ Intrinsic¶
Declared in 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);
Constraints¶
- Implementation checks (NPU):
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 layout must be row-major (
TileData::isRowMajor).
- Valid region:
- 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
Temporary Space¶
Without tmp (2-argument overload: TRSQRT(dst, src))¶
No tmp is required. The default-precision implementation uses vsqrt + vdiv directly.
With tmp (3-argument overload: TRSQRT(dst, src, tmp))¶
tmp is accepted by the interface but not used by the current A5 implementation. The 3-argument overload simply delegates to the 2-argument implementation (TRSQRT_IMPL<PrecisionType>(dst, src)). tmp is retained in the C++ intrinsic signature for API compatibility and potential future high-precision paths.
Examples¶
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);
}
ASM Form Examples¶
Auto Mode¶
# Auto mode: compiler/runtime-managed placement and scheduling.
%dst = pto.trsqrt %src : !pto.tile<...> -> !pto.tile<...>
Manual Mode¶
# Manual mode: resources must be bound explicitly before issuing the instruction.
# Optional for tile operands:
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%dst = pto.trsqrt %src : !pto.tile<...> -> !pto.tile<...>
PTO Assembly Form¶
%dst = trsqrt %src : !pto.tile<...>
# AS Level 2 (DPS)
pto.trsqrt ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)