Skip to content

Device descriptor image2d3d functions #315

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 7, 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
65 changes: 65 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,71 @@ DPCTL_API
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
DPCTLSyclAspectType AT);

/*!
* @brief Wrapper over
* device.get_info<info::device::image2d_max_width>().
*
* @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<info::device::image2d_max_height>().
*
* @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<info::device::image3d_max_width>().
*
* @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<info::device::image3d_max_height>().
*
* @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<info::device::image3d_max_depth>().
*
* @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
Expand Down
21 changes: 21 additions & 0 deletions dpctl-capi/source/dpctl_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,27 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
return hasAspect;
}

#define declmethod(FUNC, NAME) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

size_t DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef) \
{ \
size_t result = 0; \
auto D = unwrap(DRef); \
if (D) { \
try { \
result = D->get_info<info::device::NAME>(); \
} 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)
{
Expand Down
55 changes: 55 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,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",
Expand Down
5 changes: 5 additions & 0 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
40 changes: 40 additions & 0 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
40 changes: 40 additions & 0 deletions dpctl/tests/test_sycl_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down