Skip to content

Commit 0da4e4c

Browse files
committed
Implemented DPCTLKernel_GetName
1 parent be9ea33 commit 0da4e4c

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ cdef extern from "syclinterface/dpctl_sycl_event_interface.h":
262262

263263
cdef extern from "syclinterface/dpctl_sycl_kernel_interface.h":
264264
cdef size_t DPCTLKernel_GetNumArgs(const DPCTLSyclKernelRef KRef)
265+
cdef const char *DPCTLKernel_GetName(const DPCTLSyclKernelRef KRef)
265266
cdef void DPCTLKernel_Delete(DPCTLSyclKernelRef KRef)
266267
cdef DPCTLSyclKernelRef DPCTLKernel_Copy(const DPCTLSyclKernelRef KRef)
267268
cdef size_t DPCTLKernel_GetWorkGroupSize(const DPCTLSyclKernelRef KRef)

dpctl/program/_program.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from dpctl._backend cimport ( # noqa: E211, E402;
3636
DPCTLKernel_GetCompileSubGroupSize,
3737
DPCTLKernel_GetMaxNumSubGroups,
3838
DPCTLKernel_GetNumArgs,
39+
DPCTLKernel_GetName,
3940
DPCTLKernel_GetPreferredWorkGroupSizeMultiple,
4041
DPCTLKernel_GetPrivateMemSize,
4142
DPCTLKernel_GetWorkGroupSize,
@@ -178,7 +179,9 @@ cdef api SyclKernel SyclKernel_Make(DPCTLSyclKernelRef KRef):
178179
instance from opaque sycl kernel reference.
179180
"""
180181
cdef DPCTLSyclKernelRef copied_KRef = DPCTLKernel_Copy(KRef)
181-
return SyclKernel._create(copied_KRef, "foo")
182+
cdef const char *name = DPCTLKernel_GetName(copied_KRef)
183+
copied_name = name.decode("UTF-8")
184+
return SyclKernel._create(copied_KRef, copied_name)
182185

183186
cdef class SyclProgram:
184187
""" Wraps a ``sycl::kernel_bundle<sycl::bundle_state::executable>`` object

libsyclinterface/include/dpctl_sycl_kernel_interface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ DPCTL_C_EXTERN_C_BEGIN
5151
DPCTL_API
5252
size_t DPCTLKernel_GetNumArgs(__dpctl_keep const DPCTLSyclKernelRef KRef);
5353

54+
/*!
55+
* @brief Returns a C string for the function name.
56+
*
57+
* @param KRef DPCTLSyclKernelRef pointer to a SYCL
58+
* interoperability kernel.
59+
* @return A C string containing the name of the function.
60+
* @ingroup KernelInterface
61+
*/
62+
DPCTL_API
63+
__dpctl_give const char *
64+
DPCTLKernel_GetName(__dpctl_keep const DPCTLSyclKernelRef KRef);
65+
5466
/*!
5567
* @brief Deletes the DPCTLSyclKernelRef after casting it to a
5668
* ``sycl::kernel``.

libsyclinterface/source/dpctl_sycl_kernel_interface.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ size_t DPCTLKernel_GetNumArgs(__dpctl_keep const DPCTLSyclKernelRef KRef)
5454
return static_cast<size_t>(num_args);
5555
}
5656

57+
__dpctl_give const char *
58+
DPCTLKernel_GetName(__dpctl_keep const DPCTLSyclKernelRef KRef)
59+
{
60+
if (!KRef) {
61+
error_handler("Cannot get the name from "
62+
"DPCTLSyclKernelRef as input is a nullptr.",
63+
__FILE__, __func__, __LINE__);
64+
return nullptr;
65+
}
66+
67+
auto sycl_kernel = unwrap(KRef);
68+
auto name = sycl_kernel->get_info<info::kernel::function_name>();
69+
return dpctl::helper::cstring_from_string(name);
70+
}
71+
5772
void DPCTLKernel_Delete(__dpctl_take DPCTLSyclKernelRef KRef)
5873
{
5974
delete unwrap(KRef);

0 commit comments

Comments
 (0)