Skip to content

[SYCL] Fix an error on host when big image is used on opencl:gpu #4668

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 1 commit into from
Oct 1, 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
70 changes: 60 additions & 10 deletions sycl/source/detail/device_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,32 +668,82 @@ inline cl_uint get_device_info_host<info::device::max_write_image_args>() {

template <>
inline size_t get_device_info_host<info::device::image2d_max_width>() {
// current value is the required minimum
return 8192;
// SYCL guarantees at least 8192. Some devices already known to provide more
// than that (i.e. it is 16384 for opencl:gpu), which may create issues during
// image object allocation on host.
// Using any fixed number (i.e. 16384) brings the risk of having similar
// issues on newer devices in future. Thus it does not make sense limiting
// the returned value on host. Practially speaking the returned value on host
// depends only on memory required for the image, which also depends on
// the image channel_type and the image height. Both are not known in this
// query, thus it becomes user's responsibility to choose proper image
// parameters depending on similar query to (non-host device) and amount
// of available/allocatable memory.
return INT_MAX;
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be std::numeric_limits<std::size_t>::max().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done in #4699

}

template <>
inline size_t get_device_info_host<info::device::image2d_max_height>() {
// current value is the required minimum
return 8192;
// SYCL guarantees at least 8192. Some devices already known to provide more
// than that (i.e. it is 16384 for opencl:gpu), which may create issues during
// image object allocation on host.
// Using any fixed number (i.e. 16384) brings the risk of having similar
// issues on newer devices in future. Thus it does not make sense limiting
// the returned value on host. Practially speaking the returned value on host
// depends only on memory required for the image, which also depends on
// the image channel_type and the image width. Both are not known in this
// query, thus it becomes user's responsibility to choose proper image
// parameters depending on similar query to (non-host device) and amount
// of available/allocatable memory.
return INT_MAX;
}

template <>
inline size_t get_device_info_host<info::device::image3d_max_width>() {
// current value is the required minimum
return 2048;
// SYCL guarantees at least 8192. Some devices already known to provide more
// than that (i.e. it is 16384 for opencl:gpu), which may create issues during
// image object allocation on host.
// Using any fixed number (i.e. 16384) brings the risk of having similar
// issues on newer devices in future. Thus it does not make sense limiting
// the returned value on host. Practially speaking the returned value on host
// depends only on memory required for the image, which also depends on
// the image channel_type and the image height/depth. Both are not known
// in this query, thus it becomes user's responsibility to choose proper image
// parameters depending on similar query to (non-host device) and amount
// of available/allocatable memory.
return INT_MAX;
}

template <>
inline size_t get_device_info_host<info::device::image3d_max_height>() {
// current value is the required minimum
return 2048;
// SYCL guarantees at least 8192. Some devices already known to provide more
// than that (i.e. it is 16384 for opencl:gpu), which may create issues during
// image object allocation on host.
// Using any fixed number (i.e. 16384) brings the risk of having similar
// issues on newer devices in future. Thus it does not make sense limiting
// the returned value on host. Practially speaking the returned value on host
// depends only on memory required for the image, which also depends on
// the image channel_type and the image width/depth. Both are not known
// in this query, thus it becomes user's responsibility to choose proper image
// parameters depending on similar query to (non-host device) and amount
// of available/allocatable memory.
return INT_MAX;
}

template <>
inline size_t get_device_info_host<info::device::image3d_max_depth>() {
// current value is the required minimum
return 2048;
// SYCL guarantees at least 8192. Some devices already known to provide more
// than that (i.e. it is 16384 for opencl:gpu), which may create issues during
// image object allocation on host.
// Using any fixed number (i.e. 16384) brings the risk of having similar
// issues on newer devices in future. Thus it does not make sense limiting
// the returned value on host. Practially speaking the returned value on host
// depends only on memory required for the image, which also depends on
// the image channel_type and the image height/width, which are not known
// in this query, thus it becomes user's responsibility to choose proper image
// parameters depending on similar query to (non-host device) and amount
// of available/allocatable memory.
return INT_MAX;
}

template <>
Expand Down
12 changes: 6 additions & 6 deletions sycl/source/detail/image_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
getDevices(Context), Desc.image_width))
throw invalid_parameter_error(
"For a 1D/2D image/image array, the width must be a Value >= 1 and "
"<= CL_DEVICE_IMAGE2D_MAX_WIDTH.",
"<= info::device::image2d_max_width",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE3D) &&
!checkImageValueRange<info::device::image3d_max_width>(
getDevices(Context), Desc.image_width))
throw invalid_parameter_error(
"For a 3D image, the width must be a Value >= 1 and <= "
"CL_DEVICE_IMAGE3D_MAX_WIDTH",
"info::device::image3d_max_width",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE2D,
Expand All @@ -346,23 +346,23 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
getDevices(Context), Desc.image_height))
throw invalid_parameter_error("For a 2D image or image array, the height "
"must be a Value >= 1 and <= "
"CL_DEVICE_IMAGE2D_MAX_HEIGHT",
"info::device::image2d_max_height",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE3D) &&
!checkImageValueRange<info::device::image3d_max_height>(
getDevices(Context), Desc.image_height))
throw invalid_parameter_error(
"For a 3D image, the heightmust be a Value >= 1 and <= "
"CL_DEVICE_IMAGE3D_MAX_HEIGHT",
"info::device::image3d_max_height",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE3D) &&
!checkImageValueRange<info::device::image3d_max_depth>(
getDevices(Context), Desc.image_depth))
throw invalid_parameter_error(
"For a 3D image, the depth must be a Value >= 1 and <= "
"CL_DEVICE_IMAGE3D_MAX_DEPTH",
"info::device::image2d_max_depth",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE1D_ARRAY,
Expand All @@ -371,7 +371,7 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
getDevices(Context), Desc.image_array_size))
throw invalid_parameter_error(
"For a 1D and 2D image array, the array_size must be a "
"Value >= 1 and <= CL_DEVICE_IMAGE_MAX_ARRAY_SIZE.",
"Value >= 1 and <= info::device::image_max_array_size.",
PI_INVALID_VALUE);

if ((nullptr == UserPtr) && (0 != Desc.image_row_pitch))
Expand Down