Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use sycl_device instead of sycldevice in dldevice conversion functions
  • Loading branch information
ndgrigorian committed Jan 15, 2025
commit f15778e9ad37fe0b4c2e39dc552dd6cc7ce04ac1
8 changes: 4 additions & 4 deletions dpctl/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
)
from dpctl.tensor._device import Device
from dpctl.tensor._dldevice_conversions import (
dldevice_to_sycldevice,
sycldevice_to_dldevice,
dldevice_to_sycl_device,
sycl_device_to_dldevice,
)
from dpctl.tensor._dlpack import from_dlpack
from dpctl.tensor._indexing_functions import (
Expand Down Expand Up @@ -392,6 +392,6 @@
"take_along_axis",
"put_along_axis",
"top_k",
"dldevice_to_sycldevice",
"sycldevice_to_dldevice",
"dldevice_to_sycl_device",
"sycl_device_to_dldevice",
]
4 changes: 2 additions & 2 deletions dpctl/tensor/_dldevice_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ._usmarray import DLDeviceType


def dldevice_to_sycldevice(dl_dev: tuple):
def dldevice_to_sycl_device(dl_dev: tuple):
if isinstance(dl_dev, tuple):
if len(dl_dev) != 2:
raise ValueError("dldevice tuple must have length 2")
Expand All @@ -31,7 +31,7 @@ def dldevice_to_sycldevice(dl_dev: tuple):
return SyclDevice(str(dl_dev[1]))


def sycldevice_to_dldevice(dev: SyclDevice):
def sycl_device_to_dldevice(dev: SyclDevice):
if not isinstance(dev, SyclDevice):
raise TypeError(
"dev is expected to be a SyclDevice, got " f"{type(dev)}"
Expand Down
16 changes: 8 additions & 8 deletions dpctl/tests/test_usm_ndarray_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,36 +828,36 @@ def test_generic_container():
assert Z.device == X.device


def test_sycldevice_to_dldevice(all_root_devices):
def test_sycl_device_to_dldevice(all_root_devices):
for sycl_dev in all_root_devices:
dev = dpt.sycldevice_to_dldevice(sycl_dev)
dev = dpt.sycl_device_to_dldevice(sycl_dev)
assert type(dev) is tuple
assert len(dev) == 2
assert dev[0] == device_oneAPI
assert dev[1] == all_root_devices.index(sycl_dev)


def test_dldevice_to_sycldevice(all_root_devices):
def test_dldevice_to_sycl_device(all_root_devices):
for sycl_dev in all_root_devices:
dldev = dpt.empty(0, device=sycl_dev).__dlpack_device__()
dev = dpt.dldevice_to_sycldevice(dldev)
dev = dpt.dldevice_to_sycl_device(dldev)
assert type(dev) is dpctl.SyclDevice
assert dev == all_root_devices[dldev[1]]


def test_dldevice_conversion_arg_validation():
bad_dldevice_type = (dpt.DLDeviceType.kDLCPU, 0)
with pytest.raises(ValueError):
dpt.dldevice_to_sycldevice(bad_dldevice_type)
dpt.dldevice_to_sycl_device(bad_dldevice_type)

bad_dldevice_len = bad_dldevice_type + (0,)
with pytest.raises(ValueError):
dpt.dldevice_to_sycldevice(bad_dldevice_len)
dpt.dldevice_to_sycl_device(bad_dldevice_len)

bad_dldevice = dict()
with pytest.raises(TypeError):
dpt.dldevice_to_sycldevice(bad_dldevice)
dpt.dldevice_to_sycl_device(bad_dldevice)

bad_sycldevice = dict()
with pytest.raises(TypeError):
dpt.sycldevice_to_dldevice(bad_sycldevice)
dpt.sycl_device_to_dldevice(bad_sycldevice)