TSQRT

指令示意图

TSQRT tile operation

简介

逐元素平方根。

数学语义

对每个元素 (i, j) 在有效区域内:

\[ \mathrm{dst}_{i,j} = \sqrt{\mathrm{src}_{i,j}} \]

汇编语法

PTO-AS 形式:参见 PTO-AS Specification.

同步形式:

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

AS Level 1 (SSA)

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

AS Level 2 (DPS)

pto.tsqrt ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)

AS Level 1(SSA)

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

AS Level 2(DPS)

pto.tsqrt 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 TSQRT(TileDataDst &dst, TileDataSrc &src, WaitEvents &... events);

约束

  • 实现检查 (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 布局 must be row-major (TileData::isRowMajor).
  • 有效区域:
    • The op uses dst.GetValidRow() / dst.GetValidCol() as the iteration domain.
  • Domain / NaN:
    • Behavior is target-defined (e.g., for negative inputs).

示例

自动(Auto)

#include <pto/pto-inst.hpp>

using namespace pto;

void example_auto() {
  using TileT = Tile<TileType::Vec, float, 16, 16>;
  TileT src, dst;
  TSQRT(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);
  TSQRT(dst, src);
}