TPOW

指令示意图

TPOW tile operation

简介

逐元素幂运算:计算每个元素的 baseexp 次幂。

数学语义

R = dst.GetValidRow()C = dst.GetValidCol()。对 0 <= i < R0 <= j < C

\[ \mathrm{dst}_{i,j} = \mathrm{base}_{i,j}^{\mathrm{exp}_{i,j}} \]

对于浮点类型,计算遵循 dst = exp(ln(|base|) * exp),并对负数底数和整数指数进行特殊处理。

汇编语法

PTO-AS 形式:参见 PTO-AS 规范

同步形式:

%dst = tpow %base, %exp, %tmp : !pto.tile<...>

降低时可能引入内部临时 Tile;C++ 内建接口需要显式传入 tmp 操作数。

AS Level 1(SSA)

%dst = pto.tpow %base, %exp, %tmp : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>

AS Level 2(DPS)

pto.tpow ins(%base, %exp, %tmp : !pto.tile_buf<...>, !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)

C++ 内建接口

声明于 include/pto/common/pto_instr.hpp

template <auto PrecisionType = PowAlgorithm::DEFAULT, typename DstTile, typename BaseTile, typename ExpTile,
          typename TmpTile, typename... WaitEvents>
PTO_INTERNAL RecordEvent TPOW(DstTile &dst, BaseTile &base, ExpTile &exp, TmpTile &tmp, WaitEvents &... events);

PrecisionType 可选值:

  • PowAlgorithm::DEFAULT:普通算法,速度较快但精度较低。
  • PowAlgorithm::HIGH_PRECISION:高精度算法,速度较慢但精度更高。

约束

通用约束或检查

  • dstbaseexp 必须均为 TileType::Vec
  • 所有 Tile 必须使用行主序布局(TileData::isRowMajor)。
  • dstbaseexp 的元素类型必须一致。
  • 静态有效区域约束:TileData::ValidRow <= TileData::RowsTileData::ValidCol <= TileData::Cols
  • 运行时有效区域检查:
    • dst.GetValidRow() == base.GetValidRow()
    • dst.GetValidCol() == base.GetValidCol()
    • dst.GetValidRow() == exp.GetValidRow()
    • dst.GetValidCol() == exp.GetValidCol()
  • 内建接口签名要求显式传入 tmp 操作数。

A2A3 实现检查

  • 支持的元素类型:int32_tint16_tint8_tuint32_tuint16_tuint8_tfloat
  • A2A3 不支持 HIGH_PRECISION 算法;PrecisionType 选项将被忽略。
  • 额外的 tmp 运行时有效区域检查:
    • dst.GetValidRow() == tmp.GetValidRow()
    • dst.GetValidCol() == tmp.GetValidCol()

A5 实现检查

  • DEFAULT 算法支持的元素类型:uint8_tint8_tuint16_tint16_tuint32_tint32_thalffloatbfloat16_t
  • HIGH_PRECISION 算法支持的元素类型:halffloatbfloat16_t(仅支持浮点类型)。
  • 整数类型使用独立的整数幂计算路径。

示例

自动(Auto)

#include <pto/pto-inst.hpp>

using namespace pto;

void example_auto() {
  using TileT = Tile<TileType::Vec, float, 16, 16>;
  TileT base, exp, dst, tmp;
  TPOW(dst, base, exp, tmp);
  TPOW<PowAlgorithm::HIGH_PRECISION>(dst, base, exp, tmp);
}

手动(Manual)

#include <pto/pto-inst.hpp>

using namespace pto;

void example_manual() {
  using TileT = Tile<TileType::Vec, float, 16, 16>;
  TileT base, exp, dst, tmp;
  TASSIGN(base, 0x1000);
  TASSIGN(exp, 0x2000);
  TASSIGN(dst, 0x3000);
  TASSIGN(tmp, 0x4000);
  TPOW(dst, base, exp, tmp);
}

汇编示例(ASM)

自动模式

# 自动模式:由编译器/运行时负责资源放置与调度。
%dst = pto.tpow %base, %exp, %tmp : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>

手动模式

# 手动模式:先显式绑定资源,再发射指令。
# 可选(当该指令包含 tile 操作数时):
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
# pto.tassign %arg2, @tile(0x3000)
%dst = pto.tpow %base, %exp, %tmp : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>

PTO 汇编形式

```text %dst = tpow %base, %exp, %tmp : !pto.tile<...>

AS Level 2 (DPS)

pto.tpow ins(%base, %exp, %tmp : !pto.tile_buf<...>, !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>) ```"