19
19
20
20
import numpy as np
21
21
import pytest
22
- from helper import has_cpu , has_gpu , has_sycl_platforms
23
22
24
23
import dpctl
25
24
from dpctl .memory import (
@@ -43,15 +42,14 @@ def __sycl_usm_array_interface(self):
43
42
return iface
44
43
45
44
46
- @pytest .mark .skipif (
47
- not has_sycl_platforms (),
48
- reason = "No SYCL devices except the default host device." ,
49
- )
50
45
def test_memory_create (memory_ctor ):
51
46
import sys
52
47
53
48
nbytes = 1024
54
- queue = dpctl .SyclQueue ()
49
+ try :
50
+ queue = dpctl .SyclQueue ()
51
+ except dpctl .SyclQueueCreationError :
52
+ pytest .skip ("SyclQueue() failed, skip further testing..." )
55
53
mobj = memory_ctor (nbytes , alignment = 64 , queue = queue )
56
54
assert mobj .nbytes == nbytes
57
55
assert hasattr (mobj , "__sycl_usm_array_interface__" )
@@ -65,20 +63,23 @@ def test_memory_create(memory_ctor):
65
63
assert sys .getsizeof (mobj ) > nbytes
66
64
67
65
68
- @pytest .mark .skipif (
69
- not has_sycl_platforms (),
70
- reason = "No SYCL devices except the default host device." ,
71
- )
72
66
def test_memory_create_with_np ():
73
67
nbytes = 16384
68
+ try :
69
+ dpctl .SyclQueue ()
70
+ except dpctl .SyclQueueCreationError :
71
+ pytest .skip ("SyclQueue() failed, skip further testing..." )
74
72
mobj = dpctl .memory .MemoryUSMShared (np .int64 (nbytes ))
75
73
assert mobj .nbytes == nbytes
76
74
assert hasattr (mobj , "__sycl_usm_array_interface__" )
77
75
78
76
79
77
def _create_memory ():
80
78
nbytes = 1024
81
- queue = dpctl .SyclQueue ()
79
+ try :
80
+ queue = dpctl .SyclQueue ()
81
+ except dpctl .SyclQueueCreationError :
82
+ pytest .skip ("SyclQueue() failed, skip further testing..." )
82
83
mobj = MemoryUSMShared (nbytes , alignment = 64 , queue = queue )
83
84
return mobj
84
85
@@ -90,10 +91,6 @@ def _create_host_buf(nbytes):
90
91
return ba
91
92
92
93
93
- @pytest .mark .skipif (
94
- not has_sycl_platforms (),
95
- reason = "No SYCL devices except the default host device." ,
96
- )
97
94
def test_memory_without_context ():
98
95
mobj = _create_memory ()
99
96
@@ -102,7 +99,6 @@ def test_memory_without_context():
102
99
assert mobj .get_usm_type (syclobj = dpctl .SyclContext ()) == "shared"
103
100
104
101
105
- @pytest .mark .skipif (not has_cpu (), reason = "No SYCL CPU device available." )
106
102
def test_memory_cpu_context ():
107
103
mobj = _create_memory ()
108
104
@@ -111,41 +107,38 @@ def test_memory_cpu_context():
111
107
usm_type = mobj .get_usm_type ()
112
108
assert usm_type == "shared"
113
109
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" )
115
114
# type as view from CPU queue
116
115
usm_type = mobj .get_usm_type (cpu_queue )
117
116
# type can be unknown if current queue is
118
117
# not in the same SYCL context
119
118
assert usm_type in ["unknown" , "shared" ]
120
119
121
120
122
- @pytest .mark .skipif (not has_gpu (), reason = "No OpenCL GPU queues available" )
123
121
def test_memory_gpu_context ():
124
122
mobj = _create_memory ()
125
123
126
124
# GPU context
127
125
usm_type = mobj .get_usm_type ()
128
126
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" )
130
131
usm_type = mobj .get_usm_type (gpu_queue )
131
132
assert usm_type in ["unknown" , "shared" ]
132
133
133
134
134
- @pytest .mark .skipif (
135
- not has_sycl_platforms (),
136
- reason = "No SYCL devices except the default host device." ,
137
- )
138
135
def test_buffer_protocol ():
139
136
mobj = _create_memory ()
140
137
mv1 = memoryview (mobj )
141
138
mv2 = memoryview (mobj )
142
139
assert mv1 == mv2
143
140
144
141
145
- @pytest .mark .skipif (
146
- not has_sycl_platforms (),
147
- reason = "No SYCL devices except the default host device." ,
148
- )
149
142
def test_copy_host_roundtrip ():
150
143
mobj = _create_memory ()
151
144
host_src_obj = _create_host_buf (mobj .nbytes )
@@ -155,10 +148,6 @@ def test_copy_host_roundtrip():
155
148
assert host_src_obj == host_dest_obj
156
149
157
150
158
- @pytest .mark .skipif (
159
- not has_sycl_platforms (),
160
- reason = "No SYCL devices except the default host device." ,
161
- )
162
151
def test_zero_copy ():
163
152
mobj = _create_memory ()
164
153
mobj2 = type (mobj )(mobj )
@@ -169,14 +158,13 @@ def test_zero_copy():
169
158
assert mobj_data == mobj2_data
170
159
171
160
172
- @pytest .mark .skipif (
173
- not has_sycl_platforms (),
174
- reason = "No SYCL devices except the default host device." ,
175
- )
176
161
def test_pickling (memory_ctor ):
177
162
import pickle
178
163
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" )
180
168
host_src_obj = _create_host_buf (mobj .nbytes )
181
169
mobj .copy_from_host (host_src_obj )
182
170
@@ -192,14 +180,13 @@ def test_pickling(memory_ctor):
192
180
), "Pickling/unpickling should be changing pointer"
193
181
194
182
195
- @pytest .mark .skipif (
196
- not has_sycl_platforms (),
197
- reason = "No SYCL devices except the default host device." ,
198
- )
199
183
def test_pickling_reconstructor_invalid_type (memory_ctor ):
200
184
import pickle
201
185
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" )
203
190
good_pickle_bytes = pickle .dumps (mobj )
204
191
usm_types = expected_usm_type_str (memory_ctor ).encode ("utf-8" )
205
192
i = good_pickle_bytes .rfind (usm_types )
@@ -231,48 +218,44 @@ def expected_usm_type_enum(ctor):
231
218
return mapping .get (ctor , 0 )
232
219
233
220
234
- @pytest .mark .skipif (
235
- not has_sycl_platforms (),
236
- reason = "No SYCL devices except the default host device." ,
237
- )
238
221
def 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" )
240
226
m = memory_ctor (1024 , alignment = 64 , queue = q )
241
227
assert m .nbytes == 1024
242
228
assert m .get_usm_type () == expected_usm_type_str (memory_ctor )
243
229
assert m .get_usm_type_enum () == expected_usm_type_enum (memory_ctor )
244
230
245
231
246
- @pytest .mark .skipif (
247
- not has_sycl_platforms (),
248
- reason = "No SYCL devices except the default host device." ,
249
- )
250
232
def 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" )
252
237
m = memory_ctor (1024 , queue = q )
253
238
assert m .nbytes == 1024
254
239
assert m .get_usm_type () == expected_usm_type_str (memory_ctor )
255
240
assert m .get_usm_type_enum () == expected_usm_type_enum (memory_ctor )
256
241
257
242
258
- @pytest .mark .skipif (
259
- not has_sycl_platforms (),
260
- reason = "No SYCL devices except the default host device." ,
261
- )
262
243
def 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" )
264
248
assert m .nbytes == 1024
265
249
assert m .get_usm_type () == expected_usm_type_str (memory_ctor )
266
250
assert m .get_usm_type_enum () == expected_usm_type_enum (memory_ctor )
267
251
268
252
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 ():
274
254
ctor = MemoryUSMDevice
275
- m = ctor (1024 )
255
+ try :
256
+ m = ctor (1024 )
257
+ except dpctl .SyclDeviceCreationError :
258
+ pytest .skip ("No SYCL devices available" )
276
259
assert m .nbytes == 1024
277
260
q = m .sycl_queue
278
261
assert m .get_usm_type (syclobj = q ) == expected_usm_type_str (ctor )
@@ -286,12 +269,11 @@ def test_usm_type_execeptions():
286
269
m .get_usm_type_enum (syclobj = list ())
287
270
288
271
289
- @pytest .mark .skipif (
290
- not has_sycl_platforms (),
291
- reason = "No SYCL devices except the default host device." ,
292
- )
293
272
def 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" )
295
277
m2 = Dummy (m .nbytes )
296
278
hb = np .random .randint (0 , 256 , size = 256 , dtype = "|u1" )
297
279
m2 .copy_from_host (hb )
@@ -552,15 +534,14 @@ def test_with_constructor(memory_ctor):
552
534
check_view (v )
553
535
554
536
555
- @pytest .mark .skipif (
556
- not has_sycl_platforms (),
557
- reason = "No SYCL devices except the default host device." ,
558
- )
559
537
def test_cpython_api (memory_ctor ):
560
538
import ctypes
561
539
import sys
562
540
563
- mobj = memory_ctor (1024 )
541
+ try :
542
+ mobj = memory_ctor (1024 )
543
+ except dpctl .SyclDeviceCreationError :
544
+ pytest .skip ("No SYCL devices available" )
564
545
mod = sys .modules [mobj .__class__ .__module__ ]
565
546
# get capsules storing function pointers
566
547
mem_ptr_fn_cap = mod .__pyx_capi__ ["Memory_GetUsmPointer" ]
0 commit comments