Skip to content

Refactor: share host_build_graph's a2a3/a5 host logic through src/common - #2060

Merged
poursoul merged 2 commits into
hw-native-sys:mainfrom
poursoul:refactor/hbg-host-to-common
Aug 29, 2026
Merged

poursoul merged 2 commits into
hw-native-sys:mainfrom
poursoul:refactor/hbg-host-to-common

Conversation

@poursoul

@poursoul poursoul commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

What

host_build_graph's a2a3 and a5 trees were near-duplicates. This moves the
host-side duplication into src/common/host_build_graph and leaves the arch
trees holding the rest. Net -10,700 lines across the two commits, no
behavioral change.

  1. a2ae12a3 — host and dual-target sources: dep_gen_host_graph,
    host_phase_trace, host_tensor_access, ready_queue_sizing (host-only),
    plus orchestrator, runtime_core, runtime_init, tensormap,
    shared_memory, runtime (host + aicpu). Also collapses non-substantive
    drift between the copies: three include guards to #pragma once, two blank
    lines, and comment text that had diverged.
  2. b73ba0ea — 16 shared headers plus graph_recorder_pool.cpp, with no
    forwarding shims.

Scope: host logic only

Deliberately not merged: the scheduler's own implementation, the AICPU and
AICore sources, and orchestration_api.h / arg_with_deps.h. Several of those
are byte-identical between the arches today and still stay per-arch — that is
the intended boundary for this change, not an oversight. What did move is host
logic plus the basics the scheduler and host both depend on (types, task/SM
layout, the Runtime core).

How the include path works

src/common/host_build_graph is on every hbg target's include path. That is what
lets the runtime-agnostic platform/ and common/worker/ sources reach this
runtime's runtime.h and types.h by bare name — they resolve to the shared
copies when compiled for host_build_graph, and to tensormap_and_ringbuffer's
own copies when compiled for that runtime. "runtime" precedes the shared
directory on the path, so an arch-local header of the same name still wins.

Sources under src/common name the shared headers with their
host_build_graph/ prefix rather than relying on that include path, because
cpput compiles them with its own include configuration. Only the
runtime-agnostic files keep bare names, which is what keeps them usable from
either runtime.

.cpp files split into host/, device/, shared/ subdirectories naming the
targets that compile them, because every source_dirs entry is collected by a
recursive glob and host-only code uses the STL containers the AICPU target
forbids.

RUNTIME_MAX_WORKER

The one semantic change here. It now resolves through PLATFORM_MAX_CORES
instead of a literal 72 / 108 spelled twice per architecture, which leaves
runtime.h and scheduler_context.h identical across the two. The value is
still per-arch — it comes from the platform's own core count, and
tensormap_and_ringbuffer has spelled it this way all along — and an absent
definition is a compile error rather than a silently wrong struct layout.

Files that still differ by architecture (10)

File Reason
scheduler/scheduler_types.h #2056's A5 scheduler contracts
runtime/dispatch_payload.h #2056
common/intrinsic.h #2056
runtime/async_wait.h #2056
aicore/aicore_executor.cpp #2056
scheduler/scheduler_dispatch.cpp #2056
host/runtime_maker.cpp a5 exports simpler_aicpu_query_topology
scheduler/scheduler_completion.cpp a5's PMU record carries the AICore register token
backend/sdma/sdma_completion_scheduler.h a2a3 invalidates the record's cache line
host/runtime_compile_info.cpp orchestration toolchain selection differs; a2a3's copy looks like it was cloned from tmr without adjusting — worth a separate look

The first six are #2056's a5-side changes, which landed while this branch was in
flight. Three of them (intrinsic.h, async_wait.h, dispatch_payload.h) are
small enough that they could be shared once that divergence is reconciled;
sharing them here would have meant reverting part of #2056, so they stay put.

Verified locally

  • Both arches cold rebuild (host / aicpu / aicore), cmake cache cleared
  • tensormap_and_ringbuffer cold rebuild + 25 scene tests pass — the include
    split does not touch it
  • cpput 123/123 (cold configure)
  • Full sim suites (examples + tests/st): a2a3sim and a5sim both exit 0
  • pre-commit 14/14

