Merged
fix(machine): Add value depend check for ifstmt #7392
可惜春残风雨又Add on 24 days ago
fix(machine): Add value depend check for ifstmt #7392
Merged
可惜春残风雨又Add on 24 days ago
可惜春残风雨又
可惜春残风雨又Collaborators
24 days ago

检测值依赖和 insert wait_aicore_start 的时候,增加 ifstmt 的检测

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 可惜春残风雨又's contribution.)
可惜春残风雨又可惜春残风雨又Collaborators
24 days ago Created pull request, commit e17c5522
atomgit-bot
atomgit-bot
24 days ago Comments:

变更摘要

本 PR 针对 if 语句(ir::IfStmt)补齐了值与依赖相关的检测逻辑:在此前只覆盖 for 循环的机器侧 IR 后端流程中,为 if 条件表达式增加值依赖描述解析、缓存抑制标记设置,以及必要时插入 WaitAicoreStart 同步语句,并同步在 ir_backend.h 中声明新接口、在单元测试中补充覆盖。

主要改动

  • if 条件值依赖检测: 新增 InsertCacheStopForIfCond,通过 IrParseValueDependDesc 解析 ifStmt->condition_ 并读取当前动态函数的值依赖描述,在存在输入/张量数据依赖时置位 hasValueDepend,存在张量数据依赖时额外置位 disableCtrlFlowCache;同时对 nullptr 的 DyndevAttribute 做空值保护直接返回。
  • if 条件核同步插入: 新增 InsertWaitAicoreStartForIfCond,对非立即数且有效的条件表达式调用 CheckExprDependCore 判断是否依赖核(含运算嵌套场景),命中则在控制流输出中按缩进写入 WaitAicoreStart(startArgs);。
  • 接入 if 语句生成流程: 在 VisitIfStmtForControlFlow 中于构建条件表达式并输出 if (...) 之前调用上述两个函数,使 if 分支与 for 循环在值依赖与核同步处理上保持一致。
  • 接口声明: 在 ir_backend.h 中为 InsertCacheStopForIfCond 与 InsertWaitAicoreStartForIfCond 增加声明,供后端其他编译单元调用。
  • 单元测试覆盖: 在 test_ir_backend.cpp 中新增 MakeGetInputDataExpr、MakeGetTensorDataExpr 构造辅助函数,并为两个新函数分别添加参数化场景测试,覆盖空属性、普通符号条件、GetInputData/GetTensorData 条件、主机侧就绪张量、立即数以及算术语境内嵌条件等情形。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
24 days ago Comments:

代码审查

审查结论

问题统计:P0 = 0,P1 = 0,P2 = 0,P3 = 2。

变更文件覆盖确认

  • framework/src/machine/host/ir_backend.cpp —— 2 处问题(均为 P3:if 条件值依赖标记按 dynFunc 聚合造成跨 if 串扰;if 条件依赖 GetTensorData 时不插入 WaitAicoreStart)
  • framework/src/machine/host/ir_backend.h —— 无问题
  • framework/tests/ut/machine/src/test_ir_backend.cpp —— 无独立新问题(UT 的 CreateIfStmt 签名、GetInputData/GetTensorData 符号前缀均与生产代码匹配;但未覆盖跨 if 聚合语义,已并入第 1 条建议)

总体风险判断:本 PR 在 if 分支上补齐了值依赖检测与 WaitAicoreStart 插入,插入点顺序(等待语句位于 if ( 之前)、tensorNameToDependCore 的填充时机、CheckValueDependCpuTensor 的后置调用时机均正确,未发现会导致编译失败、崩溃或控制流失效的高危问题。剩余两点均为“检测粒度/覆盖完整性”层面的低风险改进项,不影响合并。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
24 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
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
9.2.0 ✅ Andy-lb, jason_yuan_ye (2/2) ✅ Andy-lb (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
可惜春残风雨又
可惜春残风雨又Collaborators
24 days ago Comments:

/compile

likedislike
CANN-robotCANN-robotCollaborators
24 days ago Set xinweiliu,cam_bxh,dai-zhentao,TianXL,lululu40888,shi-dingkun,gguuaanngg,codehjp423,jiangtao_rts,gitcode-chenjiao,hanxiaolong,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,gcw_kUomxQ2l,Andy-lb,WenboCodes as approver
可惜春残风雨又可惜春残风雨又Collaborators
24 days ago Pre merge succeeded (commit_id: c3a9623596fed7a0b576278e5daf0c4564b17a11)
CANN-robotCANN-robotCollaborators
24 days ago Set TianXL,jiangtao_rts,gitcode-chenjiao,hanxiaolong,gcw_kUomxQ2l,Andy-lb as approver
CANN-robot
CANN-robotCollaborators
24 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
24 days ago Added label: ci-pipeline-running
atomgit-bot
atomgit-bot24 days agoStart code review1
framework/tests/ut/machine/src/test_ir_backend.cpp
@@ -440,0 +461,4 @@
461+ ValDependTensorMeta meta;
462+ InsertCacheStopForIfCond(ifStmt.get(), fixture.dynFunc.get(), meta);
463+ EXPECT_FALSE(meta.hasValueDepend);
464+ EXPECT_FALSE(meta.disableCtrlFlowCache);
atomgit-bot
atomgit-bot24 days agoComments:

🟡 Medium Priority

变更行:新增用例第 1 段(456–465 行)在 fixture.dynFunc->SetDyndevAttribute(nullptr) 后,用同一个 MakeGetInputDataExpr("ARG_x") 条件调用 InsertCacheStopForIfCond,并断言 EXPECT_FALSE(meta.hasValueDepend)(463 行)。

证据链与失败模式:同一测试的第 3 段(479–484 行)用的是完全相同的 GetInputData 条件表达式,且 dynAttr 的 valueDependDescDict 为空,却断言 EXPECT_TRUE(meta.hasValueDepend)。两段唯一差别是 dyndev 属性是否存在,说明实现里在属性为空时就直接提前返回、完全跳过了条件表达式的值依赖分析(而 CheckExprDependCore/ExprPtrToSymbolicScalar 这类分析本身并不依赖 dyndev 属性)。但空 dyndev 属性在本代码库中是被显式支持的正常输入而不是纯防御分支(同文件 355–357 行 IrBuildVirtualLoopFunc 对属性为空返回 func 本身即有专门用例)。因此若生产上存在“无 dyndev 属性的 DYNAMIC 函数 + if 条件读取 core 产出张量的 GetInputData”这一路径,就会漏判值依赖:hasValueDepend 为 false 意味着控制流缓存 key 不含值哈希(对照 476 行注释“value-hash validated”),后续复用缓存时会用旧值判分支,导致控制流走错、结果错误。本用例把这种“属性缺失即放弃检测”的行为固化成了期望值,会让上述回归永远无法被测试发现。

建议:核实 dyndev 属性为空时是否应放弃值依赖检测:若不应放弃,改为断言 hasValueDepend 为 true 并修正实现;若确实应放弃,补充注释说明“无 dyndev 属性的函数不参与控制流缓存”这一前提。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
24 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
24 days ago Added label: ci-pipeline-passed
Andy-lb
Andy-lbCollaborators
24 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
24 days ago Added label: approved
袁野
袁野Collaborators
24 days ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
24 days ago Added label: lgtm
CANN-robot
CANN-robotCollaborators
24 days ago Comments:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
可惜春残风雨又可惜春残风雨又Collaborators
24 days ago Resolved final issue
CANN-robotCANN-robotCollaborators
24 days ago Merged pull request