Skip to content

Device memory sizes #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dpctl-capi/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ DPCTL_API
uint32_t
DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over device.get_info<info::device::global_mem_size>().
*
* @param DRef Opaque pointer to a ``sycl::device``
* @return Returns the valid result if device exists else returns 0.
* @ingroup DeviceInterface
*/
DPCTL_API
uint64_t
DPCTLDevice_GetGlobalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over device.get_info<info::device::local_mem_size>().
*
* @param DRef Opaque pointer to a ``sycl::device``
* @return Returns the valid result if device exists else returns 0.
* @ingroup DeviceInterface
*/
DPCTL_API
uint64_t
DPCTLDevice_GetLocalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper for get_info<info::device::max_work_item_dimensions>().
*
Expand Down
31 changes: 31 additions & 0 deletions dpctl-capi/source/dpctl_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,37 @@ DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef)
return nComputeUnits;
}

uint64_t
DPCTLDevice_GetGlobalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
uint64_t GlobalMemSize = 0;
auto D = unwrap(DRef);
if (D) {
try {
GlobalMemSize = D->get_info<info::device::global_mem_size>();
} catch (runtime_error const &re) {
// \todo log error
std::cerr << re.what() << '\n';
}
}
return GlobalMemSize;
}

uint64_t DPCTLDevice_GetLocalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
uint64_t LocalMemSize = 0;
auto D = unwrap(DRef);
if (D) {
try {
LocalMemSize = D->get_info<info::device::local_mem_size>();
} catch (runtime_error const &re) {
// \todo log error
std::cerr << re.what() << '\n';
}
}
return LocalMemSize;
}

uint32_t
DPCTLDevice_GetMaxWorkItemDims(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
Expand Down
14 changes: 14 additions & 0 deletions dpctl-capi/tests/test_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetMaxComputeUnits)
EXPECT_TRUE(n > 0);
}

TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemSize)
{
size_t gm_sz = 0;
EXPECT_NO_FATAL_FAILURE(gm_sz = DPCTLDevice_GetGlobalMemSize(DRef));
EXPECT_TRUE(gm_sz > 0);
}

TEST_P(TestDPCTLSyclDeviceInterface, ChkGetLocalMemSize)
{
size_t lm_sz = 0;
EXPECT_NO_FATAL_FAILURE(lm_sz = DPCTLDevice_GetLocalMemSize(DRef));
EXPECT_TRUE(lm_sz > 0);
}

TEST_P(TestDPCTLSyclDeviceInterface, ChkGetMaxWorkItemDims)
{
size_t n = 0;
Expand Down
10 changes: 6 additions & 4 deletions 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, uint64_t
from libc.stdint cimport int64_t, uint32_t
from libcpp cimport bool


Expand Down Expand Up @@ -149,6 +149,8 @@ cdef extern from "dpctl_sycl_device_interface.h":
cdef _backend_type DPCTLDevice_GetBackend(const DPCTLSyclDeviceRef)
cdef _device_type DPCTLDevice_GetDeviceType(const DPCTLSyclDeviceRef)
cdef const char *DPCTLDevice_GetDriverVersion(const DPCTLSyclDeviceRef DRef)
cdef size_t DPCTLDevice_GetGlobalMemSize(const DPCTLSyclDeviceRef DRef)
cdef size_t DPCTLDevice_GetLocalMemSize(const DPCTLSyclDeviceRef DRef)
cdef uint32_t DPCTLDevice_GetMaxComputeUnits(const DPCTLSyclDeviceRef DRef)
cdef uint32_t DPCTLDevice_GetMaxNumSubGroups(const DPCTLSyclDeviceRef DRef)
cdef size_t DPCTLDevice_GetMaxWorkGroupSize(const DPCTLSyclDeviceRef DRef)
Expand Down Expand Up @@ -239,9 +241,9 @@ cdef extern from "dpctl_sycl_event_interface.h":
size_t index)
cdef DPCTLEventVectorRef DPCTLEvent_GetWaitList(
DPCTLSyclEventRef ERef)
cdef uint64_t DPCTLEvent_GetProfilingInfoSubmit(DPCTLSyclEventRef ERef)
cdef uint64_t DPCTLEvent_GetProfilingInfoStart(DPCTLSyclEventRef ERef)
cdef uint64_t DPCTLEvent_GetProfilingInfoEnd(DPCTLSyclEventRef ERef)
cdef size_t DPCTLEvent_GetProfilingInfoSubmit(DPCTLSyclEventRef ERef)
cdef size_t DPCTLEvent_GetProfilingInfoStart(DPCTLSyclEventRef ERef)
cdef size_t DPCTLEvent_GetProfilingInfoEnd(DPCTLSyclEventRef ERef)


