Skip to content

Commit

Permalink
[SYCL] Fix remove_decoration for cv-qual decorated ponters/refs (inte…
Browse files Browse the repository at this point in the history
…l#12691)

Previous implementation was incorrect because multiple specialization
were matching resulting in an ambiguity.
  • Loading branch information
aelovikov-intel committed Feb 12, 2024
1 parent 3843e6b commit b06cfb5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
65 changes: 35 additions & 30 deletions sycl/include/sycl/access/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,44 @@ struct deduce_AS
};
#endif

template <typename T> struct remove_decoration_impl {
using type = T;
};

#ifdef __SYCL_DEVICE_ONLY__
template <typename T> struct remove_decoration_impl<__OPENCL_GLOBAL_AS__ T> {
using type = T;
};

#ifdef __ENABLE_USM_ADDR_SPACE__
template <typename T>
struct remove_decoration_impl<__OPENCL_GLOBAL_DEVICE_AS__ T> {
using type = T;
};

template <typename T>
struct remove_decoration_impl<__OPENCL_GLOBAL_HOST_AS__ T> {
using type = T;
};

#endif // __ENABLE_USM_ADDR_SPACE__

template <typename T> struct remove_decoration_impl<__OPENCL_PRIVATE_AS__ T> {
using type = T;
};

template <typename T> struct remove_decoration_impl<__OPENCL_LOCAL_AS__ T> {
using type = T;
};

template <typename T> struct remove_decoration_impl<__OPENCL_CONSTANT_AS__ T> {
using type = T;
};
#endif // __SYCL_DEVICE_ONLY__
} // namespace detail

template <typename T> struct remove_decoration {
using type = T;
using type = typename detail::remove_decoration_impl<T>::type;
};

// Propagate through const qualifier.
Expand Down Expand Up @@ -287,35 +321,6 @@ template <typename T> struct remove_decoration<const T &> {
using type = const typename remove_decoration<T>::type &;
};

#ifdef __SYCL_DEVICE_ONLY__
template <typename T> struct remove_decoration<__OPENCL_GLOBAL_AS__ T> {
using type = T;
};

#ifdef __ENABLE_USM_ADDR_SPACE__
template <typename T> struct remove_decoration<__OPENCL_GLOBAL_DEVICE_AS__ T> {
using type = T;
};

template <typename T> struct remove_decoration<__OPENCL_GLOBAL_HOST_AS__ T> {
using type = T;
};

#endif // __ENABLE_USM_ADDR_SPACE__

template <typename T> struct remove_decoration<__OPENCL_PRIVATE_AS__ T> {
using type = T;
};

template <typename T> struct remove_decoration<__OPENCL_LOCAL_AS__ T> {
using type = T;
};

template <typename T> struct remove_decoration<__OPENCL_CONSTANT_AS__ T> {
using type = T;
};
#endif // __SYCL_DEVICE_ONLY__

template <typename T>
using remove_decoration_t = typename remove_decoration<T>::type;

Expand Down
18 changes: 18 additions & 0 deletions sycl/test/type_traits/type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,23 @@ int main() {
test_is_same_vector_size<true, s::constant_ptr<s::int2>, s::int2>();
test_is_same_vector_size<false, s::constant_ptr<s::int2>, float>();

#ifdef __SYCL_DEVICE_ONLY__
static_assert(
std::is_same_v<
s::remove_decoration_t<const __attribute__((opencl_global)) int>,
const int>);
static_assert(
std::is_same_v<s::remove_decoration_t<const volatile
__attribute__((opencl_global)) int>,
const volatile int>);
static_assert(
std::is_same_v<
s::remove_decoration_t<const __attribute__((opencl_global)) int *>,
const int *>);
static_assert(std::is_same_v<s::remove_decoration_t<const __attribute__((
opencl_global)) int *const>,
const int *const>);
#endif

return 0;
}

0 comments on commit b06cfb5

Please sign in to comment.