2424
2525import  dpctl 
2626
27- 
28- @pytest .mark .skipif ( 
27+ skip_no_platform  =  pytest .mark .skipif (
2928    not  has_sycl_platforms (), reason = "No SYCL platforms available" 
3029)
30+ skip_no_gpu  =  pytest .mark .skipif (
31+     not  has_gpu (), reason = "No OpenCL GPU queues available" 
32+ )
33+ skip_no_cpu  =  pytest .mark .skipif (
34+     not  has_cpu (), reason = "No OpenCL CPU queues available" 
35+ )
36+ 
37+ 
38+ @skip_no_platform  
3139def  test_is_in_device_context_outside_device_ctxt ():
3240    assert  not  dpctl .is_in_device_context ()
3341
3442
35- @pytest . mark . skipif ( not   has_gpu (),  reason = "No OpenCL GPU queues available" )  
43+ @skip_no_gpu  
3644def  test_is_in_device_context_inside_device_ctxt_gpu ():
3745    with  dpctl .device_context ("opencl:gpu:0" ):
3846        assert  dpctl .is_in_device_context ()
3947
4048
41- @pytest . mark . skipif ( not   has_cpu (),  reason = "No OpenCL CPU queues available" )  
49+ @skip_no_cpu  
4250def  test_is_in_device_context_inside_device_ctxt_cpu ():
4351    with  dpctl .device_context ("opencl:cpu:0" ):
4452        assert  dpctl .is_in_device_context ()
4553
4654
47- @pytest . mark . skipif ( not   has_gpu (),  reason = "No OpenCL GPU queues available" )  
48- @pytest . mark . skipif ( not   has_cpu (),  reason = "No OpenCL CPU queues available" )  
55+ @skip_no_gpu  
56+ @skip_no_cpu  
4957def  test_is_in_device_context_inside_nested_device_ctxt ():
5058    with  dpctl .device_context ("opencl:cpu:0" ):
5159        with  dpctl .device_context ("opencl:gpu:0" ):
@@ -54,7 +62,7 @@ def test_is_in_device_context_inside_nested_device_ctxt():
5462    assert  not  dpctl .is_in_device_context ()
5563
5664
57- @pytest . mark . skipif ( not   has_cpu (),  reason = "No OpenCL CPU queues available" )  
65+ @skip_no_cpu  
5866def  test_is_in_device_context_inside_nested_device_ctxt_cpu ():
5967    cpu  =  dpctl .SyclDevice ("cpu" )
6068    n  =  cpu .max_compute_units 
@@ -75,17 +83,13 @@ def test_is_in_device_context_inside_nested_device_ctxt_cpu():
7583    assert  0  ==  dpctl .get_num_activated_queues ()
7684
7785
78- @pytest .mark .skipif ( 
79-     not  has_sycl_platforms (), reason = "No SYCL platforms available"  
80- ) 
86+ @skip_no_platform  
8187def  test_get_current_device_type_outside_device_ctxt ():
8288    assert  dpctl .get_current_device_type () is  not None 
8389
8490
85- @pytest .mark .skipif ( 
86-     not  has_sycl_platforms (), reason = "No SYCL platforms available"  
87- ) 
88- @pytest .mark .skipif (not  has_gpu (), reason = "No OpenCL GPU queues available" ) 
91+ @skip_no_platform  
92+ @skip_no_gpu  
8993def  test_get_current_device_type_inside_device_ctxt ():
9094    assert  dpctl .get_current_device_type () is  not None 
9195
@@ -95,8 +99,8 @@ def test_get_current_device_type_inside_device_ctxt():
9599    assert  dpctl .get_current_device_type () is  not None 
96100
97101
98- @pytest . mark . skipif ( not   has_cpu (),  reason = "No OpenCL CPU queues available" )  
99- @pytest . mark . skipif ( not   has_gpu (),  reason = "No OpenCL GPU queues available" )  
102+ @skip_no_cpu  
103+ @skip_no_gpu  
100104def  test_get_current_device_type_inside_nested_device_ctxt ():
101105    assert  dpctl .get_current_device_type () is  not None 
102106
@@ -110,15 +114,13 @@ def test_get_current_device_type_inside_nested_device_ctxt():
110114    assert  dpctl .get_current_device_type () is  not None 
111115
112116
113- @pytest .mark .skipif ( 
114-     not  has_sycl_platforms (), reason = "No SYCL platforms available"  
115- ) 
117+ @skip_no_platform  
116118def  test_num_current_queues_outside_with_clause ():
117119    assert  0  ==  dpctl .get_num_activated_queues ()
118120
119121
120- @pytest . mark . skipif ( not   has_gpu (),  reason = "No OpenCL GPU queues available" )  
121- @pytest . mark . skipif ( not   has_cpu (),  reason = "No OpenCL CPU queues available" )  
122+ @skip_no_gpu  
123+ @skip_no_cpu  
122124def  test_num_current_queues_inside_with_clause ():
123125    with  dpctl .device_context ("opencl:cpu:0" ):
124126        assert  1  ==  dpctl .get_num_activated_queues ()
@@ -127,8 +129,8 @@ def test_num_current_queues_inside_with_clause():
127129    assert  0  ==  dpctl .get_num_activated_queues ()
128130
129131
130- @pytest . mark . skipif ( not   has_gpu (),  reason = "No OpenCL GPU queues available" )  
131- @pytest . mark . skipif ( not   has_cpu (),  reason = "No OpenCL CPU queues available" )  
132+ @skip_no_gpu  
133+ @skip_no_cpu  
132134def  test_num_current_queues_inside_threads ():
133135    from  threading  import  Thread 
134136
@@ -145,9 +147,7 @@ def SessionThread():
145147        Session2 .start ()
146148
147149
148- @pytest .mark .skipif ( 
149-     not  has_sycl_platforms (), reason = "No SYCL platforms available"  
150- ) 
150+ @skip_no_platform  
151151def  test_get_current_backend ():
152152    dpctl .get_current_backend ()
153153    dpctl .get_current_device_type ()
0 commit comments