Merged
feat(IR): Check or render the func builder #5746
feat(IR): Check or render the func builder #5746
Merged
Jie YinAdd on Aug 27
Jie Yin
Jie YinCollaborators
Aug 27

feat(IR): Check or render the func builder

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Jie Yin's contribution.)
Jie YinJie YinCollaborators
Aug 27 Created pull request, commit fb6fd158
atomgit-bot
atomgit-bot
Aug 27 Comments:

变更摘要

本 PR 为 IR 的 func builder(RootFunctionBuilder,即 ir_func_builder.cpp)相关测试引入"检查或渲染"(check/render)的 golden 快照机制:test_common.py 中的 check_snapshot 由接收字符串改为接收 Path,并新增 PYPTO_RENDER_IR 环境变量开关,设置后直接把 str(func) 写入 golden 文件完成渲染/更新,否则读取 golden 文件做 diff 校验。同时将多份测试中内联的 IR 字符串迁移为独立的 .pypto golden 文件,并将所有调用点统一改为按路径传入。

主要改动

  • check_snapshot 支持渲染模式:python/tests/ut/ir/test_common.py 中 check_snapshot(func, golden_path) 改为接收 Path 类型,新增 PYPTO_RENDER_IR 环境变量分支——置位时写入 str(func) 到 golden 路径并打印 Updated: 后返回,否则读取 golden 与 str(func) 做 strip 后对比并输出 unified diff。
  • func builder 测试接入 golden 快照:test_ir_func_builder.py 的 _run_root_only 新增 golden_name 参数,在 canonicalize/dce/create_root_functions 之前通过 check_snapshot(prog, golden_path) 对 program 做快照;并新增 test_ir_func_builder_data/ 目录下 11 个 .pypto golden 文件覆盖各分支场景。
  • 外部化冗余 token 测试的内联基准:test_remove_redundant_pass.py 将 16 组内联的 BEFORE_IR_* / IR_* 字符串常量抽取到 test_remove_redundant_pass_data/ 目录下的 .pypto 文件,测试改为以路径形式传给 check_snapshot。
  • 移除 infer token pass 测试的归一化逻辑:test_infer_pass.py 删除 _NormalizedSnapshot 类、_normalize_token_names 正则归一化及 _check_snapshot 包装,统一改用 check_snapshot;同时 test_for_input.pypto、test_for_output.pypto、test_for_read_output.pypto 三个 golden 文件中的 loop_idx_N 占位符替换为具体编号(如 loop_idx_28、loop_idx_10)。
  • 批量迁移快照调用点:test_attr_move.py、test_token_pass_inplace.py 以及 test_merge_pass/ 下多个测试(test_fillpad.py、test_merge_pass1.py~test_merge_pass8.py 等)将 check_snapshot(func, IR.read_text()) 改为 check_snapshot(func, IR),统一以 Path 传入 golden 文件。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 27 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 27 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 27 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
repo-cann/pypto ✅ DCGDDD, congqiannan (2/2) ✅ congqiannan (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Aug 27 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
Aug 27 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
Jie YinJie YinCollaborators
Aug 27 Associated issue: [Task|任务跟踪]: 新IR适配
Jie Yin
Jie YinCollaborators
Aug 27 Comments:

compile

likedislike
Jie YinJie YinCollaborators
Aug 27 Pre merge succeeded (commit_id: 63bb50c5679eaa7cdab5c1185e042e71e7115895)
CANN-robotCANN-robotCollaborators
Aug 27 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Aug 27 Comments:

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

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
UT_Test_Py3_ninja_simulation ✅ SUCCESS
UT_Test_Py3_ninja ✅ SUCCESS >>>>>
UT_Test_Cpp_make_gnu_part_1 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_2 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_3 ✅ SUCCESS
UT_Test_Cpp_make_clang_part1 ✅ SUCCESS
UT_Test_Cpp_make_clang_part2 ✅ SUCCESS
UT_Test_Cpp_make_clang_part3 ✅ SUCCESS
UT_Test_kirinx90 ✅ SUCCESS
UT_Test_kirin9030 ✅ SUCCESS
UT_Test_report ✅ SUCCESS >>>>>
PreSmoke_A900 ✅ SUCCESS >>>>>

[2026-08-27 21:16:46]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Aug 27 Comments:

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

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>>
StaticCheck_md ✅ SUCCESS

[2026-08-27 21:01:55]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Aug 27 Comments:

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

任务名称状态日志下载链接
get_pr_file ✅ SUCCESS
static-check ✅ SUCCESS
compile ✅ SUCCESS

[2026-08-27 21:17:39]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
Aug 27 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Aug 27 Added label: ci-pipeline-passed
Jie Yin
Jie YinCollaborators
Aug 28 Comments:

/check-pr

likedislike
CANN-robot
CANN-robotCollaborators
Aug 28 Comments:

The following labels are not ready.

lgtm: Please wait for reviewers to review the code.

approved: Please wait for committers to review the code.

likedislike
congqiannan
congqiannanCollaborators
Aug 28 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 28 Added label: approved
杨旭
杨旭Collaborators
Aug 28 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Aug 28 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 28 Merged pull request