1- # # ===------------- sycl_core.pyx - dpctl module -------*- Cython -*--------===# #
2- # #
3- # # Data Parallel Control (dpCtl)
4- # #
5- # # Copyright 2020 Intel Corporation
6- # #
7- # # Licensed under the Apache License, Version 2.0 (the "License");
8- # # you may not use this file except in compliance with the License.
9- # # You may obtain a copy of the License at
10- # #
11- # # http://www.apache.org/licenses/LICENSE-2.0
12- # #
13- # # Unless required by applicable law or agreed to in writing, software
14- # # distributed under the License is distributed on an "AS IS" BASIS,
15- # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16- # # See the License for the specific language governing permissions and
17- # # limitations under the License.
18- # #
19- # # ===----------------------------------------------------------------------===# #
20- # #
21- # # \file
22- # # This file implements a sub-set of Sycl's interface using dpctl's CAPI.
23- # #
24- # # ===----------------------------------------------------------------------===# #
1+ # ===------------ sycl_core.pyx - dpctl module -------*- Cython -*---------- ===#
2+ #
3+ # Data Parallel Control (dpCtl)
4+ #
5+ # Copyright 2020 Intel Corporation
6+ #
7+ # Licensed under the Apache License, Version 2.0 (the "License");
8+ # you may not use this file except in compliance with the License.
9+ # You may obtain a copy of the License at
10+ #
11+ # http://www.apache.org/licenses/LICENSE-2.0
12+ #
13+ # Unless required by applicable law or agreed to in writing, software
14+ # distributed under the License is distributed on an "AS IS" BASIS,
15+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ # See the License for the specific language governing permissions and
17+ # limitations under the License.
18+ #
19+ # ===----------------------------------------------------------------------- ===#
20+ #
21+ # \file
22+ # This file implements a sub-set of Sycl's interface using dpctl's CAPI.
23+ #
24+ # ===----------------------------------------------------------------------- ===#
2525
2626# distutils: language = c++
2727# cython: language_level=3
@@ -46,16 +46,12 @@ __all__ = [
4646 " has_sycl_platforms" ,
4747 " set_default_queue" ,
4848 " is_in_device_context" ,
49- " create_program_from_source" ,
50- " create_program_from_spirv" ,
5149 " device_type" ,
5250 " backend_type" ,
5351 " device_context" ,
5452 " SyclContext" ,
5553 " SyclDevice" ,
5654 " SyclEvent" ,
57- " SyclKernel" ,
58- " SyclProgram" ,
5955 " SyclQueue"
6056]
6157
@@ -92,12 +88,6 @@ cdef class UnsupportedDeviceError (Exception):
9288 """
9389 pass
9490
95- cdef class SyclProgramCompilationError (Exception ):
96- """ This exception is raised when a sycl program could not be built from
97- either a spirv binary file or a string source.
98- """
99- pass
100-
10191cdef class SyclKernelSubmitError (Exception ):
10292 """ This exception is raised when a sycl program could not be built from
10393 either a spirv binary file or a string source.
@@ -306,88 +296,6 @@ cdef class SyclEvent:
306296 """
307297 return int (< size_t> self ._event_ref)
308298
309-
310- cdef class SyclKernel:
311- """ Wraps a sycl::kernel object created from an OpenCL interoperability
312- kernel.
313- """
314-
315- @staticmethod
316- cdef SyclKernel _create (DPCTLSyclKernelRef kref):
317- cdef SyclKernel ret = SyclKernel.__new__ (SyclKernel)
318- ret._kernel_ref = kref
319- ret._function_name = DPCTLKernel_GetFunctionName(kref)
320- return ret
321-
322- def __dealloc__ (self ):
323- DPCTLKernel_Delete(self ._kernel_ref)
324- DPCTLCString_Delete(self ._function_name)
325-
326- def get_function_name (self ):
327- """ Returns the name of the Kernel function.
328- """
329- return self ._function_name.decode()
330-
331- def get_num_args (self ):
332- """ Returns the number of arguments for this kernel function.
333- """
334- return DPCTLKernel_GetNumArgs(self ._kernel_ref)
335-
336- cdef DPCTLSyclKernelRef get_kernel_ref (self ):
337- """ Returns the DPCTLSyclKernelRef pointer for this SyclKernel.
338- """
339- return self ._kernel_ref
340-
341- def addressof_ref (self ):
342- """ Returns the address of the C API DPCTLSyclKernelRef pointer
343- as a long.
344-
345- Returns:
346- The address of the DPCTLSyclKernelRef object used to create this
347- SyclKernel cast to a long.
348- """
349- return int (< size_t> self ._kernel_ref)
350-
351- cdef class SyclProgram:
352- """ Wraps a sycl::program object created from an OpenCL interoperability
353- program.
354-
355- SyclProgram exposes the C API from dpctl_sycl_program_interface.h. A
356- SyclProgram can be created from either a source string or a SPIR-V
357- binary file.
358- """
359-
360- @staticmethod
361- cdef SyclProgram _create (DPCTLSyclProgramRef pref):
362- cdef SyclProgram ret = SyclProgram.__new__ (SyclProgram)
363- ret._program_ref = pref
364- return ret
365-
366- def __dealloc__ (self ):
367- DPCTLProgram_Delete(self ._program_ref)
368-
369- cdef DPCTLSyclProgramRef get_program_ref (self ):
370- return self ._program_ref
371-
372- cpdef SyclKernel get_sycl_kernel(self , str kernel_name):
373- name = kernel_name.encode(' utf8' )
374- return SyclKernel._create(DPCTLProgram_GetKernel(self ._program_ref,
375- name))
376-
377- def has_sycl_kernel (self , str kernel_name ):
378- name = kernel_name.encode(' utf8' )
379- return DPCTLProgram_HasKernel(self ._program_ref, name)
380-
381- def addressof_ref (self ):
382- """ Returns the address of the C API DPCTLSyclProgramRef pointer
383- as a long.
384-
385- Returns:
386- The address of the DPCTLSyclProgramRef object used to create this
387- SyclProgram cast to a long.
388- """
389- return int (< size_t> self ._program_ref)
390-
391299import ctypes
392300
393301cdef class SyclQueue:
@@ -894,80 +802,6 @@ cpdef get_current_backend():
894802 """
895803 return _mgr.get_current_backend()
896804
897- def create_program_from_source (SyclQueue q , unicode source , unicode copts = " " ):
898- """
899- Creates a Sycl interoperability program from an OpenCL source string.
900-
901- We use the DPCTLProgram_CreateFromOCLSource() C API function to create
902- a Sycl progrma from an OpenCL source program that can contain multiple
903- kernels.
904-
905- Parameters:
906- q (SyclQueue) : The :class:`SyclQueue` for which the
907- :class:`SyclProgram` is going to be built.
908- source (unicode): Source string for an OpenCL program.
909- copts (unicode) : Optional compilation flags that will be used
910- when compiling the program.
911-
912- Returns:
913- program (SyclProgram): A :class:`SyclProgram` object wrapping the sycl::program returned by the C API.
914- """
915-
916- BE = q.get_sycl_backend()
917- if BE != backend_type.opencl:
918- raise ValueError (
919- " Cannot create program for a " , BE, " type backend. Currently only "
920- " OpenCL devices are supported for program creations."
921- )
922-
923- cdef DPCTLSyclProgramRef Pref
924- cdef bytes bSrc = source.encode(' utf8' )
925- cdef bytes bCOpts = copts.encode(' utf8' )
926- cdef const char * Src = < const char * > bSrc
927- cdef const char * COpts = < const char * > bCOpts
928- cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref()
929- Pref = DPCTLProgram_CreateFromOCLSource(CRef, Src, COpts)
930-
931- if Pref is NULL :
932- raise SyclProgramCompilationError()
933-
934- return SyclProgram._create(Pref)
935-
936- cimport cython.array
937-
938- def create_program_from_spirv (SyclQueue q , const unsigned char[:] IL ):
939- """
940- Creates a Sycl interoperability program from an SPIR-V binary.
941-
942- We use the DPCTLProgram_CreateFromOCLSpirv() C API function to create
943- a Sycl progrma from an compiled SPIR-V binary file.
944-
945- Parameters:
946- q (SyclQueue): The :class:`SyclQueue` for which the
947- :class:`SyclProgram` is going to be built.
948- IL (const char[:]) : SPIR-V binary IL file for an OpenCL program.
949-
950- Returns:
951- program (SyclProgram): A :class:`SyclProgram` object wrapping the sycl::program returned by the C API.
952- """
953- BE = q.get_sycl_backend()
954- if BE != backend_type.opencl:
955- raise ValueError (
956- " Cannot create program for a " , BE, " type backend. Currently only "
957- " OpenCL devices are supported for program creations."
958- )
959-
960- cdef DPCTLSyclProgramRef Pref
961- cdef const unsigned char * dIL = & IL[0 ]
962- cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref()
963- cdef size_t length = IL.shape[0 ]
964- Pref = DPCTLProgram_CreateFromOCLSpirv(CRef, < const void * > dIL, length)
965- if Pref is NULL :
966- raise SyclProgramCompilationError()
967-
968- return SyclProgram._create(Pref)
969-
970-
971805from contextlib import contextmanager
972806
973807@contextmanager
0 commit comments