Skip to content

Refactor: stop host_build_graph's host side reaching into device facilities - #2098

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
poursoul:refactor/time-host-orchestration-with-a-host-clock
Sep 2, 2026
Merged

ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
poursoul:refactor/time-host-orchestration-with-a-host-clock

Conversation

@poursoul

@poursoul poursoul commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #2094, which moved host_build_graph's orchestration to the host. That move left the host side still reaching for device-side facilities in two places.

1. The clock went through a device counter to read a host wall-clock

orchestrator.cpp runs on the host, but its per-sub-step profiling called get_sys_cnt_aicpu — a device cycle counter. On the host that resolved to a stand-in reading CLOCK_MONOTONIC and scaling it by PLATFORM_PROF_SYS_CNT_FREQ:

host nanoseconds → notional device cycles → accumulate → log as `cycles=`

Neither a real cycle count nor a readable duration, and it made host timing depend on a device frequency constant. It now reads clock_gettime directly and carries nanoseconds — OrchProfilingData's *_cycle fields become *_ns, the macros are ORCH_STEP_START/LAP, and the bind's log line reads ns=.

This changes a DFX log line's unit and field names. SIMPLER_ORCH_PROFILING is off by default, so nothing on a normal build moves.

That was the host's only caller of that symbol, so host/aicpu_shims.cpp is deleted. Its other definition, get_reg_ptr, had no caller at all — disassembling the host .so under default, ORCH_PROFILING and SCHED_PROFILING finds zero call sites in every one. The comment justifying it named a route_ready_once path that exists nowhere in the tree.

2. The orchestrator held a pointer into the scheduler

OrchestratorState carried SchedulerState *scheduler — pointing at a struct that lives in device memory the host never maps. It is tmr-era residue from when both ran on the AICPU in one address space and the orchestrator could enqueue into the scheduler's queues directly; its own comment said "For simulated mode only".

Nothing read it. submit_task copied it into a local whose only use was a (void) cast, and two call sites asserted it non-null without ever dereferencing. The member, the init() parameter that filled it, and both assertions are gone.

That was orchestrator.h's only use of SchedulerState, so the header stops including scheduler/scheduler.h — 1336 lines of device dispatch logic the host compiled to reach a pointer it never followed. Eight unit tests that had been reaching SchedulerState / SchedulerLayout through that chain now include it directly.

The AICPU side is untouched

libaicpu_kernel.so carries its own get_sys_cnt_aicpu from platform/.../device_time.cpp — 195 call sites under SCHED_PROFILING, zero undefined references — and never compiled the deleted file. The two .sos are each loaded RTLD_LOCAL, so their symbols were never shared.

Test

  • Built in four configurations — default, SIMPLER_ORCH_PROFILING, SIMPLER_SCHED_PROFILING, SIMPLER_DFX=0 — zero warnings. A path that only exists under a conditional is invisible to a single build.
  • Symbols: host .so has zero call sites and zero undefined references for both removed symbols under every configuration; libaicpu_kernel.so unchanged.
  • ctest: 128/128
  • Scene tests: a2a3sim 10 passed, a5sim 7 passed

Not run on real hardware — this touches a DFX path that is off by default. CI's onboard jobs cover it.


An unrelated include-hygiene pass that had been sharing this branch is split out into its own PR, since it is a mechanical 48-file change with a different subject.

@coderabbitai

coderabbitai Bot commented Sep 2, 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: Team

Run ID: 09218e63-19f1-49af-b70c-33dca14fbbe6

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
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 2fc0e6ef-4aa0-4e16-8990-94b093e58b4e

📥 Commits

Reviewing files that changed from the base of the PR and between 1f3995c and 81f2e05.

📒 Files selected for processing (5)
  • src/a2a3/runtime/host_build_graph/host/runtime_maker.cpp
  • src/a5/runtime/host_build_graph/host/runtime_maker.cpp
  • src/common/host_build_graph/host/aicpu_shims.cpp
  • src/common/host_build_graph/host/orchestrator.cpp
  • src/common/host_build_graph/orchestrator.h
💤 Files with no reviewable changes (1)
  • src/common/host_build_graph/host/aicpu_shims.cpp

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Host orchestration profiling now measures phase durations with CLOCK_MONOTONIC, stores nanosecond values, and reports them with ns= labels. Obsolete AICPU host shims and profiling includes were removed.

