Skip to content

Commit 39639f6

Browse files
[NFC][SYCL] Use get_elem_type_t instead of TryToGetElementType<T>::type (#12738)
1 parent 8f182cd commit 39639f6

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,7 @@ class __image_array_slice__ {
11211121

11221122
constexpr static int AdjustedDims = (Dimensions == 2) ? 4 : Dimensions + 1;
11231123

1124-
template <typename CoordT,
1125-
typename CoordElemType =
1126-
typename detail::TryToGetElementType<CoordT>::type>
1124+
template <typename CoordT, typename CoordElemType = get_elem_type_t<CoordT>>
11271125
sycl::vec<CoordElemType, AdjustedDims>
11281126
getAdjustedCoords(const CoordT &Coords) const {
11291127
CoordElemType LastCoord = 0;

sycl/include/sycl/detail/generic_type_traits.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,6 @@ template <typename T>
301301
using make_unsinged_integer_t =
302302
make_type_t<T, gtl::scalar_unsigned_integer_list>;
303303

304-
// TryToGetElementType<T>::type is T::element_type or T::value_type if those
305-
// exist, otherwise T.
306-
template <typename T> class TryToGetElementType {
307-
static T check(...);
308-
template <typename A> static typename A::element_type check(const A &);
309-
template <typename A> static typename A::value_type check(const A &);
310-
311-
public:
312-
using type = decltype(check(T()));
313-
static constexpr bool value = !std::is_same_v<T, type>;
314-
};
315-
316304
// select_apply_cl_scalar_t selects from T8/T16/T32/T64 basing on
317305
// sizeof(IN). expected to handle scalar types.
318306
template <typename T, typename T8, typename T16, typename T32, typename T64>
@@ -525,6 +513,18 @@ template <typename T, typename Enable = void> struct RelConverter {
525513
static R apply(value_t value) { return value; }
526514
};
527515

516+
// TryToGetElementType<T>::type is T::element_type or T::value_type if those
517+
// exist, otherwise T.
518+
template <typename T> class TryToGetElementType {
519+
static T check(...);
520+
template <typename A> static typename A::element_type check(const A &);
521+
template <typename A> static typename A::value_type check(const A &);
522+
523+
public:
524+
using type = decltype(check(T()));
525+
static constexpr bool value = !std::is_same_v<T, type>;
526+
};
527+
528528
template <typename T>
529529
struct RelConverter<T,
530530
typename std::enable_if_t<TryToGetElementType<T>::value>> {

sycl/include/sycl/detail/image_accessor_util.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,6 @@ void imageWriteHostImpl(const CoordT &Coords, const WriteDataT &Color,
773773
break;
774774
case image_channel_type::fp16:
775775
writePixel(
776-
// convertWriteDataToHalf<typename
777-
// TryToGetElementType<WriteDataT>::type>(
778776
convertWriteData<half>(Color, ImgChannelType),
779777
reinterpret_cast<half *>(Ptr), ImgChannelOrder, ImgChannelType);
780778
break;
@@ -915,7 +913,7 @@ DataT getColor(const int4 PixelCoord, const addressing_mode SmplAddrMode,
915913
DataT RetData;
916914
if (isOutOfRange(PixelCoord, SmplAddrMode, ImgRange)) {
917915
float4 BorderColor = getBorderColor(ImgChannelOrder);
918-
RetData = BorderColor.convert<typename TryToGetElementType<DataT>::type>();
916+
RetData = BorderColor.convert<get_elem_type_t<DataT>>();
919917
} else {
920918
RetData = ReadPixelData<DataT>(PixelCoord, ImgPitch, ImgChannelType,
921919
ImgChannelOrder, BasePtr, ElementSize);
@@ -984,7 +982,7 @@ DataT ReadPixelDataLinearFiltMode(const int8 CoordValues, const float4 abc,
984982
// (1 – a) * b * Ci0j1 + a * b * Ci1j1;
985983
// For 1D image: j0 = 0, j1 = 0, k0 = 0, k1 = 0, b = 0.5, c = 0.5.
986984
// RetData = (1 – a) * Ci0 + a * Ci1;
987-
return RetData.convert<typename TryToGetElementType<DataT>::type>();
985+
return RetData.convert<get_elem_type_t<DataT>>();
988986
}
989987

990988
// imageReadSamplerHostImpl method is called by the read API in image accessors

sycl/test-e2e/Basic/image/image_accessor_readwrite.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ template <typename WriteDataT, int ImgType, int read_write> class kernel_class;
2727

2828
template <typename ReadDataT,
2929
typename = typename std::enable_if<
30-
(!(std::is_same<ReadDataT, s::cl_float4>::value) &&
31-
!(std::is_same<ReadDataT, s::cl_half4>::value))>::type>
30+
(!(std::is_same_v<ReadDataT, s::cl_float4>) &&
31+
!(std::is_same_v<ReadDataT, s::cl_half4>))>::type>
3232
void check_read_data(ReadDataT ReadData, ReadDataT ExpectedColor) {
33-
using ReadDataType = typename s::detail::TryToGetElementType<ReadDataT>::type;
33+
using ReadDataType = typename ReadDataT::element_type;
3434
bool CorrectData = false;
3535
if ((ReadData.x() == ExpectedColor.x()) &&
3636
(ReadData.y() == ExpectedColor.y()) &&

0 commit comments

Comments
 (0)