Skip to content

UPSTREAM PR #20536: ggml/hip: fix APU compatibility - soft error handling for hipMemAdviseSetCoarseGrain - #1255

Open
loci-dev wants to merge 2 commits into
mainfrom
loci/pr-20536-fix-hip-apu-compatibility
Open

UPSTREAM PR #20536: ggml/hip: fix APU compatibility - soft error handling for hipMemAdviseSetCoarseGrain#1255
loci-dev wants to merge 2 commits into
mainfrom
loci/pr-20536-fix-hip-apu-compatibility

Conversation

@loci-dev

Copy link
Copy Markdown

Note

Source pull request: ggml-org/llama.cpp#20536

Description:

Problem

On AMD APU/iGPU devices (unified memory architecture, e.g. AMD Strix Halo gfx1151), hipMemAdviseSetCoarseGrain returns
hipErrorInvalidValue because this hint is not applicable to UMA systems. The current code wraps this call in CUDA_CHECK(), which treats
it as a fatal error and crashes.

Fix

Treat hipMemAdviseSetCoarseGrain as an optional performance hint:

  • Remove CUDA_CHECK() wrapper
  • Clear any resulting error with hipGetLastError() to prevent propagation

This matches the intent of the existing comment ("fall back to cudaMalloc if not supported") and is consistent with how optional hints are
handled elsewhere.

Additional Changes

  • Add GGML_LOG_DEBUG pre-allocation memory logging to help diagnose memory issues on APU systems
  • Store totalGlobalMem in device info struct for future use

Testing

Tested on AMD Strix Halo (gfx1151), 128GB unified memory, Windows 11:

  • ✅ Before: crash on hipMemAdviseSetCoarseGrain with hipErrorInvalidValue
  • ✅ After: runs successfully, no error propagation

Context: ROCm APU Large BAR Bug

AMD APUs on Windows are currently limited to ~64GB hipMallocManaged allocations due to a ROCm runtime bug where largeBar_ is
unconditionally disabled for all APU devices in HIP mode. This causes the Windows GART allocator's 50%-of-RAM cap to trigger prematurely.

A fix has been submitted to ROCm upstream:
ROCm/rocm-systems#4077

Without that ROCm fix, APUs are still limited to ~64GB regardless of this change. However, this PR is independently valuable:

  1. Prevents crashes on APUs with current ROCm versions
  2. Enables full functionality once users update to a patched ROCm runtime
  3. The debug logging helps users diagnose memory allocation issues

Impact

  • ✅ APU/iGPU users: no more crashes when using GGML_CUDA_ENABLE_UNIFIED_MEMORY
  • ✅ Discrete GPU users: no change (hint is valid and still applied)
  • ✅ No performance regression

moonshadow-25 and others added 2 commits March 14, 2026 12:47
…eSetCoarseGrain

On AMD APU/iGPU devices (unified memory architecture), hipMemAdviseSetCoarseGrain
returns hipErrorInvalidValue because the hint is not applicable to UMA systems.
The previous CUDA_CHECK() call treated this as a fatal error, causing crashes on
APU systems such as AMD Strix Halo (gfx1151).

Fix: treat hipMemAdviseSetCoarseGrain as an optional performance hint - call it
without error checking and clear any resulting error with hipGetLastError().

Also add pre-allocation debug logging (GGML_LOG_DEBUG) to help diagnose memory
issues on APU systems, and store totalGlobalMem in device info.

Context: AMD APUs on Windows are affected by a ROCm runtime bug that limits
hipMallocManaged to ~64GB regardless of available system RAM. A fix has been
submitted upstream: ROCm/rocm-systems#4077

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@loci-review

loci-review Bot commented Mar 15, 2026

Copy link
Copy Markdown

No meaningful performance changes were detected across 120078 analyzed functions in the following binaries: build.bin.llama-tts, build.bin.libmtmd.so, build.bin.libllama.so, build.bin.llama-bench, build.bin.llama-cvector-generator, build.bin.llama-quantize, build.bin.llama-qwen2vl-cli, build.bin.llama-tokenize, build.bin.llama-gemma3-cli, build.bin.llama-gguf-split, build.bin.llama-llava-cli, build.bin.llama-minicpmv-cli, build.bin.libggml-base.so, build.bin.libggml-cpu.so, build.bin.libggml.so.

🔎 Full breakdown: Loci Inspector
💬 Questions? Tag @loci-dev

@loci-dev
loci-dev force-pushed the main branch 12 times, most recently from e6c519b to 59f2b25 Compare March 23, 2026 02:17
@loci-dev
loci-dev force-pushed the main branch 9 times, most recently from 89a1190 to 8fec234 Compare March 30, 2026 02:18
@loci-dev
loci-dev force-pushed the main branch 5 times, most recently from 6c480d8 to 1497621 Compare April 2, 2026 02:17
@loci-dev
loci-dev force-pushed the main branch 9 times, most recently from a8215be to 34734bc Compare April 9, 2026 02:17
@loci-dev
loci-dev force-pushed the main branch 9 times, most recently from 245e873 to d101579 Compare April 17, 2026 02:18
@loci-dev
loci-dev force-pushed the main branch 3 times, most recently from 7638ab4 to f1b46d5 Compare April 20, 2026 02:19
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.

2 participants