Merged
fix(radix_top_k): 修复 WS 变体 V→MTE3 同步缺失与 CreateVecIndex4TopK 越界,统一跨核前缀和累加为 int64 #6396
Nice tryAdd on 24 days ago
fix(radix_top_k): 修复 WS 变体 V→MTE3 同步缺失与 CreateVecIndex4TopK 越界,统一跨核前缀和累加为 int64 #6396
Merged
Merged fromNice_try/ops-math_workaddutintocann/ops-mathmaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for Nice try's contribution.)24 days ago Added label: cann-cla/yes
CANN-robot
24 days ago Comments:
24 days ago Comments:
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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| */*/README.md | ✅ 蔡雯雯, 陈兴宇, yue-ma (3/2) | ✅ 蔡雯雯 (1/1) |
| repo-cann/ops-math | ✅ yue-ma, 陈兴宇 (2/2) | ✅ 陈兴宇, yue-ma (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Nice_try, thanks for your pull request. All authors of the commits have signed the CLA. 👍


24 days ago Set yue-ma,zhou-qilong,gitee-duhuiping,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,gitcode-chenjiao,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,fengying555682,xuejinghui,zhanw_coding,clinglai0517,caiwenwen,yanglu-1 as approver
24 days ago Set yue-ma,zhou-qilong,gitee-duhuiping,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,gitcode-chenjiao,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,fengying555682,xuejinghui,zhanw_coding,clinglai0517,caiwenwen,yanglu-1 as approver
24 days ago Set yue-ma,zhou-qilong,gitee-duhuiping,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,gitcode-chenjiao,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,fengying555682,xuejinghui,zhanw_coding,clinglai0517,caiwenwen,yanglu-1 as approver
24 days ago Set yue-ma,zhou-qilong,gitee-duhuiping,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,gitcode-chenjiao,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,fengying555682,xuejinghui,zhanw_coding,clinglai0517,caiwenwen,yanglu-1 as approver
24 days ago Change title to "[WIP]fix(radix_top_k): 修复 WS 变体 V→MTE3 同步缺失与 CreateVecIndex4TopK 越界,统一跨核前缀和累加为 int64", originally titled "[WIP]update comment and add host ut".
24 days ago Change title to "[WIP]fix(radix_top_k): 修复 WS 变体 V→MTE3 同步缺失与 CreateVecIndex4TopK 越界,统一跨核前缀和累加为 int64", originally titled "[WIP]update comment and add host ut".
24 days ago Modify description of pull request
Nice try
24 days ago Comments:
24 days ago Comments:
compile


24 days ago Pre merge succeeded (commit_id: 9c2993abb2553cf8743d78948eb7064b297edad4)
CANN-robot
24 days ago Comments:
24 days ago Comments:
| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


24 days ago Added label: ci-pipeline-running
24 days ago Removed label: ci-pipeline-running
24 days ago Added label: ci-pipeline-passed
sunchun
23 days ago Comments:
23 days ago Comments:
您好,PR已满足合入指标,请尽快联系Committer进行合入。如暂时不需要合入,请在PR标题前加[WIP]


23 days ago Draft state has been cancelled
23 days ago Pre merge succeeded (commit_id: 3ec20e4784df0efd28f21187e8ec2093f646dd80)
23 days ago Pre merge succeeded (commit_id: 5c33476a0d48adbaf04c9596ab593faf9239dcde)
23 days ago Removed label: cann-cla/yes
23 days ago Removed label: ci-pipeline-passed
CANN-robot
23 days ago Comments:
23 days ago Comments:
23 days ago Added label: cann-cla/yes
Nice try
23 days ago Comments:
23 days ago Comments:
compile


23 days ago Pre merge succeeded (commit_id: afa758202f7a4c559638401777d306b3a782b17f)
CANN-robot
23 days ago Comments:
23 days ago Comments:
| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


23 days ago Added label: ci-pipeline-running
23 days ago Removed label: ci-pipeline-running
23 days ago Added label: ci-pipeline-passed
23 days ago Resolved final issue
chenxingyu18
23 days ago Comments:
23 days ago Comments:
/lgtm
/approve


23 days ago Added label: approved
23 days ago Added label: lgtm
23 days ago Closed associated issue
23 days ago Merged pull request
描述
改动原因
RadixTopK 在 int64 大 shape(sortLen 超 int32 上限)与 WS 变体路径上存在三处缺陷,且 host UT 的 tiling key 期望值只编码 3 位,int64 主路径恒测不到:
Add在 V 流水线写tileTopK,紧接着 MTE3 读同一块 UB;PipeBarrier<PIPE_V>只保证 V 流水线内部顺序,SToMTE3Sync只覆盖 S→MTE3,两者都管不到 V→MTE3,MTE3 可能读到 Add 之前的旧值,导致该段 k 配额错乱。同文件AddTileHist2TileTopKInWs对同样的 Add→CopyOut 序列用的是VToMTE3Sync。tileNum_ > MAX_TILE_NUM_IN_UB,此时CreateVecIndex4TopK中的无符号相减会下溢成巨大值,再被tileLen_兜住,最终GetWithOffset(maxIndexLen, tileNumAlign_ * 4)的偏移会写出 6144 元素 buffer。sortLen > 2^31,UB 变体用 int32 累加(cumSumValuePrev/remainCoreBoundaryNum)存在溢出风险;同时 WS 变体维护了一份只差累加器类型的ComputeCumSumPrevI64。ComputeExpectedTilingKey只编码sorted/largest/isLargeShape3 位,未编码isInt64Shape(bit3),int64 主路径(sortLen > 2^31)恒测不到。改动方法
op_kernel/radix_top_k_ws.hHandleLastRoundBoundary中 Add→CopyTileTopKUb2Ws 的同步由SToMTE3Sync()改为VToMTE3Sync(),与同文件AddTileHist2TileTopKInWs口径一致;CreateVecIndex4TopK增加前置防御:tileNumAlign_ >= MAX_TILE_NUM_IN_UB时直接return 0,下游走「现算索引」分支,与maxIndexLen==0的既有兜底行为一致;ComputeCumSumPrevI64,改用基类ComputeCumSumPrev(出参已是 int64),消除 UB/WS 两份仅差累加器类型的实现。op_kernel/radix_top_k_common.h:ComputeCumSumPrev出参由int32_t&改为int64_t&(每 core 边界 bin 计数 < 2^31,int64 累加对 int32 形状同样安全);IsNaNValue的 float 位模式读取由指针 reinterpret 改为 union,规避浮点相等/自比较类告警;补充提取相与计数相 NaN 规范化口径不对称的说明。op_kernel/radix_top_k_ub.h:cumSumValuePrev/remainCoreBoundaryNum改为 int64,回写tileTopK时显式static_cast<int32_t>(per-core 配额 < 该 tile 边界 bin 计数 < 2^31,int32 通道安全)。op_host/radix_top_k_tiling.cpp:新增static_assert(LARGE_SORT_LEN < INT32_SORT_LEN_MAX),把「isInt64Shape_ 蕴含 isLargeShape_」钉死,避免后续调大LARGE_SORT_LEN时 i64 分支被漏掉;needWorkspace/GetWorkspaceSize两处|| isInt64Shape_补充防御性冗余注释。tests/ut/op_host/test_radix_top_k_tiling.cpp:ComputeExpectedTilingKey补齐第 4 位 isInt64Shape(与GET_TPL_TILING_KEY(sorted, largest, isLargeShape, isInt64Shape)一一对应,此前 int64 主路径恒测不到);新增两条用例:i64_shape_tiling_key_bit3(sortLen=2^31 ⇒ bit3+bit2、indices int64、必须申请 workspace)、i64_shape_reject_int32_indices(sortLen > 2^31 且 indices int32 必须 tiling 失败);MakeRadixTopKTilingContext支持指定输出 indices dtype。math/radix_top_k/README.md:约束说明由「无」改为「本算子为选取类实现,输出为选中元素在排序轴上的索引序,不保证有序」。math/topk/op_api/topk.cpp:补充 int64 大 shape 分支拦截条件的注释(说明放掉 k 比例门限与 MIN_K 门限、且 int64 索引无法通过 GatherElementsV2 补有序性的原因),不改变逻辑。关联的Issue
测试
math/radix_top_k/tests/ut/op_host/test_radix_top_k_tiling.cpp):修正 tiling key 期望值编码并新增 int64 主路径两条用例;本地未执行,预期由 CI 运行。文档更新
更新
math/radix_top_k/README.md约束说明(补充输出无序约束);另含op_host/op_kernel注释更新,不涉及其他文档。类型标签