Repository navigation
[Engine] Inkling 2 on AMD: GPU doorbell for experts in RAM - #306
Open
okada-shogo wants to merge 2 commits into
Open
okada-shogo wants to merge 2 commits into
okada-shogo wants to merge 2 commits into
Conversation
…VRAM routes on the card, with no host round trip a layer Until now HIP had no doorbell, so an Inkling 2 token with some routed experts outside VRAM waited for the host at every layer (the router's scores to the host, an event wait, the picks back): 48 host round trips a token, 30-90 us each under WSL2 (dxg). With the doorbell the card routes, rings the host for the experts it lacks and goes on; the host's CPU workers answer through pinned memory, and the whole token is one recording. - bell.cuh: the card's side of the bell. On HIP: system-scope atomic loads and a release store for the bell's words, an acquire fence after the wait, s_sleep between looks. CUDA keeps its volatile accesses and __nanosleep(500) (the same code as before). - Engine::hmalloc(..., live): the bell, the token's input (h_x_) and the host's answer (h_cpu_) are hipHostMallocCoherent on HIP (hipHostMalloc's default memory is not coherent). CUDA unchanged. - bell_serve(): on HIP one hipStreamQuery after the token's launches. Under dxg a launch followed only by a look at host memory was not submitted within 2 s in 32 of 40 tries on an RX 9070 XT; one query fixed it. - bell_serve() gives up after 60 s with neither a ring nor the card's end (the card's waits end, the call throws), and run()/step() end the card's waits when a throw comes after a ring was launched (bell_unwind()). - poly_bell_test: ring and answer while the card waits, a whole pass in one recording, a token-sized pass (1,536 kernels in two recordings), an answer 3 s late, an abort. Routing on the card is the doorbell's own (route_rows(), as on CUDA and as HIP already routes with every expert in VRAM). It rounds the router's sigmoid differently from the host's route_by(), so the result is not bit-identical to HIP main's host-routed path (on CUDA main the doorbell differs from STRATA_POLY_BELL=0 in the same way). STRATA_POLY_BELL=0 gives main's bits. The doorbell is VecSzn's design (after Strata v0.2.19's Inkling hybrid mode); this ports it to HIP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
added a commit
to okada-shogo/PolyStrata
that referenced
this pull request
Nov 24, 2026
With the HIP doorbell (simplexai-labs#306) a token routes on the card, so the per-layer rule for partial caches must not turn the token's recording off. bell_on() is false on HIP without simplexai-labs#306, so this changes nothing on its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
With the doorbell (bell_on(): Inkling 2 with experts outside VRAM, now on HIP as well) a token alone is routed on the card: route_card(), whose gate sigmoid uses the card's expf. A window of several tokens (--window N lookup guesses, the drafter's verify) went to moe(), which routed each row on the host: route(), the same formula with the host's std::exp. The two need not round alike in the last bit, so a guessed token's expert weights (and, at a near tie, an expert) could differ from the ones it got alone, and greedy answers with guesses parted from the answers without them. run() now does for a window what step() does for its rows since 1d4d9e2: where a token alone routes on the card, up() routes the window's rows there before the router's event, copies the picks and weights to pinned memory (h_ids_, h_wts_, now also allocated for bells() with a window over 1), and moe() takes them (step_ids_). step()'s tests move into picks_like_alone() and picks_like_alone(L), shared by both; step() behaves as before. Not in a window's halves (they need reads_by_layer(), which no family with the doorbell has), not with --cache-bias, and not on Metal (no doorbell there). Class: same bits as one token at a time. RX 9070 XT, IQ4_NL, frozen experts at equal placement, STRATA_SPEC_FIXED=1, 128 tokens of code 2048 and chat/prose 8192: --window 4 and the DSpark drafter differed from no guesses in 6 of 6 before, 0 of 6 after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 CUDA, main has a "doorbell" for decode (
STRATA_POLY_BELL): the GPU routes the token itself and asks the CPU workers for the experts it lacks by setting a flag in pinned memory, so there is no host round trip. AMD (HIP) did not have it. When some routed experts were outside VRAM, an Inkling 2 decode token waited for the host at each of its 48 layer visits: the router's scores went to the host, the host waited on an event, and the expert picks came back. Under WSL2 (dxg), one such round trip costs 30-90 µs.This PR turns on main's doorbell for HIP. The card routes the token, signals the host through pinned memory for the experts it lacks, and goes on with the experts it has. The host's CPU workers answer the same way. The token's layers run as one recorded graph, with no host round trip inside it. On an RX 9070 XT, IQ4_NL decode is 39.4% faster after a short prompt and 14.8% faster after 8,192 tokens.
Decode tok/s, RX 9070 XT 16 GB (WSL2, ROCm 7.2.4), mean of 3 runs (warm-up request, rotated order, free placement):
Native Linux, the same RX 9070 XT (Fedora, in-tree amdgpu, ROCm 7.2.4; a host round trip costs 18 µs there against 41-97 µs under WSL2), mean of 3 runs,
--threads 11 --vram-reserve-mib 700:On native Linux UD-Q2_K_XL holds 3,058 of 3,072 experts, so it rarely rings; its rows are within noise.
UD-Q2_K_XL fits the card whole (3,072 of 3,072 experts in VRAM), so it never uses the doorbell: its rows are a control (no change expected). Prompt speed was not A/B-timed: a prompt's calls have more than one row, so they never use the doorbell.
Accuracy class: routing rounding, not the same bits. The card's routing is the same as CUDA's doorbell, and the same as HIP's own routing when every expert is in VRAM (
route_rows(), the GPU'sexpf). HIP main routed these tokens on the host (route_by(),std::exp). The two round the router's sigmoid a little differently. On CUDA, main's doorbell also differs fromSTRATA_POLY_BELL=0in the same way. The KL check is within the noise of a placement control: top-1 is the same at 30-31 of 32 steps, as for the control (31-32 of 32).STRATA_POLY_BELL=0turns the doorbell off and gives old main's bits.Accuracy: KL against main, per text and placement (RX 9070 XT, IQ4_NL)
KL(main ‖ this PR) over main's top 20 at each step, RX 9070 XT, IQ4_NL, 2,048-token prompts + 32 written. This PR is
fed main's tokens. The control is main again, with 10 fewer experts in VRAM (frozen) or in a second process (free).
Texts a and b are GPL text the model knows by heart; text c is random synthetic sentences (nothing memorized):
moves by more than 0.5 nat (reference-unstable).
Host round trips: bench report diagnosis (RX 9070 XT, IQ4_NL)
strata-poly --bench-report(branch port/bench-roofline: #285 and its report), quick tier, decoding one token per call. Left: that build. Right: the same build merged with this PR. One run each. The bench text finds ~100% of its experts in VRAM, so CPU experts are almost absent here.Each run (decode tok/s)
main held 2,388 of 3,072 IQ4_NL experts in VRAM, this PR 2,385-2,386.
Related discussion
#200, comment #200 (comment) (AMD as separate PRs, one
optimization per PR).
Approach
engine/src/poly/bell.cuh(new): the card's side of the doorbell.ack/abort, a system-scope release store ofring, an acquire fenceafter the wait, and
s_sleepbetween polls.__nanosleep(500)as before, so the generated code is unchanged.bell_ring_kernelandbell_add_kerneluse it. Nothing else in the kernels changes.Engine::hmalloc(..., live)makes the bell, the token's input (h_x_) and the host's answer(
h_cpu_)hipHostMallocMapped | hipHostMallocCoherenton HIP. hipHostMalloc's default memory is not coherent, soa running kernel could read it from a cache.
bell_serve()on HIP makes onehipStreamQueryafter the token's launches. Under WSL2, a launch followed only by polling host memory was sometimes not submitted for over 2 s (32 of 40 tries in a probe on an RX 9070 XT); one query after the launch fixed it. After that, the serve loop's event queries keep making HIP calls.bell_serve()now gives up after 60 s with neither a request from the card nor the end of the card's work. It ends the card's waits (abort), syncs and throws, where the process would otherwise hang.run()/step()after a doorbell kernel was launched ends the card's waits too (bell_unwind()).STRATA_POLY_BELL=0is unchanged: no doorbell, and the host routes as in old main. It is documented indocs/SETTINGS.mdanddocs/models/inkling.md.With other open PRs:
[Engine] Inkling 2 on AMD under WSL2: simpler decode graph #293 (HIP: layer recordings only for a whole pass) needs a one-line change with this PR. Without it the two together are slower than [Engine] Inkling 2 on AMD under WSL2: simpler decode graph #293 alone. Native Linux, the AMD combined branch (both PRs and others), decode tok/s, mean of 3 runs:
("without this PR" is the "no fix" binary run with
STRATA_POLY_BELL=0.) [Engine] Inkling 2 on AMD under WSL2: simpler decode graph #293 merges without conflict, but its new lineif (replay && n == 1 && !layer_records() && !card_routes()) replay = false;also turns off the whole-tokengraph on the doorbell path. Whichever merges second must add
&& !bell_on(n). Checked by trial merge:identity is the same as this PR's and decode works (39.5 tok/s in the frozen identity run against this PR's 39.5).
It can't be in this PR, because
layer_records()isn't on main yet.[Engine] Inkling 2: merge small decode kernels for CPU experts #288 (CUDA: fewer decode launches on the doorbell path, with
route_ringand merged kernels at the end of a layer): one comment conflict inkernels.cu. Itsink_moe_bell_conv_addkernel should call
bell_wait()frombell.cuhin place of its own loop. With that, the merge builds for HIPand
poly_inkling2_testpasses on the RX 9070 XT.[Engine] Retry instead of failing when a CUDA graph is out of VRAM #301 (graph out of VRAM): merges without conflict. Its
drop_recordings()comment says HIP has no doorbell, whichis no longer true with this PR. The
cudaStreamSynchronizethere is still safe: nothing is recorded between adoorbell request and its answer (checked in
run(),step()and the drafter). Whichever lands second only updatesthe comment.
Validation
Passed:
poly_bell_test(new), RX 9070 XT (gfx1201, WSL2, ROCm 7.2.4) and RTX 2070 (sm_75):16 checks, 0 failed. Cases:poly_inkling2_test: RX 9070 XT336 checks, 0 failedfor this PR and for this PR merged with [Engine] Inkling 2: merge small decode kernels for CPU experts #288; RTX 2070425 checks, 0 failed.strata-poly --tokens @ids302 --max-new 64 --top-probs 20,STRATA_FREEZE_EXPERTS=1:STRATA_GPU_EXPERTS=600, IQ4_NL and UD-Q2_K_XL loop, graphs and--no-graphs: this PRagainst main 36e654b SAME in all 4.
STRATA_GPU_EXPERTS=1600, IQ4_NL:STRATA_POLY_BELL=0against main SAME. The doorbellagainst main: DIFF (routing class, above). Same tokens, top-1 the same at 64 of 64 steps. Router wait 2.8 → 0.3
ms/token. Graphs and
--no-graphsgive the same bits.kl.sh,cmp47.py --ref2with the safeguards (median, mean without the top step, JS,mode-flip tags, a placement control).
strata-poly --serve --prompt-cache 0 --conversation-cache-mib 0 --max-context 32768 --kv fp16, a16-token warm-up request, then 256 tokens after 302 or 8,192, free placement, 3 rounds with the order rotated.
Machine: Salad RX 9070 XT + Ryzen 7 9850X3D, 23 GB RAM, WSL2. Both builds came from the same build run (
rbuild, ROCm 7.2.4 container, gfx1201, AVX2).STRATA_POLY_BELL=0, 3 rounds rotated,--serveas below with--threads 11 --vram-reserve-mib 700. The written tokens withSTRATA_POLY_BELL=0equal main's in every case where main's own runs agree with each other (IQ4_NL after 8,192, UD-Q2_K_XL after 302 and 8,192). With the doorbell on, IQ4_NL after 8,192 is the same too, and UD-Q2_K_XL differs (routing class).Failed:
Not run:
STRATA_GPU_EXPERTS) on native Linux: main itself refuses every cap there ("the card has N MiB for the expert cache, the first N experts take a few MiB more"), so only free-placement runs were compared.Limits
STRATA_POLY_BELL=0is the opt-out.
experts from disk) keeps that kernel running. 3 s was fine under WSL2. The 60 s timeout ends anything longer.
trips did.
so the doorbell stays on by default on every AMD system (no gate by OS);
STRATA_POLY_BELL=0turns it off.🤖 Generated with Claude Code