已合并
【PR】: revert reorganize tensor layout utilities and update codegen #1898
【PR】: revert reorganize tensor layout utilities and update codegen #1898
已合并
Phl17创建于 8月31日
Phl17成员
8月31日

Pull Request

描述

本 PR 为回退性质的变更:撤销此前对 tensor layout 工具类的重新组织,并将 codegen 的 padding 模式选择逻辑与相关测试期望同步更新。核心内容包括:将 TensorLayoutUtils 与 DiscontinuityInfo 的命名空间由 ascgen_utils 改回 optimize 并删除对应单测文件;重写 reg_api_call_utils.cpp 中的 GetPaddingMode,使其不再依赖 AnalyzeLoadDiscontinuity,改为依据 TileInner 切分轴位置及 repeat/stride 的静态相等性判断 Compact/Normal 模式;同时大量单测与 e2e 测试的期望 kernel 输出、indirect load/store 测试的 index 布局随之调整。

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

描述测试此变更的步骤和前提条件:
1.
2.

核对清单

其他信息

在此添加任何其他关于本次 PR 的说明。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 Phl17 的贡献)
PPhl17成员
8月31日 添加了label:enhancement
PPhl17成员
8月31日 创建了 pull request,commit 18dace2e
atomgit-bot
atomgit-bot
8月31日 评论:

变更摘要

本 PR 为回退性质的变更:撤销此前对 tensor layout 工具类的重新组织,并将 codegen 的 padding 模式选择逻辑与相关测试期望同步更新。核心内容包括:将 TensorLayoutUtils 与 DiscontinuityInfo 的命名空间由 ascgen_utils 改回 optimize 并删除对应单测文件;重写 reg_api_call_utils.cpp 中的 GetPaddingMode,使其不再依赖 AnalyzeLoadDiscontinuity,改为依据 TileInner 切分轴位置及 repeat/stride 的静态相等性判断 Compact/Normal 模式;同时大量单测与 e2e 测试的期望 kernel 输出、indirect load/store 测试的 index 布局随之调整。

主要改动

  • 工具类命名空间回退: tensor_layout_utils.cpp/.h 中 TensorLayoutUtils 与 DiscontinuityInfo 的命名空间由 ascgen_utils 改回 optimize,同步更新 load_to_nddma_template.cpp、nddma_template.cpp、un_alignment_strategy.cpp 中的调用,并删除 test_tensor_layout_utils.cpp 中的 7 个相关单测。
  • GetPaddingMode 逻辑重写: 签名由 GetPaddingMode(const Tensor &) 扩展为 GetPaddingMode(const TPipe &, const Tensor &, const DataCopyParams &),移除对 TensorLayoutUtils::AnalyzeLoadDiscontinuity 的依赖,改为:当 vectorized 轴中存在非首轴的 TileInner 轴或 repeats 不足时返回 Normal,否则通过 af::SymbolicUtils::StaticCheckEq 校验末维 repeat 与 stride 是否相等来决定 Compact/Normal;reg_broadcast_api_call.cpp 中对应移除对 GetPaddingMode 及 kCompactPddingMode 的使用。
  • codegen 期望输出调整: 多个测试文件的期望 kernel 字符串在 AscendC::PaddingMode::Compact 与 AscendC::PaddingMode::Normal 之间切换,包括 test_codegen_load_reg_api_call.cpp、test_codegen_store_reg_api_call.cpp、floortoint_float_backend_generate.cpp、load_where_x2_x3_is_ubscalar_store_backend_generate.cpp,以匹配新的 padding 模式判定逻辑。
  • indirect load/store 测试调整: 移除 kInputStride1/kIndexStride1 中按 kExpectSimt/kExpectSk 条件改写 stride 的逻辑;index 由按行重复的二维布局改为每行一维索引(index_repeats、index_strides、index_count 相应调整),并在 broadcast 之前新增 INT32→INT64 的 Cast 节点。
  • load_nan_out_for_store 测试简化: 移除 std::fill_n 的 y 缓冲零初始化与强制 tiling_data.block_dim = 1 的设置,并将测试 shape 从 {2,8,32}/{8,16,32}/{96,16,32} 调整为 {2,8,8}/{8,16,16}/{96,16,16}。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月31日 评论:

