UPSTREAM PR #20536: ggml/hip: fix APU compatibility - soft error handling for hipMemAdviseSetCoarseGrain - #1255
Open
loci-dev wants to merge 2 commits into
Open
UPSTREAM PR #20536: ggml/hip: fix APU compatibility - soft error handling for hipMemAdviseSetCoarseGrain#1255loci-dev wants to merge 2 commits into
loci-dev wants to merge 2 commits into
Conversation
…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>
|
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 |
loci-dev
force-pushed
the
main
branch
12 times, most recently
from
March 23, 2026 02:17
e6c519b to
59f2b25
Compare
loci-dev
force-pushed
the
main
branch
9 times, most recently
from
March 30, 2026 02:18
89a1190 to
8fec234
Compare
loci-dev
force-pushed
the
main
branch
5 times, most recently
from
April 2, 2026 02:17
6c480d8 to
1497621
Compare
loci-dev
force-pushed
the
main
branch
9 times, most recently
from
April 9, 2026 02:17
a8215be to
34734bc
Compare
loci-dev
force-pushed
the
main
branch
9 times, most recently
from
April 17, 2026 02:18
245e873 to
d101579
Compare
loci-dev
force-pushed
the
main
branch
3 times, most recently
from
April 20, 2026 02:19
7638ab4 to
f1b46d5
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.
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),
hipMemAdviseSetCoarseGrainreturnshipErrorInvalidValuebecause this hint is not applicable to UMA systems. The current code wraps this call inCUDA_CHECK(), which treatsit as a fatal error and crashes.
Fix
Treat
hipMemAdviseSetCoarseGrainas an optional performance hint:CUDA_CHECK()wrapperhipGetLastError()to prevent propagationThis 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
GGML_LOG_DEBUGpre-allocation memory logging to help diagnose memory issues on APU systemstotalGlobalMemin device info struct for future useTesting
Tested on AMD Strix Halo (gfx1151), 128GB unified memory, Windows 11:
hipMemAdviseSetCoarseGrainwithhipErrorInvalidValueContext: ROCm APU Large BAR Bug
AMD APUs on Windows are currently limited to ~64GB
hipMallocManagedallocations due to a ROCm runtime bug wherelargeBar_isunconditionally 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:
Impact
GGML_CUDA_ENABLE_UNIFIED_MEMORY