pip install cannot complete on an a2a3 box right now because a5 onboard's
aicore target fails to build there (use of undeclared identifier 'aicore' in
scheduler_types.h, from #2056). That reproduces on clean main and CI's a5
jobs are green, so it is a local toolchain gap rather than a regression — but it
does block local scene tests until worked around with
ASCEND_HOME_PATH=/nonexistent pip install --no-build-isolation -e ..

🤖 Generated with Claude Code

The two architectures' host_build_graph trees were near-duplicates. Every
source moved here was byte-identical between them; what stays in the arch
trees is what genuinely differs.

- src/common/host_build_graph gains host/, device/ and shared/
  subdirectories naming the targets that compile each .cpp. The split is
  required because every build_config source_dirs entry is collected by a
  recursive glob, and host-only code uses the STL containers the AICPU
  target forbids.
- Host-only: dep_gen_host_graph, host_phase_trace, host_tensor_access and
  ready_queue_sizing, plus their four headers. Host and AICPU both:
  orchestrator, runtime_core, runtime_init, tensormap, shared_memory and
  runtime.
- RUNTIME_MAX_WORKER resolves through PLATFORM_MAX_CORES instead of a
  literal 72 / 108 spelled twice per architecture, which leaves runtime.h
  and scheduler_context.h identical across the two. The value is still
  per-arch, and an absent definition is a compile error rather than a
  silently wrong struct layout.
- Remaining non-substantive drift collapsed: three include guards to
  #pragma once (their names claimed TENSORMAP_AND_RINGBUFFER and two
  carried a PTO_ prefix), two blank lines, and comment text that had
  diverged between the copies.
- cpput's twelve repeated five-file source lists become one
  HBG_ORCH_SHARED_SOURCES, now that both architectures compile the same
  translation units.
- graph_recorder_pool.h's single std::lock_guard becomes
  std::scoped_lock, matching the five other lock sites in that file.

Four files still differ by architecture and stay put:
runtime_compile_info.cpp, runtime_maker.cpp (a5 exports
simpler_aicpu_query_topology), sdma_completion_scheduler.h (a2a3
invalidates the record's cache line) and scheduler_completion.cpp (the a5
PMU record carries the AICore register token).
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 123 files, which is 23 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a74d10b-743e-4f38-85ac-0c2203f03688

📥 Commits

Reviewing files that changed from the base of the PR and between 89ba2a3 and 5c04231.

