Skip to content

Commit 1d99b7b

Browse files
Addresses #587 on DPCTL-CAPI side
Adds DPCTLDevice_GetGlobalMemSize(DRef) which gives size of device global memory in bytes as uint64_t (aka size_t) Adds DPCTLDevice_GetLocalMemSize(DRef) which gives size of device local memory in bytes as uint64_t
1 parent 4962d64 commit 1d99b7b

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,28 @@ DPCTL_API
177177
uint32_t
178178
DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef);
179179

180+
/*!
181+
* @brief Wrapper over device.get_info<info::device::global_mem_size>().
182+
*
183+
* @param DRef Opaque pointer to a ``sycl::device``
184+
* @return Returns the valid result if device exists else returns 0.
185+
* @ingroup DeviceInterface
186+
*/
187+
DPCTL_API
188+
uint64_t
189+
DPCTLDevice_GetGlobalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef);
190+
191+
/*!
192+
* @brief Wrapper over device.get_info<info::device::local_mem_size>().
193+
*
194+
* @param DRef Opaque pointer to a ``sycl::device``
195+
* @return Returns the valid result if device exists else returns 0.
196+
* @ingroup DeviceInterface
197+
*/
198+
DPCTL_API
199+
uint64_t
200+
DPCTLDevice_GetLocalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef);
201+
180202
/*!
181203
* @brief Wrapper for get_info<info::device::max_work_item_dimensions>().
182204
*

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,37 @@ DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef)
186186
return nComputeUnits;
187187
}
188188

189+
uint64_t
190+
DPCTLDevice_GetGlobalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
191+
{
192+
uint64_t GlobalMemSize = 0;
193+
auto D = unwrap(DRef);
194+
if (D) {
195+
try {
196+
GlobalMemSize = D->get_info<info::device::global_mem_size>();
197+
} catch (runtime_error const &re) {
198+
// \todo log error
199+
std::cerr << re.what() << '\n';
200+
}
201+
}
202+
return GlobalMemSize;
203+
}
204+
205+
uint64_t DPCTLDevice_GetLocalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
206+
{
207+
uint64_t LocalMemSize = 0;
208+
auto D = unwrap(DRef);
209+
if (D) {
210+
try {
211+
LocalMemSize = D->get_info<info::device::local_mem_size>();
212+
} catch (runtime_error const &re) {
213+
// \todo log error
214+
std::cerr << re.what() << '\n';
215+
}
216+
}
217+
return LocalMemSize;
218+
}
219+
189220
uint32_t
190221
DPCTLDevice_GetMaxWorkItemDims(__dpctl_keep const DPCTLSyclDeviceRef DRef)
191222
{

dpctl-capi/tests/test_sycl_device_interface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetMaxComputeUnits)
132132
EXPECT_TRUE(n > 0);
133133
}
134134

135+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemSize)
136+
{
137+
size_t gm_sz = 0;
138+
EXPECT_NO_FATAL_FAILURE(gm_sz = DPCTLDevice_GetGlobalMemSize(DRef));
139+
EXPECT_TRUE(gm_sz > 0);
140+
}
141+
142+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetLocalMemSize)
143+
{
144+
size_t lm_sz = 0;
145+
EXPECT_NO_FATAL_FAILURE(lm_sz = DPCTLDevice_GetLocalMemSize(DRef));
146+
EXPECT_TRUE(lm_sz > 0);
147+
}
148+
135149
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetMaxWorkItemDims)
136150
{
137151
size_t n = 0;

0 commit comments

Comments
 (0)