Skip to content

Fix host-build-graph validation and teardown defects - #1674

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix-hbg-coderabbit
Aug 4, 2026
Merged

Fix host-build-graph validation and teardown defects#1674
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix-hbg-coderabbit

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve 128-bit MIX placement across every a2a3/a5 cluster and initialize
    scheduler tracker state deterministically.
  • Publish executor cleanup only after the last scheduler thread destroys the
    per-run runtime, then grant one thread the exclusive deinit() claim.
  • Reject zero/overflowing block-subtask totals and forged tensor producer IDs
    with INVALID_ARGS instead of asserting or dereferencing an unbound slot.
  • Correct the host-graph scalar-access, dispatch-payload, profiling, and runtime
    lifecycle documentation in both architecture trees.
  • Add architecture-parity unit tests plus simulation regressions for teardown
    ordering, invalid inputs, and dispatch above bit 63.

The prior pending_task == nullptr drain guard was removed. Its CodeRabbit
finding was withdrawn after confirming that incomplete drain state is
intentionally reset by deinit() and the guard only made an unreachable state
look recoverable.

Testing

  • Editable runtime rebuild: a2a3sim and a5sim runtime binaries compiled.
  • C++ UT: test_thread_completion_gate, test_hbg_core_tracker, and
    test_a5_hbg_core_tracker passed.
  • a2a3sim HBG sweep: 23 passed, 5 skipped.
  • a5sim HBG sweep: 14 passed, 1 skipped.
  • Targeted validation and wide-dispatch scenes passed again on both simulators
    after formatting.
  • Full staged-file pre-commit gate passed, including clang-format, clang-tidy,
    cpplint, markdownlint, Ruff, and Pyright.

Hardware tests were not run locally because this host has no npu-smi device.

@coderabbitai

coderabbitai Bot commented Aug 4, 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 Plus

Run ID: dd68330c-fd0e-4bcd-9ff6-83216ad7d62a

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

The changes add atomic ownership for executor cleanup, null-task checks in wait and drain paths, safer MIX-cluster bit construction, and zero initialization for cluster_count_ in the a2a3 and a5 runtime variants.

Changes

Runtime safety and scheduler state

Layer / File(s) Summary
Atomic executor cleanup ownership
src/a2a3/.../aicpu_executor.cpp, src/a5/.../aicpu_executor.cpp
aicpu_execute uses atomic compare-and-exchange so only one thread performs final cleanup.
Null-task handling in waits and drain mode
src/a2a3/.../pto_runtime2.cpp, src/a5/.../pto_runtime2.cpp, src/a2a3/.../scheduler_completion.cpp, src/a5/.../scheduler_completion.cpp
Producer waits, consumer waits, and drain handling return before task dereferences when no task exists.
Scheduler bitmask and state initialization
src/a2a3/.../scheduler_dispatch.cpp, src/a5/.../scheduler_dispatch.cpp, src/a2a3/.../scheduler_types.h, src/a5/.../scheduler_types.h
MIX dispatch paths use CoreTracker::BitStates::bit, and cluster_count_ initializes to zero.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

A rabbit checks each task in sight,
Guards empty slots from runtime fright.
One thread cleans, bits safely gleam,
Counts begin at zero in the stream.
Hop, hop—safer code takes flight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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
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 The title clearly summarizes the pull request's main focus on fixing host-build-graph validation and teardown defects.
Description check ✅ Passed The description directly covers the validation, teardown, scheduler, testing, and documentation changes in the 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.

Actionable comments posted: 1

