Skip to content

feat: AMD Instinct MI300X + MI355X (gfx942/gfx950) ROCm support - #61

Merged
TheTom merged 2 commits into
TheTom:feature/turboquant-kv-cachefrom
andyluo7:add-rocm-mi300x-support
Apr 9, 2026
Merged

TheTom merged 2 commits into
TheTom:feature/turboquant-kv-cachefrom
andyluo7:add-rocm-mi300x-support

Conversation

@andyluo7

@andyluo7 andyluo7 commented Apr 7, 2026 •

Copy link
Copy Markdown

Summary

TurboQuant KV cache compression works on AMD Instinct datacenter GPUs:

  • MI300X (gfx942): Zero code changes — compiles and runs via HIP translation
  • MI355X (gfx950): Adds CDNA4 arch defines (5 files, ~20 lines changed)

Code Changes (gfx950 only)

File Change
vendors/hip.h Add CDNA4 define for __gfx950__, include in CDNA family
common.cuh Add GGML_CUDA_CC_CDNA4 constant + IS_CDNA4 macro
mma.cuh Route CDNA4 to compatible MFMA (bf16_1k, i32x32, f32x4 — NOT xf32)
mmq.cuh Include CDNA4 in stream-k dispatch
common.cuh Exclude CDNA4 from CDNA3-specific e4m3_fnuz FP8 path

Test Results

MI300X (gfx942, ROCm 7.0.2)

KV Cache pp512 (tok/s) tg128 (tok/s) vs f16 prefill vs f16 decode
f16 24,453 ± 230 181.2 ± 2.0 baseline baseline
turbo3 ~25,200 ~160 +3% 88%
turbo4 25,427 ± 17 161.1 ± 0.2 +4% 89%

MI355X (gfx950, ROCm 7.0.1)

KV Cache pp512 (tok/s) tg128 (tok/s) vs f16 prefill vs f16 decode
f16+FA 40,013 ± 902 254.5 ± 1.0 baseline baseline
turbo3 39,140 ± 475 162.3 ± 0.1 98% 64%
turbo4 39,232 ± 508 214.1 ± 0.7 98% 84%

WHT Kernel Correctness

Roundtrip max error: 2.980232e-07 — PASS ✅

Known Issues

  • MI355X non-FA MMQ crashes (xf32 MFMA unsupported on gfx950). TurboQuant types force FA and work correctly.
  • This is a pre-existing upstream llama.cpp issue, not TurboQuant-specific.

Environment

  • MI300X: gfx942, 192 GB HBM3, ROCm 7.0.2
  • MI355X: gfx950, 288 GB HBM3e, ROCm 7.0.1
  • Model: Qwen2.5-1.5B-Instruct Q4_K_M

TurboQuant KV cache compression (turbo2/turbo3/turbo4) builds and runs
correctly on AMD Instinct MI300X with ROCm 7.0.2. Zero code changes
required — existing CUDA kernels compile via HIP translation.

Test results (Qwen2.5-1.5B Q4_K_M, single MI300X):
- WHT roundtrip: PASS (max error 2.98e-07)
- turbo3 prefill: +3% vs f16 (25,200 vs 24,453 tok/s)
- turbo3 decode: 88% of f16 (160 vs 181 tok/s)
- turbo4 prefill: +4% vs f16 (25,427 vs 24,453 tok/s)
- turbo4 decode: 89% of f16 (161 vs 181 tok/s)

MI355X (gfx950) compiles but needs gfx950 added to llama.cpp's
MMQ kernel dispatch (upstream issue, not TurboQuant-specific).

Tested-by: Andy Luo <[email protected]>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Apr 7, 2026
Add AMD Instinct MI355X (gfx950) architecture support:

