Pull Request has been successfully merged by CANN-robot.
(Thank you for wangqun23's contribution.)变更摘要
该 PR 针对 ReplaceTensor 图变换过程中出现的空指针问题做了防御性修复,核心围绕 UnionFind 并查集与张量排序索引的构建:在 BuildTensorOrderIndexMap 中过滤空张量并补录 Function::GetIncast() 中未与算子连接的 incast 张量,在并查集的构造、合并、查找与分组环节对空指针及缺失顶点做兜底处理,同时新增 UT 用例覆盖「未连接 incast 与 Assemble 输出共享 rawmagic」的场景。另外将两处日志级别由 WARN 下调为 DEBUG。
主要改动
- 补录未连接的 incast 张量:
ReplaceTensor::BuildTensorOrderIndexMap引入addTensorlambda,跳过空指针并保留首次出现顺序,并遍历function.GetIncast()把未与任何算子相连的 incast 记入tensorToOrderIndex,避免 base 张量选择时空指针访问。 UnionFind空指针与缺失顶点防护: 构造函数跳过nullptr顶点并使用emplace;Unite在任一参数为空时直接返回;Find变为非 const 方法,对空指针返回nullptr,对不在parentMap中的张量按单点根节点补注册。rankMap访问方式调整:Unite内对rankMap的读写由operator[]改为rankMap.at(...),GetGroups去掉 const 限定并跳过遗留的空键,且不再使用mutable。- 日志级别下调:
InferShapeFuncRegistry未注册 infershape 的提示由PASS_LOGW改为PASS_LOGD,LargeBitmap::ClearBit越界提示由APASS_LOG_WARN_F改为APASS_LOG_DEBUG_F,减少非异常路径的告警噪音。 - 新增单元测试:
test_replace_tensor.cpp增加ConstructUnconnectedIncastGraph与CheckUnconnectedIncast,构造未连接 incast 与Assemble输出共享 rawmagic 的图,验证 pass 执行成功、rawmagic 一致以及 token 依赖被正确重连。


代码审查
审查结论
各文件审查情况
framework/src/interface/operation/op_infer_shape_impl.h:无问题。PASS_LOGD宏确实存在于framework/include/tilefwk/pypto_fwk_log.h:42,编译无忧;该分支是“op 未注册 infershape 时回退用 shape 填 validshape”的预期路径,降级为 DEBUG 属于合理的降噪。framework/src/passes/block_graph_pass/memory_reuse/large_bm.cpp:1 个 P3(ClearBit日志降级掩盖了ResizeBits中永不生效的清理循环,且与同文件SetBit/GetBit的越界告警级别不一致)。framework/src/passes/tile_graph_pass/graph_constraint/replace_tensor.cpp:无问题。addTensor跳过 nullptr 并保留首次出现顺序;新增的 incast 追加在末尾,而含 incast/outcast 的组会在FindBaseTensor首个循环中提前返回,不会改变原有 base 选择结果;同时补齐了tensorToOrderIndex.at()的索引缺失来源。framework/src/passes/tile_graph_pass/graph_constraint/replace_tensor.h:无问题。Find改为非 const、去掉mutable、GetGroups去掉 const 的唯一调用方(RunOnFunction中的uf)本就是非 const 对象;新的 null 守卫与“缺失顶点补为单点根”不会把 nullptr 写入parentMap/rankMap,Unite/GetGroups的at()访问在“键与 rank 成对插入”的不变式下安全。framework/tests/ut/passes/src/test_replace_tensor.cpp:1 个 P3(新增用例的 rawmagic 断言在改动前就已成立,未覆盖 base raw 的实际传播)。
发现统计
- P0/P1/P2:0
- P3:2(
large_bm.cpp日志/死循环可见性;新增 UT 断言空转)
整体风险判断
低风险。本 PR 的核心改动方向正确且自洽:union-find 的 nullptr 顶点被彻底排除在返回分组之外,缺失顶点改为显式补为单点根,构建索引时补齐了游离 incast,从源头消除了“分组里出现 nullptr → base 选择空指针解引用”的路径;两条 P3 均为可选的可维护性/测试增强项,不构成功能回归。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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 |
|---|---|---|
| framework/src/interface/operation | ✅ xinweiliu, zhangxiangjie (2/2) | ✅ xinweiliu (1/1) |
| framework/src/passes | ✅ zhangyuebing, zhangxiangjie (2/2) | ✅ zhangyuebing (1/1) |
| repo-cann/pypto | ✅ zhangyuebing, xinweiliu, zhangxiangjie (3/2) | ✅ zhangyuebing, xinweiliu (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
wangqun23, thanks for your pull request. All authors of the commits have signed the CLA. 👍


背景
由于框架的修改,在Token开启的情况下,存在与Assemble输出同RawMagic的Incast不与其他op相连接的情况,目前仅限于Incast存在类似情况,即Incast游离在其他连接关系之外。导致ReplaceTensor里的map的value存储空指针,后续使用空指针导致段错误。
方案
针对map可能访问不存在的key做补充和校验。
对可能的空指针使用新增校验。
Related Issue: #3806