Skip to content

Commit

Permalink
[NFC][SYCL] Inline/drop is_genint_v type trait (#15707)
Browse files Browse the repository at this point in the history
It's only used in a single header for extra filtering of `cl_int` and
`cl_float`. We don't need the entirety of "generic" integer types to do
that.

Note `(Dims > 0) && ` that I'm dropping here seemed to have no effect as
`IsValidCoordDataT` helper ensures `Dims` can't be non-positive. Also,
it would be a compiler error and not an SFINAE-based selection because
of that helper anyway.
  • Loading branch information
aelovikov-intel authored Oct 15, 2024
1 parent 0d3eb05 commit b2f6326
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
59 changes: 29 additions & 30 deletions sycl/include/sycl/accessor_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
namespace sycl {
inline namespace _V1 {
namespace detail {
template <int Dim, typename T> struct IsValidCoordDataT;
template <typename T> struct IsValidCoordDataT<1, T> {
constexpr static bool value = detail::is_contained<
T, detail::type_list<opencl::cl_int, opencl::cl_float>>::type::value;
template <int Dim, typename T, bool AllowFP = true> struct IsValidCoordDataT;
template <typename T, bool AllowFP> struct IsValidCoordDataT<1, T, AllowFP> {
constexpr static bool value =
std::is_same_v<T, opencl::cl_int> ||
(AllowFP && std::is_same_v<T, opencl::cl_float>);
};
template <typename T> struct IsValidCoordDataT<2, T> {
constexpr static bool value = detail::is_contained<
T, detail::type_list<vec<opencl::cl_int, 2>,
vec<opencl::cl_float, 2>>>::type::value;
template <typename T, bool AllowFP> struct IsValidCoordDataT<2, T, AllowFP> {
constexpr static bool value =
std::is_same_v<T, vec<opencl::cl_int, 2>> ||
(AllowFP && std::is_same_v<T, vec<opencl::cl_float, 2>>);
};
template <typename T> struct IsValidCoordDataT<3, T> {
constexpr static bool value = detail::is_contained<
T, detail::type_list<vec<opencl::cl_int, 4>,
vec<opencl::cl_float, 4>>>::type::value;
template <typename T, bool AllowFP> struct IsValidCoordDataT<3, T, AllowFP> {
constexpr static bool value =
std::is_same_v<T, vec<opencl::cl_int, 4>> ||
(AllowFP && std::is_same_v<T, vec<opencl::cl_float, 4>>);
};

template <int Dim, typename T> struct IsValidUnsampledCoord2020DataT;
Expand Down Expand Up @@ -448,12 +449,12 @@ class image_accessor
// (accessTarget == access::target::image && accessMode == access::mode::read)
// || (accessTarget == access::target::host_image && ( accessMode ==
// access::mode::read || accessMode == access::mode::read_write))
template <typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<
(Dims > 0) && (IsValidCoordDataT<Dims, CoordT>::value) &&
(detail::is_genint_v<CoordT>) &&
((IsImageAcc && IsImageAccessReadOnly) ||
(IsHostImageAcc && IsImageAccessAnyRead))>>
template <
typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<
(IsValidCoordDataT<Dims, CoordT, /* AllowFP = */ false>::value) &&
((IsImageAcc && IsImageAccessReadOnly) ||
(IsHostImageAcc && IsImageAccessAnyRead))>>
DataT read(const CoordT &Coords) const {
#ifdef __SYCL_DEVICE_ONLY__
return __invoke__ImageRead<DataT, OCLImageTy, CoordT>(MImageObj, Coords);
Expand All @@ -470,7 +471,7 @@ class image_accessor
// access::mode::read || accessMode == access::mode::read_write))
template <typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<
(Dims > 0) && (IsValidCoordDataT<Dims, CoordT>::value) &&
(IsValidCoordDataT<Dims, CoordT>::value) &&
((IsImageAcc && IsImageAccessReadOnly) ||
(IsHostImageAcc && IsImageAccessAnyRead))>>
DataT read(const CoordT &Coords, const sampler &Smpl) const {
Expand All @@ -494,10 +495,10 @@ class image_accessor
// accessMode == access::mode::read_write))
template <
typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<(Dims > 0) && (detail::is_genint_v<CoordT>) &&
(IsValidCoordDataT<Dims, CoordT>::value) &&
((IsImageAcc && IsImageAccessWriteOnly) ||
(IsHostImageAcc && IsImageAccessAnyWrite))>>
typename = std::enable_if_t<
(IsValidCoordDataT<Dims, CoordT, /* AllowFP = */ false>::value) &&
((IsImageAcc && IsImageAccessWriteOnly) ||
(IsHostImageAcc && IsImageAccessAnyWrite))>>
void write(const CoordT &Coords, const DataT &Color) const {
#ifdef __SYCL_DEVICE_ONLY__
__invoke__ImageWrite<OCLImageTy, CoordT, DataT>(MImageObj, Coords, Color);
Expand Down Expand Up @@ -546,23 +547,21 @@ class __image_array_slice__ {
size_t Idx)
: MBaseAcc(BaseAcc), MIdx(Idx) {}

template <typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<
(Dims > 0) && (IsValidCoordDataT<Dims, CoordT>::value)>>
template <
typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<(IsValidCoordDataT<Dims, CoordT>::value)>>
DataT read(const CoordT &Coords) const {
return MBaseAcc.read(getAdjustedCoords(Coords));
}

template <typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<(Dims > 0) &&
IsValidCoordDataT<Dims, CoordT>::value>>
typename = std::enable_if_t<IsValidCoordDataT<Dims, CoordT>::value>>
DataT read(const CoordT &Coords, const sampler &Smpl) const {
return MBaseAcc.read(getAdjustedCoords(Coords), Smpl);
}

template <typename CoordT, int Dims = Dimensions,
typename = std::enable_if_t<(Dims > 0) &&
IsValidCoordDataT<Dims, CoordT>::value>>
typename = std::enable_if_t<IsValidCoordDataT<Dims, CoordT>::value>>
void write(const CoordT &Coords, const DataT &Color) const {
return MBaseAcc.write(getAdjustedCoords(Coords), Color);
}
Expand Down
3 changes: 0 additions & 3 deletions sycl/include/sycl/detail/generic_type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ template <typename T>
inline constexpr bool is_vgenfloat_v =
is_contained_v<T, gtl::vector_floating_list>;

template <typename T>
inline constexpr bool is_genint_v = is_contained_v<T, gtl::signed_int_list>;

template <typename T>
inline constexpr bool is_geninteger_v = is_contained_v<T, gtl::integer_list>;

Expand Down

0 comments on commit b2f6326

Please sign in to comment.