Skip to content

Fix: stage bgemm's C accumulator to the device (host_build_graph) - #1488

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/issue-1483-bgemm-inout-accumulator
Jul 26, 2026
Merged

Fix: stage bgemm's C accumulator to the device (host_build_graph)#1488
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/issue-1483-bgemm-inout-accumulator

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1483tests/st/a2a3/host_build_graph/bgemm intermittently failed its golden compare with max_diff of 1e25–1e36, but only in full-suite sim runs, never in isolation.

Root cause

C is declared D.OUT in the orchestration signature, but the task graph read-modify-writes it: p_add.add_inout(c_view) feeds kernel_tile_add, whose first k iteration TLOADs C before any task has written it.

The runtime stages only IN/INOUT tensors host→device (src/a2a3/runtime/host_build_graph/host/runtime_maker.cpp"pure write-only OUTPUT buffers are never read by the kernel"), and since #1365 (affb4612) it no longer zero-fills OUT buffers either. So C accumulated onto whatever the device allocation happened to hold. On sim that allocation is a plain malloc block on a process-lifetime worker (memory_allocator.cpp): fresh zeros when the case runs alone, a previous case's bytes under the full suite. Same class as #1449.

Both sibling bgemm variants already tag their accumulator correctly — examples/a5/tensormap_and_ringbuffer/bgemm and examples/a2a3/tensormap_and_ringbuffer/benchmark_bgemm use D.INOUT. The hbg ST was the only one mislabelling it.

Fix

  • signature: [D.IN, D.IN, D.OUT][D.IN, D.IN, D.INOUT].
  • Seed C with a non-zero base (0.25) and drop C[:] = 0.0 from compute_golden, so golden is C_init + A @ B. This makes the staging load-bearing: a zeroed or unstaged device buffer can no longer match, so a future regression fails deterministically instead of hiding behind a happens-to-be-zero allocation.
  • Drop the pytest.mark.skip that quarantined the case — the defect it tracked is fixed, so the case runs in CI again.
  • Orchestration header comment and README updated — the comment previously asserted "C arrives zero-initialized (pure OUTPUT), so the accumulation is exact", which is no longer true.

Verification

  • Failing repro first: with the non-zero base applied but the signature still D.OUT, the case fails on the first attempt with max_diff=8.0e+35 — the reported signature, now deterministic rather than one run in two or three.
  • With the fix: passes in isolation on a2a3sim and onboard on a2a3 under task-submit.
  • pytest examples tests/st --platform a2a3sim --device 0-15 --pto-session-timeout 600 --require-pto-isa — green on 5/5 consecutive runs, 3 before and 2 after the rebase onto 23de96e0 (issue reported ~1-in-2-to-3 failures).
  • pre-commit clean on all three changed files.

Scope

I surveyed every other add_inout orchestration under tests/st/a2a3/host_build_graph/: available_aicore_counts and predicated_dispatch already declare their tensors INOUT, and dump_args / matmul / vector_example cover their OUT tensor with an add_output before any read. bgemm was the only offender, so no other test is touched.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 26, 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: 20 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: c6fb3f07-56f7-4340-9459-8dc675b30de6

📥 Commits

Reviewing files that changed from the base of the PR and between 23de96e and b7d0fd8.

📒 Files selected for processing (3)
  • tests/st/a2a3/host_build_graph/bgemm/README.md
  • tests/st/a2a3/host_build_graph/bgemm/kernels/orchestration/bgemm_orch.cpp
  • tests/st/a2a3/host_build_graph/bgemm/test_bgemm.py

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.

Fixes hw-native-sys#1483

`tests/st/a2a3/host_build_graph/bgemm` declared its `C` argument `D.OUT`,
but the task graph read-modify-writes it: `p_add.add_inout(c_view)` feeds
`kernel_tile_add`, whose first `k` iteration `TLOAD`s `C` before any task
has written it.

The runtime stages only IN/INOUT tensors host->device
(`runtime_maker.cpp`, "pure write-only OUTPUT buffers are never read by
the kernel"), and since hw-native-sys#1365 it no longer zero-fills OUT buffers either.
So `C` accumulated onto whatever the device allocation happened to hold.
On sim that allocation is a plain `malloc` block on a process-lifetime
worker: fresh zeros when the case runs alone, a previous case's bytes in
a full-suite run — hence a golden mismatch of 1e25-1e36 that reproduced
only under the full suite. Same class as hw-native-sys#1449.

Declare `C` INOUT, matching the two sibling bgemm variants
(`examples/a5/tensormap_and_ringbuffer/bgemm`,
`examples/a2a3/tensormap_and_ringbuffer/benchmark_bgemm`), which already
tag their accumulator that way.

Seed `C` with a non-zero base (0.25) so the staging is load-bearing and
the case is deterministic: golden is now `C_init + A @ B`, which a
zeroed or unstaged device buffer cannot match. Without the signature fix
this fails every run instead of one in two or three — verified, it
reproduces the reported 1e35 magnitude on the first attempt.

Drop the `pytest.mark.skip` that quarantined the case: the underlying
defect is fixed, so the case runs in CI again.

Verified: bgemm passes 3/3 in isolation on a2a3sim and onboard on a2a3;
the full `pytest examples tests/st --platform a2a3sim` suite is green
3/3 runs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ChaoWao
ChaoWao force-pushed the fix/issue-1483-bgemm-inout-accumulator branch from 0cae19b to b7d0fd8 Compare July 26, 2026 04:34
@ChaoWao
ChaoWao merged commit d60b8ac into hw-native-sys:main Jul 26, 2026
15 checks passed
@ChaoWao
ChaoWao deleted the fix/issue-1483-bgemm-inout-accumulator branch July 26, 2026 04:52
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.

[Bug] bgemm (host_build_graph) intermittently produces garbage output in full sim-suite runs

1 participant