Skip to content

Commit ffd1042

Browse files
1e-toetotmeni
andauthored
Device descriptor image2d3d functions (#315)
* Add image2d_max_width * Add imageXd_max_X functions * Added properties to SyclDevice Co-authored-by: etotmeni <elena.totmenina@intel.com>
1 parent dc96e47 commit ffd1042

File tree

6 files changed

+226
-0
lines changed

6 files changed

+226
-0
lines changed

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,71 @@ 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::image2d_max_width>().
272+
*
273+
* @param DRef Opaque pointer to a sycl::device
274+
* @return Returns the maximum width of a 2D image
275+
* or 1D image in pixels. The minimum value is
276+
* 8192 if the SYCL device has aspect::image.
277+
*/
278+
DPCTL_API
279+
size_t
280+
DPCTLDevice_GetImage2dMaxWidth(__dpctl_keep const DPCTLSyclDeviceRef DRef);
281+
282+
/*!
283+
* @brief Wrapper over
284+
* device.get_info<info::device::image2d_max_height>().
285+
*
286+
* @param DRef Opaque pointer to a sycl::device
287+
* @return Returns the maximum height of a 2D image
288+
* or 1D image in pixels. The minimum value is
289+
* 8192 if the SYCL device has aspect::image.
290+
*/
291+
DPCTL_API
292+
size_t
293+
DPCTLDevice_GetImage2dMaxHeight(__dpctl_keep const DPCTLSyclDeviceRef DRef);
294+
295+
/*!
296+
* @brief Wrapper over
297+
* device.get_info<info::device::image3d_max_width>().
298+
*
299+
* @param DRef Opaque pointer to a sycl::device
300+
* @return Returns the maximum width of a 3D image
301+
* in pixels. The minimum value is
302+
* 2048 if the SYCL device has aspect::image.
303+
*/
304+
DPCTL_API
305+
size_t
306+
DPCTLDevice_GetImage3dMaxWidth(__dpctl_keep const DPCTLSyclDeviceRef DRef);
307+
308+
/*!
309+
* @brief Wrapper over
310+
* device.get_info<info::device::image3d_max_height>().
311+
*
312+
* @param DRef Opaque pointer to a sycl::device
313+
* @return Returns the maximum height of a 3D image
314+
* The minimum value is
315+
* 2048 if the SYCL device has aspect::image.
316+
*/
317+
DPCTL_API
318+
size_t
319+
DPCTLDevice_GetImage3dMaxHeight(__dpctl_keep const DPCTLSyclDeviceRef DRef);
320+
321+
/*!
322+
* @brief Wrapper over
323+
* device.get_info<info::device::image3d_max_depth>().
324+
*
325+
* @param DRef Opaque pointer to a sycl::device
326+
* @return Returns the maximum depth of a 3D image
327+
* The minimum value is
328+
* 2048 if the SYCL device has aspect::image.
329+
*/
330+
DPCTL_API
331+
size_t
332+
DPCTLDevice_GetImage3dMaxDepth(__dpctl_keep const DPCTLSyclDeviceRef DRef);
333+
269334
/*!
270335
* @brief Returns a vector of sub devices
271336
* partitioned from this SYCL device based on the count parameter. The returned

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,27 @@ 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) \
397+
{ \
398+
size_t result = 0; \
399+
auto D = unwrap(DRef); \
400+
if (D) { \
401+
try { \
402+
result = D->get_info<info::device::NAME>(); \
403+
} catch (runtime_error const &re) { \
404+
std::cerr << re.what() << '\n'; \
405+
} \
406+
} \
407+
return result; \
408+
}
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);
414+
#undef declmethod
415+
395416
bool DPCTLDevice_GetSubGroupIndependentForwardProgress(
396417
__dpctl_keep const DPCTLSyclDeviceRef DRef)
397418
{

dpctl-capi/tests/test_sycl_device_interface.cpp

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

278+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage2dMaxWidth)
279+
{
280+
size_t image_2d_max_width = 0;
281+
EXPECT_NO_FATAL_FAILURE(image_2d_max_width =
282+
DPCTLDevice_GetImage2dMaxWidth(DRef));
283+
size_t min_val = 8192;
284+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
285+
DPCTL_StrToAspectType("image"))))
286+
EXPECT_TRUE(image_2d_max_width >= min_val);
287+
}
288+
289+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage2dMaxHeight)
290+
{
291+
size_t image_2d_max_height = 0;
292+
EXPECT_NO_FATAL_FAILURE(image_2d_max_height =
293+
DPCTLDevice_GetImage2dMaxHeight(DRef));
294+
size_t min_val = 8192;
295+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
296+
DPCTL_StrToAspectType("image"))))
297+
EXPECT_TRUE(image_2d_max_height >= min_val);
298+
}
299+
300+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage3dMaxWidth)
301+
{
302+
size_t image_3d_max_width = 0;
303+
EXPECT_NO_FATAL_FAILURE(image_3d_max_width =
304+
DPCTLDevice_GetImage3dMaxWidth(DRef));
305+
size_t min_val = 2048;
306+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
307+
DPCTL_StrToAspectType("image"))))
308+
EXPECT_TRUE(image_3d_max_width >= min_val);
309+
}
310+
311+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage3dMaxHeight)
312+
{
313+
size_t image_3d_max_height = 0;
314+
EXPECT_NO_FATAL_FAILURE(image_3d_max_height =
315+
DPCTLDevice_GetImage3dMaxHeight(DRef));
316+
size_t min_val = 2048;
317+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
318+
DPCTL_StrToAspectType("image"))))
319+
EXPECT_TRUE(image_3d_max_height >= min_val);
320+
}
321+
322+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetImage3dMaxDepth)
323+
{
324+
size_t image_3d_max_depth = 0;
325+
EXPECT_NO_FATAL_FAILURE(image_3d_max_depth =
326+
DPCTLDevice_GetImage3dMaxDepth(DRef));
327+
size_t min_val = 2048;
328+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
329+
DPCTL_StrToAspectType("image"))))
330+
EXPECT_TRUE(image_3d_max_depth >= min_val);
331+
}
332+
278333
INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns,
279334
TestDPCTLSyclDeviceInterface,
280335
::testing::Values("opencl",

dpctl/_backend.pxd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ 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 size_t DPCTLDevice_GetImage2dMaxWidth(const DPCTLSyclDeviceRef DRef)
184+
cdef size_t DPCTLDevice_GetImage2dMaxHeight(const DPCTLSyclDeviceRef DRef)
185+
cdef size_t DPCTLDevice_GetImage3dMaxWidth(const DPCTLSyclDeviceRef DRef)
186+
cdef size_t DPCTLDevice_GetImage3dMaxHeight(const DPCTLSyclDeviceRef DRef)
187+
cdef size_t DPCTLDevice_GetImage3dMaxDepth(const DPCTLSyclDeviceRef DRef)
183188
cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually(
184189
const DPCTLSyclDeviceRef DRef, size_t count)
185190
cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByCounts(

dpctl/_sycl_device.pyx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ from ._backend cimport (
5858
DPCTLSyclDeviceSelectorRef,
5959
DPCTLDevice_HasAspect,
6060
DPCTLSyclDeviceType,
61+
DPCTLDevice_GetImage2dMaxWidth,
62+
DPCTLDevice_GetImage2dMaxHeight,
63+
DPCTLDevice_GetImage3dMaxWidth,
64+
DPCTLDevice_GetImage3dMaxHeight,
65+
DPCTLDevice_GetImage3dMaxDepth,
6166
DPCTLDevice_GetSubGroupIndependentForwardProgress,
6267
DPCTLDevice_GetPreferredVectorWidthChar,
6368
DPCTLDevice_GetPreferredVectorWidthShort,
@@ -401,6 +406,41 @@ cdef class SyclDevice(_SyclDevice):
401406
cdef _aspect_type AT = _aspect_type._usm_system_allocator
402407
return DPCTLDevice_HasAspect(self._device_ref, AT)
403408

409+
@property
410+
def image_2d_max_width(self):
411+
""" Returns the maximum width of a 2D image or 1D image in pixels.
412+
The minimum value is 8192 if the SYCL device has aspect::image.
413+
"""
414+
return DPCTLDevice_GetImage2dMaxWidth(self._device_ref)
415+
416+
@property
417+
def image_2d_max_height(self):
418+
""" Returns the maximum height of a 2D image or 1D image in pixels.
419+
The minimum value is 8192 if the SYCL device has aspect::image.
420+
"""
421+
return DPCTLDevice_GetImage2dMaxHeight(self._device_ref)
422+
423+
@property
424+
def image_3d_max_width(self):
425+
""" Returns the maximum width of a 3D image in pixels.
426+
The minimum value is 2048 if the SYCL device has aspect::image.
427+
"""
428+
return DPCTLDevice_GetImage3dMaxWidth(self._device_ref)
429+
430+
@property
431+
def image_3d_max_height(self):
432+
""" Returns the maximum height of a 3D image in pixels.
433+
The minimum value is 2048 if the SYCL device has aspect::image.
434+
"""
435+
return DPCTLDevice_GetImage3dMaxHeight(self._device_ref)
436+
437+
@property
438+
def image_3d_max_depth(self):
439+
""" Returns the maximum depth of a 3D image in pixels.
440+
The minimum value is 2048 if the SYCL device has aspect::image.
441+
"""
442+
return DPCTLDevice_GetImage3dMaxDepth(self._device_ref)
443+
404444
@property
405445
def default_selector_score(self):
406446
cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create()

dpctl/tests/test_sycl_device.py

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

243243

244+
def check_get_image_2d_max_width(device):
245+
try:
246+
device.image_2d_max_width
247+
except Exception:
248+
pytest.fail("image_2d_max_width call failed")
249+
250+
251+
def check_get_image_2d_max_height(device):
252+
try:
253+
device.image_2d_max_height
254+
except Exception:
255+
pytest.fail("image_2d_max_height call failed")
256+
257+
258+
def check_get_image_3d_max_width(device):
259+
try:
260+
device.image_3d_max_width
261+
except Exception:
262+
pytest.fail("image_3d_max_width call failed")
263+
264+
265+
def check_get_image_3d_max_height(device):
266+
try:
267+
device.image_3d_max_height
268+
except Exception:
269+
pytest.fail("image_3d_max_height call failed")
270+
271+
272+
def check_get_image_3d_max_depth(device):
273+
try:
274+
device.image_3d_max_depth
275+
except Exception:
276+
pytest.fail("image_3d_max_depth call failed")
277+
278+
244279
def check_get_sub_group_independent_forward_progress(device):
245280
try:
246281
device.sub_group_independent_forward_progress
@@ -423,6 +458,11 @@ def check_print_device_info(device):
423458
check_has_aspect_usm_shared_allocations,
424459
check_has_aspect_usm_restricted_shared_allocations,
425460
check_has_aspect_usm_system_allocator,
461+
check_get_image_2d_max_width,
462+
check_get_image_2d_max_height,
463+
check_get_image_3d_max_width,
464+
check_get_image_3d_max_height,
465+
check_get_image_3d_max_depth,
426466
check_create_sub_devices_equally,
427467
check_create_sub_devices_by_counts,
428468
check_create_sub_devices_by_affinity_not_applicable,

0 commit comments

Comments
 (0)