Merged
feat(pypto_pro):auto pipeline support mutiple loops #6038
huanyongbenAdd on Sep 8
feat(pypto_pro):auto pipeline support mutiple loops #6038
Merged
huanyongbenAdd on Sep 8
huanyongben
Sep 8

1、自动pipeline支持算子中存在多个独立的计算阶段,分别进行pipeline转换
2、修复框架bug

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for huanyongben's contribution.)
huanyongbenhuanyongben
Sep 8 Created pull request, commit bb6e6f64
atomgit-bot
atomgit-bot
Sep 8 Comments:

变更摘要

该 PR 为 auto pipeline 增加多循环支持:一个 kernel 内可以存在多个 pipeline 循环,每个循环拥有独立的 ctx 环形缓冲、任务计数器、drain 与同步。核心改动是 _analyzer.py 的 analyze_pipeline 由返回单个 PipelineInfo 改为按源码顺序返回 PipelineInfo 列表,内核级事实(buffer 声明、sync 上下文、var_sections 等)在各循环间按引用共享;PipelineConfig.preload 扩展为可按循环逐个配置;所有变换生成的变量/结构名带上循环索引后缀以避免命名冲突;校验拆分为内核级(validate_kernel_structure、validate_kernel_buffers)与单循环级两类。同时收紧了循环体规则:仅「两个 stage 之间、为 ctx 快照提供值」的语句会被提升到快照之前,循环体内非 stage 的 buffer 访问与在循环体内取 slot 的行为被明确拒绝。

主要改动

  • 多循环分析支持(_analyzer.py):analyze_pipeline 改为返回按源码顺序的 PipelineInfo 列表,新增 _find_pipeline_loops、_scan_kernel_buffers、_scan_loop_accesses、buffers_touched 等函数;PipelineInfo 新增 loop_index、outer_loop、lifted_stmts/lifted_origin_ids 字段,group_names、sync 等内核级事实在所有循环间按引用共享。
  • preload 支持按循环配置(config.py):PipelineConfig.preload 类型由 int 扩展为 int | tuple[int, ...],新增 preload_of(loop_index) 按循环取值(单值对所有循环生效,元组按源码顺序一一对应),并在 __post_init__ 中校验每个值非负、拒绝空序列。
  • 生成符号按循环索引命名(_transformer.py、_astutil.py):新增 _ctx_arr_name、_ctx_struct_name、_sync_id_var、_drain_var_name、_ctx_var_name 及 task_id_var(loop_index),除循环 0 保留裸名外,其余循环的 ctx 数组、ctx 结构体、任务计数器、drain 变量均带 _<index> 后缀,避免多循环共享函数作用域时互相覆盖。
  • 校验拆分为内核级与单循环级(_validate.py):新增 validate_kernel_structure(含 _check_preload_count 校验 preload 数量与循环数匹配、_check_distinct_outer_loops 拒绝两个 pipeline 挂在同一外层循环下)与 validate_kernel_buffers(每个声明了 fwd_ids/bwd_ids 的 cross-core buffer 必须被某 pipeline 使用);_check_cross_core_users 改为按循环统计使用方,并删除原单循环限制 _check_single_pipeline_loop。
  • 事件 id 解析与地址复用分配修正(_cross_core_scanner.py、_sync_graph.py):CrossCoreBuffer 由 fwd_id_count/bwd_id_count 改为保存实际 id 元组 fwd_ids/bwd_ids,lifted_ids 携带 buffer 名以便按使用循环放置声明;_used_event_ids 改为按本循环触碰的 buffer 声明读取(使以名称给定的 id 对分配器可见),allocate_reuse_ids 生成的组名按内核连续编号并通过新增的 SyncPlan.reuse_ids 归属到各循环;同时新增 reject_buffer_access_outside_stages(拒绝循环体内非 stage 的 buffer 访问)与 _reject_tile_returning_function(拒绝 helper 函数返回 tile/group)。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 8 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 8 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 8 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
docs ✅ foundea, gaoxiang618, wangbing110 (3/2) ✅ foundea (1/1)
python/pypto_pro ✅ gaoxiang618, foundea, wangbing110 (3/2) ✅ wangbing110, gaoxiang618 (2/1)
repo-cann/pypto ✅ gaoxiang618, foundea, wangbing110 (3/2) ✅ foundea, wangbing110, gaoxiang618 (3/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 8 Set xinweiliu,lyz0328,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
15 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 9 Added label: cann-cla/yes
huanyongben
huanyongben
Sep 9 Comments:

compile

likedislike
huanyongbenhuanyongben
Sep 9 Pre merge succeeded (commit_id: 27fdcea924ac8cf0f8cc73f652b37f3ad6d2ae15)
CANN-robot
CANN-robotCollaborators
Sep 9 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 9 Added label: ci-pipeline-running
6 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 10 Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
Sep 10 Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Added label: cann-cla/yes
huanyongben
huanyongben
Sep 10 Comments:

compile

likedislike
huanyongbenhuanyongben
Sep 10 Pre merge succeeded (commit_id: b8d3cef61f54ec9bb590d98d8f84c93447a68b3b)
CANN-robot
CANN-robotCollaborators
Sep 10 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 10 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 10 Added label: ci-pipeline-passed
huanyongbenhuanyongben
Sep 10 Modify description of pull request
poorwillpoorwillCollaborators
Sep 10 Approval passed
poorwillpoorwillCollaborators
Sep 10 Approval passed
poorwill
poorwillCollaborators
Sep 10 Comments:

/approve
/lgtm

likedislike
gaoxiang618
gaoxiang618Collaborators
Sep 10 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Added label: lgtm
zhangzhong
zhangzhongCollaborators
Sep 10 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Added label: approved
CANN-robotCANN-robotCollaborators
Sep 10 Merged pull request