Skip to content

Commit a3ce695

Browse files
SyclKernel_Make now takes KernelRef and const char * for the name.
Nullptr is also handled, interpreting it as "default_name". Pybind11 caster provides a fixed name 'dpctl4pybind11_kernel'
1 parent 0da4e4c commit a3ce695

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

dpctl/apis/include/dpctl4pybind11.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct dpctl_capi
9898

9999
// program
100100
DPCTLSyclKernelRef (*SyclKernel_GetKernelRef_)(PySyclKernelObject *);
101-
PySyclKernelObject *(*SyclKernel_Make_)(DPCTLSyclKernelRef);
101+
PySyclKernelObject *(*SyclKernel_Make_)(DPCTLSyclKernelRef, const char *);
102102

103103
DPCTLSyclKernelBundleRef (*SyclProgram_GetKernelBundleRef_)(
104104
PySyclProgramObject *);
@@ -561,7 +561,8 @@ template <> struct type_caster<sycl::kernel>
561561
{
562562
auto &api = ::dpctl::detail::dpctl_capi::get();
563563
auto tmp =
564-
api.SyclKernel_Make_(reinterpret_cast<DPCTLSyclKernelRef>(&src));
564+
api.SyclKernel_Make_(reinterpret_cast<DPCTLSyclKernelRef>(&src),
565+
"dpctl4pybind11_kernel");
565566
return handle(reinterpret_cast<PyObject *>(tmp));
566567
}
567568

dpctl/program/_program.pyx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ from dpctl._backend cimport ( # noqa: E211, E402;
3535
DPCTLKernel_GetCompileNumSubGroups,
3636
DPCTLKernel_GetCompileSubGroupSize,
3737
DPCTLKernel_GetMaxNumSubGroups,
38-
DPCTLKernel_GetNumArgs,
3938
DPCTLKernel_GetName,
39+
DPCTLKernel_GetNumArgs,
4040
DPCTLKernel_GetPreferredWorkGroupSizeMultiple,
4141
DPCTLKernel_GetPrivateMemSize,
4242
DPCTLKernel_GetWorkGroupSize,
@@ -167,21 +167,25 @@ cdef class SyclKernel:
167167
cdef size_t n = DPCTLKernel_GetCompileSubGroupSize(self._kernel_ref)
168168
return n
169169

170+
170171
cdef api DPCTLSyclKernelRef SyclKernel_GetKernelRef(SyclKernel ker):
171172
""" C-API function to access opaque kernel reference from
172173
Python object of type :class:`dpctl.program.SyclKernel`.
173174
"""
174175
return ker.get_kernel_ref()
175176

176-
cdef api SyclKernel SyclKernel_Make(DPCTLSyclKernelRef KRef):
177+
178+
cdef api SyclKernel SyclKernel_Make(DPCTLSyclKernelRef KRef, const char *name):
177179
"""
178180
C-API function to create :class:`dpctl.program.SyclKernel`
179181
instance from opaque sycl kernel reference.
180182
"""
181183
cdef DPCTLSyclKernelRef copied_KRef = DPCTLKernel_Copy(KRef)
182-
cdef const char *name = DPCTLKernel_GetName(copied_KRef)
183-
copied_name = name.decode("UTF-8")
184-
return SyclKernel._create(copied_KRef, copied_name)
184+
if (name is NULL):
185+
return SyclKernel._create(copied_KRef, "default_name")
186+
else:
187+
return SyclKernel._create(copied_KRef, name.decode("utf-8"))
188+
185189

186190
cdef class SyclProgram:
187191
""" Wraps a ``sycl::kernel_bundle<sycl::bundle_state::executable>`` object
@@ -309,12 +313,14 @@ cpdef create_program_from_spirv(SyclQueue q, const unsigned char[:] IL,
309313

310314
return SyclProgram._create(KBref)
311315

316+
312317
cdef api DPCTLSyclKernelBundleRef SyclProgram_GetKernelBundleRef(SyclProgram pro):
313318
""" C-API function to access opaque kernel bundle reference from
314319
Python object of type :class:`dpctl.program.SyclKernel`.
315320
"""
316321
return pro.get_program_ref()
317322

323+
318324
cdef api SyclProgram SyclProgram_Make(DPCTLSyclKernelBundleRef KBRef):
319325
"""
320326
C-API function to create :class:`dpctl.program.SyclProgram`

0 commit comments

Comments
 (0)