Skip to content

Commit f5d155e

Browse files
author
khaled
committed
Addressing all review comments
Remove device='gpu' in tests/types/USMNdArray/test_array_creation_errors.py
1 parent de96969 commit f5d155e

File tree

2 files changed

+47
-117
lines changed

2 files changed

+47
-117
lines changed

numba_dpex/dpnp_iface/arrayobj.py

Lines changed: 40 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ def _parse_device_filter_string(device):
125125
return device_filter_str
126126
elif isinstance(device, str):
127127
return device
128-
else:
128+
elif device is None or isinstance(device, types.NoneType):
129129
return None
130-
# raise TypeError(
131-
# "The parameter 'device' is neither of "
132-
# + "'str' nor 'types.StringLiteral'"
133-
# )
130+
else:
131+
raise TypeError(
132+
"The parameter 'device' is neither of "
133+
+ "'str', 'types.StringLiteral' nor 'None'"
134+
)
134135

135136

136137
def build_dpnp_ndarray(
@@ -160,13 +161,12 @@ def build_dpnp_ndarray(
160161
corresponding to a non-partitioned SYCL device, an instance of
161162
:class:`dpctl.SyclQueue`, or a `Device` object returnedby
162163
`dpctl.tensor.usm_array.device`. Default: `None`.
163-
sycl_queue (:class:`dpctl.SyclQueue`, optional): The SYCL queue to use
164-
for output array allocation and copying. sycl_queue and device
165-
are exclusive keywords, i.e. use one or another. If both are
166-
specified, a TypeError is raised unless both imply the same
167-
underlying SYCL queue to be used. If both are None, a cached
168-
queue targeting default-selected device is used for allocation
169-
and copying. Default: `None`.
164+
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
165+
optional): The SYCL queue to use for output array allocation and
166+
copying. sycl_queue and device are exclusive keywords, i.e. use
167+
one or another. If both are specified, a TypeError is raised. If
168+
both are None, a cached queue targeting default-selected device
169+
is used for allocation and copying. Default: `None`.
170170
171171
Raises:
172172
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -177,13 +177,6 @@ def build_dpnp_ndarray(
177177
represent dpctl.tensor.usm_ndarray.
178178
"""
179179

180-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
181-
raise errors.TypingError(
182-
"numba_dpex.dpnp_iface.arrayobj.build_dpnp_ndarray(): "
183-
"`device` and `sycl_queue` are exclusive keywords, "
184-
"i.e. use one or other."
185-
)
186-
187180
# If a dtype value was passed in, then try to convert it to the
188181
# corresponding Numba type. If None was passed, the default, then pass None
189182
# to the DpnpNdArray constructor. The default dtype will be derived based
@@ -228,7 +221,7 @@ def ol_dpnp_empty(
228221
sycl_queue=None,
229222
):
230223
"""Implementation of an overload to support dpnp.empty() inside
231-
a jit function.
224+
a dpjit function.
232225
233226
Args:
234227
shape (numba.core.types.containers.UniTuple or
@@ -260,10 +253,9 @@ def ol_dpnp_empty(
260253
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
261254
optional): The SYCL queue to use for output array allocation and
262255
copying. sycl_queue and device are exclusive keywords, i.e. use
263-
one or another. If both are specified, a TypeError is raised
264-
unless both imply the same underlying SYCL queue to be used.
265-
If both are None, a cached queue targeting default-selected
266-
device is used for allocation and copying. Default: `None`.
256+
one or another. If both are specified, a TypeError is raised. If
257+
both are None, a cached queue targeting default-selected device
258+
is used for allocation and copying. Default: `None`.
267259
268260
Raises:
269261
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -274,13 +266,6 @@ def ol_dpnp_empty(
274266
function: Local function `impl_dpnp_empty()`.
275267
"""
276268

277-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
278-
raise errors.TypingError(
279-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
280-
"`device` and `sycl_queue` are exclusive keywords, "
281-
"i.e. use one or other."
282-
)
283-
284269
_ndim = _ty_parse_shape(shape)
285270
_dtype = _parse_dtype(dtype)
286271
_layout = _parse_layout(order)
@@ -344,7 +329,7 @@ def ol_dpnp_zeros(
344329
sycl_queue=None,
345330
):
346331
"""Implementation of an overload to support dpnp.zeros() inside
347-
a jit function.
332+
a dpjit function.
348333
349334
Args:
350335
shape (numba.core.types.containers.UniTuple or
@@ -376,10 +361,9 @@ def ol_dpnp_zeros(
376361
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
377362
optional): The SYCL queue to use for output array allocation and
378363
copying. sycl_queue and device are exclusive keywords, i.e. use
379-
one or another. If both are specified, a TypeError is raised
380-
unless both imply the same underlying SYCL queue to be used.
381-
If both are None, a cached queue targeting default-selected
382-
device is used for allocation and copying. Default: `None`.
364+
one or another. If both are specified, a TypeError is raised. If
365+
both are None, a cached queue targeting default-selected device
366+
is used for allocation and copying. Default: `None`.
383367
384368
Raises:
385369
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -390,13 +374,6 @@ def ol_dpnp_zeros(
390374
function: Local function `impl_dpnp_zeros()`.
391375
"""
392376

393-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
394-
raise errors.TypingError(
395-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
396-
"`device` and `sycl_queue` are exclusive keywords, "
397-
"i.e. use one or other."
398-
)
399-
400377
_ndim = _ty_parse_shape(shape)
401378
_layout = _parse_layout(order)
402379
_dtype = _parse_dtype(dtype)
@@ -460,7 +437,7 @@ def ol_dpnp_ones(
460437
sycl_queue=None,
461438
):
462439
"""Implementation of an overload to support dpnp.ones() inside
463-
a jit function.
440+
a dpjit function.
464441
465442
Args:
466443
shape (numba.core.types.containers.UniTuple or
@@ -492,10 +469,9 @@ def ol_dpnp_ones(
492469
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
493470
optional): The SYCL queue to use for output array allocation and
494471
copying. sycl_queue and device are exclusive keywords, i.e. use
495-
one or another. If both are specified, a TypeError is raised
496-
unless both imply the same underlying SYCL queue to be used.
497-
If both are None, a cached queue targeting default-selected
498-
device is used for allocation and copying. Default: `None`.
472+
one or another. If both are specified, a TypeError is raised. If
473+
both are None, a cached queue targeting default-selected device
474+
is used for allocation and copying. Default: `None`.
499475
500476
Raises:
501477
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -506,13 +482,6 @@ def ol_dpnp_ones(
506482
function: Local function `impl_dpnp_ones()`.
507483
"""
508484

509-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
510-
raise errors.TypingError(
511-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
512-
"`device` and `sycl_queue` are exclusive keywords, "
513-
"i.e. use one or other."
514-
)
515-
516485
_ndim = _ty_parse_shape(shape)
517486
_dtype = _parse_dtype(dtype)
518487
_layout = _parse_layout(order)
@@ -577,7 +546,7 @@ def ol_dpnp_full(
577546
sycl_queue=None,
578547
):
579548
"""Implementation of an overload to support dpnp.full() inside
580-
a jit function.
549+
a dpjit function.
581550
582551
Args:
583552
shape (numba.core.types.containers.UniTuple or
@@ -612,10 +581,9 @@ def ol_dpnp_full(
612581
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
613582
optional): The SYCL queue to use for output array allocation and
614583
copying. sycl_queue and device are exclusive keywords, i.e. use
615-
one or another. If both are specified, a TypeError is raised
616-
unless both imply the same underlying SYCL queue to be used.
617-
If both are None, a cached queue targeting default-selected
618-
device is used for allocation and copying. Default: `None`.
584+
one or another. If both are specified, a TypeError is raised. If
585+
both are None, a cached queue targeting default-selected device
586+
is used for allocation and copying. Default: `None`.
619587
620588
Raises:
621589
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -626,13 +594,6 @@ def ol_dpnp_full(
626594
function: Local function `impl_dpnp_full()`.
627595
"""
628596

629-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
630-
raise errors.TypingError(
631-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
632-
"`device` and `sycl_queue` are exclusive keywords, "
633-
"i.e. use one or other."
634-
)
635-
636597
_ndim = _ty_parse_shape(shape)
637598
_dtype = _parse_dtype(dtype)
638599
_layout = _parse_layout(order)
@@ -733,10 +694,9 @@ def ol_dpnp_empty_like(
733694
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
734695
optional): The SYCL queue to use for output array allocation and
735696
copying. sycl_queue and device are exclusive keywords, i.e. use
736-
one or another. If both are specified, a TypeError is raised
737-
unless both imply the same underlying SYCL queue to be used.
738-
If both are None, a cached queue targeting default-selected
739-
device is used for allocation and copying. Default: `None`.
697+
one or another. If both are specified, a TypeError is raised. If
698+
both are None, a cached queue targeting default-selected device
699+
is used for allocation and copying. Default: `None`.
740700
741701
Raises:
742702
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -747,13 +707,6 @@ def ol_dpnp_empty_like(
747707
function: Local function `impl_dpnp_empty_like()`.
748708
"""
749709

750-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
751-
raise errors.TypingError(
752-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
753-
"`device` and `sycl_queue` are exclusive keywords, "
754-
"i.e. use one or other."
755-
)
756-
757710
if shape:
758711
raise errors.TypingError(
759712
"The parameter shape is not supported "
@@ -858,10 +811,9 @@ def ol_dpnp_zeros_like(
858811
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
859812
optional): The SYCL queue to use for output array allocation and
860813
copying. sycl_queue and device are exclusive keywords, i.e. use
861-
one or another. If both are specified, a TypeError is raised
862-
unless both imply the same underlying SYCL queue to be used.
863-
If both are None, a cached queue targeting default-selected
864-
device is used for allocation and copying. Default: `None`.
814+
one or another. If both are specified, a TypeError is raised. If
815+
both are None, a cached queue targeting default-selected device
816+
is used for allocation and copying. Default: `None`.
865817
866818
Raises:
867819
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -872,13 +824,6 @@ def ol_dpnp_zeros_like(
872824
function: Local function `impl_dpnp_zeros_like()`.
873825
"""
874826

875-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
876-
raise errors.TypingError(
877-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
878-
"`device` and `sycl_queue` are exclusive keywords, "
879-
"i.e. use one or other."
880-
)
881-
882827
if shape:
883828
raise errors.TypingError(
884829
"The parameter shape is not supported "
@@ -982,10 +927,9 @@ def ol_dpnp_ones_like(
982927
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
983928
optional): The SYCL queue to use for output array allocation and
984929
copying. sycl_queue and device are exclusive keywords, i.e. use
985-
one or another. If both are specified, a TypeError is raised
986-
unless both imply the same underlying SYCL queue to be used.
987-
If both are None, a cached queue targeting default-selected
988-
device is used for allocation and copying. Default: `None`.
930+
one or another. If both are specified, a TypeError is raised. If
931+
both are None, a cached queue targeting default-selected device
932+
is used for allocation and copying. Default: `None`.
989933
990934
Raises:
991935
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -995,12 +939,6 @@ def ol_dpnp_ones_like(
995939
Returns:
996940
function: Local function `impl_dpnp_ones_like()`.
997941
"""
998-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
999-
raise errors.TypingError(
1000-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
1001-
"`device` and `sycl_queue` are exclusive keywords, "
1002-
"i.e. use one or other."
1003-
)
1004942

1005943
if shape:
1006944
raise errors.TypingError(
@@ -1110,10 +1048,9 @@ def ol_dpnp_full_like(
11101048
sycl_queue (:class:`numba_dpex.core.types.dpctl_types.DpctlSyclQueue`,
11111049
optional): The SYCL queue to use for output array allocation and
11121050
copying. sycl_queue and device are exclusive keywords, i.e. use
1113-
one or another. If both are specified, a TypeError is raised
1114-
unless both imply the same underlying SYCL queue to be used.
1115-
If both are None, a cached queue targeting default-selected
1116-
device is used for allocation and copying. Default: `None`.
1051+
one or another. If both are specified, a TypeError is raised. If
1052+
both are None, a cached queue targeting default-selected device
1053+
is used for allocation and copying. Default: `None`.
11171054
11181055
Raises:
11191056
errors.TypingError: If both `device` and `sycl_queue` are provided.
@@ -1124,13 +1061,6 @@ def ol_dpnp_full_like(
11241061
function: Local function `impl_dpnp_full_like()`.
11251062
"""
11261063

1127-
if sycl_queue and not isinstance(sycl_queue, types.misc.Omitted) and device:
1128-
raise errors.TypingError(
1129-
"numba_dpex.dpnp_iface.arrayobj.ol_dpnp_empty(): "
1130-
"`device` and `sycl_queue` are exclusive keywords, "
1131-
"i.e. use one or other."
1132-
)
1133-
11341064
if shape:
11351065
raise errors.TypingError(
11361066
"The parameter shape is not supported "

numba_dpex/tests/types/USMNdArray/test_exceptions.py renamed to numba_dpex/tests/types/USMNdArray/test_array_creation_errors.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def test_init():
2424
assert usma.usm_type == "device"
2525
assert str(usma.queue.sycl_device.device_type) == "device_type.cpu"
2626

27-
usma = USMNdArray(1, device="gpu", queue=None)
28-
assert usma.dtype.name == "float64"
29-
assert usma.ndim == 1
30-
assert usma.layout == "C"
31-
assert usma.addrspace == 1
32-
assert usma.usm_type == "device"
33-
assert str(usma.queue.sycl_device.device_type) == "device_type.gpu"
27+
# usma = USMNdArray(1, device="gpu", queue=None)
28+
# assert usma.dtype.name == "float64"
29+
# assert usma.ndim == 1
30+
# assert usma.layout == "C"
31+
# assert usma.addrspace == 1
32+
# assert usma.usm_type == "device"
33+
# assert str(usma.queue.sycl_device.device_type) == "device_type.gpu"
3434

3535
queue = dpctl.SyclQueue()
3636
usma = USMNdArray(1, device=None, queue=queue)

0 commit comments

Comments
 (0)