Skip to content

Commit f48cf30

Browse files
Merge pull request #894 from IntelPython/gh-886-more-device-attributes
gh-886: Added 3 new device attributes and kernel's device-specific attributes
2 parents d3ce471 + 706237c commit f48cf30

16 files changed

+904
-87
lines changed

dpctl/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@
7373
from ._device_selection import select_device_with_aspects
7474
from ._sycl_timer import SyclTimer
7575
from ._version import get_versions
76-
from .enum_types import backend_type, device_type, event_status_type
76+
from .enum_types import (
77+
backend_type,
78+
device_type,
79+
event_status_type,
80+
global_mem_cache_type,
81+
)
7782

7883
__all__ = [
7984
"SyclContext",
@@ -127,6 +132,7 @@
127132
"device_type",
128133
"backend_type",
129134
"event_status_type",
135+
"global_mem_cache_type",
130136
]
131137
__all__ += [
132138
"get_include",

dpctl/_backend.pxd

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
types defined by dpctl's C API.
2222
"""
2323

24-
from libc.stdint cimport int64_t, uint32_t
24+
from libc.stdint cimport int64_t, uint32_t, uint64_t
2525
from libcpp cimport bool
2626

2727

@@ -112,6 +112,12 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h":
112112
_RUNNING 'DPCTL_RUNNING'
113113
_COMPLETE 'DPCTL_COMPLETE'
114114

115+
ctypedef enum _global_mem_cache_type 'DPCTLGlobalMemCacheType':
116+
_MEM_CACHE_TYPE_INDETERMINATE 'DPCTL_MEM_CACHE_TYPE_INDETERMINATE'
117+
_MEM_CACHE_TYPE_NONE 'DPCTL_MEM_CACHE_TYPE_NONE'
118+
_MEM_CACHE_TYPE_READ_ONLY 'DPCTL_MEM_CACHE_TYPE_READ_ONLY'
119+
_MEM_CACHE_TYPE_READ_WRITE 'DPCTL_MEM_CACHE_TYPE_READ_WRITE'
120+
115121

116122
cdef extern from "syclinterface/dpctl_sycl_types.h":
117123
cdef struct DPCTLOpaqueSyclContext
@@ -195,6 +201,10 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
195201
_partition_affinity_domain_type PartitionAffinityDomainTy)
196202
cdef DPCTLSyclDeviceRef DPCTLDevice_GetParentDevice(const DPCTLSyclDeviceRef DRef)
197203
cdef size_t DPCTLDevice_GetProfilingTimerResolution(const DPCTLSyclDeviceRef DRef)
204+
cdef uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(const DPCTLSyclDeviceRef DRef)
205+
cdef uint64_t DPCTLDevice_GetGlobalMemCacheSize(const DPCTLSyclDeviceRef DRef)
206+
cdef _global_mem_cache_type DPCTLDevice_GetGlobalMemCacheType(
207+
const DPCTLSyclDeviceRef DRef)
198208

199209

200210
cdef extern from "syclinterface/dpctl_sycl_device_manager.h":
@@ -254,6 +264,14 @@ cdef extern from "syclinterface/dpctl_sycl_event_interface.h":
254264
cdef extern from "syclinterface/dpctl_sycl_kernel_interface.h":
255265
cdef size_t DPCTLKernel_GetNumArgs(const DPCTLSyclKernelRef KRef)
256266
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)
257275

258276

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

dpctl/_sycl_device.pyx

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ from ._backend cimport ( # noqa: E211
3434
DPCTLDevice_GetBackend,
3535
DPCTLDevice_GetDeviceType,
3636
DPCTLDevice_GetDriverVersion,
37+
DPCTLDevice_GetGlobalMemCacheLineSize,
38+
DPCTLDevice_GetGlobalMemCacheSize,
39+
DPCTLDevice_GetGlobalMemCacheType,
3740
DPCTLDevice_GetGlobalMemSize,
3841
DPCTLDevice_GetImage2dMaxHeight,
3942
DPCTLDevice_GetImage2dMaxWidth,
@@ -87,12 +90,13 @@ from ._backend cimport ( # noqa: E211
8790
_aspect_type,
8891
_backend_type,
8992
_device_type,
93+
_global_mem_cache_type,
9094
_partition_affinity_domain_type,
9195
)
9296

93-
from .enum_types import backend_type, device_type
97+
from .enum_types import backend_type, device_type, global_mem_cache_type
9498

95-
from libc.stdint cimport int64_t, uint32_t
99+
from libc.stdint cimport int64_t, uint32_t, uint64_t
96100
from libc.stdlib cimport free, malloc
97101

98102
from ._sycl_platform cimport SyclPlatform
@@ -1098,6 +1102,52 @@ cdef class SyclDevice(_SyclDevice):
10981102
raise RuntimeError("Failed to get device timer resolution.")
10991103
return timer_res
11001104

1105+
@property
1106+
def global_mem_cache_type(self):
1107+
""" Global device cache memory type.
1108+
1109+
Returns:
1110+
global_mem_cache_type: type of cache memory
1111+
Raises:
1112+
A RuntimeError is raised if an unrecognized memory type
1113+
is reported by runtime.
1114+
"""
1115+
cdef _global_mem_cache_type gmcTy = (
1116+
DPCTLDevice_GetGlobalMemCacheType(self._device_ref)
1117+
)
1118+
if gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_READ_WRITE:
1119+
return global_mem_cache_type.read_write
1120+
elif gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_READ_ONLY:
1121+
return global_mem_cache_type.read_only
1122+
elif gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_NONE:
1123+
return global_mem_cache_type.none
1124+
elif gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_INDETERMINATE:
1125+
raise RuntimeError("Unrecognized global memory cache type reported")
1126+
1127+
@property
1128+
def global_mem_cache_size(self):
1129+
""" Global device memory cache size.
1130+
1131+
Returns:
1132+
int: Cache size in bytes
1133+
"""
1134+
cdef uint64_t cache_sz = DPCTLDevice_GetGlobalMemCacheSize(
1135+
self._device_ref
1136+
)
1137+
return cache_sz
1138+
1139+
@property
1140+
def global_mem_cache_line_size(self):
1141+
""" Global device memory cache line size.
1142+
1143+
Returns:
1144+
int: Cache size in bytes
1145+
"""
1146+
cdef uint64_t cache_line_sz = DPCTLDevice_GetGlobalMemCacheLineSize(
1147+
self._device_ref
1148+
)
1149+
return cache_line_sz
1150+
11011151
cdef cpp_bool equals(self, SyclDevice other):
11021152
""" Returns ``True`` if the :class:`dpctl.SyclDevice` argument has the
11031153
same _device_ref as this SyclDevice.

dpctl/enum_types.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,22 @@ class event_status_type(Enum):
9696
submitted = auto()
9797
running = auto()
9898
complete = auto()
99+
100+
101+
class global_mem_cache_type(Enum):
102+
"""
103+
An enumeration of global memory cache types for a device.
104+
105+
:Example:
106+
.. code-block:: python
107+
108+
import dpctl
109+
dev = dpctl.SyclDevice()
110+
print(dev.global_mem_cache_type)
111+
# Possible output: <global_mem_cache_type.read_write: 4>
112+
"""
113+
114+
indeterminate = auto()
115+
none = auto()
116+
read_only = auto()
117+
read_write = auto()

dpctl/program/_program.pyx

Lines changed: 70 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,68 @@ cdef class SyclKernel:
95102
"""
96103
return int(<size_t>self._kernel_ref)
97104

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

99168
cdef class SyclProgram:
100169
""" Wraps a ``sycl::kernel_bundle<sycl::bundle_state::executable>`` object

0 commit comments

Comments
 (0)