Skip to content

Commit 96de2e1

Browse files
author
Diptorup Deb
committed
Allow program creation only for OpenCL for the time being.
1 parent ae6873d commit 96de2e1

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

dpctl/sycl_core.pyx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,14 @@ def create_program_from_source (SyclQueue q, unicode source, unicode copts=""):
710710
syc::program returned by the C API.
711711
'''
712712

713-
cdef DPPLSyclProgramRef Pref
713+
BE = q.get_sycl_backend()
714+
if BE != backend_type.opencl:
715+
raise ValueError(
716+
"Cannot create program for a ", BE, "type backend. Currently only "
717+
"OpenCL devices are supported for program creations."
718+
)
714719

720+
cdef DPPLSyclProgramRef Pref
715721
cdef bytes bSrc = source.encode('utf8')
716722
cdef bytes bCOpts = copts.encode('utf8')
717723
cdef const char *Src = <const char*>bSrc
@@ -741,6 +747,12 @@ def create_program_from_spirv (SyclQueue q, const unsigned char[:] IL):
741747
program (SyclProgram): A SyclProgram object wrapping the
742748
syc::program returned by the C API.
743749
'''
750+
BE = q.get_sycl_backend()
751+
if BE != backend_type.opencl:
752+
raise ValueError(
753+
"Cannot create program for a ", BE, "type backend. Currently only "
754+
"OpenCL devices are supported for program creations."
755+
)
744756

745757
cdef DPPLSyclProgramRef Pref
746758
cdef const unsigned char *dIL = &IL[0]

dpctl/tests/test_sycl_program.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,48 @@ def test_create_program_from_spirv(self):
8181
self.assertEqual(addKernel.get_num_args(), 3)
8282
self.assertEqual(axpyKernel.get_num_args(), 4)
8383

84+
@unittest.skipUnless(
85+
dpctl.has_gpu_queues(backend_ty=dpctl.backend_type.opencl),
86+
"No Level0 GPU queues available"
87+
)
88+
class TestProgramForLevel0GPU (unittest.TestCase):
89+
90+
def test_create_program_from_spirv(self):
91+
92+
CURR_DIR = os.path.dirname(os.path.abspath(__file__))
93+
spirv_file = os.path.join(CURR_DIR, 'input_files/multi_kernel.spv')
94+
with open(spirv_file, 'rb') as fin:
95+
spirv = fin.read()
96+
with dpctl.device_context("level0:gpu:0"):
97+
q = dpctl.get_current_queue()
98+
try:
99+
prog = dpctl.create_program_from_spirv(q,spirv)
100+
self.fail(
101+
"Tried to create program for an unsupported Level0 GPU."
102+
)
103+
except ValueError:
104+
pass
105+
106+
def test_create_program_from_source (self):
107+
oclSrc = " \
108+
kernel void add(global int* a, global int* b, global int* c) { \
109+
size_t index = get_global_id(0); \
110+
c[index] = a[index] + b[index]; \
111+
} \
112+
kernel void axpy(global int* a, global int* b, global int* c, int d) { \
113+
size_t index = get_global_id(0); \
114+
c[index] = a[index] + d*b[index]; \
115+
}"
116+
with dpctl.device_context("level0:gpu:0"):
117+
q = dpctl.get_current_queue()
118+
try:
119+
prog = dpctl.create_program_from_source(q, oclSrc)
120+
self.fail(
121+
"Tried to create program for an unsupported Level0 GPU."
122+
)
123+
except ValueError:
124+
pass
125+
84126

85127
if __name__ == '__main__':
86128
unittest.main()

0 commit comments

Comments
 (0)