You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Issue]: 100% GPU usage and high power draw when creating multiple HW queues with MES on RDNA3 #153
Followup to ROCm/legacy-rocm-build#2625 since further debugging revealed it to be an amdgpu/amdkfd driver issue.
When running llama.cpp's server example on ROCm, using an RDNA3 GPU, GPU usage is shown as 100% and a high power consumption is measured at the wall outlet, even with the server at idle.
Investigating further, it seems that the issue is related to HIP stream usage: GPU usage first shoots up to persistent 100% when llama.cpp tries to create its second HIP stream. If I limit llama.cpp to use only a single stream, then GPU load behaves normally until it begins writing into GPU memory using hipMemcpy or hipMemset, at which point it permanently (EDIT: for the lifetime of the process that performed the hipMemcpy) jumps up to 100%, and stays there until llama.cpp is closed.
In minimal testcases, the following scenarios all yielded 100% GPU usage, despite never actually executing any user code on the GPU:
Creating a HIP stream while another HIP stream is open. Once triggered, closing the HIP streams doesn't help. (If I open a stream and close it, then open another one, with no overlap in time between the 2 streams, the issue isn't seen.)
Writing to GPU memory while a HIP stream is open. Once triggered, neither closing the HIP stream nor deallocating the memory previously written will cause the GPU load to come down, only killing the process helps. (If I close the stream before writing to GPU memory, the issue isn't seen, even if that memory was allocated before or during the stream's lifetime.)
Creating a HIP stream after any GPU memory write has taken place, even if the previously written memory is freed before the stream is created. Once triggered, closing the HIP stream doesn't help.
The issue is reproducible with the latest code in this repository, using ROCm 5.7.1 on a Radeon RX 7900 XT, and also on a Radeon RX 7800 XT.
Setting the module option "sched_policy=2" seems to be a viable workaround, at the cost of slightly higher power consumption when the GPU is fully idle, and the local ttyX consoles becoming laggy. ("sched_policy=1" didn't help.)
Debugging this further, it seems that excessive power usage starts when the offending operation (memory write or stream creation) creates a new HW queue. On RDNA3, this always uses MES, even when mes=0 is specified in the module parameters.
Within the MES code, mes_v11_0_add_hw_queue then calls mes_v11_0_submit_pkt_and_poll_completion, which calls amdgpu_ring_commit. As soon as amdgpu_ring_commit returns, GPU usage spikes to 100%, and remains there, using about 100W of excess power.
Thanks for your report. We've got someone setting up a system internally to reproduce the issue and try to isolate where this GPU usage bug is coming from.
So our dev couldn't repro it with the following config:
OS: Ubuntu 22.04 6.2.0-37-generic
GPU: Radeon PRO W7900 (this is a Navi31 GPU)
DRIVER: ROCm 5.7.1 6.2.4-1664922.22.04
He saw the 100% spikes but the usage went down again afterwards. Can you get the VBIOS for your card? rocm-smi --showvbios should be sufficient, or "dmesg|grep ATOM"
The 100% GPU usage does go back down if the test program exits completely - but only then; this is the issue. It can be made more visible by extending the delay in my minimal testcases at the end of execution to e.g. a minute, which will cause 1 minute of inappropriate 100% GPU load.
rocm-smi --showvbios from system 1 (RX 7900 XT):
========================= ROCm System Management Interface =========================
====================================== VBIOS =======================================
GPU[0] : VBIOS version: 113-D70401-00
====================================================================================
=============================== End of ROCm SMI Log ================================
rocm-smi --showvbios from system 2 (RX 7800 XT):
========================= ROCm System Management Interface =========================
====================================== VBIOS =======================================
GPU[0] : VBIOS version: 113-APM6767CL-100
====================================================================================
=============================== End of ROCm SMI Log ================================
So our dev couldn't repro it with the following config:
He saw the 100% spikes but the usage went down again afterwards.
So it sounds like you can reproduce it? I can also reproduce this issue with a newer kernel on arch linux (Linux 6.6.1-arch1-1) on a 7900 XT (VBIOS version: 113-D70401-00).
Just to be clear the issue is that calling hipStreamCreate shouldn't max out the GPU usage. Even after calling hipStreamDestroy the max usage continues. The only thing that allows the GPU to return to idle is closing the program.
I can reproduce this as well, ASRock 7900 XTX (ref design).
I've used repro1.cpp from the other thread, and I can clearly see in rocm-smi that the GPU usage remains at 100% after the program outputs HIP stream destroyed, waiting 5 more secods. Only when the program finishes, the GPU usage goes down again.
rocm-smi --showvbios
======================= ROCm System Management Interface =======================
==================================== VBIOS =====================================
GPU[0] : VBIOS version: 113-D7020100-102
================================================================================
============================= End of ROCm SMI Log ==============================
I now also tried the minimal testcases with both of my GPUs (6750 XT, 7900 XTX) in the system and only with the 7900 XTX.
I was not really able to reproduce the issue with the minimal testcase when both GPUs are in the system. @Googulator I tried HIP_VISIBLE_DEVICES=<gpu id> to select the device. I'm not sure if that works with the minimal example.
When I removed the 6750 XT I was able to reproduce the issue with repro1.cpp
Additionally I observed that sometimes (I could not reproduce it reliably) the GPU usage stays at 100% even after the process exits. Only after a reboot the usage goes back down.
llama.cpp sitting idling ~140W on 7900 XTX ... this is unacceptable .
As a side note, power limiting overall is way too convoluted (couldn't even set it up) compared to nvidia, where you just do -pl <watts>.
I've found that at least for llama.cpp, setting GPU_MAX_HW_QUEUES=1 in the environment works around this issue with no clear performance impact, but substantial power/thermal budget improvement. I still think this seems like a major issue that should be fixed without obscure environment variables.
Reacted by sirmo, ice0, Laura, Googulator, JustGitting, lin72h, hiepxanh, Teerapol Saengsukhiran, snigavik1982, The Civilized Gamer and 2 more
We're not sure that the patch will fix it, but the patch missed the ROCm 6.0 cutoff, hence it not being here yet.
It'll be in ROCm 6.1 (unless they pick a really weird branching point). It can also be manually applied by editing the file in /usr/src/ and then rebuilding via dkms, if you wanted to give it a shot
What is the actual development repository for the kernel driver then, if not this one? The freedesktop one appears to be a staging repository for patches ready for upstreaming, not actual development.
Right now, the upstream repo (maintained by Alex Deucher) is for the upstream kernel, which is where most of our patches come from. The DKMS code (which is exposed here) is not upstreamable, so we've got KCL (Kernel Compatibility Layer), IPC and RDMA here but not upstream. What happens is that the patches going into amd-staging-drm-next are picked over to this DKMS-supported branch by the KCL team. They adapt all patches to work on the various kernels that we support. Then that internal branch is what's used for ROCm releases, so we can support more OSes than just Ubuntu (or whatever distro supports the latest upstream kernel)
Currently we (more accurately, I) just update the master branch to reflect the latest ROCm release branch at release time, with no real develop branch to speak of. This is primarily because development on the DKMS branch is still done internally. I'm working on seeing if we can try to at least try to mirror the internal mainline branch here as well on some sort of weekly cadence, instead of just dealing with updates at release time, but the process is taking a while. Lots of hoops to jump through.
Just adding to this issue that the issue still persists on ROCm 7.1.1 with Kernel 6.14.0-37 on Ubuntu 24.4 and TensorFlow 2.19.1. HW: RDNA4 (RX 9080 XT, VBIOS version: 115-G295BP00-100)
Here is a repro. The GPU will stay at 100% as long as the process is running:
/*
* Minimal reproducer for ROCm RDNA3/RDNA4 100% GPU usage bug
* https://github.com/ROCm/amdgpu/issues/153
*
* Build: gcc -o gpu_bug_demo gpu_bug_demo.c -I/usr/local/lib/tensorflow-2.19.1/include \
* -L/usr/local/lib/tensorflow-2.19.1/lib -ltensorflow -Wl,-rpath,/usr/local/lib/tensorflow-2.19.1/lib
*
* Run (shows bug): TF_FORCE_GPU_ALLOW_GROWTH=true ./gpu_bug_demo
* Run (workaround): GPU_MAX_HW_QUEUES=3 TF_FORCE_GPU_ALLOW_GROWTH=true ./gpu_bug_demo
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "tensorflow/c/c_api.h"
#include "tensorflow/c/eager/c_api.h"
static void deallocator(void* data, size_t len, void* arg) { free(data); }
int main() {
setbuf(stdout, NULL);
printf("ROCm RDNA 100%% GPU bug reproducer\n\n");
// Create TensorFlow context (triggers HW queue creation)
TF_Status* status = TF_NewStatus();
TFE_ContextOptions* opts = TFE_NewContextOptions();
TFE_Context* ctx = TFE_NewContext(opts, status);
TFE_DeleteContextOptions(opts);
if (TF_GetCode(status) != TF_OK) {
fprintf(stderr, "Error: %s\n", TF_Message(status));
return 1;
}
// Create minimal tensor on GPU (triggers more HW queues)
int64_t dims[] = {2, 2};
float* data = malloc(4 * sizeof(float));
data[0] = 1.0f; data[1] = 2.0f; data[2] = 3.0f; data[3] = 4.0f;
TF_Tensor* t = TF_NewTensor(TF_FLOAT, dims, 2, data, 4 * sizeof(float), deallocator, NULL);
TFE_TensorHandle* h = TFE_NewTensorHandle(t, status);
TFE_TensorHandle* h_gpu = TFE_TensorHandleCopyToDevice(h, ctx, "/device:GPU:0", status);
// One MatMul to ensure GPU is used
TFE_Op* op = TFE_NewOp(ctx, "MatMul", status);
TFE_OpSetDevice(op, "/device:GPU:0", status);
TFE_OpAddInput(op, h_gpu, status);
TFE_OpAddInput(op, h_gpu, status);
TFE_TensorHandle* result;
int n = 1;
TFE_Execute(op, &result, &n, status);
// Sync GPU
TF_Tensor* rt = TFE_TensorHandleResolve(result, status);
TF_DeleteTensor(rt);
printf("Computation done. GPU should be idle but isn't.\n");
printf("Check with: rocm-smi --showuse\n");
printf("Press Ctrl+C to exit.\n\n");
// Sleep - GPU stays at 100% even though nothing is running
while (1) sleep(1);
return 0;
}
Just adding to this issue that the issue still persists on ROCm 7.1.1 with Kernel 6.14.0-37 on Ubuntu 24.4 and TensorFlow 2.19.1. HW: RDNA4 (RX 9080 XT, VBIOS version: 115-G295BP00-100)
Sad to hear, but at least we have RX 9080 XT confirmed😁
Activity
kentrussell commentedon Nov 14, 2023
Thanks for your report. We've got someone setting up a system internally to reproduce the issue and try to isolate where this GPU usage bug is coming from.
Googulator commentedon Nov 21, 2023
Are there any updates? Were you successful in reproducing this?
kentrussell commentedon Nov 21, 2023
I'll try to get an update from the dev who was assigned to repro it.
EDIT: The dev assigned to it was a bit backlogged but he's getting on reproducing it this week. Thanks for your patience!
kentrussell commentedon Nov 23, 2023
So our dev couldn't repro it with the following config:
OS: Ubuntu 22.04 6.2.0-37-generic
GPU: Radeon PRO W7900 (this is a Navi31 GPU)
DRIVER: ROCm 5.7.1 6.2.4-1664922.22.04
He saw the 100% spikes but the usage went down again afterwards. Can you get the VBIOS for your card? rocm-smi --showvbios should be sufficient, or "dmesg|grep ATOM"
Googulator commentedon Nov 24, 2023
The 100% GPU usage does go back down if the test program exits completely - but only then; this is the issue. It can be made more visible by extending the delay in my minimal testcases at the end of execution to e.g. a minute, which will cause 1 minute of inappropriate 100% GPU load.
rocm-smi --showvbios from system 1 (RX 7900 XT):
rocm-smi --showvbios from system 2 (RX 7800 XT):
lufixSch commentedon Dec 2, 2023
Any updates on this? I am observing the same issue with llama.cpp on my RX 7900 XTX
I'm adding my
rocm-smi --showvbiosas well. Maybe it helps.rocm-smi
GPU0 is the 7900 XTX. GPU1 is a 6750 XT (there is no issue with this one)gartnera commentedon Dec 3, 2023
So it sounds like you can reproduce it? I can also reproduce this issue with a newer kernel on arch linux (
Linux 6.6.1-arch1-1) on a 7900 XT (VBIOS version: 113-D70401-00).Just to be clear the issue is that calling
hipStreamCreateshouldn't max out the GPU usage. Even after callinghipStreamDestroythe max usage continues. The only thing that allows the GPU to return to idle is closing the program.gotzl commentedon Dec 5, 2023
I can reproduce this as well, ASRock 7900 XTX (ref design).
I've used
repro1.cppfrom the other thread, and I can clearly see inrocm-smithat the GPU usage remains at 100% after the program outputsHIP stream destroyed, waiting 5 more secods. Only when the program finishes, the GPU usage goes down again.rocm-smi --showvbios
lufixSch commentedon Dec 6, 2023
I now also tried the minimal testcases with both of my GPUs (6750 XT, 7900 XTX) in the system and only with the 7900 XTX.
I was not really able to reproduce the issue with the minimal testcase when both GPUs are in the system. @Googulator I tried
HIP_VISIBLE_DEVICES=<gpu id>to select the device. I'm not sure if that works with the minimal example.When I removed the 6750 XT I was able to reproduce the issue with
repro1.cppAdditionally I observed that sometimes (I could not reproduce it reliably) the GPU usage stays at 100% even after the process exits. Only after a reboot the usage goes back down.
kentrussell commentedon Dec 6, 2023
@Ori-Messinger Any progress on this one? I know you've got a bunch of issues to repro ATM
tada123 commentedon Dec 12, 2023
I also face the same issue on
Linux archlinux-pc 6.1.67-1-lts #1 SMP PREEMPT_DYNAMIC Mon, 11 Dec 2023 12:58:39 +0000 x86_64 GNU/LinuxwithThe problem disappears when using
linux-ltsolder kernel.Also, diff between
rocminfooutput on different kernels looks like this:morphles commentedon Dec 21, 2023
llama.cpp sitting idling ~140W on 7900 XTX ... this is unacceptable .
As a side note, power limiting overall is way too convoluted (couldn't even set it up) compared to nvidia, where you just do
-pl <watts>.65a commentedon Dec 31, 2023
This also affects W7900 cards on ROCm 6.0, kernel 6.6.8. A solution is desirable to avoid burning electricity and creating heat for no reason.
99W draw with nothing in VRAM and inference not running.
radeontopreports Graphics Pipe, Clip Rectangle and Shader Clock at 100%.EDIT: Filed https://gitlab.freedesktop.org/drm/amd/-/issues/3080 to ensure this is also on the radar there.
65a commentedon Jan 1, 2024
I've found that at least for llama.cpp, setting
GPU_MAX_HW_QUEUES=1in the environment works around this issue with no clear performance impact, but substantial power/thermal budget improvement. I still think this seems like a major issue that should be fixed without obscure environment variables.Googulator commentedon Jan 21, 2024
Is this commit intended to be a fix for this issue?
https://gitlab.freedesktop.org/agd5f/linux/-/commit/7e505b272c7adb68c5353944eda4befb95e83935
I haven't been able to find it in this repository, only on the Freedesktop one.
kentrussell commentedon Jan 29, 2024
We're not sure that the patch will fix it, but the patch missed the ROCm 6.0 cutoff, hence it not being here yet.
It'll be in ROCm 6.1 (unless they pick a really weird branching point). It can also be manually applied by editing the file in /usr/src/ and then rebuilding via dkms, if you wanted to give it a shot
Googulator commentedon Jan 30, 2024
What is the actual development repository for the kernel driver then, if not this one? The freedesktop one appears to be a staging repository for patches ready for upstreaming, not actual development.
kentrussell commentedon Jan 30, 2024
We're working on that currently.
Right now, the upstream repo (maintained by Alex Deucher) is for the upstream kernel, which is where most of our patches come from. The DKMS code (which is exposed here) is not upstreamable, so we've got KCL (Kernel Compatibility Layer), IPC and RDMA here but not upstream. What happens is that the patches going into amd-staging-drm-next are picked over to this DKMS-supported branch by the KCL team. They adapt all patches to work on the various kernels that we support. Then that internal branch is what's used for ROCm releases, so we can support more OSes than just Ubuntu (or whatever distro supports the latest upstream kernel)
Currently we (more accurately, I) just update the master branch to reflect the latest ROCm release branch at release time, with no real develop branch to speak of. This is primarily because development on the DKMS branch is still done internally. I'm working on seeing if we can try to at least try to mirror the internal mainline branch here as well on some sort of weekly cadence, instead of just dealing with updates at release time, but the process is taking a while. Lots of hoops to jump through.
Wintoplay commentedon Mar 9, 2024
@65a Thank, It works.
kentrussell commentedon Jun 20, 2024
We've got an RLC FW fix coming in ROCm 6.2 that should also work to address this issue.
Marcel2508 commentedon Feb 7, 2025
Hey, is this issue still persistent, how have you solved it? I've got an ACER Nitro AMD Radeon RX 7600 XT OC and I observed the issue with Debian 12 (Kernel 6.1), Ubuntu 24.04 (Kernel 6.8) - and on windows. But only after installing the rocm library (specifically the amdgpu-dkms driver)..
I was not able yet to find a solution (tested rocm versions 6.3, 6.2, 5.7) as explained here: https://rocm.docs.amd.com/projects/install-on-linux/en/latest/install/quick-start.html or here: https://rocm.docs.amd.com/projects/install-on-linux/en/docs-6.2.4/install/quick-start.html
papillon commentedon Jan 10, 2026
Just adding to this issue that the issue still persists on ROCm 7.1.1 with Kernel 6.14.0-37 on Ubuntu 24.4 and TensorFlow 2.19.1. HW: RDNA4 (RX 9080 XT, VBIOS version: 115-G295BP00-100)
Here is a repro. The GPU will stay at 100% as long as the process is running:
adsick commentedon Apr 24, 2026
Sad to hear, but at least we have RX 9080 XT confirmed😁
ggml-cuda : no stream created for a size query or a synchronize with …