已合并
【质量加固】为只读成员函数补充 const 修饰 #4615
【质量加固】为只读成员函数补充 const 修饰 #4615
已合并
WXQ123123创建于 6 天前
WXQ123123
6 天前

Summary

  • 对应 Issue: https://gitcode.com/cann/ge/issues/517
  • 规则1:为不修改成员变量的只读成员函数补充 const 修饰(共 10 处)
  • 改动文件与已有质量加固 PR(4496/4572/4576/4594/4597/4608/4611 等)不重复

修改清单

  1. EnginePartitioner::HasSecondPath
  2. BlockMemAssigner::GetOutputNodeReuseMemFlagByIndex
  3. BlockMemAssigner::GetInputNodeReuseMemFlag
  4. NotaskPassBase::IsPreNodeTypeValid
  5. NotaskPassBase::IsPreNodeAttrValid
  6. VariableOpPass::GetRefVars
  7. L2MemPool::GetStream
  8. HostExecutorDumper::IsInDumpStep
  9. DflowGraphManager::GetOptionsRunGraphFlag
  10. TransOpWithoutReshapeFusionPass::CheckIfHasSameOutControlEdge

Test plan

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 WXQ123123 的贡献)
WWXQ123123
6 天前 创建了 pull request,commit a338b471
WWXQ123123
6 天前 关联了issue:GE定向“质量加固”社区有奖任务
atomgit-bot
atomgit-bot
6 天前 评论:

变更摘要