Code changes:
- vendors/hip.h: Add CDNA4 define for __gfx950__, include in CDNA family
- common.cuh: Add GGML_CUDA_CC_CDNA4 constant and IS_CDNA4 macro
- mma.cuh: Route CDNA4 to compatible MFMA instructions
  * bf16: mfma_f32_16x16x16bf16_1k (same as CDNA3)
  * int8: mfma_i32_16x16x32_i8 (same as CDNA3)
  * f32: mfma_f32_16x16x4f32 (CDNA2 path, NOT xf32 which doesn't exist on gfx950)
- mmq.cuh: Include CDNA4 in stream-k dispatch
- common.cuh: Exclude CDNA4 from CDNA3-specific e4m3_fnuz FP8 path (gfx950 uses standard e4m3fn)

MI355X test results (Qwen2.5-1.5B Q4_K_M, single GPU):
- turbo3: 39,140 tok/s prefill (98% of f16), 162 tok/s decode (64%)
- turbo4: 39,232 tok/s prefill (98% of f16), 214 tok/s decode (84%)
- WHT roundtrip: PASS (max error 2.98e-07)

Note: non-FA MMQ path crashes on gfx950 (xf32 MFMA unsupported).
TurboQuant types force FA and work correctly.

Tested-by: Andy Luo <[email protected]>
@andyluo7 andyluo7 changed the title docs: AMD Instinct MI300X (gfx942) ROCm test results feat: AMD Instinct MI300X + MI355X (gfx942/gfx950) ROCm support Apr 7, 2026
@TheTom
TheTom force-pushed the feature/turboquant-kv-cache branch from 10cb187 to 0d6b38a Compare April 8, 2026 23:49
@TheTom

TheTom commented Apr 9, 2026

Copy link
Copy Markdown
Owner

Thanks for the added AMD Instinct support! Built locally on M5 Max (Metal) for posterity — clean build, binary loads, no regressions on the Mac side. The CDNA4 changes are properly gated behind __gfx950__ so zero impact on Metal/CUDA paths. Merging.

@TheTom
TheTom merged commit 157cb85 into TheTom:feature/turboquant-kv-cache Apr 9, 2026
1 check passed
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
…Erkenntnissen aktualisiert

AtomicBot-ai#58 KV Cache Size Limiting:
- Status ☐→⏭️ (verschoben)
- PR ggml-org#18747 ist noch OPEN (nicht gemerged)
- TurboQuant (bereits vorhanden) ist komplementär und höhere Priorität
- PR liefert nur Infrastruktur, keine echten PagedAttention-Benefits

AtomicBot-ai#61 Persistent VRAM Expert Cache:
- PR ggml-org#23170 ist 'no-op when made correct' (RFC ggml-org#24528)
- Eigentliche Lösung: PR ggml-org#24524 (closed, 2222 Zeilen, invertiertes
  execution model, MUL_MAT_ID auf CPU, GPU cached rows parallel)
- 10% Experten → 80% cache hits, Top 30% → 95% hits
- arXiv: ProMoE, MoE-Infinity, DuoServe-MoE, Caching Analysis
- Empfehlung: PR ggml-org#24524 Design manuell portieren (1-2 Wochen)
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
…at_id / scheduler integration

Portiert PR ggml-org#24524 (leloch) Commit 1/3: Backend-agnostische Function-Table
(ggml_moe_cache, zero-initialized) als Brücke zwischen ggml-cpu und CUDA-Backend.

- ggml-backend-moe-cache.h (neu, 95 Zeilen): struct ggml_moe_cache_api mit
  begin/plan/dispatch/collect/stats/redirect_offer/redirect_finalize/
  glu_hits/invalidate/node_time. Zero-initialized global, populated by CUDA
  backend at registry time.
- ggml-cpu.c (+71 Zeilen): Thread 0 in mul_mat_id partitioniert hits/misses
  gegen cache, dispatcht hit-rows als batched GPU launch, andere Threads
  berechnen miss-rows. Collect am Ende synchronisiert GPU results in dst.
  Sentinel-id Handling (i02 < 0 → zero dst row).
- ops.cpp (+13 Zeilen): swiglu_f32 glu_hits mask — überspringt dst rows die
  cache fused auf GPU berechnet hat.
- ggml-backend.cpp (+59 Zeilen): invalidate hook in buffer_free,
  redirect_offer vor CPU split, redirect_finalize an consumer copy site.

Ohne CUDA-Backend: alle Hooks sind null-check no-ops (zero-initialized).
Build grün auf Hydra (CUDA+CPU). Keine Verhaltensänderung ohne Registration.

ROADMAP AtomicBot-ai#61 Status: ☐ → 🔄. Session-Plan hinzugefügt.
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
Portiert PR ggml-org#24524 (leloch) Commit 2/3: Vollständige CUDA-Implementierung
des persistenten VRAM Expert Cache.

