Skip to content

Add: READMEs for the four a2a3 paged_attention variants - #1571

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:docs/paged-attention-variant-readmes
Jul 29, 2026
Merged

Add: READMEs for the four a2a3 paged_attention variants#1571
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:docs/paged-attention-variant-readmes

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Four sibling directories share a name prefix and nothing in the tree said what separates them. Diffing settles it, and each README now leads with the answer.

Directory What the diff shows
paged_attention The baseline. Four tasks per KV block (QK / SF / PV / UP) in a plain PTO2_SCOPE(), ordering derived by TensorMap from shared tensors.
paged_attention_manual_scope All four kernels byte-identical to the baseline's. Only paged_attention_orch.cpp differs, 45 lines of 292.
paged_attention_unroll_manual_scope Not manual-scope-plus-unroll. Every file differs; aiv_softmax_prepare.cpp changes 312 lines against a 156-line original. Batches KV blocks into groups of N_UNROLL — four tasks per group, not per block.
paged_attention_ringbuffer No kernels at all. Points CALLABLE at tests/st/.../batch_paged_attention/kernels and exists to stress ring rotation at ring_task_window: 64 — 256× below the 16384 default (PTO2_TASK_WINDOW_SIZE).

Two details worth surfacing that are otherwise only visible by reading the C++:

  • manual_scope demonstrates both dependency APIs in one file, and the choice is principled: the primitive PTO2TaskId deps[] + set_dependencies(deps, n) for SF and PV, whose predecessor set is fixed; L0TaskArgsWithDeps<>::add_dep for UP, whose edges are conditional (previous group's UP only when one exists; the allocation task only on the last iteration, and only to keep scratch alive). It also shows an edge deliberately left outUP reads SF's mi/li, but SF → PV → UP already orders it.
  • manual_scope's Case1 needs ring_task_window: 32768. Long-context cases put more than 16384 in-flight tasks in one MANUAL scope and can wedge the orchestrator with FLOW_CONTROL_DEADLOCK (code 3) at the default.

Correction to the index

examples/a2a3/tensormap_and_ringbuffer/README.md (merged in #1564) described the unroll variant as "Manual scope plus loop unrolling." That is wrong — the kernels are rewritten. The row now says so, and the manual-scope row records the byte-identical kernels.

Testing

  • markdownlint-cli2 --config tests/lint/.markdownlint.yaml — 0 errors on all five files
  • Every relative link resolves
  • Kernel-diff line counts reproduced with diff <baseline>/<file> <variant>/<file> | grep -c '^[<>]'
  • PTO2_TASK_WINDOW_SIZE 16384 confirmed at src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_runtime2_types.h:66; case names and runtime_env values read from each CASES list
  • Examples not executed — no built project venv in this worktree; documentation only

Docs only; no code, test, or build files touched.

Four sibling directories share a name prefix and nothing tells you what
separates them. Diffing establishes it, and each README now leads with the
answer:

- `paged_attention` is the baseline: four tasks per KV block (QK / SF / PV /
  UP) inside a plain scope, with TensorMap deriving the ordering from the
  tensors the tasks share.
- `paged_attention_manual_scope` has **byte-identical kernels** — all four —
  and differs only in orchestration, 45 lines of 292. It is the cheapest way
  to see what MANUAL scope costs, and it deliberately uses both dependency
  APIs in one file: the primitive `set_dependencies(deps, n)` for tasks with a
  fixed predecessor set, and `L0TaskArgsWithDeps<>::add_dep` for `UP`, whose
  edges are conditional.
- `paged_attention_unroll_manual_scope` is **not** the manual-scope variant
  plus an unroll. Every file differs; `aiv_softmax_prepare.cpp` changes 312
  lines against a 156-line original. It batches KV blocks into groups of
  `N_UNROLL` and submits four tasks per group rather than per block.
- `paged_attention_ringbuffer` contains **no kernels at all** — it points at
  the `tests/st` batch-paged-attention sources and exists to stress ring
  rotation at `ring_task_window: 64`, 256x below the 16384 default.

The directory index carried a wrong one-liner for the unroll variant
("manual scope plus loop unrolling"); it now describes a second
implementation, and the manual-scope row states the byte-identical kernels.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@ChaoWao, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 556edd9c-2340-44fb-9b40-c48de81d6d08

📥 Commits

Reviewing files that changed from the base of the PR and between 8e89f01 and 6accc66.

📒 Files selected for processing (5)
  • examples/a2a3/tensormap_and_ringbuffer/README.md
  • examples/a2a3/tensormap_and_ringbuffer/paged_attention/README.md
  • examples/a2a3/tensormap_and_ringbuffer/paged_attention_manual_scope/README.md
  • examples/a2a3/tensormap_and_ringbuffer/paged_attention_ringbuffer/README.md
  • examples/a2a3/tensormap_and_ringbuffer/paged_attention_unroll_manual_scope/README.md

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.

@ChaoWao
ChaoWao merged commit 7e66f46 into hw-native-sys:main Jul 29, 2026
14 checks passed
@ChaoWao
ChaoWao deleted the docs/paged-attention-variant-readmes branch July 29, 2026 07:38
ChaoWao added a commit that referenced this pull request Jul 29, 2026
The three a5 examples with no a2a3 counterpart to read instead.

`bgemm` keeps its kernel in `kernels/mix/` rather than `kernels/aic/` plus
`kernels/aiv/`, and that directory name is the example. One source is
registered as two incores with different core_types; `__DAV_CUBE__` compiles
the TLOAD/TMATMUL/TPUSH half and `__DAV_VEC__` the TPOP/TADD/TSTORE half, both
over the same three-tensor args[]. The matmul product moves between them
through VEC_FIFO and never reaches GM — only the accumulator C round-trips.
a2a3's `benchmark_bgemm` computes the same thing with separate sources and a
GM round trip, so the two are not ports of each other.

`urma_deferred_completion_demo` and `sdma_async_completion_demo` run an
identical two-rank protocol over different transports; `kernel_consumer.cpp`
is byte-identical between them, leaving the transport as the only variable.
Both are gated behind a workspace overlay that defaults OFF, and the two
overlays are mutually exclusive in one build — `CommContext` exposes a single
workSpace/workSpaceSize pair, so the CMakeLists raises a FATAL_ERROR if both
are on. A stock build therefore skips both tests even on a5 silicon: a green
CI run is not coverage of either path. Each README gives the two-step
invocation, since the env var is read once by runtime_builder.py to compile
the overlay in and once by the test's skipif.

The a5 index gains those facts, and its `paged_attention_unroll_manual_scope`
row is corrected the same way the a2a3 index was in #1571: the kernels are
rewritten (softmax_prepare changes 269 lines against a 149-line original), so
it is a second implementation rather than manual scope plus an unroll. The
manual_scope row now records that its four kernels are byte-identical to the
baseline's and only the orchestration differs, 52 lines of 288.
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