🤖 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/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp`:
- Around line 661-662: The null pending-task checks in scheduler_completion.cpp
at lines 661-662 and 666-667 must abort the open drain transaction before
returning. Route each null scheduled_task_slot_state path through the
dispatcher-owned abort flow that clears the drained slot_state and restarts the
state machine, preventing follower spins and allowing future drains to reopen.
🪄 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: 14035f49-6935-4d60-a7a1-a6a51babaee7

📥 Commits

Reviewing files that changed from the base of the PR and between a032884 and a3f5013.

📒 Files selected for processing (10)
  • src/a2a3/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/a2a3/runtime/host_build_graph/runtime/orchestrator_core/pto_runtime2.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_types.h
  • src/a5/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/a5/runtime/host_build_graph/runtime/orchestrator_core/pto_runtime2.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_types.h

Comment thread src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp Outdated
@ChaoWao
ChaoWao force-pushed the fix-hbg-coderabbit branch 7 times, most recently from 91d01af to 0db7c02 Compare August 4, 2026 07:53
@ChaoWao ChaoWao changed the title Fix hbg null-pointer and UB defects (both arches) Fix host-build-graph validation and teardown defects Aug 4, 2026
@ChaoWao
ChaoWao force-pushed the fix-hbg-coderabbit branch 2 times, most recently from a310c2b to 3c9bc61 Compare August 4, 2026 08:46
- Preserve 128-bit MIX placement across all clusters and initialize
  tracker state deterministically
- Publish cleanup eligibility only after the last thread finishes runtime
  destruction, with an exclusive cleanup claim
- Reject invalid block/subtask totals and forged tensor producer IDs with
  INVALID_ARGS instead of asserting or dereferencing an unbound slot
- Correct scalar-access, dispatch-payload, profiling, and runtime lifecycle
  documentation for host graph construction
- Add architecture-parity unit and simulation coverage for validation,
  teardown ordering, and wide dispatch
@ChaoWao
ChaoWao force-pushed the fix-hbg-coderabbit branch from 3c9bc61 to cb7046e Compare August 4, 2026 09:31
@ChaoWao
ChaoWao merged commit e041083 into hw-native-sys:main Aug 4, 2026
32 of 33 checks passed
@ChaoWao
ChaoWao deleted the fix-hbg-coderabbit branch August 4, 2026 11:03
ChaoWao added a commit to YunjiQin/simpler that referenced this pull request Aug 4, 2026
…h sources

The host_build_graph_validation and host_build_graph_wide_dispatch scene-test
orchestration sources use the pre-rename type names L0TaskArgs, L2TaskArgs and
the GM-address-bearing Tensor. These sources landed via hw-native-sys#1674, outside this
rename branch's base, so the L0->Core, L2TaskArgs->ChipTaskArgs and
Tensor->ChipTensor renames never reached them. Update them to
CoreTaskArgs/CoreTaskArgsWithDeps, ChipTaskArgs and ChipTensor so the renamed
tree compiles, matching the spelling already used in sibling orchestration
sources.

Co-Authored-By: Claude <noreply@anthropic.com>
ChaoWao added a commit to YunjiQin/simpler that referenced this pull request Aug 4, 2026
…t sources

The host_build_graph_validation and host_build_graph_wide_dispatch scene-test
sources landed via hw-native-sys#1674, outside this rename branch's base, so the L0->Core,
L2TaskArgs->ChipTaskArgs and Tensor->ChipTensor renames never reached them:

- orchestration .cpp: L0TaskArgs/L0TaskArgsWithDeps -> CoreTaskArgs/
  CoreTaskArgsWithDeps, L2TaskArgs -> ChipTaskArgs, GM-address Tensor ->
  ChipTensor.
- host_build_graph_validation Python test: the device-descriptor import
  simpler.task_interface.Tensor -> ChipTensor (the Tensor.make arg builder),
  which otherwise aborts pytest collection with ImportError.

host_build_graph_wide_dispatch uses simpler_setup.Tensor (the scene-test arg
spec), which is a separate type and is not renamed.
ChaoWao added a commit to YunjiQin/simpler that referenced this pull request Aug 4, 2026
…r names

Files that landed on main via hw-native-sys#1674 and hw-native-sys#1684 sit outside this rename branch's
base and still use the pre-rename names. Bring them onto the renamed types and
doc paths so the tree compiles, imports, and links cleanly:

- host_build_graph_validation/wide_dispatch orchestration .cpp (hw-native-sys#1674):
  L0TaskArgs/L0TaskArgsWithDeps -> CoreTaskArgs/CoreTaskArgsWithDeps,
  L2TaskArgs -> ChipTaskArgs, GM-address Tensor -> ChipTensor.
- host_build_graph_validation Python test (hw-native-sys#1674): the device-descriptor
  import simpler.task_interface.Tensor -> ChipTensor (the .make arg builder),
  which otherwise aborted pytest collection with ImportError.
- SUBMIT_BY_CLUSTER.md example (hw-native-sys#1674) and build_config.py comment (hw-native-sys#1674):
  L0TaskArgs -> CoreTaskArgs, Tensor -> ChipTensor.
- troubleshooting/device-error-codes/README.md index (hw-native-sys#1684): inbound link
  l0-swimlane-profiling.md -> core-swimlane-profiling.md, the swimlane doc
  this rename renamed.

host_build_graph_wide_dispatch uses simpler_setup.Tensor (the scene-test arg
spec), a separate type that is not renamed.
ChaoWao added a commit that referenced this pull request Aug 4, 2026
* Rename: L3L2 identifiers to WorkerChip

The worker-chip message queue, orchestration comm, endpoint and region types
carried the numeric topology level in their names. Codestyle rule 13 reserves
numeric levels for architecture prose and names software entities by role, so
the L3+ recursive scheduling context is Worker and the chip runtime context is
Chip.

- L3L2Queue* -> WorkerChipQueue*, L3L2Orch* -> WorkerChipOrch*,
  L3L2Endpoint* -> WorkerChipEndpoint*, L3L2Region* -> WorkerChipRegion*
- L3L2_* and CTRL_L3_L2_* constants -> WORKER_CHIP_* / CTRL_WORKER_CHIP_*;
  their values are unchanged, so the wire layout is untouched
- l3_l2_* functions, Python modules, headers and example directories ->
  worker_chip_*
- _L2HostL3L2Region* -> _HostWorkerChipRegion*, collapsing the doubled context
- the four renamed headers use #pragma once, their guard names having
  disagreed with the new paths

Device-log text and architecture prose keep the L3-L2 spelling, which the rule
sanctions for topology description. No compatibility aliases are kept.

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

* Rename: L3Host identifiers to WorkerHost

The host-side registry and lease types for a worker-owned mapped region named
the numeric topology level rather than the owning software context. Codestyle
rule 13 puts L3+ recursive scheduling in the Worker context.

- L3HostMappedRegion* -> WorkerHostMappedRegion* (Handle, Entry, Registry,
  Lease, CleanupErrors)
- L3HostRegionMapping* -> WorkerHostRegionMapping*
- l3_host_* helpers and attributes -> worker_host_*

No compatibility aliases are kept.

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

* Rename: L2TaskArgs to ChipTaskArgs and L2 queue ends to Chip/Worker

The orchestration entry argument holder is the chip-level container -- its own
comment already said so -- and the message queue named its two ends by numeric
level. Codestyle rule 13 names the chip runtime context Chip and the L3+
recursive scheduling context Worker.

- L2TaskArgs -> ChipTaskArgs
- L2ChildOnboardRegion* -> ChipChildOnboardRegion*, g_l2_child_onboard_regions
  -> g_chip_child_onboard_regions
- WORKER_CHIP_QUEUE_L3_ABORT_FLAG_OFFSET -> ..._WORKER_ABORT_FLAG_OFFSET and
  WORKER_CHIP_QUEUE_L2_ABORT_FLAG_OFFSET -> ..._CHIP_ABORT_FLAG_OFFSET, with
  the l3_/l2_abort_flag_offset layout fields following; offsets are unchanged
- WorkerChipQueue.l2_task_arg_scalars() -> chip_task_arg_scalars()

No compatibility aliases are kept.

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

* Rename: L2Swimlane to ChipSwimlane and L0 swimlane to core swimlane

The swimlane collectors, their records, the DFX flag and the pytest option all
named the numeric topology level. Codestyle rule 13 names the chip runtime
context Chip and the AIC/AIV task-construction context Core.

- L2Swimlane* -> ChipSwimlane*, L2SWIMLANE_* -> CHIP_SWIMLANE_*,
  SIMPLER_DFX_FLAG_L2_SWIMLANE -> SIMPLER_DFX_FLAG_CHIP_SWIMLANE
- l2_swimlane_* functions, fields, records and JSON artifact names ->
  chip_swimlane_*
- pytest --enable-l2-swimlane -> --enable-chip-swimlane and
  --l2-swimlane-records-json -> --chip-swimlane-records-json, with the CI
  workflows and scene-test plumbing following
- simpler_setup.tools.l0_swimlane -> core_swimlane, and the intra-core
  swimlane is called the core swimlane throughout docs and skills
- tests/st/{a2a3,a5}/tensormap_and_ringbuffer/dfx/l2_swimlane ->
  dfx/chip_swimlane
- the four swimlane headers use #pragma once

Prose keeps numeric levels where it describes topology; the feature itself is
named after its owning context. No compatibility aliases are kept, so an
external caller passing --enable-l2-swimlane must move to the new spelling.

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

* Rename: L0 task-construction types to Core

The per-core task argument and predicate types named the numeric topology level.
Codestyle rule 13 names the AIC/AIV task-construction context Core and lists
CoreTaskArgs and CoreTaskPredicate as the intended spellings.

- L0TaskArgs -> CoreTaskArgs, L0TaskArgsWithDeps -> CoreTaskArgsWithDeps
- L0TaskPredicate -> CoreTaskPredicate, L0PredicateOperand ->
  CorePredicateOperand

L0A / L0B / L0C, L0TileShape and the other AICore on-chip memory names are
untouched: they name a hardware storage hierarchy, not a topology level.

No compatibility aliases are kept, so orchestration sources outside this repo
must move to the new spelling.

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

* Rename: the GM-address-bearing Tensor to ChipTensor

Two public types were called Tensor: the C++ descriptor in
src/common/task_interface/tensor.h, which embeds a device address and is
materialized by a ChipWorker, and simpler_setup.Tensor, the address-free
scene-test arg spec. Codestyle rule 13 names the first after its owning
context and reserves the unprefixed name for the address-free L3+ form, so the
two no longer collide.

- C++ Tensor -> ChipTensor across the runtimes, the orchestration API, the
  AICore kernels that read __gm__ ChipTensor* task args, and the tests
- the nanobind class binds as ChipTensor, so simpler.task_interface.ChipTensor
  is the Python spelling; simpler_setup.Tensor is unchanged and its 100 users
  are untouched
- docs describing the L2 ABI follow

The struct layout, its 128-byte size assertion and the TensorMap offset
assertions are unchanged, so the wire format is identical.

GlobalTensor, LocalTensor, TensorMap, TensorKey, TensorArgType, RemoteTensorRef
and torch.Tensor are all distinct names and are untouched.

No compatibility alias is kept, so kernel sources outside this repo must move
to the new spelling.

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

* Rename: catch up concurrent main additions to the Core/Chip/ChipTensor names

Files that landed on main via #1674 and #1684 sit outside this rename branch's
base and still use the pre-rename names. Bring them onto the renamed types and
doc paths so the tree compiles, imports, and links cleanly:

- host_build_graph_validation/wide_dispatch orchestration .cpp (#1674):
  L0TaskArgs/L0TaskArgsWithDeps -> CoreTaskArgs/CoreTaskArgsWithDeps,
  L2TaskArgs -> ChipTaskArgs, GM-address Tensor -> ChipTensor.
- host_build_graph_validation Python test (#1674): the device-descriptor
  import simpler.task_interface.Tensor -> ChipTensor (the .make arg builder),
  which otherwise aborted pytest collection with ImportError.
- SUBMIT_BY_CLUSTER.md example (#1674) and build_config.py comment (#1674):
  L0TaskArgs -> CoreTaskArgs, Tensor -> ChipTensor.
- troubleshooting/device-error-codes/README.md index (#1684): inbound link
  l0-swimlane-profiling.md -> core-swimlane-profiling.md, the swimlane doc
  this rename renamed.

host_build_graph_wide_dispatch uses simpler_setup.Tensor (the scene-test arg
spec), a separate type that is not renamed.

Co-authored-by: wcwxy <26245345+ChaoWao@users.noreply.github.com>
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