Refactor: extract leftover shared chunks from run() and finalize()#926
Conversation
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.
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
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. Comment |
There was a problem hiding this comment.
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.
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
init_runtime_args_with_metadata(Runtime&)kernel_args_.init_runtime_args, then publishlog_level/log_info_v/device_idinto KernelArgs fromHostLogger::get_instance().start_shared_collectors_for_run()thread_factorylambda and calls.start()on the four shared collectors (l2_perf,dump,pmu,scope_stats) gated by their enable flags.teardown_shared_collectors_after_run()l2_perfaddsread_phase_header_metadata+export_swimlane_json;dumpexports dump files;pmujust reconciles;scope_statswrites JSONL.a2a3 still inlines its
dep_gen_collector_start + teardown (withdep_gen_replay_emit_deps_json) right after the shared helpers — that's a2a3-only.finalize_common()tweakResets
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'sfinalize()no longer needs the three explicit= 0lines after callingfinalize_common().Verification
Test plan