Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WangKunLoveReading opened this issue Jan 4, 2023 · 2 comments

Comments

@WangKunLoveReading
Copy link

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

@Waweshirush
Copy link

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.

@wookayin
Copy link

wookayin commented Nov 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants