Pull Request has been successfully merged by CANN-robot.
(Thank you for huanyongben's contribution.)变更摘要
该 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)。


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


/approve
/lgtm


/approve
/lgtm


/approve
/lgtm


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