Skip to content

[SYCL] Ensure utility methods are not exported from image_impl #1760

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 3 commits into from
May 27, 2020
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
21 changes: 0 additions & 21 deletions sycl/include/CL/sycl/detail/image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,27 +233,6 @@ class __SYCL_EXPORT image_impl final : public SYCLMemObjT {
private:
vector_class<device> getDevices(const ContextImplPtr Context);

template <info::device Param>
bool checkImageValueRange(const ContextImplPtr Context, const size_t Value) {
const auto &Devices = getDevices(Context);
return Value >= 1 && std::all_of(Devices.cbegin(), Devices.cend(),
[Value](const device &Dev) {
return Value <= Dev.get_info<Param>();
});
}

template <typename T, typename... Args> bool checkAnyImpl(T) { return false; }

template <typename ValT, typename VarT, typename... Args>
bool checkAnyImpl(ValT Value, VarT Variant, Args... Arguments) {
return (Value == Variant) ? true : checkAnyImpl(Value, Arguments...);
}

template <typename T, typename... Args>
bool checkAny(const T Value, Args... Arguments) {
return checkAnyImpl(Value, Arguments...);
}

RT::PiMemObjectType getImageType() {
if (Dimensions == 1)
return (MIsArrayImage ? PI_MEM_TYPE_IMAGE1D_ARRAY : PI_MEM_TYPE_IMAGE1D);
Expand Down
44 changes: 35 additions & 9 deletions sycl/source/detail/image_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,36 @@
#include <CL/sycl/image.hpp>
#include <detail/context_impl.hpp>

#include <algorithm>
#include <vector>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {

template <info::device Param>
static bool checkImageValueRange(const std::vector<device> &Devices,
const size_t Value) {
return Value >= 1 && std::all_of(Devices.cbegin(), Devices.cend(),
[Value](const device &Dev) {
return Value <= Dev.get_info<Param>();
});
}

template <typename T, typename... Args> static bool checkAnyImpl(T) {
return false;
}

template <typename ValT, typename VarT, typename... Args>
static bool checkAnyImpl(ValT Value, VarT Variant, Args... Arguments) {
return (Value == Variant) ? true : checkAnyImpl(Value, Arguments...);
}

template <typename T, typename... Args>
static bool checkAny(const T Value, Args... Arguments) {
return checkAnyImpl(Value, Arguments...);
}

uint8_t getImageNumberChannels(image_channel_order Order) {
switch (Order) {
case image_channel_order::a:
Expand Down Expand Up @@ -308,16 +334,16 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
void *UserPtr) {
if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE1D, PI_MEM_TYPE_IMAGE1D_ARRAY,
PI_MEM_TYPE_IMAGE2D_ARRAY, PI_MEM_TYPE_IMAGE2D) &&
!checkImageValueRange<info::device::image2d_max_width>(Context,
Desc.image_width))
!checkImageValueRange<info::device::image2d_max_width>(
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.",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE3D) &&
!checkImageValueRange<info::device::image3d_max_width>(Context,
Desc.image_width))
!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",
Expand All @@ -326,23 +352,23 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE2D,
PI_MEM_TYPE_IMAGE2D_ARRAY) &&
!checkImageValueRange<info::device::image2d_max_height>(
Context, Desc.image_height))
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",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE3D) &&
!checkImageValueRange<info::device::image3d_max_height>(
Context, Desc.image_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",
PI_INVALID_VALUE);

if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE3D) &&
!checkImageValueRange<info::device::image3d_max_depth>(Context,
Desc.image_depth))
!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",
Expand All @@ -351,7 +377,7 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE1D_ARRAY,
PI_MEM_TYPE_IMAGE2D_ARRAY) &&
!checkImageValueRange<info::device::image_max_array_size>(
Context, Desc.image_array_size))
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.",
Expand Down