@@ -30,16 +30,16 @@ cimport cython.array
30
30
from dpctl._backend cimport ( # noqa: E211, E402
31
31
DPCTLCString_Delete,
32
32
DPCTLKernel_Delete,
33
- DPCTLKernel_GetFunctionName,
34
33
DPCTLKernel_GetNumArgs,
35
- DPCTLProgram_CreateFromOCLSource ,
36
- DPCTLProgram_CreateFromSpirv ,
37
- DPCTLProgram_Delete ,
38
- DPCTLProgram_GetKernel ,
39
- DPCTLProgram_HasKernel ,
34
+ DPCTLKernelBundle_CreateFromOCLSource ,
35
+ DPCTLKernelBundle_CreateFromSpirv ,
36
+ DPCTLKernelBundle_Delete ,
37
+ DPCTLKernelBundle_GetKernel ,
38
+ DPCTLKernelBundle_HasKernel ,
40
39
DPCTLSyclContextRef,
40
+ DPCTLSyclDeviceRef,
41
+ DPCTLSyclKernelBundleRef,
41
42
DPCTLSyclKernelRef,
42
- DPCTLSyclProgramRef,
43
43
)
44
44
45
45
__all__ = [
@@ -51,8 +51,8 @@ __all__ = [
51
51
]
52
52
53
53
cdef class SyclProgramCompilationError(Exception ):
54
- """ This exception is raised when a ``sycl::program `` could not be built from
55
- either a SPIR-V binary file or a string source.
54
+ """ This exception is raised when a ``sycl::kernel_bundle `` could not be
55
+ built from either a SPIR-V binary file or a string source.
56
56
"""
57
57
pass
58
58
@@ -61,20 +61,19 @@ cdef class SyclKernel:
61
61
"""
62
62
"""
63
63
@staticmethod
64
- cdef SyclKernel _create(DPCTLSyclKernelRef kref):
64
+ cdef SyclKernel _create(DPCTLSyclKernelRef kref, str name ):
65
65
cdef SyclKernel ret = SyclKernel.__new__ (SyclKernel)
66
66
ret._kernel_ref = kref
67
- ret._function_name = DPCTLKernel_GetFunctionName(kref)
67
+ ret._function_name = name
68
68
return ret
69
69
70
70
def __dealloc__ (self ):
71
71
DPCTLKernel_Delete(self ._kernel_ref)
72
- DPCTLCString_Delete(self ._function_name)
73
72
74
73
def get_function_name (self ):
75
74
""" Returns the name of the ``sycl::kernel`` function.
76
75
"""
77
- return self ._function_name.decode()
76
+ return self ._function_name
78
77
79
78
def get_num_args (self ):
80
79
""" Returns the number of arguments for this kernel function.
@@ -98,42 +97,45 @@ cdef class SyclKernel:
98
97
99
98
100
99
cdef class SyclProgram:
101
- """ Wraps a ``sycl::program`` object created from an OpenCL interoperability
102
- program.
100
+ """ Wraps a ``sycl::kernel_bundle<sycl::bundle_state::executable>`` object
101
+ created using SYCL interoperability layer with underlying backends. Only the
102
+ OpenCL and Level-Zero backends are currently supported.
103
103
104
- SyclProgram exposes the C API from ``dpctl_sycl_program_interface .h``. A
105
- SyclProgram can be created from either a source string or a SPIR-V
106
- binary file.
104
+ SyclProgram exposes the C API from ``dpctl_sycl_kernel_bundle_interface .h``.
105
+ A SyclProgram can be created from either a source string or a SPIR-V
106
+ binary file.
107
107
"""
108
108
109
109
@staticmethod
110
- cdef SyclProgram _create(DPCTLSyclProgramRef pref ):
110
+ cdef SyclProgram _create(DPCTLSyclKernelBundleRef KBRef ):
111
111
cdef SyclProgram ret = SyclProgram.__new__ (SyclProgram)
112
- ret._program_ref = pref
112
+ ret._program_ref = KBRef
113
113
return ret
114
114
115
115
def __dealloc__ (self ):
116
- DPCTLProgram_Delete (self ._program_ref)
116
+ DPCTLKernelBundle_Delete (self ._program_ref)
117
117
118
- cdef DPCTLSyclProgramRef get_program_ref(self ):
118
+ cdef DPCTLSyclKernelBundleRef get_program_ref(self ):
119
119
return self ._program_ref
120
120
121
121
cpdef SyclKernel get_sycl_kernel(self , str kernel_name):
122
122
name = kernel_name.encode(' utf8' )
123
- return SyclKernel._create(DPCTLProgram_GetKernel(self ._program_ref,
124
- name))
123
+ return SyclKernel._create(
124
+ DPCTLKernelBundle_GetKernel(self ._program_ref, name),
125
+ kernel_name
126
+ )
125
127
126
128
def has_sycl_kernel (self , str kernel_name ):
127
129
name = kernel_name.encode(' utf8' )
128
- return DPCTLProgram_HasKernel (self ._program_ref, name)
130
+ return DPCTLKernelBundle_HasKernel (self ._program_ref, name)
129
131
130
132
def addressof_ref (self ):
131
- """ Returns the address of the C API DPCTLSyclProgramRef pointer
133
+ """ Returns the address of the C API DPCTLSyclKernelBundleRef pointer
132
134
as a long.
133
135
134
136
Returns:
135
- The address of the ``DPCTLSyclProgramRef `` pointer used to create
136
- this :class:`dpctl.SyclProgram` object cast to a ``size_t``.
137
+ The address of the ``DPCTLSyclKernelBundleRef `` pointer used to
138
+ create this :class:`dpctl.SyclProgram` object cast to a ``size_t``.
137
139
"""
138
140
return int (< size_t> self ._program_ref)
139
141
@@ -142,9 +144,10 @@ cpdef create_program_from_source(SyclQueue q, unicode src, unicode copts=""):
142
144
"""
143
145
Creates a Sycl interoperability program from an OpenCL source string.
144
146
145
- We use the ``DPCTLProgram_CreateFromOCLSource()`` C API function to
146
- create a ``sycl::program`` from an OpenCL source program that can
147
- contain multiple kernels. Note currently only supported for OpenCL.
147
+ We use the ``DPCTLKernelBundle_CreateFromOCLSource()`` C API function
148
+ to create a ``sycl::kernel_bundle<sycl::bundle_state::executable>``
149
+ from an OpenCL source program that can contain multiple kernels.
150
+ Note: This function is currently only supported for the OpenCL backend.
148
151
149
152
Parameters:
150
153
q (SyclQueue) : The :class:`SyclQueue` for which the
@@ -155,33 +158,37 @@ cpdef create_program_from_source(SyclQueue q, unicode src, unicode copts=""):
155
158
156
159
Returns:
157
160
program (SyclProgram): A :class:`SyclProgram` object wrapping the
158
- ``sycl::program`` returned by the C API.
161
+ ``sycl::kernel_bundle<sycl::bundle_state::executable>`` returned
162
+ by the C API.
159
163
160
164
Raises:
161
- SyclProgramCompilationError: If a SYCL program could not be created.
165
+ SyclProgramCompilationError: If a SYCL kernel bundle could not be
166
+ created.
162
167
"""
163
168
164
- cdef DPCTLSyclProgramRef Pref
169
+ cdef DPCTLSyclKernelBundleRef KBref
165
170
cdef bytes bSrc = src.encode(' utf8' )
166
171
cdef bytes bCOpts = copts.encode(' utf8' )
167
172
cdef const char * Src = < const char * > bSrc
168
173
cdef const char * COpts = < const char * > bCOpts
169
174
cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref()
170
- Pref = DPCTLProgram_CreateFromOCLSource(CRef, Src, COpts)
175
+ cdef DPCTLSyclDeviceRef DRef = q.get_sycl_device().get_device_ref()
176
+ KBref = DPCTLKernelBundle_CreateFromOCLSource(CRef, DRef, Src, COpts)
171
177
172
- if Pref is NULL :
178
+ if KBref is NULL :
173
179
raise SyclProgramCompilationError()
174
180
175
- return SyclProgram._create(Pref )
181
+ return SyclProgram._create(KBref )
176
182
177
183
178
184
cpdef create_program_from_spirv(SyclQueue q, const unsigned char [:] IL,
179
185
unicode copts = " " ):
180
186
"""
181
187
Creates a Sycl interoperability program from an SPIR-V binary.
182
188
183
- We use the ``DPCTLProgram_CreateFromOCLSpirv()`` C API function to
184
- create a ``sycl::program`` object from an compiled SPIR-V binary file.
189
+ We use the ``DPCTLKernelBundle_CreateFromOCLSpirv()`` C API function to
190
+ create a ``sycl::kernel_bundle<sycl::bundle_state::executable>`` object
191
+ from an compiled SPIR-V binary file.
185
192
186
193
Parameters:
187
194
q (SyclQueue): The :class:`SyclQueue` for which the
@@ -192,20 +199,25 @@ cpdef create_program_from_spirv(SyclQueue q, const unsigned char[:] IL,
192
199
193
200
Returns:
194
201
program (SyclProgram): A :class:`SyclProgram` object wrapping the
195
- ``sycl::program`` returned by the C API.
202
+ ``sycl::kernel_bundle<sycl::bundle_state::executable>`` returned by
203
+ the C API.
196
204
197
205
Raises:
198
- SyclProgramCompilationError: If a SYCL program could not be created.
206
+ SyclProgramCompilationError: If a SYCL kernel bundle could not be
207
+ created.
199
208
"""
200
209
201
- cdef DPCTLSyclProgramRef Pref
210
+ cdef DPCTLSyclKernelBundleRef KBref
202
211
cdef const unsigned char * dIL = & IL[0 ]
203
212
cdef DPCTLSyclContextRef CRef = q.get_sycl_context().get_context_ref()
213
+ cdef DPCTLSyclDeviceRef DRef = q.get_sycl_device().get_device_ref()
204
214
cdef size_t length = IL.shape[0 ]
205
215
cdef bytes bCOpts = copts.encode(' utf8' )
206
216
cdef const char * COpts = < const char * > bCOpts
207
- Pref = DPCTLProgram_CreateFromSpirv(CRef, < const void * > dIL, length, COpts)
208
- if Pref is NULL :
217
+ KBref = DPCTLKernelBundle_CreateFromSpirv(
218
+ CRef, DRef, < const void * > dIL, length, COpts
219
+ )
220
+ if KBref is NULL :
209
221
raise SyclProgramCompilationError()
210
222
211
- return SyclProgram._create(Pref )
223
+ return SyclProgram._create(KBref )
0 commit comments