Skip to content

Add: host_build_graph regression test and an under-count check - #1472

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:available-counts-undercount-test
Jul 26, 2026
Merged

ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:available-counts-undercount-test

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #1458, addressing two review findings that landed after it merged.

The under-count check did not check under-counts

The scene test built its expected block slots from the count the runtime
reported:

clusters = int(test_args.shape[0])
for block_idx in range(clusters):   # expectation derived from the claim
    ...

A count that is too small is self-consistent under that comparison: the
orchestration launches fewer blocks, the host expects fewer blocks, the tail
stays zero on both sides, green. The docstring and #1458's body claimed the
tail zeros caught it. They did not.

Fix: a Pinned case fixes block_dim, so the host has an expectation that
does not come from the runtime and can assert the exact value. The pinned width
(4) differs from every platform's auto width — 8 on sim, the driver's answer
onboard — so a count sourced from the ceiling rather than from this run fails it
too. The Auto case keeps the range / ratio / spend checks and is now
documented as unable to detect an under-count.

Over-counting was and remains covered in both: the cohort asks for
require_sync_start, so it needs every block co-resident and the deadlock guard
fires on device.

The host_build_graph fix had no test

#1458's central bugfix was that host orchestration read a cluster count of zero,
and it shipped with coverage on tensormap_and_ringbuffer only. The same case
now runs on host_build_graph.

Verified it is a real regression test, not just an extra green tick — against
the pre-fix ordering (shape publication moved back after the bind, host reading
worker_count / 3) it fails:

Assertion failed: block_num >= 1 && "block_num must be >= 1"
  pto_orchestrator.cpp:889

because host orchestration read 0 and asked for a cohort that wide.

Dropping the dummy_task producer

shape no longer gets a dummy_task producer. host_build_graph runs its
orchestrator to completion on the host, before the device executes anything,
so a producer's task_state can never reach COMPLETED and
set_tensor_data's wait_for_tensor_ready spins out to
PTO2_TENSOR_DATA_TIMEOUT_CYCLES (orch_error_code=8 TENSOR_WAIT_TIMEOUT).
The MIX cohort already keeps the graph non-empty and shape has neither
producer nor consumer, so the write goes straight through on both runtimes.

Verification

Tests only — no src/ changes.

Suite Result
pytest examples tests/st --platform a2a3sim 52 passed, 0 failed
pytest examples tests/st --platform a5sim 39 passed, 0 failed
pytest examples tests/st --platform a2a3 (onboard, task-submit) 61 passed, 0 failed
pre-commit (all hooks) passed

All three new/changed cases confirmed executed, not silently deselected.

Note on #1458's reported numbers: it cited "58/58 cases" for the sim suites.
58 is the resource-phase scheduler group count, not the test count — with
-q the child pytest output is collapsed. The real figures are the ones above;
coverage was never missing, the label was wrong.

Interaction with #1309

Commented there: #1458's SIM_AUTO_BLOCKDIM = 8 invalidates #1309's premise
that block_dim=0 resolves to PLATFORM_MAX_BLOCKDIM on sim. Zeroing the
pinned values now breaks spmd_sync_start (block_num=12) and
spmd_sync_start_edge (block_num=23) against a limit of 8. The SPMD cohort
rework that fixes it is next.

The scene test derived its expected block slots from the count the runtime
reported, so a count that was too small was self-consistent and passed. It
also ran on tensormap_and_ringbuffer only, leaving the host_build_graph read
path — the one that was returning zero — uncovered.

- A Pinned case fixes block_dim, giving the host an expectation independent of
  what the runtime reported. It is the only case that can catch an under-count;
  the Auto case, which takes whatever the platform resolves, cannot. The pinned
  width differs from every platform's auto width, so a count sourced from the
  ceiling rather than from this run fails it too.
- The same case runs on host_build_graph. Against the pre-fix ordering it fails
  at `block_num >= 1` in submit_task, because host orchestration read a cluster
  count of zero and asked for a cohort that wide.
- The shape tensor no longer takes a dummy_task producer. host_build_graph runs
  its orchestrator to completion on the host before the device executes
  anything, so a producer's task_state can never reach COMPLETED and
  set_tensor_data's wait_for_tensor_ready spins out to
  PTO2_TENSOR_DATA_TIMEOUT_CYCLES. The MIX cohort already keeps the graph
  non-empty, and shape has neither producer nor consumer.
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a host-build orchestration fixture that reports available AICore counts, validates pinned and automatic execution modes, and removes dummy shape producers from existing A2A3 and A5 fixtures.

