Skip to content

Refactor: converge A2A3 and A5 TMR internals - #1718

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
yanghaoran29:codex/issue-1582-tmr-cleanup
Aug 7, 2026
Merged

Refactor: converge A2A3 and A5 TMR internals#1718
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
yanghaoran29:codex/issue-1582-tmr-cleanup

Conversation

@yanghaoran29

Copy link
Copy Markdown
Contributor

Summary

Converge the remaining low-risk A2/A3 and A5 tensormap_and_ringbuffer runtime differences identified in #1582.

What changed

  • Complete the Add manual-scope v0 to tensormap runtime #568 scope API alignment by allowing A2/A3 PTO2_SCOPE_GUARD(...) to forward PTO2ScopeMode, with AUTO/MANUAL lifetime coverage.
  • Reuse A5 PTO2TaskPayload::prefetch(), remove the duplicate helper, dead A2/A3 aliases/overloads, stale internal names, and A5's always-zero sched_scan_cycle leftover from the cleanup scoped to A2/A3 in Refactor: drop SCHED_IDLE_WAIT phase records and vestigial SCAN slot #869.
  • Convert all remaining TMR include guards to #pragma once and correct stale init_data_from_layout references.
  • Fix A5 multi-ring, slot-size, retained-buffer, and chip-swimlane profiling documentation.

The cleanup is intentionally limited to the TMR runtime; host_build_graph is unchanged.

Verification

  • Built all A2A3SIM and A5SIM runtimes.
  • pre-commit run --files $(git diff --name-only upstream/main...) passed, including clang-tidy, cpplint, and markdownlint.
  • Fresh C++ UT build passed.
  • ctest -LE requires_hardware --output-on-failure: 89/89 passed.
  • Focused A2/A3 scope-guard test passed after adding both AUTO and MANUAL coverage.
  • git diff --check and residual-symbol/header scans passed.

mkdocs build --strict was not available locally because mkdocs is not installed in the current environment; Markdown lint passed and CI will run the repository docs job.

Related to #1582.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review 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: Pro Plus

Run ID: 2d2b641e-d7aa-4a25-ae5c-239f2f61730e

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
📝 Walkthrough

Walkthrough

The change aligns a2a3 and a5 runtime APIs, removes scheduler scan profiling, updates profiling documentation, replaces header guards with #pragma once, and adds scope-mode forwarding tests.

Changes

Runtime API and behavior

Layer / File(s) Summary
API and runtime alignment
src/a2a3/runtime/tensormap_and_ringbuffer/orchestration/pto_orchestration_api.h, src/a2a3/runtime/..., src/a5/runtime/..., tests/ut/cpp/a2a3/test_a2a3_fatal.cpp
Scope guards forward optional arguments. Scheduler layout reservation no longer uses task-window sizes. Payload prefetching uses PTO2TaskPayload::prefetch. Related names and documentation are updated.
Profiling counter and trace alignment
src/a2a3/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp, src/a5/runtime/.../scheduler/*, src/a5/runtime/.../docs/profiling_levels.md
Scan profiling counters and logs are removed. Task-token recording, buffer rotation, fanout joining, and task-count names are updated.
Header and declaration normalization
src/a2a3/runtime/tensormap_and_ringbuffer/**/*.h, src/a5/runtime/tensormap_and_ringbuffer/**/*.h
Traditional include guards are replaced with #pragma once across runtime and host headers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

Poem

