TCOLSUM¶
指令示意图¶
简介¶
通过对行求和来归约每一列。
数学语义¶
设 R = src.GetValidRow(),C = src.GetValidCol()。对 0 <= j < C:
\[ \mathrm{dst}_{0,j} = \sum_{i=0}^{R-1} \mathrm{src}_{i,j} \]
isBinary 选择实现路径(二叉树累加 vs. 顺序累加)。
汇编语法¶
PTO-AS 形式:参见 PTO-AS 规范。
同步形式:
%dst = tcolsum %src {isBinary = false} : !pto.tile<...> -> !pto.tile<...>
降低时可能引入内部临时 Tile;C++ 内建接口需要显式传入 tmp 操作数。
AS Level 1(SSA)¶
%dst = pto.tcolsum %src : !pto.tile<...> -> !pto.tile<...>
%dst = pto.tcolsum %src, %tmp {isBinary = false} : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
AS Level 2(DPS)¶
pto.tcolsum ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
pto.tcolsum ins(%src, %tmp {isBinary = false} : !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++ 内建接口¶
声明于 include/pto/common/pto_instr.hpp:
template <typename TileDataOut, typename TileDataIn, typename... WaitEvents>
PTO_INST RecordEvent TCOLSUM(TileDataOut &dst, TileDataIn &src, WaitEvents &... events);
template <typename TileDataOut, typename TileDataIn, typename TileDataTmp, typename... WaitEvents>
PTO_INST RecordEvent TCOLSUM(TileDataOut &dst, TileDataIn &src, TileDataTmp &tmp, bool isBinary, WaitEvents &... events);
约束¶
通用约束或检查¶
dst和src必须为TileType::Vec。dst和src必须使用标准 ND 布局:行主且非分形(BLayout::RowMajor、SLayout::NoneBox)。dst和src的元素类型必须一致。- 运行时检查:
src.GetValidCol() == dst.GetValidCol()src.GetValidRow() != 0src.GetValidCol() != 0src.GetValidCol()必须不大于按src元素计的tmp行跨度
isBinary选择已检查到的后端路径:true:使用tmp做二叉树累加false:直接在dst上做顺序累加
A2A3 实现检查¶
- 支持的元素类型:
half、float、int16_t、int32_t。 tmp必须为TileType::Vec,且使用标准 ND 布局:行主且非分形(BLayout::RowMajor、SLayout::NoneBox)。tmp的元素类型必须与src和dst一致。- 若
src.GetValidRow() == 0或src.GetValidCol() == 0,实现会直接返回。
A5 实现检查¶
- A5 共享列归约检查允许的元素类型为:
half、float、int8_t、uint8_t、int16_t、uint16_t、int32_t、uint32_t、bfloat16_t。 - 已检查到的 A5
TCOLSUM路径中,tmp仍只用于二叉累加路径;TCOLSUM_IMPL中没有额外显式加入tmp的编译期类型/布局断言。
示例¶
自动(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, 1, 16>;
using TmpT = Tile<TileType::Vec, float, 16, 16>;
SrcT src;
DstT dst;
TmpT tmp;
TCOLSUM(dst, src, tmp, /*isBinary=*/false);
}
手动(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, 1, 16>;
using TmpT = Tile<TileType::Vec, float, 16, 16>;
SrcT src;
DstT dst;
TmpT tmp;
TASSIGN(src, 0x1000);
TASSIGN(dst, 0x2000);
TASSIGN(tmp, 0x3000);
TCOLSUM(dst, src, tmp, /*isBinary=*/false);
}
汇编示例(ASM)¶
自动模式¶
# 自动模式:由编译器/运行时负责资源放置与调度。
%dst = pto.tcolsum %src : !pto.tile<...> -> !pto.tile<...>
手动模式¶
# 手动模式:先显式绑定资源,再发射指令。
# 可选(当该指令包含 tile 操作数时):
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%dst = pto.tcolsum %src : !pto.tile<...> -> !pto.tile<...>
PTO 汇编形式¶
%dst = tcolsum %src {isBinary = false} : !pto.tile<...> -> !pto.tile<...>
# AS Level 2 (DPS)
pto.tcolsum ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)