TROWMIN¶
指令示意图¶
简介¶
通过取列间最小值来归约每一行。
数学语义¶
设 R = src.GetValidRow(),C = src.GetValidCol()。对 0 <= i < R:
\[ \mathrm{dst}_{i,0} = \min_{0 \le j < C} \mathrm{src}_{i,j} \]
汇编语法¶
同步形式:
%dst = trowmin %src : !pto.tile<...> -> !pto.tile<...>
降低时可能引入内部临时Tile;C++内建接口需要显式传入 tmp 操作数。
AS Level 1(SSA)¶
%dst = pto.trowmin %src, %tmp : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
AS Level 2(DPS)¶
pto.trowmin ins(%src, %tmp : !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++内建接口¶
声明于 include/pto/common/pto_instr.hpp:
公共包含头为
<pto/pto-inst.hpp>,内部声明位于pto/common/pto_instr.hpp。
template <typename TileDataOut, typename TileDataIn, typename TileDataTmp, typename... WaitEvents>
PTO_INST RecordEvent TROWMIN(TileDataOut &dst, TileDataIn &src, TileDataTmp &tmp, WaitEvents &... events);
约束¶
通用约束或检查¶
dst和src必须均为TileType::Vec。src必须使用标准ND布局:行主且非分形(BLayout::RowMajor、SLayout::NoneBox)。dst必须使用以下两种非分形布局之一:- ND布局(
BLayout::RowMajor、SLayout::NoneBox),或 - 列数严格为1的DN布局(
BLayout::ColMajor、SLayout::NoneBox、Cols == 1)。
- ND布局(
dst和src的元素类型必须一致。- 运行时有效区域检查:
src.GetValidRow() != 0src.GetValidCol() != 0src.GetValidRow() == dst.GetValidRow()
- 内建接口签名要求显式传入
tmp操作数。
Atlas A2/A3 训练系列产品/Atlas A2/A3 推理系列产品实现检查¶
- 支持的元素类型 (Atlas A2/A3 训练系列产品/Atlas A2/A3 推理系列产品):
half、float、int32_t、int16_t。 - 支持的元素类型 (Ascend 950PR/Ascend 950DT):
half、float、int32_t、int16_t、int8_t、uint8_t。 - 实现同时接受ND输出和
Cols == 1的DN输出。 - 运行时检查遵循共享的行归约检查路径:
src.GetValidRow() != 0src.GetValidCol() != 0src.GetValidRow() == dst.GetValidRow()
临时空间¶
Atlas A2/A3 训练系列产品/Atlas A2/A3 推理系列产品¶
tmp 被使用作为行最小值归约的暂存存储。
- 对于整数类型(
int32_t、int16_t):tmp用作逐行累加器缓冲区(1个块)。对于每一行,tmp初始化为最大可表示值,然后通过vmin累加src的各个块。最终最小值在标量模式下从tmp读取。 tmp大小:至少1行和BLOCK_BYTE_SIZE / sizeof(T)列(int32_t为8,int16_t为16)。- 对于浮点类型(
float、half):tmp用于通过vcmin/vcgmin的二叉树归约。 - 安全的默认设置:将
tmp设为与src相同的形状。
Ascend 950PR/Ascend 950DT¶
tmp 被接口接受但Ascend 950PR/Ascend 950DT实现不使用。Ascend 950PR/Ascend 950DT后端使用基于向量寄存器的归约(vcmin 指令),不需要暂存Tile存储。tmp 仅为了与Atlas A2/A3 训练系列产品/Atlas A2/A3 推理系列产品的API兼容性而保留在C++内建接口签名中。
示例¶
自动(Auto)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using SrcT = Tile<TileType::Vec, float, 16, 16>;
using DstT = Tile<TileType::Vec, float, 16, 1, BLayout::ColMajor>;
using TmpT = Tile<TileType::Vec, float, 16, 16>;
SrcT src;
DstT dst;
TmpT tmp;
TROWMIN(dst, src, tmp);
}
手动(Manual)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using SrcT = Tile<TileType::Vec, float, 16, 16>;
using DstT = Tile<TileType::Vec, float, 16, 1, BLayout::ColMajor>;
using TmpT = Tile<TileType::Vec, float, 16, 16>;
SrcT src;
DstT dst;
TmpT tmp;
TASSIGN(src, 0x1000);
TASSIGN(dst, 0x2000);
TASSIGN(tmp, 0x3000);
TROWMIN(dst, src, tmp);
}
汇编示例(ASM)¶
自动模式¶
# 自动模式:由编译器/运行时负责资源放置与调度。
%dst = pto.trowmin %src, %tmp : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
手动模式¶
# 手动模式:先显式绑定资源,再发射指令。
# 可选(当该指令包含 tile 操作数时):
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%dst = pto.trowmin %src, %tmp : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
PTO汇编形式¶
%dst = trowmin %src : !pto.tile<...> -> !pto.tile<...>
# AS Level 2 (DPS)
pto.trowmin ins(%src, %tmp : !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)