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

fix(libcuda): fix cuDeviceGetUuid() when the UUID contains 0x00 #100

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: debug-statements
- id: double-quote-string-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
rev: v0.0.292
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -34,11 +34,11 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.9.0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.14.0
hooks:
- id: pyupgrade
args: [--py37-plus] # sync with requires-python
Expand All @@ -57,7 +57,7 @@ repos:
^docs/source/conf.py$
)
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: [".[toml]"]
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

-
- Fix `libcuda.cuDeviceGetUuid()` when the UUID contains `0x00` by [@XuehaiPan](https://github.com/XuehaiPan) in [#100](https://github.com/XuehaiPan/nvitop/pull/100).

### Removed

Expand Down
2 changes: 1 addition & 1 deletion nvitop/api/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3182,7 +3182,7 @@ def _cuda_visible_devices_parser(
raise

count = libcuda.cuDeviceGetCount()
uuids = list(map(libcuda.cuDeviceGetUuid, map(libcuda.cuDeviceGet, range(count))))
uuids = [libcuda.cuDeviceGetUuid(libcuda.cuDeviceGet(i)) for i in range(count)]
queue.put(uuids)
return
except Exception as ex: # noqa: BLE001 # pylint: disable=broad-except
Expand Down
8 changes: 4 additions & 4 deletions nvitop/api/libcuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,10 @@ def cuDeviceGetUuid(device: _c_CUdevice_t) -> str:
except CUDAError_NotFound: # noqa: F821 # pylint: disable=undefined-variable
fn = __cudaGetFunctionPointer('cuDeviceGetUuid')

uuid = _ctypes.create_string_buffer(16)
uuid = (_ctypes.c_ubyte * 16)()
ret = fn(uuid, device)
_cudaCheckReturn(ret)
uuid = ''.join(map('{:02x}'.format, uuid.value))
uuid = ''.join(map('{:02x}'.format, uuid))
return '-'.join((uuid[:8], uuid[8:12], uuid[12:16], uuid[16:20], uuid[20:32]))


Expand All @@ -710,10 +710,10 @@ def cuDeviceGetUuid_v2(device: _c_CUdevice_t) -> str:
"""
fn = __cudaGetFunctionPointer('cuDeviceGetUuid_v2')

uuid = _ctypes.create_string_buffer(16)
uuid = (_ctypes.c_ubyte * 16)()
ret = fn(uuid, device)
_cudaCheckReturn(ret)
uuid = ''.join(map('{:02x}'.format, uuid.value))
uuid = ''.join(map('{:02x}'.format, uuid))
return '-'.join((uuid[:8], uuid[8:12], uuid[12:16], uuid[16:20], uuid[20:32]))


Expand Down
2 changes: 1 addition & 1 deletion nvitop/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from termcolor import colored as _colored
except ImportError:

def _colored( # pylint: disable=unused-argument
def _colored( # pylint: disable=unused-argument,too-many-arguments
text: str,
color: str | None = None,
on_color: str | None = None,
Expand Down
8 changes: 4 additions & 4 deletions nvitop/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@


@overload
def select_devices(
def select_devices( # pylint: disable=too-many-arguments
devices: Iterable[Device] | None,
*,
format: Literal['index'], # pylint: disable=redefined-builtin
Expand All @@ -103,7 +103,7 @@ def select_devices(


@overload
def select_devices(
def select_devices( # pylint: disable=too-many-arguments
devices: Iterable[Device] | None,
*,
format: Literal['uuid'], # pylint: disable=redefined-builtin
Expand All @@ -123,7 +123,7 @@ def select_devices(


@overload
def select_devices(
def select_devices( # pylint: disable=too-many-arguments
devices: Iterable[Device] | None,
*,
format: Literal['device'], # pylint: disable=redefined-builtin
Expand All @@ -142,7 +142,7 @@ def select_devices(
...


def select_devices( # pylint: disable=too-many-branches,too-many-statements,too-many-locals,unused-argument
def select_devices( # pylint: disable=too-many-branches,too-many-statements,too-many-locals,unused-argument,too-many-arguments
devices: Iterable[Device] | None = None,
*,
format: Literal['index', 'uuid', 'device'] = 'index', # pylint: disable=redefined-builtin
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ignore = [
# internal use and may never raise at runtime
"S101",
# SIM105: use `contextlib.suppress(...)` instead of try-except-pass
# reduce unnessary function call
# reduce unnecessary function call
"SIM105",
]

Expand Down