Pull Request已成功合入, 合并人@CANN-robot
(感谢 黄晓彬 的贡献)变更摘要
该 PR 主要对 sort 和 kth_value 算子的代码进行清理(cleancode)重构,核心目标是将散落各处的魔数替换为具名常量、抽取重复逻辑为独立函数,并重构 sort_apt.cpp 中的模板分派链以提高可读性和可维护性。所有改动不涉及功能逻辑变更。
主要改动
-
魔数替换为具名常量:在多个 host 端和 kernel 端文件中,将硬编码的
2、3、4、2048等数值替换为DOUBLE_BUFFER_NUM、NON_LAST_SMALL_AXIS_MIN_AXIS_LEN、ONE_CORE_DATA_SIZE、RADIX_HIST_BUFFER_NUM、INT64_INDEX_SCALE、MERGE_WORKSPACE_BUFFER_NUM、TWO_WAY_MERGE_LIST_NUM、THREE_WAY_MERGE_LIST_NUM等常量,并在sort_tiling_common.h、merge_sort_constants.h、radix_sort_constants.h中集中定义这些常量。 -
提取
BuildSortGraph函数(aclnn_sort.cpp):将aclnnSortGetWorkspaceSize中构造排序计算图的冗长内联代码抽取为BuildSortGraph独立函数,包括 contiguous 转换、BF16/Bool 类型适配、UseNoTranspose路由判断以及 reshape/ViewCopy 链路。 -
提取
AllocateSortOutputs函数(sort.cpp):消除 dim-zero 分支和正常分支中重复的values/indices输出张量分配逻辑,统一通过AllocateSortOutputs辅助函数分配。 -
提取
SelectAndFinalizeKthValueRoute函数(kth_value_tiling_arch35.cpp):将Tiling4KthValue主流程中的路由选择与定型逻辑封装为独立函数,并提取FillRadixKernelResources函数(sort_tiling_common.cpp)整合FillRadixMoreCoreInfo中的 kernel 参数填充与 workspace 计算。 -
重构
sort_apt.cpp模板分派:引入LaunchSortKernel和LaunchRadixMoreCore模板辅助函数,将原来嵌套深、重复多的if constexpr分派链改为平铺的else if constexpr结构,并使用std::conditional_t/std::is_same_v替代sizeof(DTYPE_X)级联判断;同时在sort_tiling_key.h中为 schId 0 和 1 补充SORT_SCHID_0/SORT_SCHID_1宏定义,消除剩余硬编码。


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 |
|---|---|---|
| math/sort | ✅ 宋恺, wangrui_ (2/2) | ✅ 宋恺 (1/1) |
| repo-cann/ops-math | ✅ 宋恺, wangrui_ (2/2) | ✅ 宋恺 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
ConanHuang, thanks for your pull request. All authors of the commits have signed the CLA. 👍


流水线任务触发成功
任务链接 [0afe169986ac45ea8591ce80cd4de532][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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 | ⚠️ WARNING | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-07-21 14:38:48] CI执行结束


描述
关联的Issue
不涉及
测试
1 sort sort_with_index top_k_v2 kth_value 全量ST通过
2 二级冒烟通过
文档更新
不涉及
类型标签