代码审查

已确认的核心问题已上报。由于删除文件不在工具可访问范围内(autofuse/tests/ut/common/test_tensor_layout_utils.cpp 已被整文件删除,无法作为锚点注册 finding),该观察无法通过工具记录,我将其在总结中说明。

关闭总结

已上报 findings

  • P0 × 1(confidence 0.92):autofuse/optimize/tensor_layout_utils.cpp:18 新增的 include "schedule_utils.h" 缺少 # 前缀(diff 与工作区双重确认),导致该翻译单元语法错误、整个 optimize 库及依赖它的组件(un_alignment_strategy / load_to_nddma_template / nddma_template)编译失败,属构建级故障,必须修复后才能合入。

逐文件确认情况

  • autofuse/optimize/tensor_layout_utils.cpp — 发现问题(P0):第 18 行 include 缺 #。
  • autofuse/optimize/tensor_layout_utils.h — no issues:命名空间改为 optimize,已确认全部消费者(un_alignment_strategy/load_to_nddma_template/nddma_template,均位于 namespace optimize)同步改为非限定名,全仓库无残留 ascgen_utils::TensorLayoutUtils/DiscontinuityInfo 引用。
  • autofuse/tests/ut/common/test_tensor_layout_utils.cpp(删除)— 注意到的问题(未能注册):该文件是 AnalyzeLoadDiscontinuity(关键布局分析逻辑,驱动对齐/NDDMA 决策)唯一的直接单测套件,删除后无替代覆盖。属 P3 级覆盖回退,因工具禁止锚定已删除文件而未注册,建议在 optimize 命名空间下保留等价用例(至少保留两个失败路径用例)。
  • floortoint_float_backend_generate.cpp、load_where_x2_x3_is_ubscalar_store_backend_generate.cpp — no issues:Compact→Normal 期望与新的 GetPaddingMode 单 repeat→Normal 逻辑一致。
  • indirect_load_store_backend_generator.cpp — no issues:index 视图改为 1D({index_rows, One}/{One, Zero})并新增 INT32→INT64 Cast 节点,Cast/SetView 用法与文件内既有模式一致;移除 stride hack 属 revert 意图。
  • test_e2e_indirect_load_store_kernel.cpp — no issues:index 缓冲改 1D(kIndexRows)、InitializeData 与 KernelData 尺寸自洽,与图中 1D index 读一致。
  • test_e2e_load_nan_out_for_store_expect_kernel.cpp — no issues:移除 fill_n/block_dim=1 及改 shape 属 revert 硬化措施,无确证失败路径。
  • test_codegen_load_reg_api_call.cpp、test_codegen_store_reg_api_call.cpp — no issues:期望字符串与新启发式(多 repeat 且 repeat==stride→Compact、单 repeat→Normal)逐条自洽。
  • reg_api_call_utils.cpp/.h — no issues:GetPaddingMode 签名与两处调用点一致;ub_strides[size-2] 在 repeats.size()>1 保护下,且三个向量同长不变式被现有 SetDmaParams/SetLoopModeParams 依赖,无越界触发路径;语义上 repeats.back()==ub_strides[size-2] 恰对应 dst_stride=0 的 compact 条件,逻辑成立。
  • reg_broadcast_api_call.cpp — no issues:移除 padding_mode 分支后尾轴 size 选择退回轴类型启发式,自洽。
  • load_to_nddma_template.cpp、nddma_template.cpp、un_alignment_strategy.cpp — no issues:命名空间引用与头文件一致。

总体风险判断

