Skip to content

feat(a5/tmr): port allow_early_resolve / early-dispatch from a2a3#1423

Merged
ChaoWao merged 3 commits into
hw-native-sys:mainfrom
yanghaoran29:feat/a5-early-dispatch-migrate
Jul 21, 2026
Merged

feat(a5/tmr): port allow_early_resolve / early-dispatch from a2a3#1423
ChaoWao merged 3 commits into
hw-native-sys:mainfrom
yanghaoran29:feat/a5-early-dispatch-migrate

Conversation

@yanghaoran29

Copy link
Copy Markdown
Contributor

Bring a5 tensormap_and_ringbuffer in line with a2a3 early-dispatch (#989/#1079/#1285/#1288/#1297/#1304/#1326/#1329/#1336/#1405/#1340): prepare/publish, src_payload gate + DMB high32 doorbell, direct-only eligibility, spare-slot Phase 4b, sync_start early rendezvous, and dep_gen early_dispatch truth. Document the a5 model in RUNTIME_LOGIC §8.6.

@coderabbitai

coderabbitai Bot commented Jul 21, 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

Run ID: 9305c5e8-98e0-4299-9aac-5cf2f36e970b

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

A5 Runtime 2 gains early-dispatch scheduling with gated AICore execution, doorbell synchronization, lifecycle tracking, staged sync-start draining, updated payload layouts, and new regular, sync-start, and MIX spill tests.

Changes

A5 Early Dispatch

Layer / File(s) Summary
Dispatch contracts and lifecycle state
src/a5/platform/*/aicore/inner_kernel.h, src/a5/runtime/.../pto*_types.h, src/a5/runtime/.../pto2_dispatch_payload.h
Adds early-resolve metadata, lifecycle flags, payload offsets, src_payload, cache-line assertions, and AICore high-word doorbell reads.
Early candidate wiring and queue storage
src/a5/runtime/.../pto_orchestrator.cpp, src/a5/runtime/.../scheduler/*, src/a5/runtime/.../shared/pto_runtime2_init.cpp
Propagates early-resolve eligibility, adds tagged queues and early queue regions, and initializes their arena storage.
Batched publication and early staging
src/a5/runtime/.../scheduler/scheduler_context.h, scheduler_dispatch.cpp, scheduler/pto_scheduler.h, aicore/aicore_executor.cpp
Separates preparation from publication, stages early consumers, gates payloads with doorbells, and adds the Phase 4b dispatch path.
Gated completion and sync-start drain
src/a5/runtime/.../scheduler/scheduler_completion.cpp, scheduler_cold_path.cpp, scheduler_types.h
Handles gated pending transitions, skips staged completion polling, and coordinates staged sync-start draining and promotion.
Runtime dispatch documentation
src/a5/runtime/.../docs/RUNTIME_LOGIC.md
Documents early versus normal dispatch, queue routing, payload reconstruction, doorbells, and sync-start behavior.
Early-dispatch scenario tests
tests/st/a5/tensormap_and_ringbuffer/spmd_*early_dispatch/*, tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/*
Adds A5 scene tests and slow producer/consumer kernels for regular, sync-start, and MIX spill early-dispatch cases.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Poem

A bunny rings the doorbell bright,
Stages tasks before the night.
Queues leap, sync drains softly flow,
Gated cores wait, then ACK and go.
Tests hop through each early lane—
Carrots for the runtime brain!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% 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 states the main change: porting allow_early_resolve and early-dispatch behavior from a2a3 to a5/tmr.
Description check ✅ Passed The description directly matches the changeset, summarizing early-dispatch, prepare/publish, DMB doorbell, and documentation updates.
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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements the speculative early-dispatch model for the a5 runtime, allowing tasks to be pre-staged on idle or busy cores and gated via a high-32 doorbell on the DATA_MAIN_BASE register. The changes span the AICore execution loop, scheduler dispatch and completion logic, orchestrator dependency wiring, and documentation. Feedback on the changes suggests updating the simulation implementation of read_dmb_high32 to use an atomic acquire load (__atomic_load_n with __ATOMIC_ACQUIRE) instead of a raw volatile dereference to establish a proper happens-before relationship and prevent data races under TSAN.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/a5/platform/sim/aicore/inner_kernel.h
Bring a5 tensormap_and_ringbuffer in line with a2a3 early-dispatch
(hw-native-sys#989/hw-native-sys#1079/hw-native-sys#1285/hw-native-sys#1288/hw-native-sys#1297/hw-native-sys#1304/hw-native-sys#1326/hw-native-sys#1329/hw-native-sys#1336/hw-native-sys#1405/hw-native-sys#1340):
prepare/publish, src_payload gate + DMB high32 doorbell (sim uses
__atomic_load_n ACQUIRE), direct-only eligibility, spare-slot Phase 4b,
sync_start early rendezvous, and dep_gen early_dispatch truth. Document
the a5 model in RUNTIME_LOGIC §8.6.

Add a5 STs: plain early_dispatch plus sync_start early_dispatch and
mix_spill ports (EarlyOn/Off) for board validation.
@yanghaoran29
yanghaoran29 force-pushed the feat/a5-early-dispatch-migrate branch from cbc9612 to b66a556 Compare July 21, 2026 12:11

@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.

🧹 Nitpick comments (3)
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/orchestration/spmd_sync_start_mix_spill_orch.cpp (1)

78-79: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Wrap task submission in a manual scope.

Add rt_scope_begin(PTO2ScopeMode::MANUAL) and rt_scope_end() around the task submissions to ensure both tasks are batched and published to the scheduler simultaneously. This matches the behavior of the other early-dispatch tests in this PR and prevents non-deterministic staging behaviors.

🛠️ Proposed fix
-    PTO2TaskId prod = submit_aiv_producer(ext_output, 72, 0, early_on);
-    submit_mix_sync_consumer(ext_output, 24, 72, prod);
+    rt_scope_begin(PTO2ScopeMode::MANUAL);
+    PTO2TaskId prod = submit_aiv_producer(ext_output, 72, 0, early_on);
+    submit_mix_sync_consumer(ext_output, 24, 72, prod);
+    rt_scope_end();
🤖 Prompt for 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.

In
`@tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/orchestration/spmd_sync_start_mix_spill_orch.cpp`
around lines 78 - 79, Wrap the task submissions in the orchestration flow with a
manual runtime scope: call rt_scope_begin(PTO2ScopeMode::MANUAL) before
submit_aiv_producer, keep submit_mix_sync_consumer within the same scope, and
call rt_scope_end() afterward so both tasks are published together.
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py (1)

64-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Deduplicate kernel_spmd_write_slow.cpp.

The spmd_sync_start_mix_spill test introduces a duplicate copy of kernel_spmd_write_slow.cpp. To eliminate code duplication, it can reuse the existing kernel from spmd_sync_start_early_dispatch (as test_spmd_early_dispatch.py already does).

  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py#L64-L70: Update the "source" path for SPMD_WRITE_AIV to "../spmd_sync_start_early_dispatch/kernels/aiv/kernel_spmd_write_slow.cpp".
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/aiv/kernel_spmd_write_slow.cpp#L1-L77: Delete this duplicate file entirely.
🤖 Prompt for 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.

In
`@tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py`
around lines 64 - 70, Deduplicate the SPMD write kernel by updating
SPML_WRITE_AIV in
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py
lines 64-70 to reference
../spmd_sync_start_early_dispatch/kernels/aiv/kernel_spmd_write_slow.cpp, then
delete the duplicate file at
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/aiv/kernel_spmd_write_slow.cpp
lines 1-77.
tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/test_spmd_early_dispatch.py (1)

34-64: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Resolve static analysis warnings for mutable class attributes.

The CALLABLE and CASES class attributes have mutable default values (dict/list), which triggers Ruff's RUF012 warning. Please annotate them with typing.ClassVar to resolve this.

  • tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/test_spmd_early_dispatch.py#L34-L64: Import ClassVar from typing and annotate CALLABLE and CASES (e.g., CALLABLE: ClassVar[dict] = {...}).
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_early_dispatch/test_spmd_sync_start_early_dispatch.py#L33-L84: Annotate CALLABLE and CASES with ClassVar.
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py#L36-L87: Annotate CALLABLE and CASES with ClassVar.
🤖 Prompt for 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.

In
`@tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/test_spmd_early_dispatch.py`
around lines 34 - 64, Mutable class attributes trigger Ruff RUF012 because
CALLABLE and CASES are unannotated dict/list values. Import ClassVar from typing
and annotate both attributes in
tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/test_spmd_early_dispatch.py
(34-64),
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_early_dispatch/test_spmd_sync_start_early_dispatch.py
(33-84), and
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py
(36-87), preserving their existing values and behavior.

Source: Linters/SAST tools

🤖 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.

Nitpick comments:
In
`@tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/test_spmd_early_dispatch.py`:
- Around line 34-64: Mutable class attributes trigger Ruff RUF012 because
CALLABLE and CASES are unannotated dict/list values. Import ClassVar from typing
and annotate both attributes in
tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/test_spmd_early_dispatch.py
(34-64),
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_early_dispatch/test_spmd_sync_start_early_dispatch.py
(33-84), and
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py
(36-87), preserving their existing values and behavior.

In
`@tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/orchestration/spmd_sync_start_mix_spill_orch.cpp`:
- Around line 78-79: Wrap the task submissions in the orchestration flow with a
manual runtime scope: call rt_scope_begin(PTO2ScopeMode::MANUAL) before
submit_aiv_producer, keep submit_mix_sync_consumer within the same scope, and
call rt_scope_end() afterward so both tasks are published together.

In
`@tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py`:
- Around line 64-70: Deduplicate the SPMD write kernel by updating
SPML_WRITE_AIV in
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py
lines 64-70 to reference
../spmd_sync_start_early_dispatch/kernels/aiv/kernel_spmd_write_slow.cpp, then
delete the duplicate file at
tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/aiv/kernel_spmd_write_slow.cpp
lines 1-77.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 52f2929d-a58b-4c35-8a96-342af3cc54ab

📥 Commits

Reviewing files that changed from the base of the PR and between effffe5 and b66a556.

📒 Files selected for processing (26)
  • src/a5/platform/onboard/aicore/inner_kernel.h
  • src/a5/platform/sim/aicore/inner_kernel.h
  • src/a5/runtime/tensormap_and_ringbuffer/aicore/aicore_executor.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/docs/RUNTIME_LOGIC.md
  • src/a5/runtime/tensormap_and_ringbuffer/orchestration/pto_arg_with_deps.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto2_dispatch_payload.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_orchestrator.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_runtime2_types.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_types.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_completion.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_context.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_dispatch.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_types.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/shared/pto_runtime2_init.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/kernels/orchestration/spmd_early_dispatch_orch.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_early_dispatch/test_spmd_early_dispatch.py
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_early_dispatch/kernels/aiv/kernel_spmd_write_slow.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_early_dispatch/kernels/orchestration/spmd_sync_start_early_dispatch_orch.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_early_dispatch/test_spmd_sync_start_early_dispatch.py
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/aic/kernel_spmd_mix_slow.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/aiv/kernel_spmd_mix_slow.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/aiv/kernel_spmd_write_slow.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/kernels/orchestration/spmd_sync_start_mix_spill_orch.cpp
  • tests/st/a5/tensormap_and_ringbuffer/spmd_sync_start_mix_spill/test_spmd_sync_start_mix_spill.py

Remove the a5-only early_dispatch / sync_start early ST scenes added for
board experiments; keep the runtime port focused for CI.
Remove accidental local helpers, migrate patches, and the acc_c2v
example that were committed with the UT payload-pool fix. Keep the
early-dispatch runtime port, a2a3-ported sync_start STs, and a5 UT
payload/task pool binding.
@ChaoWao
ChaoWao merged commit 1319744 into hw-native-sys:main Jul 21, 2026
15 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