This is the code:
import pynvml
pynvml.nvmlInit()
# Get handle for GPU 0
handle = pynvml.nvmlDeviceGetHandleByIndex(0)
print(f"==>> handle: {handle}") # <pynvml.LP_struct_c_nvmlDevice_t object at 0x7f88d261c3c0>
# Get all processes using GPU 0
procs = pynvml.nvmlDeviceGetComputeRunningProcesses(handle)
# Display the information for each process
print("GPU 0:")
for proc in procs:
name = pynvml.nvmlSystemGetProcessName(proc.pid)
memory = proc.usedGpuMemory // (1024**2) # Convert bytes to MB
print(f"Process {proc.pid}, name {name}, taking memory {memory} MB.")
pynvml.nvmlShutdown()
Run the code, until handle = pynvml.nvmlDeviceGetHandleByIndex(0)
, it is still normal, but when running at procs = pynvml.nvmlDeviceGetComputeRunningProcesses(handle)
, the ternimal output Segmentation fault (core dumped)
.
My system is Ubuntu 20.04.3 LTS (Focal Fossa) running in the docker container. nvidia-ml-py version I have tried 11.525.150 and 12.560.30, both have this error. The nvidia-smi output is :
From the image, we can also see that the bottom
Processes
row does not show anything