Skip to content

[Engine] AMD on Windows: no prompt-buffer lending (fixes a crash) - #334

Closed
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/hip-win-no-lend
Closed

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/hip-win-no-lend

Conversation

@okada-shogo

Copy link
Copy Markdown
Contributor

Problem and result

On Windows HIP, strata-poly crashes on the first long prompt of every start. The crash is an access violation inside
amdhip64_7.dll (#305: RX 7600 XT, Qwen3.6 UD-Q3_K_M, 5,332 of 10,496 experts in VRAM). A short chat works.

Between prompts the engine lends the prompt-only buffers to the expert cache (lend_prompt() / take_prompt()).
Under WSL2 (ROCm 7.2.4 with librocdxg, the Windows driver underneath) this crashed in 15 of 16 runs: a SIGSEGV
inside libamdhip64, under the dequantize launch of a dense product into the lent work memory. #217 turned lending
off for HIP outside Windows only (STRATA_VMM_RELEASE_WITH_ADDRESSES). Native Windows HIP has VMM too, so it kept
lending. #305's crash fits the same path; it is not yet run with lending off.

This PR turns lending off on every HIP build. A new macro, STRATA_VMM_NO_PROMPT_LEND, is defined in
hip_compat/cuda.h. HIP on Linux is unchanged. CUDA and Metal are unchanged: the macro exists only in the HIP header.

Cost on Windows HIP: the prompt buffers (about 300 MB for Qwen3.6 at a prompt batch of 2,048) stay out of the expert
cache between prompts, as they do on Linux HIP.

Related discussion

Approach

  • hip_compat/cuda.h: #define STRATA_VMM_NO_PROMPT_LEND 1 for all HIP builds, with a comment on the two crashes.
  • Engine::alloc(): lends is false under STRATA_VMM_NO_PROMPT_LEND (it was false under
    STRATA_VMM_RELEASE_WITH_ADDRESSES). With lends false, two_scratch_ is false too, as on Linux HIP.
  • Inkling2::scores_apart(): same switch, so Inkling 2 keeps one scratch layout on Windows HIP, as on Linux HIP.
  • docs/AMD_HIP.md: one bullet in the strata-poly section.
  • The staging buffer's widening stays on for Windows. The pre-poly.10 engine had it, and that engine runs [Engine] gfx1102: 0.2.20-poly.2 crashes in amdhip64_7.dll (0xC0000005 @ 0x2d874a) on first agentic request after expert-cache growth #305's
    workload without crashing.
Why lending is the likely cause of #305
WSL2 HIP crash (#217) #305 on Windows
Where libamdhip64.so.7, inside a kernel launch amdhip64_7.dll, offset 0x2d874a
When the first prompt of 32+ tokens (15 of 16 runs) first long prompt of every start; a 20-token chat works
Experts some in RAM (2,443 of 3,072) some in RAM (5,332 of 10,496)
Driver path librocdxg (WSL2's path to the Windows driver) Windows driver
Prompt products dequantize + BLAS into the lent work memory the same path: IQ3_XXS / IQ4_XS / Q6_K experts take the BLAS loop on HIP
  • In ROCm 7.2.4's libamdhip64.so.7, the crash offset 0x2b931f reads 0x38(%rax) right after a call returns.
    The returned pointer is null. That fits a missing memory object for a kernel argument.
  • Lending came in after the pre-poly.10 engine (7a6c09836), which the reporter runs without crashes.
  • The "expert cache 5452 -> 5504" log line before the crash is mind_vram() at the start of the request. The cache
    growth itself is older than pre-poly.10.

Validation

Passed: CUDA build of the changed files (engine.cpp, inkling2.cpp, sm_75, nvcc 12.9).
HIP build of strata-poly, ROCm 7.2.4 container, gfx1102.

Failed: none.

Not run: no Windows HIP run. No gfx1102 card. The reporter in #305 is asked to test this branch.
HIP on Linux runs the same code as before (the switch was already off there).

Limits

  • The Windows crash is matched to the Linux one by symptom and code path, not by a stack trace from Windows.
    If the crash stays with this branch, an AMD_LOG_LEVEL=4 log or a minidump from the reporter is the next step.
  • Windows HIP gives up the lent VRAM, as Linux HIP already does. Not measured on Windows.

🤖 Generated with Claude Code

… build

Between prompts the expert cache takes the VRAM of the buffers only a
prompt uses (lend_prompt()), and the next long prompt maps them again
(take_prompt()).  Under WSL2 (ROCm 7.2.4 with librocdxg, the Windows
driver underneath, RX 9070 XT, some experts in RAM) that crashed in 15
of 16 runs inside the HIP runtime's kernel launch: a SIGSEGV in
libamdhip64 under the dequantize launch of a dense product into the lent
work memory.  simplexai-labs#217 turned the lending off for HIP outside Windows only,
under STRATA_VMM_RELEASE_WITH_ADDRESSES.

Native Windows HIP has VMM too, so it kept lending.  Issue 305 has an
access violation in amdhip64_7.dll that fits the same path: on the first
long prompt of every start, while a 20-token chat works (RX 7600 XT,
Qwen3.6 UD-Q3_K_M, 5,332 of 10,496 experts in VRAM; the pre-poly.10
engine, which had no lending, runs the same workload).  Not yet run on
that card with the lending off.

STRATA_VMM_NO_PROMPT_LEND, defined in hip_compat/cuda.h for every HIP
build, now turns the lending off (Engine::alloc()) and keeps Inkling 2's
scratch in one layout (Inkling2::scores_apart()).  HIP on Linux is
unchanged; CUDA and Metal are unchanged (the macro is only in the HIP
header).  On Windows HIP the prompt's buffers (about 300 MB of
Qwen3.6's at a prompt batch of 2,048) now stay out of the expert cache,
as on Linux HIP.  The lending is VecSzn's (c48d16f, 631bbe4).

Class: placement only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo

Copy link
Copy Markdown
Contributor Author

Closing for now: the reporter's test in #305 showed that turning prompt-buffer lending off does not fix the Windows crash, so the lending theory did not hold. The branch stays on our fork in case it is useful later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Engine] gfx1102: 0.2.20-poly.2 crashes in amdhip64_7.dll (0xC0000005 @ 0x2d874a) on first agentic request after expert-cache growth

1 participant