Skip to content

Commit ccd2d03

Browse files
1e-toetotmeni
andauthored
Add descriptors: max_read_image_args, max_write_image_args (#318)
* Add support for max_read_image_args and max_write_image_args descriptors Co-authored-by: etotmeni <elena.totmenina@intel.com>
1 parent 4f4adf5 commit ccd2d03

File tree

6 files changed

+94
-8
lines changed

6 files changed

+94
-8
lines changed

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,32 @@ DPCTL_API
266266
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
267267
DPCTLSyclAspectType AT);
268268

269+
/*!
270+
* @brief Wrapper over
271+
* device.get_info<info::device::max_read_image_args>().
272+
*
273+
* @param DRef Opaque pointer to a sycl::device
274+
* @return Returns the maximum number of simultaneous image objects that
275+
* can be read from by a kernel. The minimum value is 128 if the
276+
* SYCL device has aspect::image.
277+
*/
278+
DPCTL_API
279+
uint32_t
280+
DPCTLDevice_GetMaxReadImageArgs(__dpctl_keep const DPCTLSyclDeviceRef DRef);
281+
282+
/*!
283+
* @brief Wrapper over
284+
* device.get_info<info::device::max_write_image_args>().
285+
*
286+
* @param DRef Opaque pointer to a sycl::device
287+
* @return Returns the maximum number of simultaneous image objects that
288+
* can be written to by a kernel. The minimum value is 8 if the SYCL
289+
* device has aspect::image.
290+
*/
291+
DPCTL_API
292+
uint32_t
293+
DPCTLDevice_GetMaxWriteImageArgs(__dpctl_keep const DPCTLSyclDeviceRef DRef);
294+
269295
/*!
270296
* @brief Wrapper over
271297
* device.get_info<info::device::image2d_max_width>().

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
392392
return hasAspect;
393393
}
394394

395-
#define declmethod(FUNC, NAME) \
396-
size_t DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef) \
395+
#define declmethod(FUNC, NAME, TYPE) \
396+
TYPE DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef) \
397397
{ \
398-
size_t result = 0; \
398+
TYPE result = 0; \
399399
auto D = unwrap(DRef); \
400400
if (D) { \
401401
try { \
@@ -406,11 +406,13 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
406406
} \
407407
return result; \
408408
}
409-
declmethod(GetImage2dMaxWidth, image2d_max_width);
410-
declmethod(GetImage2dMaxHeight, image2d_max_height);
411-
declmethod(GetImage3dMaxWidth, image3d_max_width);
412-
declmethod(GetImage3dMaxHeight, image3d_max_height);
413-
declmethod(GetImage3dMaxDepth, image3d_max_depth);
409+
declmethod(GetMaxReadImageArgs, max_read_image_args, uint32_t);
410+
declmethod(GetMaxWriteImageArgs, max_write_image_args, uint32_t);
411+
declmethod(GetImage2dMaxWidth, image2d_max_width, size_t);
412+
declmethod(GetImage2dMaxHeight, image2d_max_height, size_t);
413+
declmethod(GetImage3dMaxWidth, image3d_max_width, size_t);
414+
declmethod(GetImage3dMaxHeight, image3d_max_height, size_t);
415+
declmethod(GetImage3dMaxDepth, image3d_max_depth, size_t);
414416
#undef declmethod
415417

416418
bool DPCTLDevice_GetSubGroupIndependentForwardProgress(

dpctl-capi/tests/test_sycl_device_interface.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,28 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthHalf)
275275
}
276276
}
277277

278+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetMaxReadImageArgs)
279+
{
280+
size_t max_read_image_args = 0;
281+
EXPECT_NO_FATAL_FAILURE(max_read_image_args =
282+
DPCTLDevice_GetMaxReadImageArgs(DRef));
283+
size_t min_val = 128;
284+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
285+
DPCTL_StrToAspectType("image"))))
286+
EXPECT_TRUE(max_read_image_args >= min_val);
287+
}
288+
289+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetMaxWriteImageArgs)
290+
{
291+
size_t max_write_image_args = 0;
292+
EXPECT_NO_FATAL_FAILURE(max_write_image_args =
293+
DPCTLDevice_GetMaxWriteImageArgs(DRef));
294+
size_t min_val = 8;
295+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
296+
DPCTL_StrToAspectType("image"))))
297+
EXPECT_TRUE(max_write_image_args >= min_val);
298+
}
299+
278300
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage2dMaxWidth)
279301
{
280302
size_t image_2d_max_width = 0;

dpctl/_backend.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ cdef extern from "dpctl_sycl_device_interface.h":
180180
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(const DPCTLSyclDeviceRef DRef)
181181
cpdef bool DPCTLDevice_HasAspect(
182182
const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT)
183+
cdef uint32_t DPCTLDevice_GetMaxReadImageArgs(const DPCTLSyclDeviceRef DRef)
184+
cdef uint32_t DPCTLDevice_GetMaxWriteImageArgs(const DPCTLSyclDeviceRef DRef)
183185
cdef size_t DPCTLDevice_GetImage2dMaxWidth(const DPCTLSyclDeviceRef DRef)
184186
cdef size_t DPCTLDevice_GetImage2dMaxHeight(const DPCTLSyclDeviceRef DRef)
185187
cdef size_t DPCTLDevice_GetImage3dMaxWidth(const DPCTLSyclDeviceRef DRef)

dpctl/_sycl_device.pyx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ from ._backend cimport (
6060
DPCTLSyclDeviceSelectorRef,
6161
DPCTLDevice_HasAspect,
6262
DPCTLSyclDeviceType,
63+
DPCTLDevice_GetMaxReadImageArgs,
64+
DPCTLDevice_GetMaxWriteImageArgs,
6365
DPCTLDevice_GetImage2dMaxWidth,
6466
DPCTLDevice_GetImage2dMaxHeight,
6567
DPCTLDevice_GetImage3dMaxWidth,
@@ -481,6 +483,22 @@ cdef class SyclDevice(_SyclDevice):
481483
DPCTLDeviceSelector_Delete(DSRef)
482484
return score
483485

486+
@property
487+
def max_read_image_args(self):
488+
""" Returns the maximum number of simultaneous image objects that
489+
can be read from by a kernel. The minimum value is 128 if the
490+
SYCL device has aspect::image.
491+
"""
492+
return DPCTLDevice_GetMaxReadImageArgs(self._device_ref)
493+
494+
@property
495+
def max_write_image_args(self):
496+
""" Returns the maximum number of simultaneous image objects that
497+
can be written to by a kernel. The minimum value is 8 if the SYCL
498+
device has aspect::image.
499+
"""
500+
return DPCTLDevice_GetMaxWriteImageArgs(self._device_ref)
501+
484502
@property
485503
def is_accelerator(self):
486504
""" Returns True if the SyclDevice instance is a SYCL accelerator

dpctl/tests/test_sycl_device.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ def check_is_host(device):
241241
pytest.fail("is_hostcall failed")
242242

243243

244+
def check_get_max_read_image_args(device):
245+
try:
246+
device.max_read_image_args
247+
except Exception:
248+
pytest.fail("max_read_image_args call failed")
249+
250+
251+
def check_get_max_write_image_args(device):
252+
try:
253+
device.max_write_image_args
254+
except Exception:
255+
pytest.fail("max_write_image_args call failed")
256+
257+
244258
def check_get_image_2d_max_width(device):
245259
try:
246260
device.image_2d_max_width
@@ -458,6 +472,8 @@ def check_print_device_info(device):
458472
check_has_aspect_usm_shared_allocations,
459473
check_has_aspect_usm_restricted_shared_allocations,
460474
check_has_aspect_usm_system_allocator,
475+
check_get_max_read_image_args,
476+
check_get_max_write_image_args,
461477
check_get_image_2d_max_width,
462478
check_get_image_2d_max_height,
463479
check_get_image_3d_max_width,

0 commit comments

Comments
 (0)