Skip to content
Closed
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
15 changes: 2 additions & 13 deletions sycl/include/sycl/builtins_utils_vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include <sycl/detail/type_traits/vec_marray_traits.hpp>

#include <sycl/builtins_utils_scalar.hpp>

#include <sycl/detail/type_traits.hpp>
Expand Down Expand Up @@ -41,19 +43,6 @@ template <typename ElementType, typename... Ts>
struct is_valid_elem_type<ElementType *, Ts...>
: std::bool_constant<check_type_in_v<ElementType, Ts...>> {};

// Utility trait for getting the number of elements in T.
template <typename T>
struct num_elements : std::integral_constant<size_t, 1> {};
template <typename T, size_t N>
struct num_elements<marray<T, N>> : std::integral_constant<size_t, N> {};
template <typename T, int N>
struct num_elements<vec<T, N>> : std::integral_constant<size_t, size_t(N)> {};
template <typename VecT, typename OperationLeftT, typename OperationRightT,
template <typename> class OperationCurrentT, int... Indexes>
struct num_elements<SwizzleOp<VecT, OperationLeftT, OperationRightT,
OperationCurrentT, Indexes...>>
: std::integral_constant<size_t, sizeof...(Indexes)> {};

// Utilty trait for checking that the number of elements in T is in Ns.
template <typename T, size_t... Ns>
struct is_valid_size
Expand Down
Loading
Loading