📒 Files selected for processing (123)
  • .claude/rules/codestyle.md
  • docs/dfx/dep-gen.md
  • docs/getting-started.md
  • src/a2a3/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/a2a3/runtime/host_build_graph/build_config.py
  • src/a2a3/runtime/host_build_graph/host/graph_recorder_pool.cpp
  • src/a2a3/runtime/host_build_graph/host/graph_recorder_pool.h
  • src/a2a3/runtime/host_build_graph/host/host_phase_trace.cpp
  • src/a2a3/runtime/host_build_graph/host/ready_queue_sizing.cpp
  • src/a2a3/runtime/host_build_graph/host/runtime_maker.cpp
  • src/a2a3/runtime/host_build_graph/orchestration/common.cpp
  • src/a2a3/runtime/host_build_graph/orchestration/orchestration_api.h
  • src/a2a3/runtime/host_build_graph/runtime/aicore_completion_mailbox.h
  • src/a2a3/runtime/host_build_graph/runtime/aicore_completion_mailbox_types.h
  • src/a2a3/runtime/host_build_graph/runtime/async_kernel_api.h
  • src/a2a3/runtime/host_build_graph/runtime/async_wait.h
  • src/a2a3/runtime/host_build_graph/runtime/backend/sdma/sdma_completion_kernel.h
  • src/a2a3/runtime/host_build_graph/runtime/backend/sdma/sdma_completion_scheduler.h
  • src/a2a3/runtime/host_build_graph/runtime/completion_token.h
  • src/a2a3/runtime/host_build_graph/runtime/constants.h
  • src/a2a3/runtime/host_build_graph/runtime/dep_compute.h
  • src/a2a3/runtime/host_build_graph/runtime/dep_gen_host_graph.h
  • src/a2a3/runtime/host_build_graph/runtime/orchestrator_core/runtime_core.cpp
  • src/a2a3/runtime/host_build_graph/runtime/runtime.h
  • src/a2a3/runtime/host_build_graph/runtime/runtime_core.h
  • src/a2a3/runtime/host_build_graph/runtime/runtime_types.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_cold_path.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_context.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_types.h
  • src/a2a3/runtime/host_build_graph/runtime/shared/runtime.cpp
  • src/a2a3/runtime/host_build_graph/runtime/shared/shared_memory.cpp
  • src/a2a3/runtime/host_build_graph/runtime/task_allocator.h
  • src/a5/runtime/host_build_graph/aicpu/aicpu_executor.cpp
  • src/a5/runtime/host_build_graph/build_config.py
  • src/a5/runtime/host_build_graph/common/runtime_status.h
  • src/a5/runtime/host_build_graph/host/dep_gen_host_graph.cpp
  • src/a5/runtime/host_build_graph/host/host_tensor_access.cpp
  • src/a5/runtime/host_build_graph/host/runtime_maker.cpp
  • src/a5/runtime/host_build_graph/orchestration/common.cpp
  • src/a5/runtime/host_build_graph/orchestration/orchestration_api.h
  • src/a5/runtime/host_build_graph/runtime/aicore_completion_mailbox.h
  • src/a5/runtime/host_build_graph/runtime/aicore_completion_mailbox_types.h
  • src/a5/runtime/host_build_graph/runtime/async_kernel_api.h
  • src/a5/runtime/host_build_graph/runtime/async_wait.h
  • src/a5/runtime/host_build_graph/runtime/backend/sdma/sdma_completion_kernel.h
  • src/a5/runtime/host_build_graph/runtime/backend/sdma/sdma_completion_scheduler.h
  • src/a5/runtime/host_build_graph/runtime/common.h
  • src/a5/runtime/host_build_graph/runtime/host_phase_trace.h
  • src/a5/runtime/host_build_graph/runtime/host_tensor_access.h
  • src/a5/runtime/host_build_graph/runtime/orchestrator.h
  • src/a5/runtime/host_build_graph/runtime/orchestrator_core/orchestrator.cpp
  • src/a5/runtime/host_build_graph/runtime/ready_queue_sizing.h
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler.h
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_cold_path.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_context.h
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp
  • src/a5/runtime/host_build_graph/runtime/scheduler/scheduler_types.h
  • src/a5/runtime/host_build_graph/runtime/shared/runtime_init.cpp
  • src/a5/runtime/host_build_graph/runtime/shared/tensormap.cpp
  • src/a5/runtime/host_build_graph/runtime/shared_memory.h
  • src/a5/runtime/host_build_graph/runtime/submit_types.h
  • src/a5/runtime/host_build_graph/runtime/tensor_create_info.h
  • src/a5/runtime/host_build_graph/runtime/tensormap.h
  • src/a5/runtime/host_build_graph/runtime/types.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/runtime.h
  • src/common/host_build_graph/common.h
  • src/common/host_build_graph/completion_token.h
  • src/common/host_build_graph/constants.h
  • src/common/host_build_graph/dep_compute.h
  • src/common/host_build_graph/dep_gen_host_graph.h
  • src/common/host_build_graph/device/graph_execution.cpp
  • src/common/host_build_graph/graph_cache.h
  • src/common/host_build_graph/graph_execution.h
  • src/common/host_build_graph/graph_recorder_pool.h
  • src/common/host_build_graph/host/dep_gen_host_graph.cpp
  • src/common/host_build_graph/host/graph_recorder_pool.cpp
  • src/common/host_build_graph/host/host_phase_trace.cpp
  • src/common/host_build_graph/host/host_tensor_access.cpp
  • src/common/host_build_graph/host/ready_queue_sizing.cpp
  • src/common/host_build_graph/host_phase_trace.h
  • src/common/host_build_graph/host_tensor_access.h
  • src/common/host_build_graph/orchestrator.h
  • src/common/host_build_graph/ready_queue_sizing.h
  • src/common/host_build_graph/runtime.h
  • src/common/host_build_graph/runtime_core.h
  • src/common/host_build_graph/runtime_status.h
  • src/common/host_build_graph/runtime_types.h
  • src/common/host_build_graph/shared/orchestrator.cpp
  • src/common/host_build_graph/shared/runtime.cpp
  • src/common/host_build_graph/shared/runtime_core.cpp
  • src/common/host_build_graph/shared/runtime_init.cpp
  • src/common/host_build_graph/shared/shared_memory.cpp
  • src/common/host_build_graph/shared/tensormap.cpp
  • src/common/host_build_graph/shared_memory.h
  • src/common/host_build_graph/submit_types.h
  • src/common/host_build_graph/task_allocator.h
  • src/common/host_build_graph/tensor_create_info.h
  • src/common/host_build_graph/tensormap.h
  • src/common/host_build_graph/types.h
  • src/common/platform/include/common/host_phase_kind.h
  • tests/ut/cpp/CMakeLists.txt
  • tests/ut/cpp/a2a3/test_dep_gen_host_graph.cpp
  • tests/ut/cpp/a2a3/test_dispatch_table.cpp
  • tests/ut/cpp/a2a3/test_graph_activation.cpp
  • tests/ut/cpp/a2a3/test_hbg_submit_poison.cpp
  • tests/ut/cpp/a2a3/test_hbg_task_allocator.cpp
  • tests/ut/cpp/a2a3/test_hbg_tensor_access.cpp
  • tests/ut/cpp/a2a3/test_hbg_tensormap.cpp
  • tests/ut/cpp/a5/test_graph_activation.cpp
  • tests/ut/cpp/a5/test_hbg_scheduler_contracts.cpp
  • tests/ut/cpp/a5/test_hbg_submit_poison.cpp
  • tests/ut/cpp/common/test_hbg_graph_async_submit.cpp
  • tests/ut/cpp/common/test_hbg_graph_definition_arena.cpp
  • tests/ut/cpp/common/test_hbg_graph_recording_bounds.cpp
  • tests/ut/cpp/common/test_hbg_graph_submit_failure.cpp
  • tests/ut/cpp/common/test_hbg_ready_queue_seed.cpp
  • tests/ut/cpp/common/test_hbg_self_relative_ptr.cpp
  • tests/ut/cpp/common/test_hbg_slot_claim.cpp
  • tests/ut/cpp/common/test_hbg_sm_compaction.cpp

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

