Skip to content

fix(sync): balance multi-tile prefetch event boundaries - #1524

Open
zhangstevenunity wants to merge 1 commit into
hw-native-sys:masterfrom
zhangstevenunity:codex/fix-issue-1519
Open

zhangstevenunity wants to merge 1 commit into
hw-native-sys:masterfrom
zhangstevenunity:codex/fix-issue-1519

Conversation

@zhangstevenunity

Copy link
Copy Markdown
Collaborator

A preload followed by a multi-tile prefetch loop initialized and drained every slot event, allowing reads or overwrites before their dependencies completed and leaving unmatched waits for odd trip counts. Compute entry and exit events from each slot's first set/wait order and the loop's final rotation position, including loops with zero iterations.

Keep boundary events scoped to their owning loop and avoid duplicate enclosing-loop events. Preserve static synchronization for unproven distinct slot expressions, and use the existing PIPE_ALL fallback when a proven rotation cannot obtain enough event IDs. Update the design documentation and strengthen the existing boundary checks.

Validation:

  • Full lit suite: 1,871 passed, 1 unsupported (VFSIM cost model disabled). After the final change for event exhaustion, rebuilt and reran all 89 sync/multi_tile/event tests; all passed.
  • New protocol regression: 30 level2/level3 configurations and 434 total executions, checking binary-event balance and tile RAW/WAR/WAW ordering. Covers odd/even/zero trips, alternate slot expressions, nested loops, epilogues, and N=2/3/4/8/16.
  • WSL CANN 8.5 Ascend910B1 simulator: the old 7-trip kernel hangs until the 60-second timeout; fixed 1/7/8-trip kernels finish with zero mismatches and zero maximum error. The final compiler emits byte-identical C++ to the simulated kernels.
  • The old 8-trip kernel also passes on this local model, so the reported even-trip device race was checked through the protocol regression rather than reproduced on hardware. CANN 9.0 hardware was not tested.
  • All builds used one job. Code compliance checks and git diff --check passed.

Fixes #1519.

@zhangstevenunity
zhangstevenunity marked this pull request as ready for review September 12, 2026 11:09
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Zhendong404 pushed a commit that referenced this pull request Sep 16, 2026
Co-authored-by: HecreReed<zhangstevenunity@sina.com>
Co-authored-by: zhangstevenunity<128771452+zhangstevenunity@users.noreply.github.com>



# message auto-generated for no-merge-commit merge:
!135 merge codex/fix-multi-tile-prefetch-sync into master

fix(sync): balance multi-tile prefetch event boundaries

Created-by: zhongxuan1
Commit-by: HecreReed;zhangstevenunity
Merged-by: cann-robot
Description: ### 当前 PR 是否有 AI 参与

- [x] 是

1. AI Agent 平台:OpenAI Codex
2. AI 模型:GPT-6
3. Prompt 上下文:用户要求 review GitHub PR #1524,修复 review 发现的问题,并在 GitCode 提交关联 issue 的 PR。

### PR 功能描述 / 为什么需要这个合入

预加载槽位 0、循环中先预取下一槽位再消费当前槽位时,多缓冲同步事件的入口和出口必须与实际迭代及槽位使用匹配,否则零次、奇数次等循环可能出现重复事件、漏等待或读写顺序错误。

移植 GitHub PR #1524 的槽位分析和循环边界修复,并修复 review 中发现的事件 ID 重分配问题:事件池不足时,先移除相关管线作用域内所有由分配器生成的入口/出口事件,再从原始依赖重新分配,避免把残留在循环边界的旧事件当作新依赖重复分配。

### 该 PR 关联的 issue

Fixes #1519

来源:#1524 ,原始提交 `46546e605b97bbabf6f472c45f60666029089be9`。保留原作者信息。

### 希望检视人员了解

新增连续 2/4/5 个预取循环和嵌套连续循环的回归,复用缓冲区以检查跨循环读写顺序;覆盖 level2/level3、零次/奇数/偶数迭代及不同槽位表达式。协议检查验证事件配对和 RAW/WAR/WAW 顺序,不依赖固定事件编号。

旧分配器在 `sequential_4-level2, upper=-1` 上复现 `duplicate set without wait: ('PIPE_MTE2', 'PIPE_V', 1)`;修复版同一测试通过。

## 改动类型 / Change Type

- [x] Bug 修复 / Bug Fix
- [x] 文档更新 / Documentation
- [x] 测试相关 / Test

## 测试信息 / Testing

- 完整 Release 构建及隔离环境 editable 安装通过。
- 预取同步协议回归通过:39 个编译配置、546 次协议执行;已安装的 PTOAS CLI 路径也通过。
- 恢复修复版后,24 项 multi-tile lit 回归全部通过。
- 分配器原生压力检查通过,覆盖 2/4/5/20 个连续双缓冲循环。
- 完整 lit:1841 通过、1 不支持、48 失败。
- 完整 CTest:73/75 通过。
- 上述 48 项 lit 和 2 项 CTest 失败均使用未修改的主干 `4f849408b` 编译器重新验证,失败集合和 CANN 版本诊断一致。当前环境为 CANN 9.0.0-beta.1,相关测试要求 9.0.0-beta.2 或更新版本;没有本次修复特有的失败。
- 变更代码规范检查:8 个文件,0 错误、0 警告;差异检查通过。

未进行 NPU 或硬件模拟器运行验证。

## 检查清单 / Checklist

- [x] 代码符合规范 / Code follows style guide
- [x] 已添加回归测试,且相关回归全部通过
- [x] 设计文档已更新
- [x] 无硬编码敏感信息 / No secrets hardcoded
- [x] 提交信息符合规范 / Commit message follows convention


See merge request: cann/pto-as!135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant