TRSQRT

Tile Operation Diagram

TRSQRT tile operation

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

PTO-AS form: see PTO-AS Specification.

Synchronous form:

%dst = trsqrt %src : !pto.tile<...>

IR Level 1 (SSA)

%dst = pto.trsqrt %src : !pto.tile<...> -> !pto.tile<...>

IR 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 TileData, typename... WaitEvents>
PTO_INST RecordEvent TRSQRT(TileData& dst, TileData& src, WaitEvents&... events);

Constraints

  • Implementation checks (NPU):
  • TileData::DType must be one of: float or half;
  • Tile location must be vector (TileData::Loc == TileType::Vec);
  • Static valid bounds: TileData::ValidRow <= TileData::Rows and TileData::ValidCol <= TileData::Cols;
  • Runtime: src.GetValidRow() == dst.GetValidRow() and src.GetValidCol() == dst.GetValidCol();
  • Tile layout must be row-major (TileData::isRowMajor).
  • Valid region:
  • The op uses dst.GetValidRow() / dst.GetValidCol() as the iteration domain.
  • Domain / NaN:
  • Behavior is target-defined (e.g., for src == 0 or negative inputs).

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: bind resources 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<...>
# IR Level 2 (DPS)
pto.trsqrt ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)