Skip to content

a5: batch sync_to_sm every K=16 local advances - #1575

Open
yanghaoran29 wants to merge 1 commit into
hw-native-sys:mainfrom
yanghaoran29:exp/pr906-F3
Open

a5: batch sync_to_sm every K=16 local advances#1575
yanghaoran29 wants to merge 1 commit into
hw-native-sys:mainfrom
yanghaoran29:exp/pr906-F3

Conversation

@yanghaoran29

@yanghaoran29 yanghaoran29 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Publish RingSchedState::last_task_alive to shared memory every 16 local advances while work remains.
  • Force-publish the drained tail so a final partial batch cannot stall reclamation.
  • Reset the publication shadow when a ring is initialized or reused.
  • Add A5 unit coverage for 1, 15, 16, and 17 advances in active and drained states.

Validation

  • Local pre-commit: passed.
  • C++ unit tests (non-hardware): 66/66 passed.

Extract from PR #906.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds an OCCUPY-based AICPU topology fallback, throttles ring scheduler updates to shared memory, and introduces A5-specific benchmark mappings with a single-example benchmark wrapper.

Changes

AICPU topology fallback

Layer / File(s) Summary
OCCUPY topology synthesis and probing
src/a5/platform/onboard/host/aicpu_topology_probe.cpp
CPU topology probing now intersects CPU_TOPO results with OCCUPY data and synthesizes entries from occupied CPU IDs when no usable CPU_TOPO entries exist.

Ring scheduler synchronization

Layer / File(s) Summary
Throttled SM publication
src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h
RingSchedState tracks the last published task counter and updates shared memory only after a 16-task advance.

A5 benchmark selection

Layer / File(s) Summary
A5 example configuration
tools/benchmark_rounds.sh
Adds A5 example cases and ordering, selects them for the A5 architecture, and supports validating a single requested example.
Case1 benchmark wrapper
tools/benchmark_a5_case1.sh
Adds strict option parsing and runs the A5 tensormap-and-ringbuffer benchmark for paged_attention_unroll.

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

Sequence Diagram(s)

sequenceDiagram
  participant Probe as probe_aicpu_topology_uncached
  participant CPU_TOPO
  participant OCCUPY as OCCUPY bitmap
  Probe->>CPU_TOPO: query_cpu_topo
  CPU_TOPO-->>Probe: entries or failure
  Probe->>OCCUPY: intersect reported CPU IDs
  OCCUPY-->>Probe: usable IDs or empty result
  Probe->>OCCUPY: synthesize pool when needed
Loading

Possibly related PRs

Poem

A rabbit found CPUs in a bitmap bright,
And taught the scheduler to hop just right.
Sixteen steps, then memory sings,
A5 benchmarks flutter on speedy wings.
paged_attention_unroll leads the way—
“Binky!” says Bunny, “let’s test today!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed It clearly summarizes the sync_to_sm batching change and the K=16 interval.
Description check ✅ Passed It is directly related to the scheduler batching change and the added validation coverage.

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/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h`:
- Line 475: Update advance_ring_pointers() and its sync_to_sm() ordering so
ring->fc.last_task_alive is stored with last_task_alive once PUBLISH_INTERVAL_K
slots have been consumed, avoiding the extra-call throttle; when reuse resets
last_published_to_sm to 0, publish immediately after the local lifetime advance.
- Around line 467-478: Update the scheduler’s terminal, idle, and drained-work
paths around advance_ring_pointers() to force-publish the current
last_task_alive watermark, including sub-interval advances of 1–15 steps.
Preserve batched sync_to_sm() behavior for ongoing work, and add coverage for 1,
15, 16, and 17 advances to verify final publication and threshold batching.

In `@tools/benchmark_a5_case1.sh`:
- Around line 17-21: Update the option handling case for -d|--device and
-n|--rounds in the argument parser to validate that a following value exists
before reading $2 or executing shift 2. When either option is missing its value,
emit the script’s usage error and terminate consistently; preserve the existing
assignments and shifts for valid values.
🪄 Autofix (Beta)

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: f3f19174-72e0-4e19-bda6-6ddebea50fd0

📥 Commits

Reviewing files that changed from the base of the PR and between b079a23 and 511a165.

📒 Files selected for processing (4)
  • src/a5/platform/onboard/host/aicpu_topology_probe.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h
  • tools/benchmark_a5_case1.sh
  • tools/benchmark_rounds.sh

Comment thread src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h Outdated
Comment thread src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h Outdated
Comment thread tools/benchmark_a5_case1.sh Outdated
Publish last_task_alive every 16 local advances while work remains, and force the drained tail so reclamation cannot stall on a partial batch. Reset the publication shadow on ring reuse and cover threshold and drain behavior in A5 unit tests.
@yanghaoran29 yanghaoran29 changed the title a5: K=16 batched sync_to_sm (PR906 F3) + OCCUPY topo fallback a5: batch sync_to_sm every K=16 local advances Jul 29, 2026
@yanghaoran29

Copy link
Copy Markdown
Contributor Author

A5 performance re-test

Re-tested paged_attention_unroll Case1 with 100 rounds on the same device (device 0), running the main baseline first and PR #1575 second under one task-submit lock.

Metric Main baseline PR #1575 Delta Change
Effective 2061.2 us 1965.6 us -95.6 us -4.64%
Orch 1906.7 us 1799.1 us -107.6 us -5.64%
Sched 2056.8 us 1960.3 us -96.5 us -4.69%
Device 2092.9 us 1996.9 us -96.0 us -4.59%
Host 148042.1 us 148592.8 us +550.7 us +0.37%

Test details:

  • Baseline: cb32999c (the main parent of the PR commit)
  • PR: 526eb8bb
  • PTO-ISA pin: 83d01313d9bfc247c4b7c8bcf969d1019f0d106f
  • Device/Effective coefficient of variation: approximately 1.5%-1.9%, so the ~4.6% device-side improvement is above the observed run-to-run noise.

On this host, both CPU topology query paths return 65534, so unmodified main and the current PR cannot pass the AICPU affinity gate. For measurement only, the same OCCUPY-only topology fallback was applied to temporary baseline and PR worktrees. It was therefore a shared control variable; the only A/B code difference was the K=16 scheduler publication change. The fallback was not added back to this PR.

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.

1 participant