Skip to content

Fix: align HBG host and device swimlane timelines - #2244

Merged
zhusy54 merged 1 commit into
hw-native-sys:mainfrom
indigo1973:hbg_swim
Sep 21, 2026
Merged

zhusy54 merged 1 commit into
hw-native-sys:mainfrom
indigo1973:hbg_swim

Conversation

@indigo1973

@indigo1973 indigo1973 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Adapt Host Build Graph swimlane artifacts and conversion so Host records and
Device records share a bounded timeline on A2/A3 and A5.

  • Export invocation-scoped host_clock_alignment..log files beside eligible
    captures while keeping cumulative Host logs in a capture-independent process
    session spool that survives consecutive capture cleanup.
  • Derive and persist a fixed-size metadata.clock_alignment mapping from native
    timing markers, apply it to single-file and multi-rank conversion, and keep
    generated metadata consistent when source writeback fails.
  • Read the runtime from document metadata, support the structured HBG Scheduler
    records and TaskId layout, name AICore Scheduler lanes by worker_id, and omit
    redundant per-stream runtime fields.
  • Render TMR TaskIds with explicit ring labels, including ring zero, across
    swimlane, dependency, and critical-path views.
  • Cover runtime-produced alignment artifacts, consecutive captures, HBG mapping
    persistence, and the retained multi-rank TMR directory merge in CI and tests.

Co-authored-by: majin0824 majin15@huawei.com

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 9dac534d-d2a9-41fe-8ba5-fb794b11def3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f95960e4-05d7-46c4-8d94-f3a2c705aade

📥 Commits

Reviewing files that changed from the base of the PR and between 8414356 and 9ccb5e7.

📒 Files selected for processing (10)
  • docs/dfx/chip-swimlane-profiling.md
  • simpler_setup/scene_test.py
  • simpler_setup/tools/README.md
  • simpler_setup/tools/containment.py
  • simpler_setup/tools/swimlane_converter.py
  • src/a2a3/runtime/host_build_graph/docs/profiling_levels.md
  • src/a5/runtime/host_build_graph/docs/profiling_levels.md
  • tests/ut/py/test_clock_alignment.py
  • tests/ut/py/test_containment.py
  • tests/ut/py/test_swimlane_converter.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds persisted Host/device clock alignment for eligible single-file captures. It adds scheduler-stream containment, alignment metadata and fallback behavior, updated profiling documentation, diagnostic logging, and tests for legacy, HBG, device-only, and invalid-input cases.

Changes

Host/device clock alignment

Layer / File(s) Summary
Alignment behavior and profiling contracts
docs/dfx/chip-swimlane-profiling.md, simpler_setup/tools/README.md, src/a2a3/runtime/host_build_graph/docs/profiling_levels.md, src/a5/runtime/host_build_graph/docs/profiling_levels.md
The documentation describes Host/device alignment, persisted mappings, Host-log handling, and Host lane availability at profiling levels 3 and 4.
Scheduler stream containment
simpler_setup/tools/containment.py, tests/ut/py/test_containment.py
Containment reads versioned scheduler_records streams with legacy fallback. Only AICPU records bound the sched join window, while other producers extend the capture extent.
Single-capture alignment flow
simpler_setup/tools/swimlane_converter.py, simpler_setup/scene_test.py, simpler_setup/tools/README.md
The converter validates, persists, reuses, and applies clock mappings. It reports alignment metadata, preserves raw timestamps, and logs non-empty successful subprocess stderr at warning level.
Alignment and conversion validation
tests/ut/py/test_clock_alignment.py, tests/ut/py/test_swimlane_converter.py
Tests cover mapping reuse and invalidation, fallback behavior, legacy inputs, diagnostic output, device-only conversion, HBG sources, scheduler streams, and explicit rank mappings.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Capture as Single-file capture
  participant Converter as swimlane_converter
  participant Logs as Host logs
  participant Metadata as metadata.clock_alignment
  Capture->>Converter: Prepare or reuse alignment
  Converter->>Logs: Match Host records when no valid saved mapping exists
  Logs-->>Converter: Host anchors and timing bounds
  Converter->>Metadata: Persist validated mapping atomically
  Converter-->>Capture: Decode with aligned or fallback timestamps
Loading

Merge Risk: ⚪ Minimal · up to 9ccb5

The alignment, containment, fallback, and persistence paths have corresponding validation coverage, with no actionable merge-blocking issue identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 45 functions across 6 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description clearly explains the HBG host/device timeline alignment changes, persisted clock mappings, scheduler-stream handling, rendering updates, and validation coverage.
Title check ✅ Passed The title clearly and concisely summarizes the primary change: aligning HBG host and device swimlane timelines.
Full details: Docstring Coverage

Explanation

Docstring coverage is 31.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 45 functions across 6 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the clocks at dawn
Host and device lines align
Scheduler streams mark the path
Saved bounds remain in time
Logs may guide the mapping
And tests guard every sign

Comment @coderabbitai help to get the list of available commands.

@indigo1973
indigo1973 force-pushed the hbg_swim branch 9 times, most recently from d96a00e to 9f970f2 Compare September 20, 2026 06:52
@indigo1973 indigo1973 changed the title Fix: adapt host build graph swimlane clock alignment Fix: align HBG host and device swimlane timelines Sep 20, 2026

@zhusy54 zhusy54 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review:必须修复项与测试精简

