Skip to content

Commit

Permalink
[SYCL] Modify detail::is_complex to handle cv qualifiers correctly (#…
Browse files Browse the repository at this point in the history
…12491)

Modify detail::is_complex to handle cv qualifiers correctly, by
replacing T with std::remove_cv_t\<T\> to strip off the cv qualifiers.
Its test cases have also been updated to check const and/or volatile
qualifers now. detail::is_plus and detail::is_multiplies are also
updated similarly to strip off const qualifers (as suggested by
@steffenlarsen, technically adding/removing volatile changes these two
types of operations, so volatile qualifers are not stripped off for
them).

---------

Signed-off-by: Hu, Peisen <[email protected]>
  • Loading branch information
HPS-1 authored Jan 27, 2024
1 parent 8d57ba7 commit 5e452ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
19 changes: 12 additions & 7 deletions sycl/include/sycl/group_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,19 @@ template <typename T, typename BinaryOperation> struct is_native_op {
// ---- is_plus
template <typename T, typename BinaryOperation>
using is_plus = std::integral_constant<
bool, std::is_same_v<BinaryOperation, sycl::plus<T>> ||
std::is_same_v<BinaryOperation, sycl::plus<void>>>;
bool,
std::is_same_v<BinaryOperation, sycl::plus<std::remove_const_t<T>>> ||
std::is_same_v<BinaryOperation, sycl::plus<std::add_const_t<T>>> ||
std::is_same_v<BinaryOperation, sycl::plus<void>>>;

// ---- is_multiplies
template <typename T, typename BinaryOperation>
using is_multiplies = std::integral_constant<
bool, std::is_same_v<BinaryOperation, sycl::multiplies<T>> ||
std::is_same_v<BinaryOperation, sycl::multiplies<void>>>;
bool,
std::is_same_v<BinaryOperation, sycl::multiplies<std::remove_const_t<T>>> ||
std::is_same_v<BinaryOperation,
sycl::multiplies<std::add_const_t<T>>> ||
std::is_same_v<BinaryOperation, sycl::multiplies<void>>>;

// ---- is_complex
// Use SFINAE so that the "true" branch could be implemented in
Expand All @@ -134,9 +139,9 @@ struct is_complex : public std::false_type {};

// ---- is_arithmetic_or_complex
template <typename T>
using is_arithmetic_or_complex = std::integral_constant<
bool, sycl::detail::is_complex<typename std::remove_cv_t<T>>::value ||
sycl::detail::is_arithmetic<T>::value>;
using is_arithmetic_or_complex =
std::integral_constant<bool, sycl::detail::is_complex<T>::value ||
sycl::detail::is_arithmetic<T>::value>;

template <typename T>
struct is_vector_arithmetic_or_complex
Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/stl_wrappers/complex
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ struct isComplex<T, std::enable_if_t<std::is_same_v<T, std::complex<float>> ||

// NOTE: std::complex<long double> not yet supported by group algorithms.
template <typename T>
struct is_complex<T, std::enable_if_t<std::is_same_v<T, std::complex<half>> ||
std::is_same_v<T, std::complex<float>> ||
std::is_same_v<T, std::complex<double>>>>
struct is_complex<T, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::complex<half>> ||
std::is_same_v<std::remove_cv_t<T>, std::complex<float>> ||
std::is_same_v<std::remove_cv_t<T>, std::complex<double>>>>
: public std::true_type {};

#ifdef __SYCL_DEVICE_ONLY__
Expand Down
5 changes: 5 additions & 0 deletions sycl/test-e2e/Complex/sycl_complex_include_order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ int main() {
queue q;
auto test = []() {
static_assert(sycl::detail::is_complex<std::complex<float>>::value);
static_assert(sycl::detail::is_complex<const std::complex<half>>::value);
static_assert(
sycl::detail::is_complex<const volatile std::complex<float>>::value);
static_assert(
sycl::detail::is_complex<volatile std::complex<double>>::value);
static_assert(sycl::detail::isComplex<std::complex<float>>::value);
#ifdef __SYCL_DEVICE_ONLY__
static_assert(
Expand Down

0 comments on commit 5e452ba

Please sign in to comment.