cdef extern from "dpctl_sycl_kernel_interface.h":
Expand Down
18 changes: 18 additions & 0 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ from ._backend cimport ( # noqa: E211
DPCTLDevice_GetBackend,
DPCTLDevice_GetDeviceType,
DPCTLDevice_GetDriverVersion,
DPCTLDevice_GetGlobalMemSize,
DPCTLDevice_GetImage2dMaxHeight,
DPCTLDevice_GetImage2dMaxWidth,
DPCTLDevice_GetImage3dMaxDepth,
DPCTLDevice_GetImage3dMaxHeight,
DPCTLDevice_GetImage3dMaxWidth,
DPCTLDevice_GetLocalMemSize,
DPCTLDevice_GetMaxComputeUnits,
DPCTLDevice_GetMaxNumSubGroups,
DPCTLDevice_GetMaxReadImageArgs,
Expand Down Expand Up @@ -656,6 +658,22 @@ cdef class SyclDevice(_SyclDevice):
"""
return DPCTLDevice_GetPreferredVectorWidthHalf(self._device_ref)

@property
def global_mem_size(self):
""" Returns the size of global memory on this device in bytes.
"""
cdef size_t global_mem_size = 0
global_mem_size = DPCTLDevice_GetGlobalMemSize(self._device_ref)
return global_mem_size

@property
def local_mem_size(self):
""" Returns the size of local memory on this device in bytes.
"""
cdef size_t local_mem_size = 0
local_mem_size = DPCTLDevice_GetLocalMemSize(self._device_ref)
return local_mem_size

@property
def vendor(self):
""" Returns the device vendor name as a string.
Expand Down
12 changes: 12 additions & 0 deletions dpctl/tests/test_sycl_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ def check_get_max_compute_units(device):
assert max_compute_units > 0


def check_get_global_mem_size(device):
global_mem_size = device.global_mem_size
assert global_mem_size > 0


def check_get_local_mem_size(device):
local_mem_size = device.local_mem_size
assert local_mem_size > 0


def check_get_max_work_item_dims(device):
max_work_item_dims = device.max_work_item_dims
assert max_work_item_dims > 0
Expand Down Expand Up @@ -529,6 +539,8 @@ def check_repr(device):
check_create_sub_devices_by_affinity_next_partitionable,
check_print_device_info,
check_repr,
check_get_global_mem_size,
check_get_local_mem_size,
]


Expand Down
4 changes: 2 additions & 2 deletions dpctl/tests/test_sycl_kernel_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_create_program_from_source(ctype_str, dtype, ctypes_ctor):
q.submit(axpyKernel, args, r).wait()
ref_c = a * np.array(d, dtype=dtype) + b
host_dt, device_dt = timer.dt
assert host_dt > device_dt
assert type(host_dt) is float and type(device_dt) is float
assert np.allclose(c, ref_c), "Failed for {}".format(r)

for gr, lr in (
Expand All @@ -106,5 +106,5 @@ def test_create_program_from_source(ctype_str, dtype, ctypes_ctor):
q.submit(axpyKernel, args, gr, lr, [dpctl.SyclEvent()]).wait()
ref_c = a * np.array(d, dtype=dtype) + b
host_dt, device_dt = timer.dt
assert host_dt > device_dt
assert type(host_dt) is float and type(device_dt) is float
assert np.allclose(c, ref_c), "Faled for {}, {}".formatg(r, lr)