Skip to content

Refactor: extract leftover shared chunks from run() and finalize()#926

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
hw-native-sys-bot:extract-leftover-helpers
May 31, 2026
Merged

Refactor: extract leftover shared chunks from run() and finalize()#926
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
hw-native-sys-bot:extract-leftover-helpers

Conversation

@hw-native-sys-bot
Copy link
Copy Markdown
Collaborator

Summary

Three more small helpers + one tweak to finalize_common(). Net -1 line, but real consolidation: each chunk that used to be duplicated in two arches now lives once.

New base helpers

Helper What
init_runtime_args_with_metadata(Runtime&) H2D the Runtime struct via kernel_args_.init_runtime_args, then publish log_level / log_info_v / device_id into KernelArgs from HostLogger::get_instance().
start_shared_collectors_for_run() Builds the thread_factory lambda and calls .start() on the four shared collectors (l2_perf, dump, pmu, scope_stats) gated by their enable flags.
teardown_shared_collectors_after_run() Post-sync stop+reconcile+export sequence for those four. l2_perf adds read_phase_header_metadata + export_swimlane_json; dump exports dump files; pmu just reconciles; scope_stats writes JSONL.

a2a3 still inlines its dep_gen_collector_ start + teardown (with dep_gen_replay_emit_deps_json) right after the shared helpers — that's a2a3-only.

finalize_common() tweak

Resets cached_gm_heap_size_ / cached_gm_sm_size_ / cached_runtime_arena_size_ alongside the other identity state. These fields live on base (moved in #922) so resetting them there is the natural home; each arch's finalize() no longer needs the three explicit = 0 lines after calling finalize_common().

Verification

  • Both arches built clean (onboard + sim, both runtimes).
  • Local a2a3 onboard smoke (dummy_task, alternating_matmul_add, prepared_callable suite, spmd_basic) — 9/9 passed in 19s.

Test plan

  • CI st-sim-a2a3 / st-sim-a5
  • CI st-onboard-a2a3 / st-onboard-a5
  • CI ut-a2a3 / ut-a5

Three more small helpers + one tweak to finalize_common(). Net -1
line, but real consolidation: each chunk that used to be duplicated
in two arches now lives once.

New base helpers (called from each arch's run()):
- init_runtime_args_with_metadata(Runtime&) — H2D the Runtime struct
  via kernel_args_.init_runtime_args, then publish log_level /
  log_info_v / device_id into KernelArgs from HostLogger.
- start_shared_collectors_for_run() — builds the thread_factory
  lambda and calls .start() on the four shared collectors
  (l2_perf, dump, pmu, scope_stats) gated by their enable flags.
- teardown_shared_collectors_after_run() — the post-sync
  stop+reconcile+export sequence for those four. l2_perf adds
  read_phase_header_metadata + export_swimlane_json; dump exports
  dump files; pmu just reconciles; scope_stats writes JSONL.

a2a3 still inlines its dep_gen collector start + teardown (with
dep_gen_replay_emit_deps_json) right after the shared helpers —
that's a2a3-only.

finalize_common() now resets cached_gm_heap_size_ / cached_gm_sm_size_
/ cached_runtime_arena_size_ alongside the other identity state. These
fields live on base (moved in PR hw-native-sys#922) so resetting them there is the
natural home; each arch's finalize() no longer needs the three explicit
= 0 lines after calling finalize_common().

Both arches built clean. a2a3 onboard smoke (dummy_task,
alternating_matmul_add, prepared_callable suite, spmd_basic) — 9/9
passed in 19s.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Warning

Review limit reached

@hw-native-sys-bot, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 44 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3c814b63-13df-4136-b051-11a2db52cea8

📥 Commits

Reviewing files that changed from the base of the PR and between c830d3a and 5b9c9fb.

📒 Files selected for processing (4)
  • src/a2a3/platform/onboard/host/device_runner.cpp
  • src/a5/platform/onboard/host/device_runner.cpp
  • src/common/platform/onboard/host/device_runner_base.cpp
  • src/common/platform/onboard/host/device_runner_base.h

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 and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 refactors the DeviceRunner implementations for the a2a3 and a5 architectures by consolidating duplicate logic into the base class DeviceRunnerBase. Specifically, it introduces shared helper methods for initializing runtime arguments, starting diagnostics collectors, and tearing them down. It also moves the clearing of cached arena sizes into the base class's finalize_common method. There are no review comments, and I have no feedback to provide.

@ChaoWao ChaoWao merged commit 80c4cfb into hw-native-sys:main May 31, 2026
16 checks passed
@ChaoWao ChaoWao deleted the extract-leftover-helpers branch May 31, 2026 01:55
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