Skip to content

Commit 0915170

Browse files
author
Diptorup Deb
authored
Merge pull request #946 from AlexanderKalistratov/use_of_cached_queue
Using cached queue instead of creating new one on type inference
2 parents 3971788 + c81f816 commit 0915170

File tree

3 files changed

+27
-41
lines changed

3 files changed

+27
-41
lines changed

numba_dpex/core/typeconv/array_conversion.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def to_usm_ndarray(suai_attrs, addrspace=address_space.GLOBAL):
3737
ndim=suai_attrs.dimensions,
3838
layout=layout,
3939
usm_type=suai_attrs.usm_type,
40-
device=suai_attrs.device,
4140
queue=suai_attrs.queue,
4241
readonly=not suai_attrs.is_writable,
4342
name=None,

numba_dpex/core/types/usm_ndarray_type.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,37 @@ def __init__(
3131
aligned=True,
3232
addrspace=address_space.GLOBAL,
3333
):
34+
if not isinstance(device, str):
35+
raise TypeError(
36+
"The device keyword arg should be a str object specifying "
37+
"a SYCL filter selector"
38+
)
39+
40+
if not isinstance(queue, dpctl.SyclQueue) and queue is not None:
41+
raise TypeError(
42+
"The queue keyword arg should be a dpctl.SyclQueue object or None"
43+
)
44+
3445
self.usm_type = usm_type
3546
self.addrspace = addrspace
3647

37-
if queue is not None and device != "unknown":
38-
if not isinstance(device, str):
39-
raise TypeError(
40-
"The device keyword arg should be a str object specifying "
41-
"a SYCL filter selector"
42-
)
43-
if not isinstance(queue, dpctl.SyclQueue):
44-
raise TypeError(
45-
"The queue keyword arg should be a dpctl.SyclQueue object"
46-
)
47-
d1 = queue.sycl_device
48-
d2 = dpctl.SyclDevice(device)
49-
if d1 != d2:
50-
raise TypeError(
51-
"The queue keyword arg and the device keyword arg specify "
52-
"different SYCL devices"
53-
)
54-
self.queue = queue
55-
self.device = device
56-
elif queue is None and device != "unknown":
57-
if not isinstance(device, str):
58-
raise TypeError(
59-
"The device keyword arg should be a str object specifying "
60-
"a SYCL filter selector"
61-
)
62-
self.queue = dpctl.SyclQueue(device)
63-
self.device = self.queue.sycl_device.filter_string
64-
elif queue is not None and device == "unknown":
65-
if not isinstance(queue, dpctl.SyclQueue):
66-
raise TypeError(
67-
"The queue keyword arg should be a dpctl.SyclQueue object"
68-
)
69-
self.device = self.queue.sycl_device.filter_string
48+
if device == "unknown":
49+
device = None
50+
51+
if queue is not None and device is not None:
52+
raise TypeError(
53+
"'queue' and 'device' keywords can not be both specified"
54+
)
55+
56+
if queue is not None:
7057
self.queue = queue
7158
else:
72-
self.queue = dpctl.SyclQueue()
73-
self.device = self.queue.sycl_device.filter_string
59+
if device is None:
60+
device = dpctl.SyclDevice()
61+
62+
self.queue = dpctl.get_device_cached_queue(device)
63+
64+
self.device = self.queue.sycl_device.filter_string
7465

7566
if not dtype:
7667
dummy_tensor = dpctl.tensor.empty(

numba_dpex/core/typing/typeof.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,14 @@ def _typeof_helper(val, array_class_type):
4242
"The usm_type for the usm_ndarray could not be inferred"
4343
)
4444

45-
try:
46-
device = val.sycl_device.filter_string
47-
except AttributeError:
48-
raise ValueError("The device for the usm_ndarray could not be inferred")
45+
assert val.sycl_queue is not None
4946

5047
return array_class_type(
5148
dtype=dtype,
5249
ndim=val.ndim,
5350
layout=layout,
5451
readonly=readonly,
5552
usm_type=usm_type,
56-
device=device,
5753
queue=val.sycl_queue,
5854
addrspace=address_space.GLOBAL,
5955
)

0 commit comments

Comments
 (0)