Skip to content

Add descriptors: max_read_image_args, max_write_image_args #318

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 9 commits into from
Apr 8, 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
26 changes: 26 additions & 0 deletions dpctl-capi/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,32 @@ DPCTL_API
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
DPCTLSyclAspectType AT);

/*!
* @brief Wrapper over
* device.get_info<info::device::max_read_image_args>().
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the maximum number of simultaneous image objects that
* can be read from by a kernel. The minimum value is 128 if the
* SYCL device has aspect::image.
*/
DPCTL_API
uint32_t
DPCTLDevice_GetMaxReadImageArgs(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::max_write_image_args>().
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the maximum number of simultaneous image objects that
* can be written to by a kernel. The minimum value is 8 if the SYCL
* device has aspect::image.
*/
DPCTL_API
uint32_t
DPCTLDevice_GetMaxWriteImageArgs(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::image2d_max_width>().
Expand Down
18 changes: 10 additions & 8 deletions dpctl-capi/source/dpctl_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
return hasAspect;
}

#define declmethod(FUNC, NAME) \
size_t DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef) \
#define declmethod(FUNC, NAME, TYPE) \
TYPE DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef) \
{ \
size_t result = 0; \
TYPE result = 0; \
auto D = unwrap(DRef); \
if (D) { \
try { \
Expand All @@ -406,11 +406,13 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
} \
return result; \
}
declmethod(GetImage2dMaxWidth, image2d_max_width);
declmethod(GetImage2dMaxHeight, image2d_max_height);
declmethod(GetImage3dMaxWidth, image3d_max_width);
declmethod(GetImage3dMaxHeight, image3d_max_height);
declmethod(GetImage3dMaxDepth, image3d_max_depth);
declmethod(GetMaxReadImageArgs, max_read_image_args, uint32_t);
declmethod(GetMaxWriteImageArgs, max_write_image_args, uint32_t);
declmethod(GetImage2dMaxWidth, image2d_max_width, size_t);
declmethod(GetImage2dMaxHeight, image2d_max_height, size_t);
declmethod(GetImage3dMaxWidth, image3d_max_width, size_t);
declmethod(GetImage3dMaxHeight, image3d_max_height, size_t);
declmethod(GetImage3dMaxDepth, image3d_max_depth, size_t);
#undef declmethod

bool DPCTLDevice_GetSubGroupIndependentForwardProgress(
Expand Down
22 changes: 22 additions & 0 deletions dpctl-capi/tests/test_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,28 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthHalf)
}
}

TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetMaxReadImageArgs)
{
size_t max_read_image_args = 0;
EXPECT_NO_FATAL_FAILURE(max_read_image_args =
DPCTLDevice_GetMaxReadImageArgs(DRef));
size_t min_val = 128;
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
DPCTL_StrToAspectType("image"))))
EXPECT_TRUE(max_read_image_args >= min_val);
}

TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetMaxWriteImageArgs)
{
size_t max_write_image_args = 0;
EXPECT_NO_FATAL_FAILURE(max_write_image_args =
DPCTLDevice_GetMaxWriteImageArgs(DRef));
size_t min_val = 8;
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
DPCTL_StrToAspectType("image"))))
EXPECT_TRUE(max_write_image_args >= min_val);
}

TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage2dMaxWidth)
{
size_t image_2d_max_width = 0;
Expand Down
2 changes: 2 additions & 0 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ cdef extern from "dpctl_sycl_device_interface.h":
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(const DPCTLSyclDeviceRef DRef)
cpdef bool DPCTLDevice_HasAspect(
const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT)
cdef uint32_t DPCTLDevice_GetMaxReadImageArgs(const DPCTLSyclDeviceRef DRef)
cdef uint32_t DPCTLDevice_GetMaxWriteImageArgs(const DPCTLSyclDeviceRef DRef)
cdef size_t DPCTLDevice_GetImage2dMaxWidth(const DPCTLSyclDeviceRef DRef)
cdef size_t DPCTLDevice_GetImage2dMaxHeight(const DPCTLSyclDeviceRef DRef)
cdef size_t DPCTLDevice_GetImage3dMaxWidth(const DPCTLSyclDeviceRef DRef)
Expand Down
18 changes: 18 additions & 0 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ from ._backend cimport (
DPCTLSyclDeviceSelectorRef,
DPCTLDevice_HasAspect,
DPCTLSyclDeviceType,
DPCTLDevice_GetMaxReadImageArgs,
DPCTLDevice_GetMaxWriteImageArgs,
DPCTLDevice_GetImage2dMaxWidth,
DPCTLDevice_GetImage2dMaxHeight,
DPCTLDevice_GetImage3dMaxWidth,
Expand Down Expand Up @@ -450,6 +452,22 @@ cdef class SyclDevice(_SyclDevice):
DPCTLDeviceSelector_Delete(DSRef)
return score

@property
def max_read_image_args(self):
""" Returns the maximum number of simultaneous image objects that
can be read from by a kernel. The minimum value is 128 if the
SYCL device has aspect::image.
"""
return DPCTLDevice_GetMaxReadImageArgs(self._device_ref)

@property
def max_write_image_args(self):
""" Returns the maximum number of simultaneous image objects that
can be written to by a kernel. The minimum value is 8 if the SYCL
device has aspect::image.
"""
return DPCTLDevice_GetMaxWriteImageArgs(self._device_ref)

@property
def is_accelerator(self):
""" Returns True if the SyclDevice instance is a SYCL accelerator
Expand Down
16 changes: 16 additions & 0 deletions dpctl/tests/test_sycl_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ def check_is_host(device):
pytest.fail("is_hostcall failed")


def check_get_max_read_image_args(device):
try:
device.max_read_image_args
except Exception:
pytest.fail("max_read_image_args call failed")


def check_get_max_write_image_args(device):
try:
device.max_write_image_args
except Exception:
pytest.fail("max_write_image_args call failed")


def check_get_image_2d_max_width(device):
try:
device.image_2d_max_width
Expand Down Expand Up @@ -458,6 +472,8 @@ def check_print_device_info(device):
check_has_aspect_usm_shared_allocations,
check_has_aspect_usm_restricted_shared_allocations,
check_has_aspect_usm_system_allocator,
check_get_max_read_image_args,
check_get_max_write_image_args,
check_get_image_2d_max_width,
check_get_image_2d_max_height,
check_get_image_3d_max_width,
Expand Down