本 PR 为质量加固改动(对应 Issue #517),旨在为不修改成员变量的只读成员函数补充 const 修饰,共涉及 10 处函数,分布在 BlockMemAssignerEnginePartitionerNotaskPassBaseVariableOpPassL2MemPoolHostExecutorDumperDflowGraphManagerTransOpWithoutReshapeFusionPass 等类中,声明(.h)与定义(.cc)同步修改,不改变任何函数行为逻辑,仅为接口签名层面的修饰符补充。

主要改动

  • 内存分配与复用查询函数补充 const:为 BlockMemAssigner::GetOutputNodeReuseMemFlagByIndexBlockMemAssigner::GetInputNodeReuseMemFlag 补充 const 修饰,表明这两类复用标志查询不修改成员状态。
  • 图分区路径判定函数补充 const:为 EnginePartitioner::HasSecondPath 补充 const 修饰,其内部仅基于 graph_info_ 判断簇间是否存在第二条路径,不改变成员变量。
  • 优化 Pass 的判定函数补充 const:为 NotaskPassBase::IsPreNodeTypeValidNotaskPassBase::IsPreNodeAttrValidVariableOpPass::GetRefVarsTransOpWithoutReshapeFusionPass::CheckIfHasSameOutControlEdge 补充 const,强化这些只读判定/查询接口的常量性约束。
  • 运行时与执行框架接口补充 const:为 L2MemPool::GetStreamHostExecutorDumper::IsInDumpStep 补充 const 修饰,其中 GetStream 仅返回 stream_ 成员,符合只读语义。
  • dflow 模块查询接口补充 const:为 DflowGraphManager::GetOptionsRunGraphFlag 补充 const 修饰,该函数仅读取初始化标志并返回是否运行图,不改动 DflowGraphManager 内部状态。
likedislike
CANN-robot
CANN-robot成员
6 天前 评论:

Hi @WXQ123123, welcome to submitting your first PR to ge!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
atomgit-bot
atomgit-bot
6 天前 评论:

代码审查

审查结论

发现的问题

共报告 1 个问题:

  • P0(1 个,confidence 0.9)compiler/graph/partition/engine_partitioner.ccHasSecondPath 增加 const 修饰后,函数体第 1224 行 graph_info_.clusters_[cluster](对 const std::unordered_map 调用非 const 的 operator[])无法编译,导致构建失败。需改为 .at(cluster) 或撤销 const。

各变更文件审查结果

文件 审查结果
compiler/graph/partition/engine_partitioner.cc 发现问题(P0,见上)
compiler/graph/partition/engine_partitioner.h no issues(声明与定义一致,均为 constgraph_info_ 非 mutable,问题根因在 .cc 函数体)
compiler/graph/passes/format_optimize/transop_without_reshape_fusion_pass.cc no issues(CheckIfHasSameOutControlEdge 函数体仅访问 Node/Anchor 对象,不触碰 pass 成员,const 安全)
compiler/graph/passes/format_optimize/transop_without_reshape_fusion_pass.h no issues(声明一致)
compiler/graph/passes/memory_optimize/notask_pass_base.cc no issues(IsPreNodeTypeValid/IsPreNodeAttrValid 仅只读访问 cur_pro_node_name_ 等成员,调用的 GetFirstNotRefNode 本身已是 const)
compiler/graph/passes/memory_optimize/notask_pass_base.h no issues(声明一致)
compiler/graph/passes/variable_optimize/variable_op_pass.cc no issues(GetRefVars 仅对 var_and_var_ref_map_ 调用 const 的 .find()
compiler/graph/passes/variable_optimize/variable_op_pass.h no issues(声明一致)
dflow/runner/compiler/model/dflow_graph_manager.cc no issues(GetOptionsRunGraphFlag 仅只读 is_initialized_options_.find()
dflow/runner/compiler/model/dflow_graph_manager.h no issues(声明一致)
runtime/v2/kernel/memory/l2_mem_pool.cc no issues(GetStream 仅返回成员 stream_;非虚函数,无重写契约问题)
runtime/v2/kernel/memory/l2_mem_pool.h no issues(声明一致)
runtime/v2/subscriber/dumper/host_executor_dumper.cc no issues(IsInDumpStep 仅只读 step_set_/step_range_,const 兼容;非基类虚函数)
runtime/v2/subscriber/dumper/host_executor_dumper.h no issues(声明一致)

总体风险评估

本 PR 为纯 const 修饰加固改动,除 engine_partitioner.cc 外其余 9 处函数的 const 化均安全且声明/定义一致。EnginePartitioner::HasSecondPath 一处 const 化会导致编译失败(构建阻断),必须修复后才能合入;修复方式明确(将函数体内 clusters_[cluster] 改为 .at(cluster)),改动极小。整体风险集中在上述单点编译错误,修复后该 PR 无其他正确性/安全/性能风险。

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

⛔ 需要修改

likedislike
CANN-robotCANN-robot成员
6 天前 添加了label:cann-cla/no
CANN-robot
CANN-robot成员
6 天前 评论:

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/ge 张德鹏, Mexyy, zhanj (3/2) 张德鹏 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
6 天前 将yangyongqiang0606,kobemini,ClarkXie,tangqunzhang,xchu42,hugo111,lining23666,fu-jun2,depeng1994,wqtshg_wt,peiyang,shengnan666,zhangfan_hanq,zhanj,zhujingjing,Mexyy,wangxiaotian995,stevenaw0,yuht9设为评审人
CANN-robotCANN-robot成员
6 天前 将yangyongqiang0606,kobemini,ClarkXie,tangqunzhang,xchu42,hugo111,lining23666,fu-jun2,depeng1994,wqtshg_wt,peiyang,shengnan666,zhangfan_hanq,zhanj,zhujingjing,Mexyy,wangxiaotian995,stevenaw0,yuht9设为审查人
WXQ123123
6 天前 评论:

/check-cla

likedislike
WXQ123123
6 天前 评论:

compile

likedislike
WWXQ123123
6 天前 update merge request[project id: 8824148, iid: 4615, commit_id: f2e2072b71912e1d205740423380a4ef0fe01c0f] virtual merging success
CANN-robot
CANN-robot成员
6 天前 评论:

CLA检查未通过,详情可参考这里

likedislike
WXQ123123
6 天前 评论:

/check-cla

likedislike
CANN-robotCANN-robot成员
6 天前 删除了label:cann-cla/no
CANN-robotCANN-robot成员
6 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6 天前 评论:

CLA检查已通过,详情可参考这里

likedislike
atomgit-bot
atomgit-bot6 天前进行代码检视1
compiler/graph/partition/engine_partitioner.h
@@ -163,3 +163,3 @@
163163 
164164 // Check if there's a second path between two clusters. The max path length is upper_bound
165- bool HasSecondPath(size_t src, size_t dst, size_t upper_bound);
165+ bool HasSecondPath(size_t src, size_t dst, size_t upper_bound) const;
atomgit-bot
atomgit-bot6 天前评论:

🔴 Critical

变更行:engine_partitioner.h:165 为 HasSecondPath(size_t src, size_t dst, size_t upper_bound) 增加了 const 修饰,对应的定义(engine_partitioner.cc:1206)也同步改为 const。

受影响行为/契约:成员函数变为 const 后,函数体内 thisconst EnginePartitioner*,因此成员 graph_info_(GraphPartitionInfo,engine_partitioner.h:191)在函数内是 const 对象。

失败模式:engine_partitioner.cc:1224 ClusterPtr cur_cluster = graph_info_.clusters_[cluster];std::unordered_map<size_t, ClusterPtr>(engine_partitioner.h:95)调用 operator[]std::unordered_map::operator[] 只有非 const 重载,对 const 容器调用属于编译错误("passing 'const unordered_map' as 'this' argument discards qualifiers" / "no matching operator[]"),导致 engine_partitioner 模块无法编译,属于构建失败。注意同函数第 1208 行用的 clusters_.at(...) 有 const 重载,可以正常编译。

建议:将 engine_partitioner.cc:1224 的 graph_info_.clusters_[cluster] 改为 graph_info_.clusters_.at(cluster)(与第 1208 行一致);或撤销 engine_partitioner.h:165 的 const 修饰。二选一即可使模块恢复编译。

likedislike
atomgit-bot
atomgit-bot6 天前进行代码检视2
compiler/graph/partition/engine_partitioner.cc
已过期
@@ -1203,7 +1203,7 @@ Status ge::EnginePartitioner::SplitSubGraphs(const ge::ComputeGraphPtr &compute_
12031203 
12041204/// before calling this function, the direct path between src and dst are already removed.
12051205/// return true if a second path is found
1206-bool ge::EnginePartitioner::HasSecondPath(size_t src, size_t dst, size_t upper_bound) {
1206+bool ge::EnginePartitioner::HasSecondPath(size_t src, size_t dst, size_t upper_bound) const {
12071207 bool has_second = false;
12081208 if (graph_info_.clusters_.at(src)->out_clu_.empty() || graph_info_.clusters_.at(dst)->in_clu_.empty()) {
12091209 return has_second;
@@ -1221,7 +1221,7 @@
12211221 size_t cluster = temp_stack.back();
12221222 second_path_ids.emplace_back(cluster);
12231223 temp_stack.pop_back();
12241224 ClusterPtr cur_cluster = graph_info_.clusters_[cluster];
atomgit-bot
atomgit-bot6 天前评论:

🔴 Critical

变更行:本 diff 将 EnginePartitioner::HasSecondPath(engine_partitioner.cc 第 1206 行)声明与定义同时加上 const 修饰。但该函数体(第 1224 行,未被本 diff 修改)仍执行 ClusterPtr cur_cluster = graph_info_.clusters_[cluster];

受影响行为/契约:graph_info_EnginePartitioner 的非 mutable 成员(engine_partitioner.h 第 191 行 GraphPartitionInfo graph_info_;),其 clusters_std::unordered_map<size_t, ClusterPtr>(engine_partitioner.h 第 95 行)。std::unordered_map::operator[] 只有非 const 版本,没有 const 重载;一旦 HasSecondPath 变为 const 成员函数,thisconst EnginePartitioner*graph_info_ 变为 const,graph_info_.clusters_[cluster] 即以 const 对象调用非 const 成员函数,属于编译期错误(g++/clang 报 "passing 'const std::unordered_map<...>' as 'this' argument discards qualifiers")。第 1208 行使用的 clusters_.at() 有 const 重载,不受影响,仅第 1224 行的 [] 调用无法编译。

失败模式:本 PR 合入后 engine_partitioner.cc 无法通过编译,属于构建失败(P0)。PR 测试计划中 "CI compile 通过" 为未勾选状态,与本问题一致。

建议:将第 1224 行 graph_info_.clusters_[cluster] 改为 graph_info_.clusters_.at(cluster)(const 兼容且不会改变合法路径语义),或撤销 HasSecondPath 的 const 修饰。

likedislike
System
系统消息系统
6 天前 评论:

changed this line on 01aaa560 view diff detail

CANN-robotCANN-robot成员
6 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6 天前 评论:

流水线任务触发成功
任务链接 [afcfbedb6a454cc982251eecc117f2a4][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_X86_compiler ❌ FAILED >>>>>
Compile_X86_executor ✅ SUCCESS >>>>> >>>>>
Compile_X86_dflow ✅ SUCCESS >>>>> >>>>>
likedislike
CANN-robot
CANN-robot成员
6 天前 评论:

流水线任务触发成功
任务链接 [999bb1ac646941bdbf0137330aaf67f6][流水线指导]

任务名称状态日志下载链接
codecheck_Pr ✅ SUCCESS
antipoison ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
codecheck_dt ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>>
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS

[2026-08-28 11:13:58]    CI执行结束

likedislike
CANN-robotCANN-robot成员
6 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6 天前 添加了label:ci-pipeline-failed
WXQ123123
6 天前 评论:

compile

likedislike
WWXQ123123
6 天前 update merge request[project id: 8824148, iid: 4615, commit_id: 082d806f7545407e032aa89dbd920d9ce5b255bf] virtual merging success
此处折叠了7条事件消息 查看更多
CANN-robotCANN-robot成员
6 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6 天前 评论:

流水线任务触发成功
任务链接 [80ddda0f34d94df89395f619e7fe95f3][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_X86_compiler_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_executor_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_dflow_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_ARM_compiler_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_ARM_executor_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_ARM_dflow_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_ARM_compiler ✅ SUCCESS >>>>> >>>>>
Compile_ARM_executor ✅ SUCCESS >>>>> >>>>>
Compile_ARM_dflow ✅ SUCCESS >>>>> >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_A900_npupool ✅ SUCCESS >>>>>

[2026-08-28 11:25:50]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
6 天前 评论:

流水线任务触发成功
任务链接 [df8b4a13192a49e993b17484ad78fea7][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_X86_compiler ✅ SUCCESS >>>>> >>>>>
Compile_X86_executor ✅ SUCCESS >>>>> >>>>>
Compile_X86_dflow ✅ SUCCESS >>>>> >>>>>
UT_Test_dflow ✅ SUCCESS
UT_Test_ge_common ✅ SUCCESS
UT_Test_parser ✅ SUCCESS
UT_Test_python ✅ SUCCESS >>>>>
UT_Test_rt ✅ SUCCESS
UT_Test_acl ✅ SUCCESS
UT_Test_autofuse ✅ SUCCESS
UT_Test_executor ✅ SUCCESS
UT_Test_autofuse_ascendc_api ✅ SUCCESS
ST_Test_dflow ✅ SUCCESS
ST_Test_ge_common ✅ SUCCESS
ST_Test_parser ✅ SUCCESS
ST_Test_python ✅ SUCCESS >>>>>
ST_Test_rt ✅ SUCCESS
ST_Test_autofuse ✅ SUCCESS
ST_Test_executor ✅ SUCCESS
ST_Test_hetero ✅ SUCCESS
ST_Test_autofuse_ascendc_api ✅ SUCCESS
ST_Test_autofuse_e2e ✅ SUCCESS
UT_Test_fe ✅ SUCCESS
UT_Test_tefusion ✅ SUCCESS
ST_Test_fe ✅ SUCCESS
ST_Test_tefusion ✅ SUCCESS
ST_Test_ge_common_atc ✅ SUCCESS
UT_Test_Report_graphengine ✅ SUCCESS >>>>>
UT_Test_Report_ge_executor_c ✅ SUCCESS >>>>>
UT_Test_Report_ge_autofuse ✅ SUCCESS >>>>>
ST_Test_Report_graphengine ✅ SUCCESS >>>>>
ST_Test_Report_ge_executor_c ✅ SUCCESS >>>>>
ST_Test_Report_ge_autofuse ✅ SUCCESS >>>>>
UT_Test_Report_fe ✅ SUCCESS >>>>>
ST_Test_Report_fe ✅ SUCCESS >>>>>

[2026-08-28 11:32:08]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
6 天前 评论:

流水线任务触发成功
任务链接 [e54c78eb9d9440efaf60a92f68a06e45][流水线指导]

任务名称状态日志下载链接
codecheck_Pr ✅ SUCCESS
antipoison ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
codecheck_dt ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>>
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS

[2026-08-28 11:22:49]    CI执行结束

likedislike
CANN-robotCANN-robot成员
6 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
6 天前 删除了label:api-check-pass
CANN-robotCANN-robot成员
6 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6 天前 添加了label:ci-pipeline-passed
夏国正成员
6 天前 评论:

/lgtm

likedislike
zhanj
zhanj成员
6 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
6 天前 添加了label:lgtm
张德鹏成员
5 天前 解决了最后一个问题
张德鹏成员
5 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
5 天前 添加了label:approved
CANN-robotCANN-robot成员
5 天前 合入了pull request