A rabbit guards each scope with care,
While scan counters fade from air.
Headers bloom with pragma light,
Tokens guide the profiling flight,
And buffers rest in slots just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.37% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: converging A2/A3 and A5 TMR internals.
Description check ✅ Passed The description directly explains the runtime convergence changes, scope, documentation updates, and verification results.
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.

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/a2a3/runtime/tensormap_and_ringbuffer/docs/profiling_levels.md`:
- Line 74: Update the scheduler output example in profiling_levels.md to remove
the stale scan row, matching the scheduler counter lists at the documented
sections. Ensure all scheduler output documentation consistently reflects only
counters that are emitted.

In `@src/a2a3/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h`:
- Line 388: Update the comment for init_data_from_layout() to state that
arena-internal pointer fields, including ready_queues[].slots, are bound by
wire_arena_pointers() rather than init_data_from_layout().

In `@src/a5/runtime/tensormap_and_ringbuffer/docs/profiling_levels.md`:
- Line 114: Remove the stale scan row from the Level 2 output example in
profiling_levels.md, leaving only the complete, dispatch, and idle phase
statistics to match the current emitted output.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a50ecad5-36d4-45c3-928f-2c58d696ec92

📥 Commits

Reviewing files that changed from the base of the PR and between 6096d32 and 4bd115d.

📒 Files selected for processing (49)
  • src/a2a3/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp
  • src/a2a3/runtime/tensormap_and_ringbuffer/common/pto_runtime_status.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/docs/profiling_levels.md
  • src/a2a3/runtime/tensormap_and_ringbuffer/host/dep_gen_replay.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/orchestration/pto_orchestration_api.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/aicore_completion_mailbox.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/aicore_completion_mailbox_types.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_async_kernel_api.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_async_wait.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_completion_token.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_constants.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_dep_compute.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_orchestrator.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_runtime2_types.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_tensormap.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_types.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/runtime.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_context.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_types.h
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/shared/pto_runtime2_init.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/common/pto_runtime_status.h
  • src/a5/runtime/tensormap_and_ringbuffer/docs/MULTI_RING.md
  • src/a5/runtime/tensormap_and_ringbuffer/docs/RUNTIME_LOGIC.md
  • src/a5/runtime/tensormap_and_ringbuffer/docs/profiling_levels.md
  • src/a5/runtime/tensormap_and_ringbuffer/host/dep_gen_replay.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/aicore_completion_mailbox.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/aicore_completion_mailbox_types.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/backend/sdma/sdma_completion_kernel.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/backend/sdma/sdma_completion_scheduler.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/backend/urma/urma_completion_kernel.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/backend/urma/urma_completion_scheduler.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_async_kernel_api.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_async_wait.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_completion_token.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_constants.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_dep_compute.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_orchestrator.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_runtime2_types.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_tensormap.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_types.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/runtime.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_cold_path.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_context.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_types.h
  • tests/ut/cpp/a2a3/test_a2a3_fatal.cpp

Comment thread src/a2a3/runtime/tensormap_and_ringbuffer/docs/profiling_levels.md
Comment thread src/a2a3/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h Outdated
Comment thread src/a5/runtime/tensormap_and_ringbuffer/docs/profiling_levels.md
Align scope-mode forwarding, payload prefetch, scheduler layout, internal names, and profiling documentation across the TMR runtimes.

Retain compatibility header guards in otherwise-unchanged headers so existing architecture detection remains available.
@yanghaoran29
yanghaoran29 force-pushed the codex/issue-1582-tmr-cleanup branch from 4c1cebb to 7a6761e Compare August 6, 2026 11:38
@ChaoWao
ChaoWao merged commit 2990441 into hw-native-sys:main Aug 7, 2026
19 checks passed
yanghaoran29 added a commit to yanghaoran29/simpler that referenced this pull request Aug 10, 2026
Close the two P4/P5 residuals flagged in hw-native-sys#1582's 2026-08-09 re-audit
(after hw-native-sys#1718 landed):

R1 — a5 lacked the scope-guard regression test that a2a3 gained in hw-native-sys#1718.
a5's `PTO2_SCOPE_GUARD(...)` has been variadic (and its MANUAL path live,
read by `rt_scope_begin` -> `begin_scope(mode)`) since the hw-native-sys#1100 import,
but `ut-a5` would not have caught a regression in MANUAL forwarding.
Mirror `ScopeGuardForwardsModeUntilLexicalScopeExit` to `test_a5_fatal.cpp`:
`FakeRuntime` gains `pending_scope_mode` (immediately after `ops`, the
prefix the inline wrappers pun through) and `last_scope_mode`;
`fake_scope_begin` records the mode; the test asserts AUTO then MANUAL
forwarding across lexical scope exit. Both test files also extend the
single `offsetof(ops) == 0` guard to a second one pinning
`pending_scope_mode` at `sizeof(PTO2RuntimeOps *)`, since the
`reinterpret_cast` now depends on the two-field prefix, not one.

R2 — a2a3 `RUNTIME_LOGIC.md` still described the retained temp buffer as
a single runner-owned instance, but the shared host-runtime callback
`get_retained_temp_buffer(runner_ctx, pipeline_slot, ...)` is per-slot
and a5's matching paragraph already says so. Align a2a3 to a5's wording
("each slot's buffer lives on the runner").

Also fix a stale accessor location in both trees' `MULTI_RING.md`:
`PTO2TaskId`'s direct accessors live in
`src/common/task_interface/pto_task_id.h`, not `pto_runtime2_types.h`.

Verification: built and ran `test_a2a3_fatal` and `test_a5_fatal` —
4/4 tests pass each (including the new a5 ScopeGuard case).
yanghaoran29 added a commit to yanghaoran29/simpler that referenced this pull request Aug 10, 2026
Close the two P4/P5 residuals flagged in hw-native-sys#1582's 2026-08-09 re-audit
(after hw-native-sys#1718 landed):

R1 — a5 lacked the scope-guard regression test that a2a3 gained in hw-native-sys#1718.
a5's `PTO2_SCOPE_GUARD(...)` has been variadic (and its MANUAL path live,
read by `rt_scope_begin` -> `begin_scope(mode)`) since the hw-native-sys#1100 import,
but `ut-a5` would not have caught a regression in MANUAL forwarding.
Mirror `ScopeGuardForwardsModeUntilLexicalScopeExit` to `test_a5_fatal.cpp`:
`FakeRuntime` gains `pending_scope_mode` (immediately after `ops`, the
prefix the inline wrappers pun through) and `last_scope_mode`;
`fake_scope_begin` records the mode; the test asserts AUTO then MANUAL
forwarding across lexical scope exit. Both test files also extend the
single `offsetof(ops) == 0` guard to a second one pinning `pending_scope_mode`
at `offsetof(PTO2Runtime, pending_scope_mode)`, directly asserting the fake
matches the production `PTO2Runtime` prefix layout the inline wrappers pun
through (not just pointer size). Both tests also seed
`pending_scope_mode = PTO2ScopeMode::MANUAL` before the first guard so the
`AUTO` assertion actually verifies the guard writes the default, rather
than reading a pre-existing `AUTO` from the member initializer.

R2 — a2a3 `RUNTIME_LOGIC.md` still described the retained temp buffer as
a single runner-owned instance, but the shared host-runtime callback
`get_retained_temp_buffer(runner_ctx, pipeline_slot, ...)` is per-slot
and a5's matching paragraph already says so. Align a2a3 to a5's wording
("each slot's buffer lives on the runner").

Also fix a stale accessor location in both trees' `MULTI_RING.md`:
`PTO2TaskId`'s direct accessors live in
`src/common/task_interface/pto_task_id.h`, not `pto_runtime2_types.h`.

Verification: built and ran `test_a2a3_fatal` and `test_a5_fatal` —
4/4 tests pass each (including the new a5 ScopeGuard case); both files are
clang-format clean (ColumnLimit 120).
ChaoZheng109 pushed a commit that referenced this pull request Aug 10, 2026
…#1752)

Close the two P4/P5 residuals flagged in #1582's 2026-08-09 re-audit
(after #1718 landed):

R1 — a5 lacked the scope-guard regression test that a2a3 gained in #1718.
a5's `PTO2_SCOPE_GUARD(...)` has been variadic (and its MANUAL path live,
read by `rt_scope_begin` -> `begin_scope(mode)`) since the #1100 import,
but `ut-a5` would not have caught a regression in MANUAL forwarding.
Mirror `ScopeGuardForwardsModeUntilLexicalScopeExit` to `test_a5_fatal.cpp`:
`FakeRuntime` gains `pending_scope_mode` (immediately after `ops`, the
prefix the inline wrappers pun through) and `last_scope_mode`;
`fake_scope_begin` records the mode; the test asserts AUTO then MANUAL
forwarding across lexical scope exit. Both test files also extend the
single `offsetof(ops) == 0` guard to a second one pinning `pending_scope_mode`
at `offsetof(PTO2Runtime, pending_scope_mode)`, directly asserting the fake
matches the production `PTO2Runtime` prefix layout the inline wrappers pun
through (not just pointer size). Both tests also seed
`pending_scope_mode = PTO2ScopeMode::MANUAL` before the first guard so the
`AUTO` assertion actually verifies the guard writes the default, rather
than reading a pre-existing `AUTO` from the member initializer.

R2 — a2a3 `RUNTIME_LOGIC.md` still described the retained temp buffer as
a single runner-owned instance, but the shared host-runtime callback
`get_retained_temp_buffer(runner_ctx, pipeline_slot, ...)` is per-slot
and a5's matching paragraph already says so. Align a2a3 to a5's wording
("each slot's buffer lives on the runner").

Also fix a stale accessor location in both trees' `MULTI_RING.md`:
`PTO2TaskId`'s direct accessors live in
`src/common/task_interface/pto_task_id.h`, not `pto_runtime2_types.h`.

Verification: built and ran `test_a2a3_fatal` and `test_a5_fatal` —
4/4 tests pass each (including the new a5 ScopeGuard case); both files are
clang-format clean (ColumnLimit 120).
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