Skip to content

Commit 2870b50

Browse files
Exported kernel device-specific properties
1 parent d359eb0 commit 2870b50

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

dpctl/_backend.pxd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ cdef extern from "syclinterface/dpctl_sycl_event_interface.h":
264264
cdef extern from "syclinterface/dpctl_sycl_kernel_interface.h":
265265
cdef size_t DPCTLKernel_GetNumArgs(const DPCTLSyclKernelRef KRef)
266266
cdef void DPCTLKernel_Delete(DPCTLSyclKernelRef KRef)
267+
cdef size_t DPCTLKernel_GetWorkGroupSize(const DPCTLSyclKernelRef KRef)
268+
cdef size_t DPCTLKernel_GetPreferredWorkGroupSizeMultiple(const DPCTLSyclKernelRef KRef)
269+
cdef size_t DPCTLKernel_GetPrivateMemSize(const DPCTLSyclKernelRef KRef)
270+
cdef uint32_t DPCTLKernel_GetMaxNumSubGroups(const DPCTLSyclKernelRef KRef)
271+
## Next line is commented out due to issue in DPC++ runtime
272+
# cdef uint32_t DPCTLKernel_GetMaxSubGroupSize(const DPCTLSyclKernelRef KRef)
273+
cdef uint32_t DPCTLKernel_GetCompileNumSubGroups(const DPCTLSyclKernelRef KRef)
274+
cdef uint32_t DPCTLKernel_GetCompileSubGroupSize(const DPCTLSyclKernelRef KRef)
267275

268276

269277
cdef extern from "syclinterface/dpctl_sycl_platform_manager.h":

dpctl/program/_program.pyx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ a OpenCL source string or a SPIR-V binary file.
2626
"""
2727

2828
cimport cython.array
29+
from libc.stdint cimport uint32_t
2930

30-
from dpctl._backend cimport ( # noqa: E211, E402
31+
from dpctl._backend cimport ( # noqa: E211, E402;
3132
DPCTLCString_Delete,
3233
DPCTLKernel_Delete,
34+
DPCTLKernel_GetCompileNumSubGroups,
35+
DPCTLKernel_GetCompileSubGroupSize,
36+
DPCTLKernel_GetMaxNumSubGroups,
3337
DPCTLKernel_GetNumArgs,
38+
DPCTLKernel_GetPreferredWorkGroupSizeMultiple,
39+
DPCTLKernel_GetPrivateMemSize,
40+
DPCTLKernel_GetWorkGroupSize,
3441
DPCTLKernelBundle_CreateFromOCLSource,
3542
DPCTLKernelBundle_CreateFromSpirv,
3643
DPCTLKernelBundle_Delete,
@@ -95,6 +102,61 @@ cdef class SyclKernel:
95102
"""
96103
return int(<size_t>self._kernel_ref)
97104

105+
@property
106+
def work_group_size(self):
107+
""" Returns the maximum number of work-items in a work-group that can
108+
be used to execute the kernel on device it was built for.
109+
"""
110+
cdef size_t v = DPCTLKernel_GetWorkGroupSize(self._kernel_ref)
111+
return v
112+
113+
@property
114+
def preferred_work_group_size_multiple(self):
115+
""" Returns a value, of which work-group size is preferred to be
116+
a multiple, for executing the kernel on the device it was built for.
117+
"""
118+
cdef size_t v = DPCTLKernel_GetPreferredWorkGroupSizeMultiple(
119+
self._kernel_ref)
120+
return v
121+
122+
@property
123+
def private_mem_size(self):
124+
""" Returns the minimum amount of private memory, in bytes, used by each
125+
work-item in the kernel.
126+
"""
127+
cdef size_t v = DPCTLKernel_GetPrivateMemSize(self._kernel_ref)
128+
return v
129+
130+
@property
131+
def max_num_sub_groups(self):
132+
""" Returns the maximum number of sub-groups for this kernel.
133+
"""
134+
cdef uint32_t n = DPCTLKernel_GetMaxNumSubGroups(self._kernel_ref)
135+
return n
136+
137+
@property
138+
def max_sub_group_size(self):
139+
""" Returns the maximum sub-groups size for this kernel.
140+
"""
141+
cdef uint32_t sz = 0
142+
return NotImplemented
143+
144+
@property
145+
def compile_num_sub_groups(self):
146+
""" Returns the number of sub-groups specified by this kernel,
147+
or 0 (if not specified).
148+
"""
149+
cdef size_t n = DPCTLKernel_GetCompileNumSubGroups(self._kernel_ref)
150+
return n
151+
152+
@property
153+
def compile_sub_group_size(self):
154+
""" Returns the required sub-group size specified by this kernel,
155+
or 0 (if not specified).
156+
"""
157+
cdef size_t n = DPCTLKernel_GetCompileSubGroupSize(self._kernel_ref)
158+
return n
159+
98160

99161
cdef class SyclProgram:
100162
""" Wraps a ``sycl::kernel_bundle<sycl::bundle_state::executable>`` object

0 commit comments

Comments
 (0)