Repository navigation
[Engine] metal: add MTLSharedEvent doorbell with defer-rank and watchdog-safe CB chunking - #474
Draft
NightRain233 wants to merge 1 commit into
Draft
NightRain233 wants to merge 1 commit into
NightRain233 wants to merge 1 commit into
Conversation
…dog-safe CB chunking
NightRain233
force-pushed
the
feat/metal-shared-event-doorbell
branch
from
December 6, 2026 05:38
fbd684b to
69ef5af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
On partial-VRAM Apple Silicon Macs (such as 16 GB M4 running Qwen4-35B-A3B
UD-IQ2_XSwith ~40% of routed experts in VRAM), every MoE layer previously synchronized back to the host via separate command buffers and host routing round-trips, adding heavy per-layer router wait latency.This PR adds a native Metal
MTLSharedEventdoorbell for partial-VRAM MoE decode, upgraded with:--defer-rankcross-layer expert deferral & 16-row batching (up to 16 rows / 128 jobs, ping-pong buffers, Inkling2metal_bell_defer_ok()guard).< 10%cached-expert floor disabling doorbell when too few experts are resident in VRAM (plusSTRATA_METAL_BELL=0rollback andSTRATA_METAL_BELL_FORCE=1override), preventingkIOGPUCommandBufferCallbackErrorTimeoutand multi-GiB AGX driver leaks when 0 experts are cached.20MoE layers/CB when>= 25%of routed experts are cached, else8;STRATA_METAL_BELL_CHUNKoverride) with zero-bubble lookahead CB pipelining (submitting chunkc + 1before serving chunkc's last slot) and cleanrec_short_/rec_off_OOM fallback torun_direct().origin/main'sbell_pending_([Engine] synchronizing the compute stream between the doorbell launch andbell_serve()aborts the process #419) (metal_sync_memory(),BellOff,bell_unwind()).Measured on Apple M4 16 GB (
Qwen4-35B-A3B-UD-IQ2_XS, integrated R3 stackbfd5d1b):--no-gpu-experts(0 experts in VRAM): cleanly disables doorbell, completes 8 tokens (7.04 tok/s,11.7 s), zero timeout and zero AGX leak (gpu_inuse = 0.51 GiB).--defer-rank 0: 28.02 tok/s (router wait cut to17.0 ms/tok,gpu_inuse = 0.18 GiBafter 22 consecutive runs — zero AGX leak).Related discussion
Tracking issue: #472. Rebased onto
origin/main(7cef952,v0.2.20-poly.11) and integrated cleanly with#419(bell_pending_).Approach
MTLSharedEventhost/GPU signaling primitives inengine/metal/include/strata/gpu/metal.hppandengine/metal/src/gpu/runtime.cpp, plusmetal_bell_ring/metal_bell_addkernels inadvanced.{metal,cpp}and zero-bandwidth negative expert-id skip inquantized.metal/basic.metal/inkling.metal.#if defined(STRATA_GPU_METAL)balanced across all shared files).STRATA_METAL_BELL,STRATA_METAL_BELL_CHUNK,STRATA_METAL_BELL_FORCE, and updatesSTRATA_POLY_BELLinterminal/data/settings-register.json+docs/SETTINGS.md.Validation
69ef5afonorigin/main7cef952):strata-poly,poly_advanced_parity,poly_quantized_parity,poly_memory_growth,poly_runtime_safety,poly_basic_parity,poly_qwen4_parity,poly_inkling_parity,poly_tiny_model_fixture): 0 errors, 0 warnings.ctest --test-dir engine/build-metal -R '^(poly_advanced_parity|poly_quantized_parity|poly_memory_growth|poly_runtime_safety|poly_basic_parity|poly_qwen4_parity|poly_balanced_qwen35moe_protocol|poly_metal_defaults)$' --output-on-failure: 14/14 passed (includesBellChunkEngine3-chunk & 1-slot-chunk parity fordefer_rank=-1anddefer_rank=1,rec_short_fallback & recovery, andbell_pending_exception-unwind test).ctest --test-dir engine/build-metal -R '^poly_inkling_parity$' --output-on-failure: 1/1 passed.python3 tools/check --only docs: passed (6/6).python3 -m unittest tools.test_settings_register: passed (8/8).backends.yml/check.yml).Limits
!all_cached(),cached >= 10%); full-VRAM hosts (all_cached()) continue on the existing zero-sync GPU path unchanged.