Skip to content

Fix: build host_build_graph orchestration on x86 hosts#1367

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:fix/hbg-orch-x86-host-aicpu-asm
Jul 15, 2026
Merged

Fix: build host_build_graph orchestration on x86 hosts#1367
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:fix/hbg-orch-x86-host-aicpu-asm

Conversation

@ChaoZheng109

Copy link
Copy Markdown
Collaborator

Why

host_build_graph runs its orchestration .so on the host CPU
(build_config: "Host runs the orchestrator to completion, populating SM +
arena, then H2Ds the image to device"), so compile_orchestration()
builds it with the bare host g++ (ToolchainType.HOST_GXX). That orch
compile unconditionally links the onboard AICPU helpers
device_time.cpp / cache_ops.cpp (added by #1236 so orch SOs using the
public AICPU helper headers resolve). Both files' bodies are
aarch64-only inline asmmrs cntvct_el0, dc civac/cvac,
dsb, isb.

On an ARM64 runner the host g++ targets aarch64, so the asm assembled
and the latent "host is aarch64" assumption stayed hidden. #1361 made
st-onboard-a2a3 eligible for the new x86_64 runners; there the host
g++ feeds aarch64 asm to the x86 assembler and every host_build_graph
L2 test fails at compile time:

src/common/platform/onboard/aicpu/device_time.cpp:15: Error: no such instruction: `mrs %rax,cntvct_el0'
RuntimeError: Orchestration compilation failed with exit code 1

tensormap_and_ringbuffer is unaffected: its orch cross-compiles with
AARCH64_GXX and runs on the device AICPU, never through the host g++.

What

Gate the asm behind __aarch64__ and add a host-portable #else:

  • device_time: derive the sys-cnt tick from std::chrono, scaled to
    the same PLATFORM_PROF_SYS_CNT_FREQ unit the DFX markers decode
    against (mirrors the existing sim variant).
  • cache_ops: no-op. The host orchestrator reaches device memory only
    through driver H2D DMA (cache-coherent on x86), so the AICPU-side
    manual cache maintenance has no host-side referent.

aarch64 (device AICPU and ARM64-host orchestration) takes the exact
same code as before — zero behavior change on every currently-working
path. Only the x86 host build gains a compilable path.

Verification

  • aarch64 branch compiles with native g++ (both files).
  • x86 #else body verified as portable C++ (chrono + macro, no asm).
  • common/platform_config.h is already on the orch include path
    (get_platform_include_dirs()src/a2a3/platform/include).
  • End-to-end x86 validation requires CI to land st-onboard-a2a3 on an
    x86_64 runner.

Note

The separate st-onboard-a5 red (/tmp/pytest-of-simpler_a5ci is not owned by the current user) is an a5-runner environment issue (stale tmp
dir), unrelated to this change.

@coderabbitai

coderabbitai Bot commented Jul 15, 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

Run ID: 7b5cc35d-4392-4419-976d-e66cb0e08a4d

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

AICPU cache maintenance now has non-AArch64 no-op implementations, while system-counter timing uses a scaled std::chrono fallback outside AArch64 builds.

Changes

AICPU portability

Layer / File(s) Summary
Cache maintenance portability
src/common/platform/onboard/aicpu/cache_ops.cpp
AArch64 builds retain cache-maintenance implementations; other architectures compile no-op invalidate_range_impl and flush_range_impl functions.
System counter portability
src/common/platform/onboard/aicpu/device_time.cpp
AArch64 builds read cntvct_el0; other architectures derive profiling ticks from std::chrono::high_resolution_clock and PLATFORM_PROF_SYS_CNT_FREQ.

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

Poem

A rabbit hops where cache winds blow,
On AArch64, the instructions flow.
Else they rest, quiet and still,
While clocks tick on with chrono skill.
Cross-platform paths now bloom—
Thump-thump! builds find room.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing x86 host orchestration builds.
Description check ✅ Passed The description is directly about the x86 host build failure and the AArch64 guard fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds support for non-aarch64 platforms in AICPU cache operations and device timing. Cache maintenance operations are stubbed out as inert on non-aarch64, and get_sys_cnt_aicpu is updated to emulate the hardware timer using a host-side clock. The review feedback correctly points out that std::chrono::high_resolution_clock should be replaced with std::chrono::steady_clock to guarantee monotonicity and avoid issues with system time adjustments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/common/platform/onboard/aicpu/device_time.cpp Outdated

@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/common/platform/onboard/aicpu/device_time.cpp`:
- Line 29: Replace std::chrono::high_resolution_clock with
std::chrono::steady_clock when capturing now in the system counter tick
implementation, preserving the existing tick conversion and return behavior so
get_sys_cnt_aicpu() remains strictly monotonic like device_time_now_ticks().
🪄 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

Run ID: b143a632-e472-466d-9b0e-49e8d8559379

📥 Commits

Reviewing files that changed from the base of the PR and between cddf2b6 and 92f0dfd.

📒 Files selected for processing (2)
  • src/common/platform/onboard/aicpu/cache_ops.cpp
  • src/common/platform/onboard/aicpu/device_time.cpp

Comment thread src/common/platform/onboard/aicpu/device_time.cpp Outdated
@ChaoZheng109 ChaoZheng109 force-pushed the fix/hbg-orch-x86-host-aicpu-asm branch 2 times, most recently from 4e997ca to 9b5a4b5 Compare July 15, 2026 08:11
host_build_graph runs its orchestration .so on the host CPU, so
compile_orchestration() builds it with the bare host g++. The orch
compile unconditionally links the onboard AICPU helpers device_time.cpp
and cache_ops.cpp, whose bodies are aarch64-only inline asm
(mrs cntvct_el0, dc civac/cvac, dsb, isb).

On an ARM64 runner the host g++ targets aarch64, so the asm assembled
and the latent host-arch assumption stayed hidden. hw-native-sys#1361 made
st-onboard-a2a3 eligible for x86_64 runners; there the host g++ feeds
aarch64 asm to the x86 assembler and every host_build_graph L2 test
fails with "Orchestration compilation failed ... no such instruction:
mrs %rax,cntvct_el0".

Gate the asm behind __aarch64__ and add a host-portable else branch:
- device_time: get_sys_cnt_aicpu() now delegates the clock read to
  device_time_now_ticks() (monotonic steady_clock off aarch64), then
  rescales ns to the PLATFORM_PROF_SYS_CNT_FREQ unit it reports in, so
  the orchestrator's cycle-based timeouts (get_sys_cnt_aicpu() - t0 >
  ..._CYCLES) and DFX decode stay valid. The prior sim variant used the
  non-monotonic high_resolution_clock; unify both on device_time_now_ticks().
- cache_ops: no-op off aarch64. The host orchestrator reaches device
  memory only through driver H2D DMA (cache-coherent on x86), so the
  AICPU-side manual cache maintenance has no host-side referent.

aarch64 (device AICPU and ARM64-host orchestration) is behaviorally
unchanged; only the x86 host build gains a compilable path.
@ChaoZheng109 ChaoZheng109 merged commit b543027 into hw-native-sys:main Jul 15, 2026
16 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.

1 participant