Skip to content

Commit

Permalink
Applying review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderKalistratov authored and khaled committed Apr 21, 2023
1 parent 294b15b commit c81f816
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
1 change: 0 additions & 1 deletion numba_dpex/core/typeconv/array_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def to_usm_ndarray(suai_attrs, addrspace=address_space.GLOBAL):
ndim=suai_attrs.dimensions,
layout=layout,
usm_type=suai_attrs.usm_type,
device=suai_attrs.device,
queue=suai_attrs.queue,
readonly=not suai_attrs.is_writable,
name=None,
Expand Down
36 changes: 10 additions & 26 deletions numba_dpex/core/types/usm_ndarray_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def __init__(
aligned=True,
addrspace=address_space.GLOBAL,
):
# Creating SyclDevice from filter_string is expensive. So, USMNdArray should be able to
# accept and SyclDevice from usm_ndarray as device parameter
if not isinstance(device, (str, dpctl.SyclDevice)):
if not isinstance(device, str):
raise TypeError(
"The device keyword arg should be a str object specifying "
"a SYCL filter selector"
Expand All @@ -47,35 +45,21 @@ def __init__(
self.usm_type = usm_type
self.addrspace = addrspace

def to_device(dev):
if isinstance(dev, dpctl.SyclDevice):
return dev
if device == "unknown":
device = None

return dpctl.SyclDevice(dev)

def device_as_string(dev):
if isinstance(dev, dpctl.SyclDevice):
return dev.filter_string

return dev
if queue is not None and device is not None:
raise TypeError(
"'queue' and 'device' keywords can not be both specified"
)

if queue is not None:
if device != "unknown":
if queue.sycl_device != to_device(device):
raise TypeError(
"The queue keyword arg and the device keyword arg specify "
"different SYCL devices"
)

self.queue = queue
else:
if device == "unknown":
device = None
if device is None:
device = dpctl.SyclDevice()

device_str = device_as_string(device)
self.queue = dpctl.tensor._device.normalize_queue_device(
device=device_str
)
self.queue = dpctl.get_device_cached_queue(device)

self.device = self.queue.sycl_device.filter_string

Expand Down
6 changes: 1 addition & 5 deletions numba_dpex/core/typing/typeof.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ def _typeof_helper(val, array_class_type):
"The usm_type for the usm_ndarray could not be inferred"
)

try:
device = val.sycl_device
except AttributeError:
raise ValueError("The device for the usm_ndarray could not be inferred")
assert val.sycl_queue is not None

return array_class_type(
dtype=dtype,
ndim=val.ndim,
layout=layout,
readonly=readonly,
usm_type=usm_type,
device=device,
queue=val.sycl_queue,
addrspace=address_space.GLOBAL,
)
Expand Down

0 comments on commit c81f816

Please sign in to comment.