@poursoul
poursoul force-pushed the refactor/hbg-host-to-common branch from b73ba0e to 5c04231 Compare August 28, 2026 09:21
Every header the two architectures held byte-identical copies of now lives
in src/common/host_build_graph, with no forwarding shim left behind. The
arch trees keep only what genuinely differs.

- src/common/host_build_graph sits on every hbg target's include path.
  That is what lets the runtime-agnostic platform and worker sources reach
  this runtime's runtime.h and types.h by bare name: they resolve to the
  shared copies when compiled for host_build_graph, and to
  tensormap_and_ringbuffer's own copies when compiled for that runtime.
  "runtime" precedes it on the path, so an arch-local header of the same
  name still wins.
- Sources under src/common name the shared headers with their
  host_build_graph/ prefix instead of relying on that include path,
  because cpput compiles them with its own include configuration. Only the
  runtime-agnostic files keep bare names, which is what keeps them usable
  from either runtime.
- cpput's hbg targets gain the same include directory, for the same
  reason.

Moved: runtime.h, types.h, runtime_types.h, tensormap.h, shared_memory.h,
runtime_core.h, submit_types.h, task_allocator.h, dep_compute.h,
orchestrator.h, tensor_create_info.h, completion_token.h, common.h,
constants.h, runtime_status.h and graph_recorder_pool.{h,cpp}.

The scheduler, AICPU and AICore headers stay per-arch, as do
orchestration_api.h and arg_with_deps.h.
@poursoul
poursoul merged commit c098493 into hw-native-sys:main Aug 29, 2026
20 checks passed
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.

2 participants