Skip to content

Commit cacc0d7

Browse files
committed
Add helper test function to obtain device ID
1 parent d7cd38c commit cacc0d7

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

dpnp/tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
import dpnp
4343

44+
from .helper import get_dev_id
45+
4446
skip_mark = pytest.mark.skip(reason="Skipping test.")
4547

4648

@@ -129,7 +131,6 @@ def pytest_collection_modifyitems(config, items):
129131
test_exclude_file_cuda = os.path.join(test_path, "skipped_tests_cuda.tbl")
130132

131133
dev = dpctl.select_default_device()
132-
dev_id = dpctl.utils.intel_device_info(dev).get("device_id", 0)
133134
is_cpu = dev.is_cpu
134135
is_gpu = dev.is_gpu
135136
support_fp64 = dev.has_aspect_fp64
@@ -139,7 +140,7 @@ def pytest_collection_modifyitems(config, items):
139140
print(
140141
f"DPNP Test scope includes all integer dtypes: {bool(dtype_config.all_int_types)}"
141142
)
142-
print(f"DPNP current device ID: {dev_id:#x}")
143+
print(f"DPNP current device ID: {get_dev_id(dev):#x}")
143144
print(f"DPNP current device is CPU: {is_cpu}")
144145
print(f"DPNP current device is GPU: {is_gpu}")
145146
print(f"DPNP current device supports fp64: {support_fp64}")

dpnp/tests/helper.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@ def _assert_shape(a, b):
2626
assert a.shape == (), f"{a.shape} != ()"
2727

2828

29-
def _get_dev_id(device=None):
30-
dev = dpctl.select_default_device() if device is None else device
31-
dev_info = dpctl.utils.intel_device_info(dev)
32-
return dev_info.get("device_id", 0)
33-
34-
3529
def _get_dev_mask(device=None):
36-
return _get_dev_id(device) & 0xFF00
30+
return get_dev_id(device) & 0xFF00
3731

3832

3933
def assert_dtype_allclose(
@@ -309,6 +303,16 @@ def get_complex_dtypes(device=None):
309303
return dtypes
310304

311305

306+
def get_dev_id(device=None):
307+
"""
308+
Obtain Intel Device ID for a device (the default device if not provided).
309+
"""
310+
311+
dev = dpctl.select_default_device() if device is None else device
312+
dev_info = dpctl.utils.intel_device_info(dev)
313+
return dev_info.get("device_id", 0)
314+
315+
312316
def get_float_dtypes(no_float16=True, device=None):
313317
"""
314318
Build a list of floating types supported by DPNP based on device capabilities.

0 commit comments

Comments
 (0)