1919
2020import numpy as np
2121import pytest
22- from helper import has_cpu , has_gpu , has_sycl_platforms
2322
2423import dpctl
2524from dpctl .memory import (
@@ -43,15 +42,14 @@ def __sycl_usm_array_interface(self):
4342 return iface
4443
4544
46- @pytest .mark .skipif (
47- not has_sycl_platforms (),
48- reason = "No SYCL devices except the default host device." ,
49- )
5045def test_memory_create (memory_ctor ):
5146 import sys
5247
5348 nbytes = 1024
54- queue = dpctl .SyclQueue ()
49+ try :
50+ queue = dpctl .SyclQueue ()
51+ except dpctl .SyclQueueCreationError :
52+ pytest .skip ("SyclQueue() failed, skip further testing..." )
5553 mobj = memory_ctor (nbytes , alignment = 64 , queue = queue )
5654 assert mobj .nbytes == nbytes
5755 assert hasattr (mobj , "__sycl_usm_array_interface__" )
@@ -65,20 +63,23 @@ def test_memory_create(memory_ctor):
6563 assert sys .getsizeof (mobj ) > nbytes
6664
6765
68- @pytest .mark .skipif (
69- not has_sycl_platforms (),
70- reason = "No SYCL devices except the default host device." ,
71- )
7266def test_memory_create_with_np ():
7367 nbytes = 16384
68+ try :
69+ dpctl .SyclQueue ()
70+ except dpctl .SyclQueueCreationError :
71+ pytest .skip ("SyclQueue() failed, skip further testing..." )
7472 mobj = dpctl .memory .MemoryUSMShared (np .int64 (nbytes ))
7573 assert mobj .nbytes == nbytes
7674 assert hasattr (mobj , "__sycl_usm_array_interface__" )
7775
7876
7977def _create_memory ():
8078 nbytes = 1024
81- queue = dpctl .SyclQueue ()
79+ try :
80+ queue = dpctl .SyclQueue ()
81+ except dpctl .SyclQueueCreationError :
82+ pytest .skip ("SyclQueue() failed, skip further testing..." )
8283 mobj = MemoryUSMShared (nbytes , alignment = 64 , queue = queue )
8384 return mobj
8485
@@ -90,10 +91,6 @@ def _create_host_buf(nbytes):
9091 return ba
9192
9293
93- @pytest .mark .skipif (
94- not has_sycl_platforms (),
95- reason = "No SYCL devices except the default host device." ,
96- )
9794def test_memory_without_context ():
9895 mobj = _create_memory ()
9996
@@ -102,7 +99,6 @@ def test_memory_without_context():
10299 assert mobj .get_usm_type (syclobj = dpctl .SyclContext ()) == "shared"
103100
104101
105- @pytest .mark .skipif (not has_cpu (), reason = "No SYCL CPU device available." )
106102def test_memory_cpu_context ():
107103 mobj = _create_memory ()
108104
@@ -111,41 +107,38 @@ def test_memory_cpu_context():
111107 usm_type = mobj .get_usm_type ()
112108 assert usm_type == "shared"
113109
114- cpu_queue = dpctl .SyclQueue ("cpu" )
110+ try :
111+ cpu_queue = dpctl .SyclQueue ("cpu" )
112+ except dpctl .SyclQueueCreationError :
113+ pytest .skip ("SyclQueue('cpu') failed, skip further testing" )
115114 # type as view from CPU queue
116115 usm_type = mobj .get_usm_type (cpu_queue )
117116 # type can be unknown if current queue is
118117 # not in the same SYCL context
119118 assert usm_type in ["unknown" , "shared" ]
120119
121120
122- @pytest .mark .skipif (not has_gpu (), reason = "No OpenCL GPU queues available" )
123121def test_memory_gpu_context ():
124122 mobj = _create_memory ()
125123
126124 # GPU context
127125 usm_type = mobj .get_usm_type ()
128126 assert usm_type == "shared"
129- gpu_queue = dpctl .SyclQueue ("opencl:gpu" )
127+ try :
128+ gpu_queue = dpctl .SyclQueue ("opencl:gpu" )
129+ except dpctl .SyclQueueCreationError :
130+ pytest .skip ("SyclQueue('opencl:gpu') failed, skipping" )
130131 usm_type = mobj .get_usm_type (gpu_queue )
131132 assert usm_type in ["unknown" , "shared" ]
132133
133134
134- @pytest .mark .skipif (
135- not has_sycl_platforms (),
136- reason = "No SYCL devices except the default host device." ,
137- )
138135def test_buffer_protocol ():
139136 mobj = _create_memory ()
140137 mv1 = memoryview (mobj )
141138 mv2 = memoryview (mobj )
142139 assert mv1 == mv2
143140
144141
145- @pytest .mark .skipif (
146- not has_sycl_platforms (),
147- reason = "No SYCL devices except the default host device." ,
148- )
149142def test_copy_host_roundtrip ():
150143 mobj = _create_memory ()
151144 host_src_obj = _create_host_buf (mobj .nbytes )
@@ -155,10 +148,6 @@ def test_copy_host_roundtrip():
155148 assert host_src_obj == host_dest_obj
156149
157150
158- @pytest .mark .skipif (
159- not has_sycl_platforms (),
160- reason = "No SYCL devices except the default host device." ,
161- )
162151def test_zero_copy ():
163152 mobj = _create_memory ()
164153 mobj2 = type (mobj )(mobj )
@@ -169,14 +158,13 @@ def test_zero_copy():
169158 assert mobj_data == mobj2_data
170159
171160
172- @pytest .mark .skipif (
173- not has_sycl_platforms (),
174- reason = "No SYCL devices except the default host device." ,
175- )
176161def test_pickling (memory_ctor ):
177162 import pickle
178163
179- mobj = memory_ctor (1024 , alignment = 64 )
164+ try :
165+ mobj = memory_ctor (1024 , alignment = 64 )
166+ except dpctl .SyclDeviceCreationError :
167+ pytest .skip ("No SYCL devices available" )
180168 host_src_obj = _create_host_buf (mobj .nbytes )
181169 mobj .copy_from_host (host_src_obj )
182170
@@ -192,14 +180,13 @@ def test_pickling(memory_ctor):
192180 ), "Pickling/unpickling should be changing pointer"
193181
194182
195- @pytest .mark .skipif (
196- not has_sycl_platforms (),
197- reason = "No SYCL devices except the default host device." ,
198- )
199183def test_pickling_reconstructor_invalid_type (memory_ctor ):
200184 import pickle
201185
202- mobj = memory_ctor (1024 , alignment = 64 )
186+ try :
187+ mobj = memory_ctor (1024 , alignment = 64 )
188+ except dpctl .SyclDeviceCreationError :
189+ pytest .skip ("No SYCL devices available" )
203190 good_pickle_bytes = pickle .dumps (mobj )
204191 usm_types = expected_usm_type_str (memory_ctor ).encode ("utf-8" )
205192 i = good_pickle_bytes .rfind (usm_types )
@@ -231,48 +218,44 @@ def expected_usm_type_enum(ctor):
231218 return mapping .get (ctor , 0 )
232219
233220
234- @pytest .mark .skipif (
235- not has_sycl_platforms (),
236- reason = "No SYCL devices except the default host device." ,
237- )
238221def test_create_with_size_and_alignment_and_queue (memory_ctor ):
239- q = dpctl .SyclQueue ()
222+ try :
223+ q = dpctl .SyclQueue ()
224+ except dpctl .SyclQueueCreationError :
225+ pytest .skip ("SyclQueue() failed, skip further testing" )
240226 m = memory_ctor (1024 , alignment = 64 , queue = q )
241227 assert m .nbytes == 1024
242228 assert m .get_usm_type () == expected_usm_type_str (memory_ctor )
243229 assert m .get_usm_type_enum () == expected_usm_type_enum (memory_ctor )
244230
245231
246- @pytest .mark .skipif (
247- not has_sycl_platforms (),
248- reason = "No SYCL devices except the default host device." ,
249- )
250232def test_create_with_size_and_queue (memory_ctor ):
251- q = dpctl .SyclQueue ()
233+ try :
234+ q = dpctl .SyclQueue ()
235+ except dpctl .SyclQueueCreationError :
236+ pytest .skip ("SyclQueue() failed, skip further testing" )
252237 m = memory_ctor (1024 , queue = q )
253238 assert m .nbytes == 1024
254239 assert m .get_usm_type () == expected_usm_type_str (memory_ctor )
255240 assert m .get_usm_type_enum () == expected_usm_type_enum (memory_ctor )
256241
257242
258- @pytest .mark .skipif (
259- not has_sycl_platforms (),
260- reason = "No SYCL devices except the default host device." ,
261- )
262243def test_create_with_size_and_alignment (memory_ctor ):
263- m = memory_ctor (1024 , alignment = 64 )
244+ try :
245+ m = memory_ctor (1024 , alignment = 64 )
246+ except dpctl .SyclDeviceCreationError :
247+ pytest .skip ("No SYCL devices available" )
264248 assert m .nbytes == 1024
265249 assert m .get_usm_type () == expected_usm_type_str (memory_ctor )
266250 assert m .get_usm_type_enum () == expected_usm_type_enum (memory_ctor )
267251
268252
269- @pytest .mark .skipif (
270- not has_sycl_platforms (),
271- reason = "No SYCL devices except the default host device." ,
272- )
273- def test_usm_type_execeptions ():
253+ def test_usm_type_exceptions ():
274254 ctor = MemoryUSMDevice
275- m = ctor (1024 )
255+ try :
256+ m = ctor (1024 )
257+ except dpctl .SyclDeviceCreationError :
258+ pytest .skip ("No SYCL devices available" )
276259 assert m .nbytes == 1024
277260 q = m .sycl_queue
278261 assert m .get_usm_type (syclobj = q ) == expected_usm_type_str (ctor )
@@ -286,12 +269,11 @@ def test_usm_type_execeptions():
286269 m .get_usm_type_enum (syclobj = list ())
287270
288271
289- @pytest .mark .skipif (
290- not has_sycl_platforms (),
291- reason = "No SYCL devices except the default host device." ,
292- )
293272def test_sycl_usm_array_interface (memory_ctor ):
294- m = memory_ctor (256 )
273+ try :
274+ m = memory_ctor (256 )
275+ except dpctl .SyclDeviceCreationError :
276+ pytest .skip ("No SYCL devices available" )
295277 m2 = Dummy (m .nbytes )
296278 hb = np .random .randint (0 , 256 , size = 256 , dtype = "|u1" )
297279 m2 .copy_from_host (hb )
@@ -552,15 +534,14 @@ def test_with_constructor(memory_ctor):
552534 check_view (v )
553535
554536
555- @pytest .mark .skipif (
556- not has_sycl_platforms (),
557- reason = "No SYCL devices except the default host device." ,
558- )
559537def test_cpython_api (memory_ctor ):
560538 import ctypes
561539 import sys
562540
563- mobj = memory_ctor (1024 )
541+ try :
542+ mobj = memory_ctor (1024 )
543+ except dpctl .SyclDeviceCreationError :
544+ pytest .skip ("No SYCL devices available" )
564545 mod = sys .modules [mobj .__class__ .__module__ ]
565546 # get capsules storing function pointers
566547 mem_ptr_fn_cap = mod .__pyx_capi__ ["Memory_GetUsmPointer" ]
0 commit comments