本 PR 整体为一次 revert(恢复 optimize 命名空间、旧 padding-mode 启发式与 1D index 图结构),各改动彼此自洽,测试期望与代码逻辑一致。但存在一处 P0 级编译错误(缺失 # 的 include),会导致整个库无法构建;该问题一旦修复,其余改动未见明确功能缺陷。

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

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
8月31日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月31日 评论:

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/graph-autofusion ✅ wangxiaotian995, xchu42 (2/2) ✅ wangxiaotian995 (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_40517592, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
8月31日 将niuyuhu,yangyongqiang0606,liyuewei,xchu42,zhang_shengjie,depeng1994,wqtshg_wt,peiyang,shengnan666,XuebinYang,sjtulxh,zhanj,zhujingjing,xuyafei,wangxiaotian995设为评审人
CANN-robotCANN-robot成员
8月31日 将niuyuhu,yangyongqiang0606,liyuewei,xchu42,zhang_shengjie,depeng1994,wqtshg_wt,peiyang,shengnan666,XuebinYang,sjtulxh,zhanj,zhujingjing,xuyafei,wangxiaotian995设为审查人
PPhl17成员
8月31日 修改了pull request 的描述
PPhl17成员
8月31日 修改了pull request 的描述
Phl17成员
8月31日 评论:

compile

likedislike
PPhl17成员
8月31日 预合并成功(commit_id: 7b13c5047f55255afdeba0a24d5d5531411a6dfa)
此处折叠了7条事件消息 查看更多
CANN-robotCANN-robot成员
8月31日 添加了label:cann-cla/yes
Phl17成员
8月31日 评论:

compile

likedislike
PPhl17成员
8月31日 预合并成功(commit_id: 44d73d843919b3cf42fe4a4d79126e80ed682d50)
CANN-robotCANN-robot成员
8月31日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
8月31日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月31日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月31日 添加了label:ci-pipeline-passed
xchu42
xchu42成员
8月31日 评论:

/lgtm

likedislike
atomgit-bot
atomgit-bot8月31日进行代码检视1
autofuse/optimize/tensor_layout_utils.cpp
@@ -15,8 +15,9 @@
1515#include "ascgen_log.h"
1616#include "ascir_ops.h"
1717#include "common_utils.h"
18+#include "schedule_utils.h"
atomgit-bot
atomgit-bot8月31日评论:

🔴 Critical

changed line: autofuse/optimize/tensor_layout_utils.cpp 第 18 行新增的 include "schedule_utils.h" 缺少预处理指令前缀 #(diff 中为 +include "schedule_utils.h",工作区文件内容经 read_file 与 grep 双重确认均为 include "schedule_utils.h",而同一文件第 11~17 行的 #include 均正常带 #)。

affected behavior/contract: 该行位于文件作用域,include 会被当作未声明标识符解析,紧随其后的字符串字面量构成非法声明,整个翻译单元出现语法错误。

failure mode: tensor_layout_utils.cpp 无法通过编译,optimize 库构建失败;由于 AnalyzeLoadDiscontinuity/TensorLayoutUtils 被 un_alignment_strategy.cpp、load_to_nddma_template.cpp、nddma_template.cpp 等生产代码引用,将连带导致依赖该库的整个 autofuse 组件(以及涉及本文件的回归测试)编译失败,属 P0 级构建故障。

suggested fix: 将行首补上 # 恢复为 #include "schedule_utils.h"(该头文件存在于 autofuse/optimize/schedule_utils.h,修复后可用;若本文件实际并不需要它,也可直接删除此行)。

建议:把第 18 行改为 #include "schedule_utils.h"(或确认本文件未使用 schedule_utils 中的符号时直接删除该 include)。

  当前建议代码无改动
likedislike
不准确?
PPhl17成员
8月31日 关联了issue:fix: 调整 tensor layout 工具归属和搬运模式
wangxiaotian995成员
8月31日 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
8月31日 添加了label:lgtm
PPhl17成员
8月31日 解决了最后一个问题
wangxiaotian995成员
8月31日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月31日 添加了label:approved
CANN-robotCANN-robot成员
8月31日 合入了pull request