Add: eager prebuilt runtime-arena prewarm at worker init#1322
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds configuration-driven runtime-arena prewarming. Python workers can accept a ChangesRuntime Arena Prewarm
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant PythonWorker
participant WorkerManager
participant ChipWorker
participant simpler_prewarm_config
participant prewarm_config_impl
PythonWorker->>WorkerManager: control_prewarm_config(worker_id, CallConfig)
WorkerManager->>ChipWorker: dispatch CTRL_PREWARM_CONFIG
ChipWorker->>simpler_prewarm_config: prewarm ring sizing
simpler_prewarm_config->>prewarm_config_impl: forward runtime_env ring parameters
prewarm_config_impl-->>ChipWorker: cache prebuilt runtime image
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 introduces an eager pre-warming mechanism (prewarm_config) to build and cache the prebuilt runtime-arena image based on the run configuration's ring sizing during initialization, thereby avoiding the cold build overhead (~800ms) on the first run. The changes span Python bindings, worker interfaces, C++ runtime makers, and hierarchical worker managers. Feedback focuses on validating the pre-warm configuration during initialization for all worker levels, adding defensive null checks and zero-initialization in control_prewarm_config to prevent undefined behavior, and using RAIIScopeGuard in the simulation implementation to ensure reliable cleanup of thread-local data.
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.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@python/simpler/task_interface.py`:
- Around line 1164-1171: Correct the kwargs documentation in the method
associated with the shown CallConfig setup: remove the invalid ring_heap
override example and document setting config.runtime_env.ring_heap before
invoking the method, unless explicit kwargs mapping is implemented. Keep the
setattr loop consistent with only valid top-level CallConfig attributes.
In `@python/simpler/worker.py`:
- Around line 2865-2878: Ensure prewarming occurs during init() for hierarchical
workers: when prewarm_config is provided, initialize/start the hierarchy from
init() rather than deferring the existing prewarm control in
_start_hierarchical() until run(). Update the relevant
_init_hierarchical/_start_hierarchical flow so the configured arena is built
before init() returns, while preserving no-op behavior when prewarm_config is
None.
In `@src/common/hierarchical/worker_manager.cpp`:
- Around line 566-574: LocalMailboxEndpoint::control_prewarm_config currently
accepts undersized or null payloads and can leave stale configuration bytes.
Validate that config is non-null and config_size equals sizeof(CallConfig)
before acquiring the lock or writing the control command; reject invalid input
through the existing error-handling mechanism, then copy the full CallConfig
without clamping.
🪄 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: 97d8560d-9a12-4ec3-962d-8e95b188617b
📒 Files selected for processing (17)
python/bindings/task_interface.cpppython/bindings/worker_bind.hpython/simpler/task_interface.pypython/simpler/worker.pysrc/a2a3/runtime/tensormap_and_ringbuffer/host/runtime_maker.cppsrc/common/hierarchical/worker.hsrc/common/hierarchical/worker_manager.cppsrc/common/hierarchical/worker_manager.hsrc/common/platform/onboard/host/c_api_shared.cppsrc/common/platform/onboard/host/device_runner_base.cppsrc/common/platform/onboard/host/device_runner_base.hsrc/common/platform/sim/host/c_api_shared.cppsrc/common/platform/sim/host/device_runner_base.cppsrc/common/platform/sim/host/device_runner_base.hsrc/common/worker/chip_worker.cppsrc/common/worker/chip_worker.hsrc/common/worker/pto_runtime_c_api.h
707fc07 to
ce104f3
Compare
|
Design: can the arena prewarm ride the existing The functionality is sound and The key observation: the arena depends only on Concretely:
That collapses ~12 of the new symbols; what stays is the part that earns its keep: the public knob Two bonuses from building inside the child's
The only thing that would justify the mailbox route is dynamic, post-init re-prewarm of a different sizing (children already forked, can't re-fork) — but the PR defines this as single-slot, one sizing per init, so that case is out of scope. "Consistency with Not blocking the concept — just think the same behavior lands with roughly a third of the API surface if it goes through |
ce104f3 to
216f7db
Compare
Populate the prebuilt runtime-arena cache eagerly at init from a declared run config, so the first simpler_run with the same ring sizing skips the ~800ms cold build. On distributed (ep>1) runs this also removes the cross-card collective-wait bubble: prebuilt skew was converting 1:1 into device_wall idle (bind_end skew ~210ms -> ~2.6ms, device_wall converges). - Extract the run-path build+upload+cache into a Runtime-free helper build_and_cache_prebuilt_arena(api, sizing); the lazy first-run miss path now builds+caches then re-binds via the cache-hit path, so run and prewarm share one code path (drops ensure_static_arenas' runtime arg + bind_launch_state). - Add simpler_prewarm_config C-API + DeviceRunnerBase::prewarm_config. The runtime-specific prewarm_config_impl is a weak no-op default in the common onboard/sim device_runner_base, overridden by the strong trb a2a3 impl -- so hbg and archs without a prewarm impl still link (a5 untouched). - Thread through ChipWorker (dlsym simpler_prewarm_config) and nanobind (_ChipWorker.prewarm_config, Worker.control_prewarm_config). - Wire the L2/L3 control path: _CTRL_PREWARM_CONFIG mailbox command + chip-loop handler + worker-manager control_prewarm_config chain; Worker.init(prewarm_config=...) prewarms in-process (L2) or dispatches per chip (L3). a2a3 tensormap_and_ringbuffer only. Validated in a2a3sim (L2 build-at- init + cache-hit on run; L3 per-chip dispatch) and on-device ep=4.
What
Populate the prebuilt runtime-arena cache eagerly at worker init from a
declared run config, so the first
simpler_runwith the same ring sizingskips the ~800ms cold arena build.
On distributed (ep>1) runs this also removes the cross-card collective-wait
bubble: prebuilt-arena skew was converting a 1:1 dispatch into
device_wallidle. Measured on a distributed run:
bind_endskew ~210ms → ~2.6ms, anddevice_wallconverges across cards.How
build_and_cache_prebuilt_arena(api, sizing). The lazy first-run miss pathnow builds+caches then re-binds via the cache-hit path, so
runandprewarmshare one code path (dropsensure_static_arenas' runtime arg +bind_launch_state).simpler_prewarm_configC-API +DeviceRunnerBase::prewarm_config. Theruntime-specific
prewarm_config_implis a weak no-op default in thecommon onboard/sim
device_runner_base, overridden by the strong trb a2a3impl — so
hbgand archs without a prewarm impl still link (a5 untouched).ChipWorker(dlsymsimpler_prewarm_config) and nanobind(
_ChipWorker.prewarm_config,Worker.control_prewarm_config)._CTRL_PREWARM_CONFIGmailbox command +chip-loop handler + worker-manager
control_prewarm_configchain;Worker.init(prewarm_config=...)prewarms in-process (L2) or dispatchesper chip (L3).
Scope / safety
is prewarmed per init.
Testing
Not yet verified on-device in this PR branch — flagging for CI / reviewer
onboard run.