必须修复

  1. Host logger 首次目录绑定与临时 capture 生命周期冲突

    Worker._submit_locked 会把本次 output_prefix 传给 Host logger,但 logger 采用第一个非空目录永久生效的策略;alignment exporter 又通过该目录路径重新打开 host.<pid>.log。如果第一次 capture 目录被删除,第二次 capture 的重新绑定会被忽略,exporter 无法重新打开旧路径,成功的运行可能最终因 alignment export 失败返回 PTO_RUNTIME_ERR_INTERNAL。另外,绑定发生在 callable/handle 验证前,一次失败 submit 也可能永久污染后续运行。

    建议把 persistent process log 放到独立于单次 capture 的稳定 process/session 目录,或实现安全的 sink rotation/rebind;同时避免失败 submit 永久改变 logger destination。

  2. 当前临时目录测试掩盖了上述问题

    test_st_log_drain_survives_temporary_capture_directories 使用 drain_host_log fixture,而该 fixture 会预先把 logger 绑定到 pytest session 目录。因此测试中的 _set_host_log_directory(capture) 实际不会切换目录,只证明 fixture 的稳定目录可读,没有覆盖生产生命周期。

    请删除或重写该测试。最小有效回归应使用同一 Worker/ChipWorker:完成第一次 capture、删除第一次 capture 目录、执行第二次 capture,并验证第二次运行和 alignment export 均成功。first_invocation=[1, 3] 不触发不同分支,也可以删除。

  3. TestConsecutiveClockAlignment 的核心断言没有进入现有 CI

    该测试仅支持 A5、标记为 manual;per-PR A5 主 sweep 会排除 manual,onboard DFX action 又没有运行 A5 HBG chip-swimlane。daily 主 sweep没有传 --enable-chip-swimlane,因此测试会在 level == 0 时返回。

    如果保留该测试,请把它接入真正启用 HBG L3 swimlane 的 CI,并确保两个 invocation 都执行。if len(invocations) == 2 应改为强断言,避免只运行一个 case 时静默通过。若有更轻量且能真实覆盖目录删除的回归,可以用其替换当前 manual scene test,不需要保留两套测试。

  4. directory 写回失败后,event 与输出 metadata 可能不一致

    single-file 路径写回失败后会更新内存 raw metadata,directory 路径目前只打印 warning。如果输入已有旧 mapping,本次 event 使用新 placement,但输出 timeline_metadata.clock_alignment 可能仍是旧 mapping;如果输入没有 mapping,输出 metadata 可能缺少本次实际使用的 mapping。

    这里重点是行为分叉,不是代码量。请保证内存中的 mapping 始终更新,源文件持久化仅为 best effort。测试只需一个最小回归:输入带旧 mapping、计算出新 mapping、模拟写回失败,断言 event 和输出 metadata 都使用新 mapping;无需扩展完整失败组合矩阵。

  5. 删除 scheduler_records.streams[].runtime

    document-level metadata.runtime 已足够,stream-level runtime 是重复数据。目前 producer、文档和 fixture 存在两种 stream shape。请删除 producer 中的该字段,同步测试和文档,并搜索 consumer 确认没有依赖。现有 producer/scene test 应显式断言 runtime 不在 stream 中,不需要新增独立测试文件。

  6. 恢复 TMR directory 覆盖,新增独立 HBG fixture

    共享 _write_l3_rank 从 TMR 改成 HBG 后,原有 multi-rank TMR directory merge 覆盖被整体替换。请恢复原 TMR fixture,并新增独立 HBG alignment fixture;保留一个 multi-rank TMR directory merge 用例即可,不需要扩展更多组合。

可精简的测试

  1. _verify_runtime_clock_logs 已检查 alignment log 数量、单一 (pid, inv) 和 required markers;TestConsecutiveClockAlignment 后续重复检查了相同内容。建议前者只负责验证 converter 执行前 native artifact 已存在,后者只保留 PID/inv 与 placement 对应、anchor 和连续 invocation 等集成断言。

  2. test_single_capture_persists_alignment... 已精确断言 anchor 和转换后的 timestamp,dispatch_time_us > 1000 以及重复的 bounds 包含关系断言信息增量较低,可删除;这项仅是精简建议,不作为合入阻塞条件。

本 review 不要求额外增加 A2/A3 hardware smoke、原任务失败时 flush 专项测试,或扩展更多 frequency/level/marker 组合。测试应聚焦于已确认的问题和本 PR 明确承诺的行为。

@indigo1973
indigo1973 force-pushed the hbg_swim branch 4 times, most recently from 538af91 to 492ab96 Compare September 20, 2026 17:12
Adapt Host Build Graph swimlane artifacts and conversion so Host records and
Device records share a bounded timeline on A2/A3 and A5.

- Export invocation-scoped host_clock_alignment.<pid>.log files beside eligible
  captures while keeping cumulative Host logs in a capture-independent process
  session spool that survives consecutive capture cleanup.
- Derive and persist a fixed-size metadata.clock_alignment mapping from native
  timing markers, apply it to single-file and multi-rank conversion, and keep
  generated metadata consistent when source writeback fails.
- Read the runtime from document metadata, support the structured HBG Scheduler
  records and TaskId layout, name AICore Scheduler lanes by worker_id, and omit
  redundant per-stream runtime fields.
- Render TMR TaskIds with explicit ring labels, including ring zero, across
  swimlane, dependency, and critical-path views.
- Cover runtime-produced alignment artifacts, consecutive captures, HBG mapping
  persistence, and the retained multi-rank TMR directory merge in CI and tests.

Co-authored-by: majin0824 <majin15@huawei.com>
@zhusy54
zhusy54 merged commit 8d4debf into hw-native-sys:main Sep 21, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants