Skip to content

Commit bcf1a14

Browse files
Added 3 more SyclDevice properties
* dpctl.SyclDevice.global_mem_cache_size * dpctl.SyclDevice.global_mem_cache_line_size * dpctl.SyclDevice.global_mem_cache_type The last property output is a new enum dpctl.global_mem_cache_type which can assume 3 values: none, read_only, and read_write
1 parent 3d50171 commit bcf1a14

File tree

5 files changed

+108
-5
lines changed

5 files changed

+108
-5
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: 11 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":

dpctl/_sycl_device.pyx

Lines changed: 50 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
@@ -1097,6 +1101,50 @@ cdef class SyclDevice(_SyclDevice):
10971101
raise RuntimeError("Failed to get device timer resolution.")
10981102
return timer_res
10991103

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def check_driver_version(device):
543543

544544
def check_vendor(device):
545545
ve = device.vendor
546-
assert ve
546+
assert ve or device.is_host
547547
assert type(ve) is str
548548

549549

@@ -563,6 +563,23 @@ def check_device_type(device):
563563
assert type(dt) is dpctl.device_type
564564

565565

566+
def check_global_mem_cache_type(device):
567+
gmc_ty = device.global_mem_cache_type
568+
assert type(gmc_ty) is dpctl.global_mem_cache_type
569+
570+
571+
def check_global_mem_cache_size(device):
572+
gmc_sz = device.global_mem_cache_size
573+
assert type(gmc_sz) is int
574+
assert gmc_sz
575+
576+
577+
def check_global_mem_cache_line_size(device):
578+
gmc_sz = device.global_mem_cache_line_size
579+
assert type(gmc_sz) is int
580+
assert gmc_sz
581+
582+
566583
list_of_checks = [
567584
check_max_compute_units,
568585
check_max_work_item_dims,
@@ -634,6 +651,9 @@ def check_device_type(device):
634651
check_default_selector_score,
635652
check_backend,
636653
check_device_type,
654+
check_global_mem_cache_type,
655+
check_global_mem_cache_size,
656+
check_global_mem_cache_line_size,
637657
]
638658

639659

0 commit comments

Comments
 (0)