Merged
fix(ir): Descend into symbolic scalar expr operands to keep loop-carried scalars alive #6093
LiuChangAdd on Sep 9
fix(ir): Descend into symbolic scalar expr operands to keep loop-carried scalars alive #6093
Merged
LiuChangAdd on Sep 9
LiuChang
LiuChangCollaborators
Sep 9

bf599774e
dd89fd6af
f14a6b6a
e2e62919e
同步主线4笔提交,从master cherry-pick到9.2.0分支

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for LiuChang's contribution.)
LiuChangLiuChangCollaborators
Sep 9 Created pull request, commit c4a2d4e2
LiuChangLiuChangCollaborators
Sep 9 Associated issue: [Requirement|需求建议]: Token的Expand展开
atomgit-bot
atomgit-bot
Sep 9 Comments:

变更摘要

本 PR 从 master cherry-pick 4 笔提交到 9.2.0 分支,核心修复 IR 中符号标量表达式(如 if 条件、标量 yield/continue 值)的操作数变量对基本访问器不可见、导致循环携带标量被误判失效的问题。改动包括:在变量收集器中新增对 ScalarExprPtr 的下钻处理(stmt_utils.cpp),在 host 后端为标量迭代参数生成初始化、逐迭代 phi 更新与循环退出绑定(ir_backend.cpp),重构 merge_stmts_pass 中分支克隆的 raw tensor 共享逻辑,并将 IR 文本 dump/load 的 memoryId 字段更名为 rawmagic,同时配套更新 LogicalTensor::Clone、EraseOperations 以及大量 golden 测试与示例。

主要改动

  • 符号标量操作数下钻收集(stmt_utils.cpp): 新增 VisitExpr_(const ScalarExprPtr&) 重载,通过 SymbolicScalar::FromExpr(op).GetVarRefs(var_uses) 收集隐藏在 RawSymbolicExpression 中的操作数变量,使循环携带的标量保持存活,对应 PR 标题所述核心修复。

  • 标量迭代参数的代码生成(ir_backend.cpp): FindExprFromForStmt 将标量 iterArgs_ 的迭代变量符号注册到 Linker;VisitForStmtForControlFlow 为标量 iterArg 输出初始化赋值(VALUE_<name> = ...)、从循环体尾部 ContinueStmt 提取新值做逐迭代 phi 更新,并在循环退出时把最终携带值绑定到 returnVars_。

  • 分支克隆的 raw tensor 共享重建(merge_stmts_pass.cpp): 新增 RawDefCollector 区分 raw 定义与 view 定义(ASSEMBLE/ASSEMBLE_SSA/ATOMIC_RMW),克隆改为统一 v->Clone() 后按 rawmagic 重建克隆变量与分支内 raw tensor 的映射,避免分支间 raw tensor 串扰。

  • IR 文本读写字段更名(io_text_dumper.cpp/io_text_loader.cpp): 逻辑张量引用的打印与解析从 memoryId 改为 rawmagic,ParseLogicalTensorVar 同步改用 rawmagic >= 0 判断回填。

  • 配套调整与测试(logical_tensor.cpp、function.cpp 及测试): LogicalTensor::Clone 提前复制 actualRawmagic/memoryId;Function::EraseOperations 在擦除后调用 RefreshVarDependency();新增 test_c2v2.py、test_yield_scalar1.pypto、test_assemble.py 等用例并批量更新 golden 文件,activation.py 示例将 GELU 由 sigmoid 近似改为基于 pypto.erf 的精确公式。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 9 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 9 Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
Sep 9 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 9 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
examples ✅ DCGDDD, tsungl4 (2/2) ✅ DCGDDD (1/1)
framework/src/interface/function ✅ DCGDDD, tsungl4 (2/2) ✅ tsungl4, DCGDDD (2/1)
framework/src/interface/ir/transforms ✅ DCGDDD, tsungl4 (2/2) ✅ DCGDDD, tsungl4 (2/1)
framework/src/interface/tensor ✅ DCGDDD, tsungl4 (2/2) ✅ DCGDDD, tsungl4 (2/1)
framework/src/machine ✅ tsungl4, DCGDDD (2/2) ✅ tsungl4 (1/1)
repo-cann/pypto ✅ DCGDDD, tsungl4 (2/2) ✅ DCGDDD, tsungl4 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 9 Set xinweiliu,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 9 Set xinweiliu,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
LiuChang
LiuChangCollaborators
Sep 9 Comments:

compile

likedislike
LiuChangLiuChangCollaborators
Sep 9 Pre merge succeeded (commit_id: 62a80891adb59ce2c30c13c3556351031842fa24)
CANN-robot
CANN-robotCollaborators
Sep 9 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 9 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 9 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 9 Added label: ci-pipeline-passed
杨旭
杨旭Collaborators
Sep 9 Comments:

/lgtm
/approve

likedislike
lidongsheng
lidongshengCollaborators
Sep 9 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 9 Added label: approved
LiuChang
LiuChangCollaborators
Sep 9 Comments:

/check-pr

likedislike
CANN-robot
CANN-robotCollaborators
Sep 9 Comments:

The following label is not ready.

lgtm: Please wait for committers to review the code.

likedislike
lidongsheng
lidongshengCollaborators
Sep 9 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 9 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 9 Merged pull request