- moe-cache.cu (neu, 1771 Zeilen): Per-(expert_size,type) slot pools mit
  LRU-Eviction, async pinned-staging insert workers, idle-time prefetch
  backfill, hot-set persistence across runs. Paired gate+up pools mit
  fused gate+up+SwiGLU batched matvec. GPU-resident dst handoff für down
  projections via pinned relay image + stream-ordered events. Decode-only
  fill, stable shape census, role-group budgeting. Baseline-sampled
  bail-out judge. CUDA errors degradieren zu CPU path.
- moe-cache.cuh (neu, 20 Zeilen): Registration entry point.
- mmvq.cu (+33 Zeilen): ggml_cuda_moe_cache_mmv — batched matvec über
  slot-pool experts mit device-side index array, optional gate fusion.
- mmvq.cuh (+15 Zeilen): Declaration.
- ggml-cuda.cu (+13 Zeilen): Include moe-cache.cuh, pool OOM trim hook
  (ggml_moe_cache_trim), registration in ggml_backend_cuda_reg.

Aktiviert via GGML_CUDA_MOE_CACHE=1 env var. Build grün auf Hydra
(CUDA+CPU, RTX 3070 Ampere). Ohne env var: Cache inaktiv, kein
Verhaltensänderung.
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
…he removal

Portiert PR ggml-org#24524 Commit 3/3 + Fork-spezifisches Cleanup:

- arg.cpp (+27 Zeilen): --moe-cache N CLI flag (0=off, N=VRAM budget MiB,
  absent=auto). Setzt GGML_CUDA_MOE_CACHE / GGML_CUDA_MOE_CACHE_BUDGET_MB
  env vars vor Backend-Registration.
- fit.cpp (+109 Zeilen): MoE-cache-aware fit placement. Bei heavily-spilling
  MoE Modellen (model_bytes >= 1.8x usable VRAM) bevorzugt fit alle Experten
  auf der CPU zu lassen — der dynamische Cache nutzt die freie VRAM besser
  als statisches partial placement. Expert-size gate verhindert falsche
  Entscheidung bei kleinen Experten.
- ggml-backend.cpp (-124 Zeilen): LFRU Expert Cache Code entfernt
  (expert_cache_enabled, expert_cache_hits/misses, expert_valid, tensor_copied,
  valid_bitset, GGML_EXPERT_CACHE env var). Dead code mit 0% hit-rate.
  thecodacus Prefetch (prefetch_experts) BLEIBT unangetastet.

Build grün auf Hydra (CUDA+CPU). test-backend-ops läuft durch ohne Crash.
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
…Cache implementiert

ROADMAP AtomicBot-ai#61 Status: 🔄 → ✅. Benchmark Styx: 37.8% hit-rate, bail-out
korrekt auf Pascal (GTX 1070 zu langsam für kleine Expert-Matvecs).
Cache designed für Ampere+ GPUs. Safety rails funktionieren wie designed.
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
… maps (UAF, state leaks)

P0 AtomicBot-ai#1 (Use-After-Free): invalidate() cleared only role_base but left
blk_down_base/blk_down_kb/blk_pair_pool/blk_down_pool stale. After a host
buffer free, moe_cache_backfill_next() would build jobs reading from freed
memory. Now clears ALL per-blk pointers that point into the freed range and
resets pool indices to -1 for affected blocks.

P1 AtomicBot-ai#3 (State leaks on model unload): glu_learn, learn_gate_dst,
learn_up_dst, redirect, g_disc (seen/pending/stable_count/any_repeat) and
backfill cursor survived invalidate() — a new model loaded at the same
addresses would hit stale learned entries and pool decisions. All cleared
now.

P2 AtomicBot-ai#7: removed unused 'self' variable in moe_cache_begin(). Added comment
documenting the owner-lock limitation (P1 AtomicBot-ai#4: not reset on model reload —
acceptable for one-model-per-process, the common case).
NighmareGit referenced this pull request in NighmareGit/atomic-llama-cpp-turboquant Aug 1, 2026
…, multi-chunk UDP hop (LEDGER AtomicBot-ai#61, KILLED at coherence gate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ggml Nvidia GPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants