Skip to content

Commit b2f6326

Browse files
[NFC][SYCL] Inline/drop is_genint_v type trait (#15707)
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.
1 parent 0d3eb05 commit b2f6326

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

sycl/include/sycl/accessor_image.hpp

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
namespace sycl {
1313
inline namespace _V1 {
1414
namespace detail {
15-
template <int Dim, typename T> struct IsValidCoordDataT;
16-
template <typename T> struct IsValidCoordDataT<1, T> {
17-
constexpr static bool value = detail::is_contained<
18-
T, detail::type_list<opencl::cl_int, opencl::cl_float>>::type::value;
15+
template <int Dim, typename T, bool AllowFP = true> struct IsValidCoordDataT;
16+
template <typename T, bool AllowFP> struct IsValidCoordDataT<1, T, AllowFP> {
17+
constexpr static bool value =
18+
std::is_same_v<T, opencl::cl_int> ||
19+
(AllowFP && std::is_same_v<T, opencl::cl_float>);
1920
};
20-
template <typename T> struct IsValidCoordDataT<2, T> {
21-
constexpr static bool value = detail::is_contained<
22-
T, detail::type_list<vec<opencl::cl_int, 2>,
23-
vec<opencl::cl_float, 2>>>::type::value;
21+
template <typename T, bool AllowFP> struct IsValidCoordDataT<2, T, AllowFP> {
22+
constexpr static bool value =
23+
std::is_same_v<T, vec<opencl::cl_int, 2>> ||
24+
(AllowFP && std::is_same_v<T, vec<opencl::cl_float, 2>>);
2425
};
25-
template <typename T> struct IsValidCoordDataT<3, T> {
26-
constexpr static bool value = detail::is_contained<
27-
T, detail::type_list<vec<opencl::cl_int, 4>,
28-
vec<opencl::cl_float, 4>>>::type::value;
26+
template <typename T, bool AllowFP> struct IsValidCoordDataT<3, T, AllowFP> {
27+
constexpr static bool value =
28+
std::is_same_v<T, vec<opencl::cl_int, 4>> ||
29+
(AllowFP && std::is_same_v<T, vec<opencl::cl_float, 4>>);
2930
};
3031

3132
template <int Dim, typename T> struct IsValidUnsampledCoord2020DataT;
@@ -448,12 +449,12 @@ class image_accessor
448449
// (accessTarget == access::target::image && accessMode == access::mode::read)
449450
// || (accessTarget == access::target::host_image && ( accessMode ==
450451
// access::mode::read || accessMode == access::mode::read_write))
451-
template <typename CoordT, int Dims = Dimensions,
452-
typename = std::enable_if_t<
453-
(Dims > 0) && (IsValidCoordDataT<Dims, CoordT>::value) &&
454-
(detail::is_genint_v<CoordT>) &&
455-
((IsImageAcc && IsImageAccessReadOnly) ||
456-
(IsHostImageAcc && IsImageAccessAnyRead))>>
452+
template <
453+
typename CoordT, int Dims = Dimensions,
454+
typename = std::enable_if_t<
455+
(IsValidCoordDataT<Dims, CoordT, /* AllowFP = */ false>::value) &&
456+
((IsImageAcc && IsImageAccessReadOnly) ||
457+
(IsHostImageAcc && IsImageAccessAnyRead))>>
457458
DataT read(const CoordT &Coords) const {
458459
#ifdef __SYCL_DEVICE_ONLY__
459460
return __invoke__ImageRead<DataT, OCLImageTy, CoordT>(MImageObj, Coords);
@@ -470,7 +471,7 @@ class image_accessor
470471
// access::mode::read || accessMode == access::mode::read_write))
471472
template <typename CoordT, int Dims = Dimensions,
472473
typename = std::enable_if_t<
473-
(Dims > 0) && (IsValidCoordDataT<Dims, CoordT>::value) &&
474+
(IsValidCoordDataT<Dims, CoordT>::value) &&
474475
((IsImageAcc && IsImageAccessReadOnly) ||
475476
(IsHostImageAcc && IsImageAccessAnyRead))>>
476477
DataT read(const CoordT &Coords, const sampler &Smpl) const {
@@ -494,10 +495,10 @@ class image_accessor
494495
// accessMode == access::mode::read_write))
495496
template <
496497
typename CoordT, int Dims = Dimensions,
497-
typename = std::enable_if_t<(Dims > 0) && (detail::is_genint_v<CoordT>) &&
498-
(IsValidCoordDataT<Dims, CoordT>::value) &&
499-
((IsImageAcc && IsImageAccessWriteOnly) ||
500-
(IsHostImageAcc && IsImageAccessAnyWrite))>>
498+
typename = std::enable_if_t<
499+
(IsValidCoordDataT<Dims, CoordT, /* AllowFP = */ false>::value) &&
500+
((IsImageAcc && IsImageAccessWriteOnly) ||
501+
(IsHostImageAcc && IsImageAccessAnyWrite))>>
501502
void write(const CoordT &Coords, const DataT &Color) const {
502503
#ifdef __SYCL_DEVICE_ONLY__
503504
__invoke__ImageWrite<OCLImageTy, CoordT, DataT>(MImageObj, Coords, Color);
@@ -546,23 +547,21 @@ class __image_array_slice__ {
546547
size_t Idx)
547548
: MBaseAcc(BaseAcc), MIdx(Idx) {}
548549

549-
template <typename CoordT, int Dims = Dimensions,
550-
typename = std::enable_if_t<
551-
(Dims > 0) && (IsValidCoordDataT<Dims, CoordT>::value)>>
550+
template <
551+
typename CoordT, int Dims = Dimensions,
552+
typename = std::enable_if_t<(IsValidCoordDataT<Dims, CoordT>::value)>>
552553
DataT read(const CoordT &Coords) const {
553554
return MBaseAcc.read(getAdjustedCoords(Coords));
554555
}
555556

556557
template <typename CoordT, int Dims = Dimensions,
557-
typename = std::enable_if_t<(Dims > 0) &&
558-
IsValidCoordDataT<Dims, CoordT>::value>>
558+
typename = std::enable_if_t<IsValidCoordDataT<Dims, CoordT>::value>>
559559
DataT read(const CoordT &Coords, const sampler &Smpl) const {
560560
return MBaseAcc.read(getAdjustedCoords(Coords), Smpl);
561561
}
562562

563563
template <typename CoordT, int Dims = Dimensions,
564-
typename = std::enable_if_t<(Dims > 0) &&
565-
IsValidCoordDataT<Dims, CoordT>::value>>
564+
typename = std::enable_if_t<IsValidCoordDataT<Dims, CoordT>::value>>
566565
void write(const CoordT &Coords, const DataT &Color) const {
567566
return MBaseAcc.write(getAdjustedCoords(Coords), Color);
568567
}

sycl/include/sycl/detail/generic_type_traits.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ template <typename T>
4646
inline constexpr bool is_vgenfloat_v =
4747
is_contained_v<T, gtl::vector_floating_list>;
4848

49-
template <typename T>
50-
inline constexpr bool is_genint_v = is_contained_v<T, gtl::signed_int_list>;
51-
5249
template <typename T>
5350
inline constexpr bool is_geninteger_v = is_contained_v<T, gtl::integer_list>;
5451

0 commit comments

Comments
 (0)