Closed
[Requirement|需求建议]: TopK RadixSelect性能优化 #2857
刘奕哲Add on Aug 3Closed at Aug 4
刘奕哲
Aug 3 Comments:
Aug 3 Comments:
/assign


Aug 3 Assign Creeeeper as responsible person
Aug 3 Associated pull request
Aug 3 Modify description of issue
Aug 3 Associated pull request
Aug 4 Close issue
Aug 5 Deleted associated pull request: fix(docs): Fix the docs
Aug 5 Added label: resolved
Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.
Background(背景信息)
TopK RadixSelect算法性能不足,需要优化
Origin(信息来源)
PyPTO Vector
Benefit / Necessity(价值/作用)
提升RadixSelect算法性能
Design(设计方案)
批量行处理(多行 tile): RadixSelectCalcB1/B2/B4 移除内层 n3Index 逐行循环,改为按 srcTileH 批量处理多行;所有工作区(srcMaskAddr、histogramAddr、highAddr 等)与 tile 定义均乘以 srcTileH,并新增 RadixSelectBatchAssign 批量计算 src/value/index 地址;sort.cpp 的 TiledTopKRadixSelect 在 cur > 0 时按 input.tileInfo.shape[cur - 1] 扩大临时张量 tmpShape[0]。
预计算零值 tile 减少指令: b2/b4 新增 tciAddr 工作区与 RadixSelectTCI,先以一次 TCI 生成全零 tciTile,后续迭代用 TMOV(histogramTmpUInt32Tile, tciTile) 复用,替代原先每轮迭代重复执行的 TCI 清零指令。
精简直方图/行最小值 gather 逻辑: 移除重复的 TEXPANDS(gatherIntTile, 0)、双重 TGATHER 与 TSELS 序列,改用 TADDS(rowMinTile, highTile, 7) 计算偏移并直接从 histogramInt32PreTile(histogramAddr - 32 的前置 tile)一次 gather,并以 RadixSelectCmps、RadixSelectFinalSelect 封装比较与最终选择(GT/EQ gather + TCONCAT)。
工具层重构(radix_select_util.h): DefineWorkSpace 由运行时尺寸改为编译期模板尺寸 DefineWorkSpace<T, size>;RSTile/DefineTile 模板参数顺序调整并新增 RSExchangeTile 派生单行 tile;新增按行循环的 RadixSelectGather(两个重载)、RadixSelectHistogram/RadixSelectHistogramB4、RadixSelectSel、RadixSelectBatchAssign、RadixSelectFinalSelect 等模板函数;PTO_RS_SORT_ADDR_DEFINE/PTO_RS_SORT_TILE_DEFINE/PTO_RS_COMMON_TILE_DEFINE 宏同步改为多行(srcTileH 倍数)工作区与 tile。
RadixSelectSortTwoBit 排序指令缩减: RadixSelectSortTwoBitCalc 增加 SRC2 参数以复用中间 tile,按 bit % 4 == 0 分支交替输入源,合并/减少 TGATHER、TCONCAT、TMOV 指令(bit == 0 时改为一次 TGATHER(tmp, src, select1, ...) 并省去末尾 TMOV(src, tmp))。