Repository navigation
ROCm Linux: rebuild libhsa-runtime64 with the KFD CWSR wave count - #255
Conversation
TheRock 7.14 and later (rocm-systems 745ebf1) size each queue's CWSR debug area from KFD topology, while amdkfd keeps 32 waves per CU below gfx1250. When the two disagree amdkfd refuses the queue and llama.cpp aborts with "ROCm error: out of memory" at hipStreamCreateWithFlags (unslothai/unsloth#12205, ROCm/TheRock#7472). Rebuild only libhsa-runtime64 from the nightly's own rocm-systems pin with the ROCm/rocm-systems#11299 wave count, check it exports every ROCR symbol the shipped one does and that libamdhip64 resolves against it, and replace every copy in the bundle.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b69ba4b52
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if new in text: | ||
| sys.exit("the pinned rocm-systems already carries the fix: delete this step") |
There was a problem hiding this comment.
Preserve already-compatible ROCm pins
When a caller selects a historical rocm_version from before rocm-systems commit 745ebf1, queues.c already contains this 32-wave branch, so new in text terminates the job instead of leaving the compatible runtime unchanged. Explicit version pins are a documented workflow input (the input description even gives a dated version), so rebuilding such a release now always fails; treat the already-patched text as a no-op and only rebuild when the vulnerable old form is present.
Useful? React with 👍 / 👎.
The disagreeing parts are gfx10.1 (40 waves per CU), which reach a Linux bundle through HSA_OVERRIDE_GFX_VERSION=10.3.0 on the gfx103X bundle. Every other leg serves GPUs that report 32 waves per CU, so keep TheRock's library byte for byte there.
Summary
Linux ROCm prebuilds ship TheRock's
libhsa-runtime64unchanged. Since TheRock 7.14 (rocm-systems 745ebf1, ROCm/rocm-systems#6125), its libhsakmt sizes each queue's CWSR debug area from KFD topology,cu_count * simd_per_cu * max_waves_per_simd, while amdkfd (kfd_queue.cget_num_waves) still usescu_count * 32below gfx1250. Since Linux 6.12 (629568d25fea) amdkfd validates that area when a queue is created:kfd_queue_buffer_get) the mapping must match exactly, so any disagreement is refused;kfd_queue_buffer_svm_get) the range only has to cover the expected size, so only a smaller area is refused.HIP reports a refused queue as
ROCm error: out of memoryat the firsthipStreamCreateWithFlags, before any model memory is touched. This is ROCm/TheRock#7472 (gfx1012, Linux 6.12). The upstream fix, ROCm/rocm-systems#11299, is open and not merged. As of10.2.0a20261009(rocm-systems8a343ff) the nightlies, rocm-systemsdevelopandtherock-10.1all still have the topology formula, and the kernel (mainline and amd-staging-drm-next) still uses 32.Who is affected
rocminfo
Max Waves Per CU(simd_per_cu * max_waves_per_simd, from the IP discovery table) is 32 on every gfx10.3, gfx11 and gfx12 part we found reports for, so those match amdkfd today. The parts that disagree are gfx10.1, which report 40:We do not publish a gfx101x bundle, so this reaches users who run the
gfx103Xbundle on a Navi1x card withHSA_OVERRIDE_GFX_VERSION=10.3.0, a common workaround, on Linux 6.12 or newer when the save area takes the non-SVM path. It also guards any future part whose firmware reports a value other than 16 waves per SIMD.This does not explain unslothai/unsloth#12205: the Radeon 680M (gfx1035) reports 32 waves per CU, so it has no mismatch. That issue is still being investigated separately.
Change
One new step in the Linux
gfx103Xleg only, after the ROCm libraries are copied and before RPATH is set. That is the only bundle a gfx10.1 card reaches (throughHSA_OVERRIDE_GFX_VERSION=10.3.0); the gfx110X, gfx1150, gfx1151, gfx120X, gfx908 and gfx90a bundles keep TheRock's library byte for byte.rocm-systemspin (and any TheRock patches) from/opt/rocm/share/therock/therock_manifest.json.projects/rocr-runtimeat that pin, apply TheRock's patches, then the fix(hsakmt): match KFD CWSR wave sizing before gfx1250 ROCm/rocm-systems#11299 change:wave_num = cu_num * 32forgfxv < GFX_VERSION_GFX1250. The step fails loudly if the pin already carries it orget_num_waves()changed upstream.hsa-runtime64with the nightly's own clang and its bundled sysdeps (rocm_sysdepsheaders and pkgconfig), so it links the samelibrocm_sysdeps_*as the shipped library.ROCR_*export the shipped one has, or iflibamdhip64.so.7has undefined symbols against it. Then replace everylibhsa-runtime64.so*copy in the bundle (the earlier copy flattens the symlinks into three files). The existing bundle completeness check still runs afterwards.Windows legs are untouched: they ship no ROCr.
Testing
b11160-mix-a6922ccis code-identical (.text/.rodata/.dynsym) to TheRock10.1.0a20260822, pind134b78, which contains 745ebf1.run:script of this step, extracted from the YAML, was run against that nightly and a copy of the shipped gfx1151 bundle: pin read from the manifest, patch applied, build OK, 280 of 280ROCR_*exports present,ldd -rclean, all three library copies replaced.10.2.0a20261009(pin8a343ff): its TheRock rocm-systems patch and the wave count patch both apply with the step's sparse checkout. Not built.ubuntu-22.04build, then a gfx1151 (Strix Halo) differential run: https://github.com/oobabooga/unsloth/actions/runs/37787382574.max_waves_per_simdwas fed to libhsakmt through anfopenshim while amdkfd kept its real value (16), recreating the gfx10.1 disagreement (20) and the opposite one (8). Each runtime ranllama-completionon a tiny GGUF with-ngl 99:HSA_USE_SVM=0HSA_USE_SVM=0out of memoryathipStreamCreateWithFlagsout of memoryathipStreamCreateWithFlagslibhsa-runtime64in the shipped gfx1151 bundle, real topology, Llama-3.2-1B Q4_K_M (https://github.com/oobabooga/unsloth/actions/runs/37939121351). Both arms fully on the GPU (34 layers on ROCm0, none on CPU), each loading its own runtime:llama-server --parallel 4, 8 concurrent requestsllama-benchpp512, ABBA x3, median (min-max)llama-benchtg128, ABBA x3, median (min-max)Not covered
gfx103Xbundle itself on RDNA2 hardware: the rebuilt runtime is the same file for every bundle, but it only ran inside the gfx1151 bundle.