Changes

Host orchestration profiling

Layer / File(s) Summary
Nanosecond profiling contract
src/common/host_build_graph/orchestrator.h
OrchProfilingData timing fields now use nanosecond-based names and comments.
Host monotonic timing
src/common/host_build_graph/host/orchestrator.cpp, src/common/host_build_graph/host/aicpu_shims.cpp
The orchestrator uses CLOCK_MONOTONIC for phase timing, updates profiling accumulators and reset logic, and removes obsolete AICPU host shims.
Nanosecond profiling output
src/a2a3/runtime/host_build_graph/host/runtime_maker.cpp, src/a5/runtime/host_build_graph/host/runtime_maker.cpp
Runtime orchestration logs read nanosecond fields and label durations with ns=.

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

Merge Risk: ⚪ Minimal · up to 81f2e

This PR switches host orchestration profiling to monotonic nanosecond timing and removes unused host shims without changing normal-build behavior or device-side execution. No actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit checks the clock at dawn
Nanoseconds hop across the lawn
Old cycle shims burrow away
ns= marks each step today
The host graph grows precise and bright

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. 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 main change: removing host-side dependencies on device facilities. It is concise and specific.
Description check ✅ Passed The description is directly related to the changeset and explains the profiling refactor, shim removal, include cleanup, scheduler pointer removal, and validation results.

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 changed the title Refactor: time host orchestration with a host clock Refactor: stop host_build_graph's host side reaching into device facilities Sep 2, 2026
@poursoul
poursoul force-pushed the refactor/time-host-orchestration-with-a-host-clock branch from ea7d5ec to c192f24 Compare September 2, 2026 08:46
…lities

hw-native-sys#2094 moved host_build_graph's orchestration to the host. Two device-side
dependencies survived that move, both of them reaching for something the host
cannot actually use.

The orchestrator's per-sub-step profiling called get_sys_cnt_aicpu, a device
cycle counter. On the host that resolved to a stand-in reading CLOCK_MONOTONIC
and scaling it by PLATFORM_PROF_SYS_CNT_FREQ, so the orchestrator turned
nanoseconds into notional device cycles, accumulated those, and the bind logged
them as `cycles=` -- neither a real cycle count nor a readable duration, and a
dependency on a device frequency constant for timing that never leaves the host.
The accumulators now read clock_gettime through a file-local inline and carry
nanoseconds: OrchProfilingData's five *_cycle fields and fanin_wait_cycle become
*_ns, the macros are ORCH_STEP_START/LAP, and the log line reads `ns=`.

That was the host's only use of get_sys_cnt_aicpu, so host/aicpu_shims.cpp goes
away. Its other definition, get_reg_ptr, had no caller at all: disassembling the
host .so under the default, ORCH_PROFILING and SCHED_PROFILING configurations
finds zero call sites in every one, and the comment explaining it named a
route_ready_once path that exists nowhere in the tree.

OrchestratorState carried SchedulerState *scheduler, pointing at a struct that
lives in device memory the host never maps -- residue from when both ran on the
AICPU in one address space and the orchestrator could enqueue into the
scheduler's queues directly. Its own comment said "For simulated mode only", and
nothing read it: submit_task copied it into a local whose only use was a (void)
cast, and two call sites asserted it non-null without dereferencing. The member,
the init() parameter that filled it, and both assertions are gone. That was
orchestrator.h's only use of SchedulerState, so the header no longer includes
scheduler/scheduler.h -- 1336 lines of device dispatch logic the host compiled to
reach a pointer it never followed. Eight unit tests that had been reaching
SchedulerState and SchedulerLayout through that chain now include it directly.

The AICPU side is untouched: libaicpu_kernel.so carries its own get_sys_cnt_aicpu
from platform/.../device_time.cpp -- 195 call sites under SCHED_PROFILING, zero
undefined references -- and never compiled the deleted file.

Built in all four profiling configurations, since a path that exists only under a
conditional is invisible to a single build.
@ChaoZheng109
ChaoZheng109 merged commit 46cc406 into hw-native-sys:main Sep 2, 2026
34 of 37 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