diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index 7255e37ac2..98496e4794 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -266,6 +266,71 @@ DPCTL_API bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT); +/*! + * @brief Wrapper over + * device.get_info(). + * + * @param DRef Opaque pointer to a sycl::device + * @return Returns the maximum width of a 2D image + * or 1D image in pixels. The minimum value is + * 8192 if the SYCL device has aspect::image. + */ +DPCTL_API +size_t +DPCTLDevice_GetImage2dMaxWidth(__dpctl_keep const DPCTLSyclDeviceRef DRef); + +/*! + * @brief Wrapper over + * device.get_info(). + * + * @param DRef Opaque pointer to a sycl::device + * @return Returns the maximum height of a 2D image + * or 1D image in pixels. The minimum value is + * 8192 if the SYCL device has aspect::image. + */ +DPCTL_API +size_t +DPCTLDevice_GetImage2dMaxHeight(__dpctl_keep const DPCTLSyclDeviceRef DRef); + +/*! + * @brief Wrapper over + * device.get_info(). + * + * @param DRef Opaque pointer to a sycl::device + * @return Returns the maximum width of a 3D image + * in pixels. The minimum value is + * 2048 if the SYCL device has aspect::image. + */ +DPCTL_API +size_t +DPCTLDevice_GetImage3dMaxWidth(__dpctl_keep const DPCTLSyclDeviceRef DRef); + +/*! + * @brief Wrapper over + * device.get_info(). + * + * @param DRef Opaque pointer to a sycl::device + * @return Returns the maximum height of a 3D image + * The minimum value is + * 2048 if the SYCL device has aspect::image. + */ +DPCTL_API +size_t +DPCTLDevice_GetImage3dMaxHeight(__dpctl_keep const DPCTLSyclDeviceRef DRef); + +/*! + * @brief Wrapper over + * device.get_info(). + * + * @param DRef Opaque pointer to a sycl::device + * @return Returns the maximum depth of a 3D image + * The minimum value is + * 2048 if the SYCL device has aspect::image. + */ +DPCTL_API +size_t +DPCTLDevice_GetImage3dMaxDepth(__dpctl_keep const DPCTLSyclDeviceRef DRef); + /*! * @brief Returns a vector of sub devices * partitioned from this SYCL device based on the count parameter. The returned diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 72daef4162..f56266b02b 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -392,6 +392,27 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, return hasAspect; } +#define declmethod(FUNC, NAME) \ + size_t DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef) \ + { \ + size_t result = 0; \ + auto D = unwrap(DRef); \ + if (D) { \ + try { \ + result = D->get_info(); \ + } catch (runtime_error const &re) { \ + std::cerr << re.what() << '\n'; \ + } \ + } \ + 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); +#undef declmethod + bool DPCTLDevice_GetSubGroupIndependentForwardProgress( __dpctl_keep const DPCTLSyclDeviceRef DRef) { diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index dd8c79874f..6a2c3f6842 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -275,6 +275,61 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthHalf) } } +TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage2dMaxWidth) +{ + size_t image_2d_max_width = 0; + EXPECT_NO_FATAL_FAILURE(image_2d_max_width = + DPCTLDevice_GetImage2dMaxWidth(DRef)); + size_t min_val = 8192; + if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType( + DPCTL_StrToAspectType("image")))) + EXPECT_TRUE(image_2d_max_width >= min_val); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage2dMaxHeight) +{ + size_t image_2d_max_height = 0; + EXPECT_NO_FATAL_FAILURE(image_2d_max_height = + DPCTLDevice_GetImage2dMaxHeight(DRef)); + size_t min_val = 8192; + if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType( + DPCTL_StrToAspectType("image")))) + EXPECT_TRUE(image_2d_max_height >= min_val); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage3dMaxWidth) +{ + size_t image_3d_max_width = 0; + EXPECT_NO_FATAL_FAILURE(image_3d_max_width = + DPCTLDevice_GetImage3dMaxWidth(DRef)); + size_t min_val = 2048; + if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType( + DPCTL_StrToAspectType("image")))) + EXPECT_TRUE(image_3d_max_width >= min_val); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage3dMaxHeight) +{ + size_t image_3d_max_height = 0; + EXPECT_NO_FATAL_FAILURE(image_3d_max_height = + DPCTLDevice_GetImage3dMaxHeight(DRef)); + size_t min_val = 2048; + if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType( + DPCTL_StrToAspectType("image")))) + EXPECT_TRUE(image_3d_max_height >= min_val); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage3dMaxDepth) +{ + size_t image_3d_max_depth = 0; + EXPECT_NO_FATAL_FAILURE(image_3d_max_depth = + DPCTLDevice_GetImage3dMaxDepth(DRef)); + size_t min_val = 2048; + if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType( + DPCTL_StrToAspectType("image")))) + EXPECT_TRUE(image_3d_max_depth >= min_val); +} + INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns, TestDPCTLSyclDeviceInterface, ::testing::Values("opencl", diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 337a784498..f479fc8fee 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -180,6 +180,11 @@ 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 size_t DPCTLDevice_GetImage2dMaxWidth(const DPCTLSyclDeviceRef DRef) + cdef size_t DPCTLDevice_GetImage2dMaxHeight(const DPCTLSyclDeviceRef DRef) + cdef size_t DPCTLDevice_GetImage3dMaxWidth(const DPCTLSyclDeviceRef DRef) + cdef size_t DPCTLDevice_GetImage3dMaxHeight(const DPCTLSyclDeviceRef DRef) + cdef size_t DPCTLDevice_GetImage3dMaxDepth(const DPCTLSyclDeviceRef DRef) cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually( const DPCTLSyclDeviceRef DRef, size_t count) cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByCounts( diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index c76ecb8f38..f0fcf77bdf 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -58,6 +58,11 @@ from ._backend cimport ( DPCTLSyclDeviceSelectorRef, DPCTLDevice_HasAspect, DPCTLSyclDeviceType, + DPCTLDevice_GetImage2dMaxWidth, + DPCTLDevice_GetImage2dMaxHeight, + DPCTLDevice_GetImage3dMaxWidth, + DPCTLDevice_GetImage3dMaxHeight, + DPCTLDevice_GetImage3dMaxDepth, DPCTLDevice_GetSubGroupIndependentForwardProgress, DPCTLDevice_GetPreferredVectorWidthChar, DPCTLDevice_GetPreferredVectorWidthShort, @@ -401,6 +406,41 @@ cdef class SyclDevice(_SyclDevice): cdef _aspect_type AT = _aspect_type._usm_system_allocator return DPCTLDevice_HasAspect(self._device_ref, AT) + @property + def image_2d_max_width(self): + """ Returns the maximum width of a 2D image or 1D image in pixels. + The minimum value is 8192 if the SYCL device has aspect::image. + """ + return DPCTLDevice_GetImage2dMaxWidth(self._device_ref) + + @property + def image_2d_max_height(self): + """ Returns the maximum height of a 2D image or 1D image in pixels. + The minimum value is 8192 if the SYCL device has aspect::image. + """ + return DPCTLDevice_GetImage2dMaxHeight(self._device_ref) + + @property + def image_3d_max_width(self): + """ Returns the maximum width of a 3D image in pixels. + The minimum value is 2048 if the SYCL device has aspect::image. + """ + return DPCTLDevice_GetImage3dMaxWidth(self._device_ref) + + @property + def image_3d_max_height(self): + """ Returns the maximum height of a 3D image in pixels. + The minimum value is 2048 if the SYCL device has aspect::image. + """ + return DPCTLDevice_GetImage3dMaxHeight(self._device_ref) + + @property + def image_3d_max_depth(self): + """ Returns the maximum depth of a 3D image in pixels. + The minimum value is 2048 if the SYCL device has aspect::image. + """ + return DPCTLDevice_GetImage3dMaxDepth(self._device_ref) + @property def default_selector_score(self): cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create() diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 78b175d4bf..755ad5a6ea 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -241,6 +241,41 @@ def check_is_host(device): pytest.fail("is_hostcall failed") +def check_get_image_2d_max_width(device): + try: + device.image_2d_max_width + except Exception: + pytest.fail("image_2d_max_width call failed") + + +def check_get_image_2d_max_height(device): + try: + device.image_2d_max_height + except Exception: + pytest.fail("image_2d_max_height call failed") + + +def check_get_image_3d_max_width(device): + try: + device.image_3d_max_width + except Exception: + pytest.fail("image_3d_max_width call failed") + + +def check_get_image_3d_max_height(device): + try: + device.image_3d_max_height + except Exception: + pytest.fail("image_3d_max_height call failed") + + +def check_get_image_3d_max_depth(device): + try: + device.image_3d_max_depth + except Exception: + pytest.fail("image_3d_max_depth call failed") + + def check_get_sub_group_independent_forward_progress(device): try: device.sub_group_independent_forward_progress @@ -423,6 +458,11 @@ 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_image_2d_max_width, + check_get_image_2d_max_height, + check_get_image_3d_max_width, + check_get_image_3d_max_height, + check_get_image_3d_max_depth, check_create_sub_devices_equally, check_create_sub_devices_by_counts, check_create_sub_devices_by_affinity_not_applicable,