Pull Request has been successfully merged by CANN-robot.
(Thank you for 刘奕哲's contribution.)变更摘要
本 PR 为性能优化(对应 issue #2857),通过批量行处理、预计算零值 tile、精简直方图/行最小值 gather 指令等手段优化 TopK RadixSelect 算法性能。核心改动集中在 framework/src/interface/tileop/vector/radix_select/ 下的 radix_select_b1.h、radix_select_b2.h、radix_select_b4.h 与 radix_select_util.h,同时在 framework/src/interface/operation/vector/sort.cpp 的 TiledTopKRadixSelect 中调整了临时张量尺寸;测试已在 A5 上完成泛化用例验证。
主要改动
-
批量行处理(多行 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/EQgather +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))。


Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| docs | ✅ 尹杰, congqiannan, lyz0328 (3/2) | ✅ 尹杰, lyz0328 (2/1) |
| repo-cann/pypto | ✅ 尹杰, congqiannan (2/2) | ✅ 尹杰 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


compile


流水线任务触发成功
任务链接 [b4dd3c074b874868ae2e2c4ed0f1bd82][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| pre_comment | ✅ SUCCESS | >>>>> | |
| UT_Test_Py3_ninja_simulation | ✅ SUCCESS | ||
| UT_Test_Py3_ninja | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_1 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_2 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_3 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part1 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part2 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part3 | ✅ SUCCESS | ||
| UT_Test_kirinx90 | ✅ SUCCESS | ||
| UT_Test_kirin9030 | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> |
[2026-08-03 11:01:23] CI执行结束


流水线任务触发成功
任务链接 [65e5d47d25054248a57400444e556aaf][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| StaticCheck_md | ✅ SUCCESS |
[2026-08-03 10:34:49] CI执行结束


流水线任务触发成功
任务链接 [f0beea71ac2c43ae8d9a8ec57205252c][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| get_pr_file | ✅ SUCCESS | ||
| static-check | ✅ SUCCESS | ||
| compile | ✅ SUCCESS |
[2026-08-03 11:01:58] CI执行结束


/approve


/approve


/lgtm


描述
通过缩减指令等方法优化 TopK Radix Select 算法性能。
测试
A5上完成泛化用例测试
关联Issue
#2857
类型标签