Changes

Available AICore Count Validation

Layer / File(s) Summary
Runtime count orchestration
tests/st/a2a3/host_build_graph/available_aicore_counts/kernels/orchestration/available_aicore_counts_orch.cpp
Queries runtime cluster and AIV counts, launches the mixed-kernel task with architecture-specific block configuration, and writes counts directly to shape.
Host-build end-to-end validation
tests/st/a2a3/host_build_graph/available_aicore_counts/test_available_aicore_counts.py
Adds pinned and automatic cases that validate reported counts, AIV proportionality, and per-cluster block contents.
Existing fixture completion and pinned checks
tests/st/a2a3/tensormap_and_ringbuffer/available_aicore_counts/..., tests/st/a5/tensormap_and_ringbuffer/available_aicore_counts/...
Removes dummy shape producer tasks and adds pinned expectations with exact cluster-count assertions.

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

Sequence Diagram(s)

sequenceDiagram
  participant HostTest
  participant Orchestration
  participant Runtime
  participant MixedKernels
  participant OutputValidation
  HostTest->>Orchestration: submit blocks and shape tensors
  Orchestration->>Runtime: query available cluster and AIV counts
  Orchestration->>MixedKernels: launch configured mixed kernels
  Orchestration->>HostTest: write counts into shape
  HostTest->>OutputValidation: validate counts and block slots
Loading

Possibly related PRs

Poem

A bunny counts cores in a neat little row,
Pins some in place, lets the others auto-go.
Mixed kernels hop with their sync-start tune,
Shape holds the numbers beneath the moon.
No dummy task blocks the burrow tonight—
Every slot lands exactly right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately summarizes the new host_build_graph regression test and the added under-count check.
Description check ✅ Passed The description is clearly related to the changeset and explains the added regression coverage and under-count validation.
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.

🧹 Nitpick comments (1)
tests/st/a2a3/host_build_graph/available_aicore_counts/test_available_aicore_counts.py (1)

61-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Annotate mutable test metadata as ClassVar.

Ruff reports RUF012 for CALLABLE and CASES. Add ClassVar annotations, or confirm this rule is not enforced for scene-test metadata.

Also applies to: 92-105

🤖 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/a2a3/host_build_graph/available_aicore_counts/test_available_aicore_counts.py`
around lines 61 - 90, Annotate the class-level mutable metadata dictionaries
CALLABLE and CASES with typing.ClassVar, preserving their existing structures
and values. Import ClassVar from typing if needed, and apply the annotation to
both symbols to satisfy Ruff RUF012.

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/a2a3/host_build_graph/available_aicore_counts/test_available_aicore_counts.py`:
- Around line 61-90: Annotate the class-level mutable metadata dictionaries
CALLABLE and CASES with typing.ClassVar, preserving their existing structures
and values. Import ClassVar from typing if needed, and apply the annotation to
both symbols to satisfy Ruff RUF012.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3bc762ea-f977-4d8a-9902-ef016268cd3a

📥 Commits

Reviewing files that changed from the base of the PR and between bdf6fed and 0bef5e7.

📒 Files selected for processing (6)
  • tests/st/a2a3/host_build_graph/available_aicore_counts/kernels/orchestration/available_aicore_counts_orch.cpp
  • tests/st/a2a3/host_build_graph/available_aicore_counts/test_available_aicore_counts.py
  • tests/st/a2a3/tensormap_and_ringbuffer/available_aicore_counts/kernels/orchestration/available_aicore_counts_orch.cpp
  • tests/st/a2a3/tensormap_and_ringbuffer/available_aicore_counts/test_available_aicore_counts.py
  • tests/st/a5/tensormap_and_ringbuffer/available_aicore_counts/kernels/orchestration/available_aicore_counts_orch.cpp
  • tests/st/a5/tensormap_and_ringbuffer/available_aicore_counts/test_available_aicore_counts.py

@ChaoWao
ChaoWao merged commit ed686a8 into hw-native-sys:main Jul 26, 2026
14 of 16 checks passed
@ChaoWao
ChaoWao deleted the available-counts-undercount-test branch July 26, 2026 01:14
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