-
Notifications
You must be signed in to change notification settings - Fork 242
cuda.core.system: More basic device-related APIs #1462
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -332,24 +332,48 @@ cdef class Device: | |||||||||||||
|
|
||||||||||||||
| cdef intptr_t _handle | ||||||||||||||
|
|
||||||||||||||
| def __init__(self, index: int | None = None, uuid: bytes | str | None = None): | ||||||||||||||
| def __init__( | ||||||||||||||
| self, | ||||||||||||||
| *, | ||||||||||||||
| index: int | None = None, | ||||||||||||||
| uuid: bytes | str | None = None, | ||||||||||||||
| pci_bus_id: bytes | str | None = None, | ||||||||||||||
| handle: int | None = None | ||||||||||||||
|
||||||||||||||
| ): | ||||||||||||||
|
Comment on lines
+335
to
+342
|
||||||||||||||
| args = [index, uuid, pci_bus_id, handle] | ||||||||||||||
| arg_count = sum(x is not None for x in args) | ||||||||||||||
|
|
||||||||||||||
| initialize() | ||||||||||||||
|
|
||||||||||||||
| if index is not None and uuid is not None: | ||||||||||||||
| raise ValueError("Handle requires only one of either device `index` or `uuid`.") | ||||||||||||||
| if index is None and uuid is None: | ||||||||||||||
| raise ValueError("Handle requires either a device `index` or `uuid`.") | ||||||||||||||
| if arg_count > 1: | ||||||||||||||
| raise ValueError("Handle requires only one of either device `index`, `uuid`, `pci_bus_id` or `handle`.") | ||||||||||||||
| if arg_count == 0: | ||||||||||||||
| raise ValueError("Handle requires either a device `index`, `uuid`, `pci_bus_id` or `handle`.") | ||||||||||||||
|
Comment on lines
+349
to
+351
|
||||||||||||||
| raise ValueError("Handle requires only one of either device `index`, `uuid`, `pci_bus_id` or `handle`.") | |
| if arg_count == 0: | |
| raise ValueError("Handle requires either a device `index`, `uuid`, `pci_bus_id` or `handle`.") | |
| raise ValueError("Device initialization requires exactly one of `index`, `uuid`, `pci_bus_id`, or `handle`.") | |
| if arg_count == 0: | |
| raise ValueError("Device initialization requires one of `index`, `uuid`, `pci_bus_id`, or `handle` to be specified.") |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new get_device_count class method lacks test coverage. Since other similar methods in this file have comprehensive test coverage, consider adding a test to validate this method works correctly and returns the expected device count.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||
| pytestmark = skip_if_nvml_unsupported | ||||||
|
|
||||||
| import array | ||||||
| import multiprocessing | ||||||
| import os | ||||||
| import re | ||||||
| import sys | ||||||
|
|
@@ -27,11 +28,6 @@ def check_gpu_available(): | |||||
| pytest.skip("No GPUs available to run device tests", allow_module_level=True) | ||||||
|
|
||||||
|
|
||||||
| def test_device_index_handle(): | ||||||
| for device in system.Device.get_all_devices(): | ||||||
| assert isinstance(device.handle, int) | ||||||
|
|
||||||
|
|
||||||
| def test_device_architecture(): | ||||||
| for device in system.Device.get_all_devices(): | ||||||
| device_arch = device.architecture | ||||||
|
|
@@ -237,3 +233,28 @@ def test_field_values(): | |||||
| field_values.validate() | ||||||
| assert len(field_values) == 1 | ||||||
| assert field_values[0].value <= old_value | ||||||
|
|
||||||
|
|
||||||
| def test_get_all_devices_with_cpu_affinity(): | ||||||
| try: | ||||||
| for i in range(multiprocessing.cpu_count()): | ||||||
| for device in system.Device.get_all_devices_with_cpu_affinity(i): | ||||||
| affinity = device.cpu_affinity | ||||||
| assert isinstance(affinity, list) | ||||||
| assert {i} == set(affinity) | ||||||
|
||||||
| assert {i} == set(affinity) | |
| assert i in affinity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
pci_bus_idparameter for Device initialization lacks test coverage. Consider adding a test that creates a Device using the pci_bus_id parameter and validates the resulting device matches the expected device.