Skip to content

Commit 69511ae

Browse files
Python API of addressing #587
Adds `dpctl.SyclDevice.global_mem_size` and `dpctl.SyclDevice.local_mem_size`
1 parent 9c9270e commit 69511ae

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

dpctl/_backend.pxd

Lines changed: 6 additions & 4 deletions
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, uint64_t
24+
from libc.stdint cimport int64_t, uint32_t
2525
from libcpp cimport bool
2626

2727

@@ -149,6 +149,8 @@ cdef extern from "dpctl_sycl_device_interface.h":
149149
cdef _backend_type DPCTLDevice_GetBackend(const DPCTLSyclDeviceRef)
150150
cdef _device_type DPCTLDevice_GetDeviceType(const DPCTLSyclDeviceRef)
151151
cdef const char *DPCTLDevice_GetDriverVersion(const DPCTLSyclDeviceRef DRef)
152+
cdef size_t DPCTLDevice_GetGlobalMemSize(const DPCTLSyclDeviceRef DRef)
153+
cdef size_t DPCTLDevice_GetLocalMemSize(const DPCTLSyclDeviceRef DRef)
152154
cdef uint32_t DPCTLDevice_GetMaxComputeUnits(const DPCTLSyclDeviceRef DRef)
153155
cdef uint32_t DPCTLDevice_GetMaxNumSubGroups(const DPCTLSyclDeviceRef DRef)
154156
cdef size_t DPCTLDevice_GetMaxWorkGroupSize(const DPCTLSyclDeviceRef DRef)
@@ -239,9 +241,9 @@ cdef extern from "dpctl_sycl_event_interface.h":
239241
size_t index)
240242
cdef DPCTLEventVectorRef DPCTLEvent_GetWaitList(
241243
DPCTLSyclEventRef ERef)
242-
cdef uint64_t DPCTLEvent_GetProfilingInfoSubmit(DPCTLSyclEventRef ERef)
243-
cdef uint64_t DPCTLEvent_GetProfilingInfoStart(DPCTLSyclEventRef ERef)
244-
cdef uint64_t DPCTLEvent_GetProfilingInfoEnd(DPCTLSyclEventRef ERef)
244+
cdef size_t DPCTLEvent_GetProfilingInfoSubmit(DPCTLSyclEventRef ERef)
245+
cdef size_t DPCTLEvent_GetProfilingInfoStart(DPCTLSyclEventRef ERef)
246+
cdef size_t DPCTLEvent_GetProfilingInfoEnd(DPCTLSyclEventRef ERef)
245247

246248

247249
cdef extern from "dpctl_sycl_kernel_interface.h":

dpctl/_sycl_device.pyx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ from ._backend cimport ( # noqa: E211
3434
DPCTLDevice_GetBackend,
3535
DPCTLDevice_GetDeviceType,
3636
DPCTLDevice_GetDriverVersion,
37+
DPCTLDevice_GetGlobalMemSize,
3738
DPCTLDevice_GetImage2dMaxHeight,
3839
DPCTLDevice_GetImage2dMaxWidth,
3940
DPCTLDevice_GetImage3dMaxDepth,
4041
DPCTLDevice_GetImage3dMaxHeight,
4142
DPCTLDevice_GetImage3dMaxWidth,
43+
DPCTLDevice_GetLocalMemSize,
4244
DPCTLDevice_GetMaxComputeUnits,
4345
DPCTLDevice_GetMaxNumSubGroups,
4446
DPCTLDevice_GetMaxReadImageArgs,
@@ -656,6 +658,22 @@ cdef class SyclDevice(_SyclDevice):
656658
"""
657659
return DPCTLDevice_GetPreferredVectorWidthHalf(self._device_ref)
658660

661+
@property
662+
def global_mem_size(self):
663+
""" Returns the size of global memory on this device in bytes.
664+
"""
665+
cdef size_t global_mem_size = 0
666+
global_mem_size = DPCTLDevice_GetGlobalMemSize(self._device_ref)
667+
return global_mem_size
668+
669+
@property
670+
def local_mem_size(self):
671+
""" Returns the size of local memory on this device in bytes.
672+
"""
673+
cdef size_t local_mem_size = 0
674+
local_mem_size = DPCTLDevice_GetLocalMemSize(self._device_ref)
675+
return global_mem_size
676+
659677
@property
660678
def vendor(self):
661679
""" Returns the device vendor name as a string.

dpctl/tests/test_sycl_device.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ def check_get_max_compute_units(device):
6161
assert max_compute_units > 0
6262

6363

64+
def check_get_global_mem_size(device):
65+
global_mem_size = device.global_mem_size
66+
assert global_mem_size > 0
67+
68+
69+
def check_get_local_mem_size(device):
70+
local_mem_size = device.local_mem_size
71+
assert local_mem_size > 0
72+
73+
6474
def check_get_max_work_item_dims(device):
6575
max_work_item_dims = device.max_work_item_dims
6676
assert max_work_item_dims > 0
@@ -529,6 +539,8 @@ def check_repr(device):
529539
check_create_sub_devices_by_affinity_next_partitionable,
530540
check_print_device_info,
531541
check_repr,
542+
check_get_global_mem_size,
543+
check_get_local_mem_size,
532544
]
533545

534546

0 commit comments

Comments
 (0)