Skip to content

Commit b20509e

Browse files
All device creation service functions raise SyclDeviceCreationError
1 parent 36e1eec commit b20509e

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

dpctl/_device_selection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import collections.abc
22
from itertools import chain
33

4-
from . import SyclDevice, get_devices
4+
from ._sycl_device import SyclDevice, SyclDeviceCreationError
5+
from ._sycl_device_factory import get_devices
56

67

78
def select_device_with_aspects(required_aspects, excluded_aspects=[]):
@@ -66,7 +67,7 @@ def select_device_with_aspects(required_aspects, excluded_aspects=[]):
6667
selected_dev = dev
6768

6869
if selected_dev is None:
69-
raise ValueError(
70+
raise SyclDeviceCreationError(
7071
f"Requested device is unavailable: "
7172
f"required_aspects={required_aspects}, "
7273
f"excluded_aspects={excluded_aspects}"

dpctl/_sycl_context.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ cdef class SyclContext(_SyclContext):
174174
Raises:
175175
MemoryError: If the constructor could not allocate necessary
176176
temporary memory.
177-
ValueError: If the :class:`dpctl.SyclContext` object creation failed.
177+
SyclContextCreationError: If the :class:`dpctl.SyclContext` object
178+
creation failed.
178179
TypeError: If the list of :class:`dpctl.SyclDevice` objects was empty,
179180
or the input capsule contained a null pointer or could not
180181
be renamed.

dpctl/_sycl_device.pyx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ cdef class SyclDevice(_SyclDevice):
223223
gpu = dpctl.select_gpu_device():
224224
gpu.print_device_info()
225225
226+
Args:
227+
arg (optional): The argument can be a selector string or None.
228+
Defaults to ``None``.
229+
230+
Raises:
231+
MemoryError: If the constructor could not allocate necessary
232+
temporary memory.
233+
SyclDeviceCreationError: If the :class:`dpctl.SyclDevice` object
234+
creation failed.
235+
TypeError: If the list of :class:`dpctl.SyclDevice` objects was empty,
236+
or the input capsule contained a null pointer or could not
237+
be renamed.
238+
239+
226240
"""
227241
@staticmethod
228242
cdef SyclDevice _create(DPCTLSyclDeviceRef dref):

dpctl/_sycl_device_factory.pyx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ from ._backend cimport ( # noqa: E211
4646
_device_type,
4747
)
4848

49+
from ._sycl_device import SyclDeviceCreationError
4950
from .enum_types import backend_type
5051
from .enum_types import device_type as device_type_t
5152

@@ -307,15 +308,15 @@ cpdef SyclDevice select_accelerator_device():
307308
dpctl.SyclDevice: A Python object wrapping the SYCL ``device``
308309
returned by the SYCL ``accelerator_selector``.
309310
Raises:
310-
ValueError: If the SYCL ``accelerator_selector`` is unable to select a
311-
``device``.
311+
dpctl.SyclDeviceCreatioError: If the SYCL ``accelerator_selector`` is
312+
unable to select a ``device``.
312313
"""
313314
cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLAcceleratorSelector_Create()
314315
cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
315316
# Free up the device selector
316317
DPCTLDeviceSelector_Delete(DSRef)
317318
if DRef is NULL:
318-
raise ValueError("Device unavailable.")
319+
raise SyclDeviceCreationError("Accelerator device is unavailable.")
319320
Device = SyclDevice._create(DRef)
320321
return Device
321322

@@ -327,15 +328,15 @@ cpdef SyclDevice select_cpu_device():
327328
dpctl.SyclDevice: A Python object wrapping the SYCL ``device``
328329
returned by the SYCL ``cpu_selector``.
329330
Raises:
330-
ValueError: If the SYCL ``cpu_selector`` is unable to select a
331-
``device``.
331+
dpctl.SyclDeviceCreationError: If the SYCL ``cpu_selector`` is
332+
unable to select a ``device``.
332333
"""
333334
cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLCPUSelector_Create()
334335
cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
335336
# Free up the device selector
336337
DPCTLDeviceSelector_Delete(DSRef)
337338
if DRef is NULL:
338-
raise ValueError("Device unavailable.")
339+
raise SyclDeviceCreationError("CPU device is unavailable.")
339340
Device = SyclDevice._create(DRef)
340341
return Device
341342

@@ -347,15 +348,15 @@ cpdef SyclDevice select_default_device():
347348
dpctl.SyclDevice: A Python object wrapping the SYCL ``device``
348349
returned by the SYCL ``default_selector``.
349350
Raises:
350-
ValueError: If the SYCL ``default_selector`` is unable to select a
351-
``device``.
351+
dpctl.SyclDeviceCreationError: If the SYCL ``default_selector`` is
352+
unable to select a ``device``.
352353
"""
353354
cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create()
354355
cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
355356
# Free up the device selector
356357
DPCTLDeviceSelector_Delete(DSRef)
357358
if DRef is NULL:
358-
raise ValueError("Device unavailable.")
359+
raise SyclDeviceCreationError("Default device is unavailable.")
359360
Device = SyclDevice._create(DRef)
360361
return Device
361362

@@ -367,15 +368,15 @@ cpdef SyclDevice select_gpu_device():
367368
dpctl.SyclDevice: A Python object wrapping the SYCL ``device``
368369
returned by the SYCL ``gpu_selector``.
369370
Raises:
370-
ValueError: If the SYCL ``gpu_selector`` is unable to select a
371-
``device``.
371+
dpctl.SyclDeviceCreationError: If the SYCL ``gpu_selector`` is
372+
unable to select a ``device``.
372373
"""
373374
cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLGPUSelector_Create()
374375
cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
375376
# Free up the device selector
376377
DPCTLDeviceSelector_Delete(DSRef)
377378
if DRef is NULL:
378-
raise ValueError("Device unavailable.")
379+
raise SyclDeviceCreationError("Device unavailable.")
379380
Device = SyclDevice._create(DRef)
380381
return Device
381382

@@ -387,14 +388,14 @@ cpdef SyclDevice select_host_device():
387388
dpctl.SyclDevice: A Python object wrapping the SYCL ``device``
388389
returned by the SYCL ``host_selector``.
389390
Raises:
390-
ValueError: If the SYCL ``host_selector`` is unable to select a
391-
``device``.
391+
dpctl.SyclDeviceCreationError: If the SYCL ``host_selector`` is
392+
unable to select a ``device``.
392393
"""
393394
cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLHostSelector_Create()
394395
cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
395396
# Free up the device selector
396397
DPCTLDeviceSelector_Delete(DSRef)
397398
if DRef is NULL:
398-
raise ValueError("Device unavailable.")
399+
raise SyclDeviceCreationError("Host device is unavailable.")
399400
Device = SyclDevice._create(DRef)
400401
return Device

0 commit comments

Comments
 (0)