fbcotter / py3nvml

Python 3 Bindings for NVML library. Get NVIDIA GPU status inside your program.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

the type of nvmlDeviceGetPciInfo(handle).busId is "bytes" not "str"

WangKunLoveReading opened this issue · comments

When I call nvmlDeviceGetPciInfo(handle) function the "busId" is "bytes" not "str"

 handle = nvmlDeviceGetHandleByIndex(i)
 devId = nvmlDeviceGetPciInfo(handle).busId

The whole nvmlPciInfo_t is:

nvmlPciInfo_t(busId: b'0000:00:0A.0', domain: 0x0000, bus: 0x00, device: 0x0A, pciDeviceId: 0x1EB810DE, pciSubSystemId: 0x12A210DE, reserved0: 0, reserved1: 0, reserved2: 0, reserved3: 0)

This line converts c_info to "str", but "busId" is "bytes"
https://github.com/fbcotter/py3nvml/blob/master/py3nvml/py3nvml.py#L2646

Is it expected output?

My test environment is python3.6

It looks like nvmlDeviceGetPciInfo is returning an instance of nvmlPciInfo_t, which has a busId field that is a bytes object. This is the expected behavior, as the busId field represents the PCI bus identifier of the device and it is typically stored as a string of hexadecimal digits.

If you want to convert the busId field to a string, you can use the decode method of the bytes object. For example:

devId = nvmlDeviceGetPciInfo(handle).busId.decode('utf-8')

This will convert the busId field to a string encoded in UTF-8. You can use a different encoding if necessary.

It looks like the code you provided is trying to convert the entire nvmlPciInfo_t object to a string, but this may not work as expected because the nvmlPciInfo_t object contains fields of different types (e.g. busId is bytes, domain is an integer, etc.). It might be better to manually extract the individual fields of the nvmlPciInfo_t object and convert them to strings as needed.

Don't use this one. This is an outdated project and no longer valid. You should use the official bindings nvidia-ml-py.