Repository navigation
[Engine] Inkling 2 on AMD: launch the shared-expert memset directly, not as a graph (HIP) - #236
Draft
okada-shogo wants to merge 8 commits into
Draft
okada-shogo wants to merge 8 commits into
okada-shogo wants to merge 8 commits into
Conversation
The HIP build of strata-poly stopped at inkling2.cu since 8ddd416: the screen kernels (scr_base_kernel, scr_step_kernel, scr_final_kernel) call __ldcs and __ldcg on uint4, uint32_t, float and float2, and HIP has those two only for halves ("no matching function for call to '__ldcs'", ten errors, ROCm 7.2.4, gfx1201). On HIP they are now plain loads: the screen uses them as cache hints, on a copy's words read once and on candidates that earlier launches wrote. CUDA builds compile the same code as before (the definitions are under __HIPCC__). Class: same bits on CUDA; HIP did not build before. Inkling 2 is VecSzn's engine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Erqa3PhC87SPTfVSKZ3Ri5
docs/models/inkling.md said "Not run yet: an AMD card". It now says what was seen on the first AMD runs of this engine: it builds for gfx1100, gfx1200 and gfx1201, main's HIP tests pass 15 of 16 on an RX 7900 XT and 11 of 16 on an RX 9070 XT (ROCm 7.2.4, a container that reaches the card through librocdxg), a prompt with experts in RAM can hang, and on the RX 9070 XT the prompt products' library gave a NaN and run-to-run differences in its test. Setup's family line (and the MCP server's copy of it) says AMD cards are not ready. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ROCm 7.2.4 under WSL2 (librocdxg 1.2.2, an RX 9070 XT) refuses
hipMemSetAccess (hipErrorInvalidValue) on a piece mapped after a larger
one in the same reservation: 64 MiB then 1 MiB, 2 then 1, 8 then 4,
64 then 4 all fail, while pieces of one size always pass (64 + 64,
8 + 8, 1 + 1). vmm_map() maps a reservation in pieces of the size it
is asked for and a shorter last one, so the expert cache lost its last
piece (3,058 of Inkling 2 Mini UD-Q2_K_XL's 3,072 experts in VRAM,
whatever the VRAM, reserve or context), and an attention cache grown to
the end of its reservation failed ("no VRAM for the attention cache
(1 MiB more)": an 8,192-token prompt at --max-context 8704).
On a Linux HIP build under WSL2 (/dev/dxg and no /dev/kfd: the test of
setup's and the launcher's WSL note, wsl_amd_note()) every piece of a
reservation is the size of its first: a reservation is a whole number
of 2 MiB units, a first map's piece the most units that divide it and
are no more than the piece asked for and the map's bytes, and a map
covers whole pieces. The expert cache reserves a whole number of its
64 MiB pieces and an attention cache a whole number of cover()'s, so
they keep those sizes; cover() counts the rows' VRAM as the pieces
vmm_map() maps. STRATA_VMM_EQUAL_PIECES=1/0 turns it on or off on any
Linux HIP build. Native Linux and Windows HIP, the pool (--vram-pool,
already one size) and CUDA are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ROCm keeps a file descriptor open for each VMM handle (its dmabuf;
librocdxg under WSL2), so the usual soft limit of 1,024 caps the
handles a process can map: with --vram-pool's 2 MiB handles an RX 9070
XT stopped at 774 of Inkling 2 Mini UD-Q2_K_XL's experts ("fail to
import fd, ret 11", and the map fails as a card without VRAM does),
where a raised limit maps 6,000 handles (12 GB). A HIP build on Linux
now raises its soft RLIMIT_NOFILE towards the hard limit (at most
2^20) at load, as any process may, and never lowers it. CUDA builds
are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mmq::mul()'s BLAS path reads a launch's bounds on the host, where Mmq::mirror() says they are, as Engine::alloc() sets it up for tab_. poly_mmq_tiles_test never called mirror(), so wherever the BLAS path takes its matrices (every HIP build: gemm_iq_f16_grouped and the int8 tiles are CUDA-only) it aborted at its first case with "the matrices' bounds are not where mirror() says" (RX 7900 XT gfx1100 and RX 9070 XT gfx1201, ROCm 7.2.4). The test now mirrors its reference bounds and its class bounds before the launches that read them, as the engine does. Only the test changes. With it the test passes (48 cases) on the RX 7900 XT (Salad container, ROCm 7.2.4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
force-pushed
the
port/amd-plain-memset
branch
from
November 22, 2026 22:22
4d765ae to
85e7407
Compare
ink_clips_kernel and ink_qkv_kernel never finished on AMD cards: an RX 9070 XT (gfx1201) under WSL2 and RX 7900 XT / RX 9070 XT containers, ROCm 7.2.4. The first prompt of Inkling 2 Mini stopped in the first layer's ink_clips launch (with AMD_SERIALIZE_KERNEL=3 the launch never returned; on Windows the driver reset the card), with or without experts on the card, and poly_inkling2_test hung in its clips and qkv cases while clip and head_rms passed. The same source built with any change to ink_clips_kernel finished, so it is the compiler's code for these two kernels, not their arithmetic. ink_clips() is ink_clip() and ink_head_rms() of its four jobs with the same bits, and ink_qkv() ink_conv() of K and V and then the same, by their own contract. On HIP they are now those launches, with the K and V rows stored by store_f16(), store_f16_at() (a recorded launch's positions) or ink_store_ring() (a window's ring), the cells the fused kernels wrote. More launches a layer on AMD; CUDA builds compile the same code as before (the change is under __HIPCC__). Class: same bits by the kernels' contract (poly_inkling2_test's clips and qkv cases, simplexai-labs#222, compare them); HIP did not run before. The kernels are VecSzn's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inux) Between prompts the expert cache takes the VRAM of the buffers only a prompt batch uses (lend_prompt()), and a prompt maps them again. ROCm on Linux gives VRAM back only with its addresses (vmm_unmap() frees and reserves them again), which the staging buffer's widening already stays away from (Engine::alloc(), `lend`). With the buffers lent strata-poly crashed in 15 of 16 runs of Inkling 2 Mini IQ4_NL on an RX 9070 XT with 2,443 of its 3,072 experts in VRAM (ROCm 7.2.4 container): SIGSEGV inside hipLaunchKernel, the dequantize launch of a prompt's dense product (Mmq::mul's BLAS path) into the lent work memory. With every expert in VRAM nothing is lent, and it ran. With this change 8 of 8 runs on that card finished (2,424 of 3,072 experts in VRAM, 16 tokens written, the same first tokens as on an RX 7900 XT). Where STRATA_VMM_RELEASE_WITH_ADDRESSES is defined (HIP on Linux) the buffers are now allocated as they are without VMM (our engine in simplexai-labs#200, which ran this case, never lent them). CUDA and Windows HIP are unchanged (the preprocessed CUDA engine.cpp is identical). Class: placement only (the buffers' VRAM stays theirs; the expert cache does not grow into it between prompts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Where run() and step() replay a token's layer launches, they recorded each layer's shared expert apart (Layer::shared) and replayed it, a graph launch a layer visit. Inkling 2's shared expert is one memset of fo_ (moe_shared()), and on HIP, where the doorbell is off, a token with experts outside VRAM goes layer by layer: 48 visits, each with that extra graph launch. A family can now say its shared expert is launched as it is (Engine::shared_recorded()), and Inkling 2 does on HIP. The same kernels in the same order, so the same bits. CUDA and the other families replay it as before. In our first Inkling engine (PR simplexai-labs#200), the same change (the shared expert launched as it is where the heads are) wrote IQ4_NL +17% faster on an RX 9070 XT (gfx1201, ROCm 7.2.4) with the same logits; there the heads were launched one by one too, here they stay recorded, so the gain is to be measured on this engine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
force-pushed
the
port/amd-plain-memset
branch
from
November 22, 2026 23:46
85e7407 to
b78f72d
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.
Status: tests pending. This draft is open for early review. Its tests are queued and will run on: Salad RX 9070 XT (gfx1201) / RX 7900 XT (gfx1100). Results will be added here; if it doesn't help, it will be closed.
Problem and result
For AMD cards (HIP), decode, when some experts are outside VRAM. It removes one graph launch per layer visit:
Inkling 2's shared-expert
memsetis launched directly instead of as a recorded graph. Same bits. Decode speed isnot measured yet on this branch. HIP only; CUDA is unchanged.
What it changes, in plain words: Inkling 2's shared expert step is a single
memsetof the bufferfo_. Whenrun()/step()replay a token's layers, they record that memset as its own graph and replay it. That is one moregraph launch per layer visit. On HIP the doorbell is off, so a token with experts outside VRAM goes layer by layer:
48 visits per token. A HIP graph launch costs the host more than the memset itself. This PR launches the memset
directly on HIP.
Related discussion
Split out of #200, as the maintainer asked there:
#200 (comment)
Stacked on #217 (AMD support, not yet working end to end: the prompt hang is open). Speed numbers come after #217 runs. This branch carries #217's first commit (b681c69, the DSpark HIP build fix), so its diff here shows that commit too. It will be rebased as #217 moves.
Approach
Engine::shared_recorded(). It returns true by default (record the shared step as a graph, as before).Inkling2returns false in HIP builds (STRATA_USE_HIP).(the hook returns true there).
heads were not recorded as graphs either. Here they are, so the gain should be smaller.
Validation
Passed:
strata-polyandpoly_inkling2_wmma_testbuild, 0 errors. Not built alone.Failed: none observed.
Not run:
Limits
🤖 Generated with Claude Code