Merged
fix(operation): Fix TopK RadixSelect Temp Workspace #6342
刘奕哲Add on Sep 15
fix(operation): Fix TopK RadixSelect Temp Workspace #6342
Merged
刘奕哲Add on Sep 15
刘奕哲
刘奕哲
Sep 15

描述

  1. 调整TopK RadixSelect算法使用的临时空间大小避免内存踩踏
  2. 修复cbrt文档渲染问题

测试

完成自测以及冒烟测试

关联Issue

#3333

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 刘奕哲's contribution.)
刘奕哲刘奕哲
Sep 15 Created pull request, commit 1e3ab142
刘奕哲刘奕哲
Sep 15 Associated issue: [Bug-Report|缺陷反馈]: TopK 算子 RadixSelect 算法精度错误
atomgit-bot
atomgit-bot
Sep 15 Comments:

变更摘要

本 PR 主要修复 TopK 的 RadixSelect 算法临时工作区(Temp Workspace)大小计算问题,避免临时空间不足导致内存踩踏:在 TiledTopKRadixSelect 中按输入数据类型字节宽度分别计算排序(sort)与 CalcTopK 阶段所需的临时块数,并以两者最大值作为临时 tensor 形状;同时新增了 NUM_VALUE_12、NUM_VALUE_22、NUM_VALUE_34、NUM_VALUE_256 等数值常量,重构了 RadixSelect 的代码生成单元测试以覆盖 INT16/FP32/INT64。PR 描述中还提到修复了 cbrt 文档渲染问题。

主要改动

  • 按数据类型计算临时空间块数:新增 RadixSelectGetSortTempBlockCount 与 RadixSelectGetCalcTopKTempBlockCount 两个函数,根据输入字节宽度(1/2、4、8)返回对应的临时块数,替换原先 blockNum 固定为 26(INT64 时为 46)的硬编码逻辑。
  • 重构 TiledTopKRadixSelect 临时空间计算:以按 128 对齐的 tile 维度 tileAlign 乘以块数得到 calcTopKWorkspace 与 sortWorkspace,其中 CalcTopK 工作区还叠加分支工作区(NUM_VALUE_256 * BytesOf(DT_INT32) * NUM_VALUE_3 与 tileAlign * BytesOf(DT_INT32) * NUM_VALUE_2 的较大值),最终临时形状取两者最大值,避免内存踩踏。
  • 新增数值常量:在 operation_common.h 中新增 NUM_VALUE_12、NUM_VALUE_22、NUM_VALUE_34、NUM_VALUE_256 常量,并将 NUM_VALUE_46 调整为 NUM_VALUE_34,供新的临时空间计算使用。
  • 重构 RadixSelect 单元测试:在 test_codegen_dyn_sort.cpp 中将原 TestRadixSelectFP32、TestRadixSelectInt64 测试提取为公共辅助函数 TestRadixSelect,并基于它新增 TestRadixSelectInt16、TestRadixSelectFP32、TestRadixSelectInt64 三个参数化测试用例。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 15 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 15 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 15 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
docs ✅ lyz0328, 尹杰 (2/2) ✅ lyz0328, 尹杰 (2/1)
framework/src/interface/operation ✅ shi-dingkun, 尹杰 (2/2) ✅ shi-dingkun, 尹杰 (2/1)
repo-cann/pypto ✅ shi-dingkun, 尹杰 (2/2) ✅ shi-dingkun, 尹杰 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

Creeeeper, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Set xinweiliu,lyz0328,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
Sep 15 Set xinweiliu,lyz0328,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
刘奕哲
刘奕哲
Sep 15 Comments:

compile

likedislike
刘奕哲刘奕哲
Sep 15 Pre merge succeeded (commit_id: 81d836a2150b352215eaf86cf09b47d047fb8d45)
CANN-robot
CANN-robotCollaborators
Sep 15 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Added label: ci-pipeline-running
6 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 16 Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
Sep 16 Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: cann-cla/yes
lyz0328
lyz0328Collaborators
Sep 16 Comments:

/approve

likedislike
刘奕哲
刘奕哲
Sep 16 Comments:

compile

likedislike
刘奕哲刘奕哲
Sep 16 Pre merge succeeded (commit_id: 30f6a0c43c532ef7dcf2cf0bbc37ef328f79801a)
CANN-robot
CANN-robotCollaborators
Sep 16 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: ci-pipeline-running
shi-dingkun
shi-dingkunCollaborators
Sep 16 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: approved
CANN-robotCANN-robotCollaborators
Sep 16 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 16 Added label: ci-pipeline-passed
Jie Yin
Jie YinCollaborators
Sep 16 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 16 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 16 Merged pull request