Pull Request has been successfully merged by CANN-robot.
(Thank you for tujun6's contribution.)变更摘要
本次 PR 主要对 math 目录下 sort 类算子(包括 sort、kth_value、sort_with_index、top_k_v2)的 AscendC MicroAPI 进行整改:将原先基于 Reg::DataCopy、__local_mem__ 等旧式写法,统一替换为语义更明确的 UB 指针类型和 Reg::LoadAlign/Reg::StoreAlign/Reg::Gather/Reg::Compares/Reg::Pack 等新 MicroAPI。改动以等价的 API 替换为主,不改变算子核心算法与数据流。
主要改动
- UB 内存指针类型整改:将
GetPhyAddr()返回的指针及相关形参/局部变量从__local_mem__统一改为__ubuf__,覆盖kth_value_radix_select.h、radix_more_core_base.h、radix_sort_simd_utils.h、top_k_radix_block_sort_*.h等文件。 - 数据搬移接口拆分:将
Reg::DataCopy根据读写语义替换为Reg::LoadAlign(UB→寄存器读取)与Reg::StoreAlign(寄存器→UB 写入),并将Reg::DataCopyGather替换为Reg::Gather。 - 比较与掩码接口替换:将
Reg::CompareScalar替换为Reg::Compares,Reg::MaskAnd替换为Reg::And,Reg::MaskSel替换为Reg::Select,Reg::MaskPack替换为Reg::Pack。 - 归约接口替换:将
Reg::ReduceSum统一替换为Reg::Reduce<ReduceType::SUM>,涉及radix_more_core_base.h与radix_sort_top_k.h中的直方图状态统计和求和逻辑。 - 保持算法逻辑不变:上述改动均为一对一的 API 等价替换,未引入新的业务逻辑、数据结构或配置变更,涉及的所有 radix sort、merge sort、top_k 核心流程保持不变。


Hi @tujun6, welcome to submitting your first PR to ops-math!
PR Merge Steps
1. CLA Signing
If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.
2. CI Check
Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.
3. Code Review
After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.


代码审查
审查完成。以下为逐文件审查结论与总体风险判断。
逐文件审查结论
| 文件 | 结论 |
|---|---|
| math/kth_value/op_kernel/arch35/kth_value_merge_sort_one_core.h | no issues |
| math/kth_value/op_kernel/arch35/kth_value_radix_select.h | no issues |
| math/sort/op_kernel/arch35/common/non_last_small_axis_base.h | no issues |
| math/sort/op_kernel/arch35/common/radix_more_core_base.h | no issues |
| math/sort/op_kernel/arch35/common/radix_sort_simd_utils.h | no issues |
| math/sort/op_kernel/arch35/sort_merge_sort.h | no issues |
| math/sort/op_kernel/arch35/sort_non_last_small_axis.h | no issues |
| math/sort_with_index/op_kernel/arch35/merge_sort_simd.h | no issues |
| math/top_k_v2/op_kernel/arch35/radix_sort_top_k.h | no issues |
| math/top_k_v2/op_kernel/arch35/radix_sort_topk_b16.h | no issues |
| math/top_k_v2/op_kernel/arch35/radix_sort_topk_b32.h | no issues |
| math/top_k_v2/op_kernel/arch35/radix_sort_topk_b64.h | no issues |
| math/top_k_v2/op_kernel/arch35/radix_sort_topk_b8.h | no issues |
| math/top_k_v2/op_kernel/arch35/top_k_merge_sort_simd.h | no issues |
| math/top_k_v2/op_kernel/arch35/top_k_radix_block_sort_b16.h | 1 issue(P1) |
| math/top_k_v2/op_kernel/arch35/top_k_radix_block_sort_b32.h | 1 issue(P1) |
| math/top_k_v2/op_kernel/arch35/top_k_radix_block_sort_b64.h | 1 issue(P1) |
| math/top_k_v2/op_kernel/arch35/top_k_radix_block_sort_b8.h | 1 issue(P1) |
汇总
- P0:0 个
- P1:4 个
- P2:0 个
- P3:0 个
总体风险判断:高风险。本次 MicroAPI 整改整体是机械且方向正确的(DataCopy→LoadAlign/StoreAlign、CompareScalar→Compares、ReduceSum→Reduce<SUM>、MaskAnd/MaskSel/MaskPack→And/Select/Pack、DataCopyGather→Gather、__local_mem__→__ubuf__ 等均方向无误),但 top_k_radix_block_sort_b16/b32/b64/b8.h 四个文件中 GetGlobalExcusiveSum 的「vsts to global」写回段被统一误改成了 LoadAlign,导致全局 exclusive 前缀和不再写回,会破坏 radix sort 的 scatter 偏移、产生错误排序结果(或编译失败),影响核心排序/ top_k 算子正确性,需在合入前修复。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 4 |
| 🟡 建议 | 0 |
⛔ 需要修改


/lgtm
/approve


/lgtm


描述
本 PR 对 sort 类算子(
sort、sort_with_index、kth_value)执行 arch35 MicroAPI 旧接口别名替换整改。CANN 9.1.0 的 arch35(ascend950)MicroAPI 中,大量旧接口名与新接口名是同一
Impl函数的别名。本次将以下旧接口统一替换为新接口名,保证代码规范并维持二进制完全等价:__local_mem____ubuf__DataCopy(RegTensor 首参)LoadAlignDataCopy(addr 首参)StoreAlignCompareScalarComparesReduceSum(3 参数 MicroAPI)Reduce<ReduceType::SUM>DataCopyGatherGather替换统计:
关联的Issue
#2665
测试
对每个算子分别执行编译验证(
bash build.sh --ops=<算子> --soc=ascend950 --opkernel -j16):.o文件的 md5。git stash暂存修改,编译原始代码,保存原始.o的 md5。git stash pop恢复修改。最终残留扫描:全部 28 类旧 API 零残留(不可替换项如
GatherMask、PrefixSum、传统高阶 API、参数结构体等保持不变属正常)。文档更新
无
类型标签