Skip to content

Commit

Permalink
Added 3 more SyclDevice properties
Browse files Browse the repository at this point in the history
  * 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
  • Loading branch information
oleksandr-pavlyk committed Aug 28, 2022
1 parent 3d50171 commit 6c1b5b8
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
8 changes: 7 additions & 1 deletion dpctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@
from ._device_selection import select_device_with_aspects
from ._sycl_timer import SyclTimer
from ._version import get_versions
from .enum_types import backend_type, device_type, event_status_type
from .enum_types import (
backend_type,
device_type,
event_status_type,
global_mem_cache_type,
)

__all__ = [
"SyclContext",
Expand Down Expand Up @@ -127,6 +132,7 @@
"device_type",
"backend_type",
"event_status_type",
"global_mem_cache_type",
]
__all__ += [
"get_include",
Expand Down
12 changes: 11 additions & 1 deletion dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
types defined by dpctl's C API.
"""

from libc.stdint cimport int64_t, uint32_t
from libc.stdint cimport int64_t, uint32_t, uint64_t
from libcpp cimport bool


Expand Down Expand Up @@ -112,6 +112,12 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h":
_RUNNING 'DPCTL_RUNNING'
_COMPLETE 'DPCTL_COMPLETE'

ctypedef enum _global_mem_cache_type 'DPCTLGlobalMemCacheType':
_MEM_CACHE_TYPE_INDETERMINATE 'DPCTL_MEM_CACHE_TYPE_INDETERMINATE'
_MEM_CACHE_TYPE_NONE 'DPCTL_MEM_CACHE_TYPE_NONE'
_MEM_CACHE_TYPE_READ_ONLY 'DPCTL_MEM_CACHE_TYPE_READ_ONLY'
_MEM_CACHE_TYPE_READ_WRITE 'DPCTL_MEM_CACHE_TYPE_READ_WRITE'


cdef extern from "syclinterface/dpctl_sycl_types.h":
cdef struct DPCTLOpaqueSyclContext
Expand Down Expand Up @@ -195,6 +201,10 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
_partition_affinity_domain_type PartitionAffinityDomainTy)
cdef DPCTLSyclDeviceRef DPCTLDevice_GetParentDevice(const DPCTLSyclDeviceRef DRef)
cdef size_t DPCTLDevice_GetProfilingTimerResolution(const DPCTLSyclDeviceRef DRef)
cdef uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(const DPCTLSyclDeviceRef DRef)
cdef uint64_t DPCTLDevice_GetGlobalMemCacheSize(const DPCTLSyclDeviceRef DRef)
cdef _global_mem_cache_type DPCTLDevice_GetGlobalMemCacheType(
const DPCTLSyclDeviceRef DRef)


cdef extern from "syclinterface/dpctl_sycl_device_manager.h":
Expand Down
52 changes: 50 additions & 2 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ from ._backend cimport ( # noqa: E211
DPCTLDevice_GetBackend,
DPCTLDevice_GetDeviceType,
DPCTLDevice_GetDriverVersion,
DPCTLDevice_GetGlobalMemCacheLineSize,
DPCTLDevice_GetGlobalMemCacheSize,
DPCTLDevice_GetGlobalMemCacheType,
DPCTLDevice_GetGlobalMemSize,
DPCTLDevice_GetImage2dMaxHeight,
DPCTLDevice_GetImage2dMaxWidth,
Expand Down Expand Up @@ -87,12 +90,13 @@ from ._backend cimport ( # noqa: E211
_aspect_type,
_backend_type,
_device_type,
_global_mem_cache_type,
_partition_affinity_domain_type,
)

from .enum_types import backend_type, device_type
from .enum_types import backend_type, device_type, global_mem_cache_type

from libc.stdint cimport int64_t, uint32_t
from libc.stdint cimport int64_t, uint32_t, uint64_t
from libc.stdlib cimport free, malloc

from ._sycl_platform cimport SyclPlatform
Expand Down Expand Up @@ -1097,6 +1101,50 @@ cdef class SyclDevice(_SyclDevice):
raise RuntimeError("Failed to get device timer resolution.")
return timer_res

@property
def global_mem_cache_type(self):
""" Global device cache memory type.
Returns:
global_mem_cache_type: type of cache memory
Raises:
A RuntimeError is raised if an unrecognized memory type
is reported by runtime.
"""
cdef _global_mem_cache_type gmcTy = (
DPCTLDevice_GetGlobalMemCacheType(self._device_ref)
)
if gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_READ_WRITE:
return global_mem_cache_type.read_only
elif gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_READ_ONLY:
return global_mem_cache_type.read_only
elif gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_NONE:
return global_mem_cache_type.none
elif gmcTy == _global_mem_cache_type._MEM_CACHE_TYPE_INDETERMINATE:
raise RuntimeError("Unrecognized global memory cache type reported")

@property
def global_mem_cache_size(self):
""" Global device memory cache size.
Returns:
int: Cache size in bytes
"""
cdef uint64_t cache_sz = DPCTLDevice_GetGlobalMemCacheSize(
self._device_ref)
return cache_sz

@property
def global_mem_cache_line_size(self):
""" Global device memory cache line size.
Returns:
int: Cache size in bytes
"""
cdef uint64_t cache_line_sz = DPCTLDevice_GetGlobalMemCacheLineSize(
self._device_ref)
return cache_line_sz

cdef cpp_bool equals(self, SyclDevice other):
""" Returns ``True`` if the :class:`dpctl.SyclDevice` argument has the
same _device_ref as this SyclDevice.
Expand Down
19 changes: 19 additions & 0 deletions dpctl/enum_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,22 @@ class event_status_type(Enum):
submitted = auto()
running = auto()
complete = auto()


class global_mem_cache_type(Enum):
"""
An enumeration of global memory cache types for a device.
:Example:
.. code-block:: python
import dpctl
dev = dpctl.SyclDevice()
print(dev.global_mem_cache_type)
# Possible output: <global_mem_cache_type.read_write: 4>
"""

indeterminate = auto()
none = auto()
read_only = auto()
read_write = auto()
20 changes: 20 additions & 0 deletions dpctl/tests/_device_attributes_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,23 @@ def check_device_type(device):
assert type(dt) is dpctl.device_type


def check_global_mem_cache_type(device):
gmc_ty = device.global_mem_cache_type
assert type(gmc_ty) is dpctl.global_mem_cache_type


def check_global_mem_cache_size(device):
gmc_sz = device.global_mem_cache_size
assert type(gmc_sz) is int
assert gmc_sz


def check_global_mem_cache_line_size(device):
gmc_sz = device.global_mem_cache_line_size
assert type(gmc_sz) is int
assert gmc_sz


list_of_checks = [
check_max_compute_units,
check_max_work_item_dims,
Expand Down Expand Up @@ -634,6 +651,9 @@ def check_device_type(device):
check_default_selector_score,
check_backend,
check_device_type,
check_global_mem_cache_type,
check_global_mem_cache_size,
check_global_mem_cache_line_size,
]


Expand Down

0 comments on commit 6c1b5b8

Please sign in to comment.