gpuopenanalytics / pynvml

Provide Python access to the NVML library for GPU diagnostics
BSD 3-Clause "New" or "Revised" License
205 stars 31 forks source link

`nvmlSystemGetProcessName` fails for WSL #49

Open fostiropoulos opened 11 months ago

fostiropoulos commented 11 months ago

nvmlSystemGetProcessName https://docs.nvidia.com/deploy/nvml-api/group__nvmlSystemQueries.html#group__nvmlSystemQueries_1gf37b04cea12ef2fcf6a463fed1b983b2

Based on the documentation returns the a string encoded in ANSI.

However it is automatically decoded in "utf-8"

https://github.com/gpuopenanalytics/pynvml/blob/43a7803c42358a87e765bb66373f3ae536d589a3/pynvml/nvml.py#L1744

For this reason the function fails in WSL where the returned process name is in ANSI. ANSI encoding is not well-supported in Linux though.

A proposed solution would be to have a special case for windows (it already exists in other parts of the library) or set errors="ignore" for this specific function call (as it appears to be the only encoded in ANSI from the documentation)

Minimal Example

from pynvml.smi import nvidia_smi as smi

import torch
torch.randn(1000).to("cuda")
_instance = smi.getInstance()
# fails here
device = _instance.DeviceQuery()
device["gpu"][0]["processes"]