Merged
fix: reduce 普通场景分配最小 workspace,避免 kernel 入口提前返回 #1142
sunzhongwen1Add on 4 days ago
fix: reduce 普通场景分配最小 workspace,避免 kernel 入口提前返回 #1142
Merged
sunzhongwen1Add on 4 days ago
sunzhongwen1
sunzhongwen1Collaborators
4 days ago

描述

ReduceOpTiling::CalcUserWorkSpace 在 groupR<=1 的普通 reduce 场景下也会调用 ascendcPlatform.GetLibApiWorkSpaceSize()。普通 reduce 不需要 AscendC 库 API 的系统 workspace,且该接口在部分平台/版本可能返回 0 或带来不必要的系统 workspace 申请;当 tiling 侧 workspace 为 0/空时,reduce kernel 入口的
if (workspace == nullptr) { return; }
会直接返回,导致算子不执行、输出未写入。

本次修改:

  • groupR > 1(group reduce):保持原逻辑,申请 GetLibApiWorkSpaceSize() + 用户 workspace;
  • groupR <= 1(普通 reduce):只分配 32B 最小 workspace,保证 kernel 入口 workspace 非空、不会提前返回,同时避免申请大块系统 workspace。

影响文件:

  • src/op_common/atvoss/reduce/reduce_tiling.cpp

关联的Issue

  • #600

测试

本 PR 未包含测试代码变更。建议在 groupR<=1 的 Reduce 用例上确认 kernel 不再因 workspace 为空提前返回,并回归 groupR>1 路径仍按 GetLibApiWorkSpaceSize() 申请 workspace。

文档更新

本次改动不涉及文档更新。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for sunzhongwen1's contribution.)
sunzhongwen1sunzhongwen1Collaborators
4 days ago Created pull request, commit d8fb8430
atomgit-bot
atomgit-bot
4 days ago Comments:

变更摘要

本 PR 修复 reduce 模版在 workspace 调用场景下的问题。改动集中在 src/op_common/atvoss/reduce/reduce_tiling.cpp 的 ReduceOpTiling::CalcUserWorkSpace() 中:在原有通过 PlatformAscendC::GetLibApiWorkSpaceSize() 获取系统 workspace 大小的分支之外,新增了非该路径(normal 场景)的处理,将系统 workspace 大小固定为 32B,并继续参与 workspaces[0] 的组装,从而避免算子 kernel 入口取到空指针。

主要改动

  • 补充 normal 场景的 workspace 兜底: 在 CalcUserWorkSpace() 的原有 if 分支后新增 else 分支,将 sysWorkSpaceSize 设为 32,使未走 AscendC 平台接口的路径也能获得非零的系统 workspace 大小。
  • 保证 workspace 首地址非空: workspaces[0] 仍按 sysWorkSpaceSize + workSpaceSize_ 计算,因此新增的 32B 预留会计入首个 workspace 地址,防止算子 kernel 入口返回空指针。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
4 days ago Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
4 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
4 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
repo-cann/opbase ✅ 王瑞, 顾宝成 (2/2) ✅ 王瑞, 顾宝成 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Set pengjiahao96,zhou-qilong,wangrui_,rxtfeng,loov1,jia0liang,zl_hw,songkai111,pingchuantang,llimwang,gubaocheng as approver
CANN-robotCANN-robotCollaborators
4 days ago Set pengjiahao96,zhou-qilong,wangrui_,rxtfeng,loov1,jia0liang,zl_hw,songkai111,pingchuantang,llimwang,gubaocheng as approver
sunzhongwen1
sunzhongwen1Collaborators
3 days ago Comments:

compile

likedislike
sunzhongwen1sunzhongwen1Collaborators
3 days ago Pre merge succeeded (commit_id: d09ec59af1c9bd4d0e90a8b2a757b46665e3452e)
CANN-robot
CANN-robotCollaborators
3 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
3 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
3 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
3 days ago Added label: ci-pipeline-passed
sunzhongwen1sunzhongwen1Collaborators
3 days ago Modify description of pull request
sunzhongwen1sunzhongwen1Collaborators
3 days ago Change title to "fix: reduce 普通场景分配最小 workspace,避免 kernel 入口提前返回", originally titled "reduce模版 workspace调用bug修复".
sunzhongwen1sunzhongwen1Collaborators
3 days ago Modify description of pull request
gubaochengCollaborators
3 days ago Comments:

/lgtm
/approve
by agent

likedislike
CANN-robotCANN-robotCollaborators
3 days ago Added label: approved
RuiWang_Collaborators
3 days ago Comments:

/lgtm
/approve

likedislike
sunzhongwen1
sunzhongwen1Collaborators
3 days ago Comments:

/check-pr

likedislike
RuiWang_Collaborators
3 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
3 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
3 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
3 days ago Merged pull request