Skip to content

Commit

Permalink
[NFC][SYCL] Use get_elem_type_t instead of TryToGetElementType<T>::ty…
Browse files Browse the repository at this point in the history
…pe (#12738)
  • Loading branch information
aelovikov-intel authored Feb 20, 2024
1 parent 8f182cd commit 39639f6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
4 changes: 1 addition & 3 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,9 +1121,7 @@ class __image_array_slice__ {

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

template <typename CoordT,
typename CoordElemType =
typename detail::TryToGetElementType<CoordT>::type>
template <typename CoordT, typename CoordElemType = get_elem_type_t<CoordT>>
sycl::vec<CoordElemType, AdjustedDims>
getAdjustedCoords(const CoordT &Coords) const {
CoordElemType LastCoord = 0;
Expand Down
24 changes: 12 additions & 12 deletions sycl/include/sycl/detail/generic_type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,6 @@ template <typename T>
using make_unsinged_integer_t =
make_type_t<T, gtl::scalar_unsigned_integer_list>;

// TryToGetElementType<T>::type is T::element_type or T::value_type if those
// exist, otherwise T.
template <typename T> class TryToGetElementType {
static T check(...);
template <typename A> static typename A::element_type check(const A &);
template <typename A> static typename A::value_type check(const A &);

public:
using type = decltype(check(T()));
static constexpr bool value = !std::is_same_v<T, type>;
};

// select_apply_cl_scalar_t selects from T8/T16/T32/T64 basing on
// sizeof(IN). expected to handle scalar types.
template <typename T, typename T8, typename T16, typename T32, typename T64>
Expand Down Expand Up @@ -525,6 +513,18 @@ template <typename T, typename Enable = void> struct RelConverter {
static R apply(value_t value) { return value; }
};

// TryToGetElementType<T>::type is T::element_type or T::value_type if those
// exist, otherwise T.
template <typename T> class TryToGetElementType {
static T check(...);
template <typename A> static typename A::element_type check(const A &);
template <typename A> static typename A::value_type check(const A &);

public:
using type = decltype(check(T()));
static constexpr bool value = !std::is_same_v<T, type>;
};

template <typename T>
struct RelConverter<T,
typename std::enable_if_t<TryToGetElementType<T>::value>> {
Expand Down
6 changes: 2 additions & 4 deletions sycl/include/sycl/detail/image_accessor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,6 @@ void imageWriteHostImpl(const CoordT &Coords, const WriteDataT &Color,
break;
case image_channel_type::fp16:
writePixel(
// convertWriteDataToHalf<typename
// TryToGetElementType<WriteDataT>::type>(
convertWriteData<half>(Color, ImgChannelType),
reinterpret_cast<half *>(Ptr), ImgChannelOrder, ImgChannelType);
break;
Expand Down Expand Up @@ -915,7 +913,7 @@ DataT getColor(const int4 PixelCoord, const addressing_mode SmplAddrMode,
DataT RetData;
if (isOutOfRange(PixelCoord, SmplAddrMode, ImgRange)) {
float4 BorderColor = getBorderColor(ImgChannelOrder);
RetData = BorderColor.convert<typename TryToGetElementType<DataT>::type>();
RetData = BorderColor.convert<get_elem_type_t<DataT>>();
} else {
RetData = ReadPixelData<DataT>(PixelCoord, ImgPitch, ImgChannelType,
ImgChannelOrder, BasePtr, ElementSize);
Expand Down Expand Up @@ -984,7 +982,7 @@ DataT ReadPixelDataLinearFiltMode(const int8 CoordValues, const float4 abc,
// (1 – a) * b * Ci0j1 + a * b * Ci1j1;
// For 1D image: j0 = 0, j1 = 0, k0 = 0, k1 = 0, b = 0.5, c = 0.5.
// RetData = (1 – a) * Ci0 + a * Ci1;
return RetData.convert<typename TryToGetElementType<DataT>::type>();
return RetData.convert<get_elem_type_t<DataT>>();
}

// imageReadSamplerHostImpl method is called by the read API in image accessors
Expand Down
6 changes: 3 additions & 3 deletions sycl/test-e2e/Basic/image/image_accessor_readwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ template <typename WriteDataT, int ImgType, int read_write> class kernel_class;

template <typename ReadDataT,
typename = typename std::enable_if<
(!(std::is_same<ReadDataT, s::cl_float4>::value) &&
!(std::is_same<ReadDataT, s::cl_half4>::value))>::type>
(!(std::is_same_v<ReadDataT, s::cl_float4>) &&
!(std::is_same_v<ReadDataT, s::cl_half4>))>::type>
void check_read_data(ReadDataT ReadData, ReadDataT ExpectedColor) {
using ReadDataType = typename s::detail::TryToGetElementType<ReadDataT>::type;
using ReadDataType = typename ReadDataT::element_type;
bool CorrectData = false;
if ((ReadData.x() == ExpectedColor.x()) &&
(ReadData.y() == ExpectedColor.y()) &&
Expand Down

0 comments on commit 39639f6

Please sign in to comment.