From a45cc1eff0e461942a66a13345fe215eee059c2c Mon Sep 17 00:00:00 2001 From: Francesco Rizzi Date: Thu, 4 May 2023 03:24:37 +0200 Subject: [PATCH] fix ternary op in subset of std algorithms not working with nvhpc (#6095) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix std algorithms for nvhpc This fixes tests disabled in fb8179f4bae685e8fc29c9fdd890b41e4c8b92ff Co-authored-by: Cezary SkrzyƄski * fix index type * improve comments * address PR comments * fix comments per CI suggestions * revert is_sort_until --- .../impl/Kokkos_AdjacentFind.hpp | 11 +++++---- .../std_algorithms/impl/Kokkos_FindEnd.hpp | 8 ++++--- .../impl/Kokkos_FindFirstOf.hpp | 9 +++---- .../impl/Kokkos_FindIfOrNot.hpp | 9 +++---- .../impl/Kokkos_IsPartitioned.hpp | 8 +++++-- .../impl/Kokkos_LexicographicalCompare.hpp | 14 ++++++----- .../std_algorithms/impl/Kokkos_Mismatch.hpp | 9 +++---- .../impl/Kokkos_PartitionPoint.hpp | 11 +++++---- .../src/std_algorithms/impl/Kokkos_Search.hpp | 8 ++++--- .../std_algorithms/impl/Kokkos_SearchN.hpp | 8 ++++--- .../TestStdAlgorithmsAdjacentFind.cpp | 6 ----- .../TestStdAlgorithmsAllAnyNoneOf.cpp | 6 ----- .../unit_tests/TestStdAlgorithmsFind.cpp | 6 ----- .../unit_tests/TestStdAlgorithmsFindEnd.cpp | 6 ----- .../TestStdAlgorithmsFindFirstOf.cpp | 6 ----- .../TestStdAlgorithmsIsSortedUntil.cpp | 6 ----- ...estStdAlgorithmsLexicographicalCompare.cpp | 6 ----- .../unit_tests/TestStdAlgorithmsMismatch.cpp | 6 ----- .../TestStdAlgorithmsPartitioningOps.cpp | 24 ------------------- .../unit_tests/TestStdAlgorithmsSearch.cpp | 6 ----- .../unit_tests/TestStdAlgorithmsSearch_n.cpp | 6 ----- 21 files changed, 57 insertions(+), 122 deletions(-) diff --git a/algorithms/src/std_algorithms/impl/Kokkos_AdjacentFind.hpp b/algorithms/src/std_algorithms/impl/Kokkos_AdjacentFind.hpp index cc6b63f028..dd785e603b 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_AdjacentFind.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_AdjacentFind.hpp @@ -42,12 +42,13 @@ struct StdAdjacentFindFunctor { const auto& next_value = m_first[i + 1]; const bool are_equal = m_p(my_value, next_value); - auto rv = - are_equal - ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::min()}; + // FIXME_NVHPC using a ternary operator causes problems + red_value_type value = {::Kokkos::reduction_identity::min()}; + if (are_equal) { + value.min_loc_true = i; + } - m_reducer.join(red_value, rv); + m_reducer.join(red_value, value); } KOKKOS_FUNCTION diff --git a/algorithms/src/std_algorithms/impl/Kokkos_FindEnd.hpp b/algorithms/src/std_algorithms/impl/Kokkos_FindEnd.hpp index 3fa41af8ea..3ec64fa43d 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_FindEnd.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_FindEnd.hpp @@ -59,9 +59,11 @@ struct StdFindEndFunctor { } } - const auto rv = - found ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::max()}; + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {::Kokkos::reduction_identity::max()}; + if (found) { + rv.max_loc_true = i; + } m_reducer.join(red_value, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_FindFirstOf.hpp b/algorithms/src/std_algorithms/impl/Kokkos_FindFirstOf.hpp index df10da2fd5..5f22d2ad13 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_FindFirstOf.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_FindFirstOf.hpp @@ -52,10 +52,11 @@ struct StdFindFirstOfFunctor { } } - const auto rv = - found ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::min()}; - + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {::Kokkos::reduction_identity::min()}; + if (found) { + rv.min_loc_true = i; + } m_reducer.join(red_value, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_FindIfOrNot.hpp b/algorithms/src/std_algorithms/impl/Kokkos_FindIfOrNot.hpp index f7ec4b1110..9c0b0c0ccd 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_FindIfOrNot.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_FindIfOrNot.hpp @@ -44,10 +44,11 @@ struct StdFindIfOrNotFunctor { // if doing find_if_not, look for when predicate is false const bool found_condition = is_find_if ? m_p(my_value) : !m_p(my_value); - auto rv = - found_condition - ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::min()}; + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {::Kokkos::reduction_identity::min()}; + if (found_condition) { + rv.min_loc_true = i; + } m_reducer.join(red_value, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_IsPartitioned.hpp b/algorithms/src/std_algorithms/impl/Kokkos_IsPartitioned.hpp index 92a22f3c3a..0fe2d246ff 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_IsPartitioned.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_IsPartitioned.hpp @@ -43,8 +43,12 @@ struct StdIsPartitionedFunctor { ::Kokkos::reduction_identity::min(); constexpr index_type m_red_id_max = ::Kokkos::reduction_identity::max(); - auto rv = predicate_value ? red_value_type{i, m_red_id_min} - : red_value_type{m_red_id_max, i}; + + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {m_red_id_max, i}; + if (predicate_value) { + rv = {i, m_red_id_min}; + } m_reducer.join(redValue, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_LexicographicalCompare.hpp b/algorithms/src/std_algorithms/impl/Kokkos_LexicographicalCompare.hpp index 170ec9f291..ad7f59232e 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_LexicographicalCompare.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_LexicographicalCompare.hpp @@ -63,12 +63,14 @@ struct StdLexicographicalCompareFunctor { const auto& my_value1 = m_first1[i]; const auto& my_value2 = m_first2[i]; - bool different = m_comparator(my_value1, my_value2) || - m_comparator(my_value2, my_value1); - auto rv = - different - ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::min()}; + const bool different = m_comparator(my_value1, my_value2) || + m_comparator(my_value2, my_value1); + + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {::Kokkos::reduction_identity::min()}; + if (different) { + rv.min_loc_true = i; + } m_reducer.join(red_value, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_Mismatch.hpp b/algorithms/src/std_algorithms/impl/Kokkos_Mismatch.hpp index 9d2e31f63f..b742684467 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_Mismatch.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_Mismatch.hpp @@ -42,10 +42,11 @@ struct StdMismatchRedFunctor { const auto& my_value1 = m_first1[i]; const auto& my_value2 = m_first2[i]; - auto rv = - !m_predicate(my_value1, my_value2) - ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::min()}; + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {i}; + if (m_predicate(my_value1, my_value2)) { + rv = {::Kokkos::reduction_identity::min()}; + } m_reducer.join(red_value, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_PartitionPoint.hpp b/algorithms/src/std_algorithms/impl/Kokkos_PartitionPoint.hpp index 2d0ae2aac6..c9517f6977 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_PartitionPoint.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_PartitionPoint.hpp @@ -39,10 +39,13 @@ struct StdPartitionPointFunctor { KOKKOS_FUNCTION void operator()(const index_type i, red_value_type& redValue) const { const auto predicate_value = m_p(m_first[i]); - auto rv = - predicate_value - ? red_value_type{::Kokkos::reduction_identity::min()} - : red_value_type{i}; + + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {i}; + if (predicate_value) { + rv = {::Kokkos::reduction_identity::min()}; + } + m_reducer.join(redValue, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_Search.hpp b/algorithms/src/std_algorithms/impl/Kokkos_Search.hpp index a612a57231..2780151f29 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_Search.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_Search.hpp @@ -60,9 +60,11 @@ struct StdSearchFunctor { } } - const auto rv = - found ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::min()}; + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {::Kokkos::reduction_identity::min()}; + if (found) { + rv = {i}; + } m_reducer.join(red_value, rv); } diff --git a/algorithms/src/std_algorithms/impl/Kokkos_SearchN.hpp b/algorithms/src/std_algorithms/impl/Kokkos_SearchN.hpp index 0d3b6bc706..98640136d4 100644 --- a/algorithms/src/std_algorithms/impl/Kokkos_SearchN.hpp +++ b/algorithms/src/std_algorithms/impl/Kokkos_SearchN.hpp @@ -59,9 +59,11 @@ struct StdSearchNFunctor { } } - const auto rv = - found ? red_value_type{i} - : red_value_type{::Kokkos::reduction_identity::min()}; + // FIXME_NVHPC using a ternary operator causes problems + red_value_type rv = {::Kokkos::reduction_identity::min()}; + if (found) { + rv.min_loc_true = i; + } m_reducer.join(red_value, rv); } diff --git a/algorithms/unit_tests/TestStdAlgorithmsAdjacentFind.cpp b/algorithms/unit_tests/TestStdAlgorithmsAdjacentFind.cpp index ee34761265..6fc9d583f3 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsAdjacentFind.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsAdjacentFind.cpp @@ -287,12 +287,6 @@ void run_all_scenarios() { } TEST(std_algorithms_nonmod_seq_ops, adjacent_find) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); run_all_scenarios(); diff --git a/algorithms/unit_tests/TestStdAlgorithmsAllAnyNoneOf.cpp b/algorithms/unit_tests/TestStdAlgorithmsAllAnyNoneOf.cpp index 1c39a4735e..cccc0f6c18 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsAllAnyNoneOf.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsAllAnyNoneOf.cpp @@ -147,12 +147,6 @@ void run_all_scenarios() { } TEST(std_algorithms_all_any_none_of_test, test) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); run_all_scenarios(); diff --git a/algorithms/unit_tests/TestStdAlgorithmsFind.cpp b/algorithms/unit_tests/TestStdAlgorithmsFind.cpp index 3b8b5e85af..5407bab224 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsFind.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsFind.cpp @@ -151,12 +151,6 @@ void run_all_scenarios() { } TEST(std_algorithms_find_test, test) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); run_all_scenarios(); diff --git a/algorithms/unit_tests/TestStdAlgorithmsFindEnd.cpp b/algorithms/unit_tests/TestStdAlgorithmsFindEnd.cpp index ddc4bc1ba6..c9e213962b 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsFindEnd.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsFindEnd.cpp @@ -348,12 +348,6 @@ void run_all_scenarios() { } TEST(std_algorithms_non_mod_seq_ops, find_end) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); } diff --git a/algorithms/unit_tests/TestStdAlgorithmsFindFirstOf.cpp b/algorithms/unit_tests/TestStdAlgorithmsFindFirstOf.cpp index c2f7a2fdb8..e9141bd27b 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsFindFirstOf.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsFindFirstOf.cpp @@ -264,12 +264,6 @@ void run_all_scenarios() { } TEST(std_algorithms_non_mod_seq_ops, find_first_of) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); } diff --git a/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp b/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp index ce8669a84f..6053c6ca57 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp @@ -185,12 +185,6 @@ void run_is_sorted_until_all_scenarios() { } TEST(std_algorithms_sorting_ops_test, is_sorted_until) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_is_sorted_until_all_scenarios(); run_is_sorted_until_all_scenarios(); run_is_sorted_until_all_scenarios(); diff --git a/algorithms/unit_tests/TestStdAlgorithmsLexicographicalCompare.cpp b/algorithms/unit_tests/TestStdAlgorithmsLexicographicalCompare.cpp index 2acd4934ac..2d4f1afdd0 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsLexicographicalCompare.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsLexicographicalCompare.cpp @@ -140,12 +140,6 @@ void run_all_scenarios() { } TEST(std_algorithms_lexicographical_compare_test, test) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif // FIXME: should this disable only custom comparator tests? #if !defined KOKKOS_ENABLE_OPENMPTARGET run_all_scenarios(); diff --git a/algorithms/unit_tests/TestStdAlgorithmsMismatch.cpp b/algorithms/unit_tests/TestStdAlgorithmsMismatch.cpp index bb4b6fb2a2..774329eef7 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsMismatch.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsMismatch.cpp @@ -189,12 +189,6 @@ void run_all_scenarios() { } TEST(std_algorithms_mismatch_test, test) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); } diff --git a/algorithms/unit_tests/TestStdAlgorithmsPartitioningOps.cpp b/algorithms/unit_tests/TestStdAlgorithmsPartitioningOps.cpp index 1bfb536c2c..94ec278af1 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsPartitioningOps.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsPartitioningOps.cpp @@ -148,12 +148,6 @@ struct std_algorithms_partitioning_test : public std_algorithms_test { }; TEST_F(std_algorithms_partitioning_test, is_partitioned_trivial) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif IsNegativeFunctor p; const auto result1 = KE::is_partitioned(exespace(), KE::cbegin(m_static_view), KE::cbegin(m_static_view), p); @@ -169,12 +163,6 @@ TEST_F(std_algorithms_partitioning_test, is_partitioned_trivial) { } TEST_F(std_algorithms_partitioning_test, is_partitioned_accepting_iterators) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif const IsNegativeFunctor p; for (int id = 0; id < FixtureViews::Count; ++id) { @@ -196,12 +184,6 @@ TEST_F(std_algorithms_partitioning_test, is_partitioned_accepting_iterators) { } TEST_F(std_algorithms_partitioning_test, is_partitioned_accepting_view) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif const IsNegativeFunctor p; for (int id = 0; id < FixtureViews::Count; ++id) { @@ -220,12 +202,6 @@ TEST_F(std_algorithms_partitioning_test, is_partitioned_accepting_view) { } TEST_F(std_algorithms_partitioning_test, partition_point) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif const IsNegativeFunctor p; for (int id = 0; id < FixtureViews::Count; ++id) { diff --git a/algorithms/unit_tests/TestStdAlgorithmsSearch.cpp b/algorithms/unit_tests/TestStdAlgorithmsSearch.cpp index ab4bf50713..c25b82a245 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsSearch.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsSearch.cpp @@ -325,12 +325,6 @@ void run_all_scenarios() { } TEST(std_algorithms_non_mod_seq_ops, search) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); } diff --git a/algorithms/unit_tests/TestStdAlgorithmsSearch_n.cpp b/algorithms/unit_tests/TestStdAlgorithmsSearch_n.cpp index a6fe9c1e89..68e2b1bf0f 100644 --- a/algorithms/unit_tests/TestStdAlgorithmsSearch_n.cpp +++ b/algorithms/unit_tests/TestStdAlgorithmsSearch_n.cpp @@ -297,12 +297,6 @@ void run_all_scenarios() { } TEST(std_algorithms_non_mod_seq_ops, search_n) { -#if defined(KOKKOS_ENABLE_CUDA) && \ - defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC - if constexpr (std::is_same_v) { - GTEST_SKIP() << "FIXME wrong result"; - } -#endif run_all_scenarios(); run_all_scenarios(); }