Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8ce7da1
Update _device_selection.py
icfaust Jun 15, 2025
c5d2b64
Update _device_selection.py
icfaust Jun 15, 2025
359f044
Update _device_selection.py
icfaust Jun 15, 2025
71ef06c
Update _device_selection.py
icfaust Jun 15, 2025
d9b4869
Update _device_selection.py
icfaust Jun 15, 2025
904e93f
Update _device_selection.py
icfaust Jun 15, 2025
c19bbd6
Update _device_selection.py
icfaust Jun 15, 2025
3711795
Update test_config.py
icfaust Jun 15, 2025
940acfc
Update test_memory_usage.py
icfaust Jun 15, 2025
e8146bb
Update _device_selection.py
icfaust Jun 15, 2025
122f170
Update _device_selection.py
icfaust Jun 15, 2025
031d473
Update _device_selection.py
icfaust Jun 15, 2025
39855cb
Update _device_selection.py
icfaust Jun 15, 2025
dd2d04d
Update _device_selection.py
icfaust Jun 15, 2025
7500c41
Update _device_selection.py
icfaust Jun 15, 2025
ff4d176
Merge branch 'main' into dev/pytorch_testing_2
icfaust Jun 25, 2025
9de4a53
Update test_config.py
icfaust Jun 25, 2025
58f68aa
Update _device_selection.py
icfaust Jun 25, 2025
700758f
Update _device_selection.py
icfaust Jun 25, 2025
ef2a6f8
Update _device_selection.py
icfaust Jun 25, 2025
060fa4d
Update _device_selection.py
icfaust Jun 25, 2025
9970c9c
Update ci.yml
icfaust Jun 25, 2025
7a512c6
Update _device_selection.py
icfaust Jun 26, 2025
7136e0e
Merge branch 'main' into dev/pytorch_testing_2
icfaust Sep 13, 2025
b9839fb
Update ci.yml
icfaust Sep 13, 2025
6f53b1a
Merge branch 'uxlfoundation:main' into dev/pytorch_testing_2
icfaust Dec 2, 2025
d0a47db
Update _device_selection.py
icfaust Dec 2, 2025
7aff323
Merge branch 'uxlfoundation:main' into dev/pytorch_testing_2
icfaust Dec 7, 2025
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
69 changes: 43 additions & 26 deletions onedal/tests/utils/_device_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,38 @@
# ==============================================================================

import functools
from collections.abc import Iterable

import pytest

from ...utils._third_party import dpctl_available
from onedal.utils._third_party import SyclQueue, dpctl_available

if dpctl_available:
import dpctl
from dpctl.memory import MemoryUSMDevice, MemoryUSMShared

queue_creation_err = dpctl._sycl_queue.SyclQueueCreationError
else:
queue_creation_err = (RuntimeError, ValueError)

def get_queues(filter_="cpu,gpu"):

# lru_cache is used to limit the number of SyclQueues generated
# @functools.lru_cache()
def get_queues(filter_: str = "cpu,gpu") -> list[SyclQueue]:
"""Get available dpctl.SycQueues for testing.

This is meant to be used for testing purposes only.

Parameters
----------
filter_ : str, default="cpu,gpu"
Configure output list with available dpctl.SycQueues for testing.
Configure output list with available SyclQueues for testing.
SyclQueues are generated from a comma-separated string with
each element conforming to SYCL's ``filter_selector``.

Returns
-------
list[dpctl.SycQueue]
The list of dpctl.SycQueue.
list[SyclQueue]
The list of SyclQueues.

Notes
-----
Expand All @@ -47,32 +55,41 @@ def get_queues(filter_="cpu,gpu"):
"""
queues = [None] if "cpu" in filter_ else []

if dpctl_available:
if dpctl.has_cpu_devices() and "cpu" in filter_:
queues.append(pytest.param(dpctl.SyclQueue("cpu"), id="SyclQueue_CPU"))
if dpctl.has_gpu_devices() and "gpu" in filter_:
queues.append(pytest.param(dpctl.SyclQueue("gpu"), id="SyclQueue_GPU"))
for i in filter_.split(","):
try:
queues.append(pytest.param(SyclQueue(i), id=f"SyclQueue_{i.upper()}"))
except queue_creation_err:
pass

return queues


def get_memory_usm():
if dpctl_available:
return [MemoryUSMDevice, MemoryUSMShared]
return []
def is_sycl_device_available(targets: Iterable[str]) -> bool:
"""Check if a SYCL device is available.

This is meant to be used for testing purposes only.
The check succeeds if all SYCL devices in targets are
available.

Parameters
----------
targets : Iterable[str]
SYCL filter strings of possible devices.

def is_dpctl_device_available(targets):
if not isinstance(targets, (list, tuple)):
raise TypeError("`targets` should be a list or tuple of strings.")
if dpctl_available:
for device in targets:
if device == "cpu" and not dpctl.has_cpu_devices():
return False
if device == "gpu" and not dpctl.has_gpu_devices():
return False
return True
return False
Returns
-------
bool
Flag if all of the SYCL targets are available.

"""
if not isinstance(targets, Iterable):
raise TypeError("`targets` should be an iterable of strings.")
for device in targets:
try:
SyclQueue(device)
except queue_creation_err:
return False
return True


def pass_if_not_implemented_for_gpu(reason=""):
Expand Down
4 changes: 2 additions & 2 deletions sklearnex/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import onedal
import sklearnex
from onedal.tests.utils._device_selection import is_dpctl_device_available
from onedal.tests.utils._device_selection import is_sycl_device_available


def test_get_config_contains_sklearn_params():
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_host_backend_target_offload(target):


@pytest.mark.skipif(
not is_dpctl_device_available(["gpu"]), reason="Requires a gpu for fallback testing"
not is_sycl_device_available(["gpu"]), reason="Requires a gpu for fallback testing"
)
def test_fallback_to_host(caplog):
# force a fallback to cpu with direct use of dispatch and PatchingConditionsChain
Expand Down
4 changes: 2 additions & 2 deletions sklearnex/tests/test_memory_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
_convert_to_dataframe,
get_dataframes_and_queues,
)
from onedal.tests.utils._device_selection import get_queues, is_dpctl_device_available
from onedal.tests.utils._device_selection import get_queues, is_sycl_device_available
from onedal.utils._array_api import _get_sycl_namespace
from sklearnex import config_context
from sklearnex.tests.utils import (
Expand Down Expand Up @@ -290,7 +290,7 @@ def test_memory_leaks(estimator, dataframe, queue, order, data_shape):


@pytest.mark.skipif(
os.getenv("ZES_ENABLE_SYSMAN") is None or not is_dpctl_device_available(["gpu"]),
os.getenv("ZES_ENABLE_SYSMAN") is None or not is_sycl_device_available(["gpu"]),
reason="SYCL device memory leak check requires the level zero sysman",
)
@pytest.mark.parametrize("queue", get_queues("gpu"))
Expand Down
Loading