Skip to content

Commit

Permalink
fix ternary op in subset of std algorithms not working with nvhpc (ko…
Browse files Browse the repository at this point in the history
…kkos#6095)

* fix std algorithms for nvhpc

This fixes tests disabled in fb8179f

Co-authored-by: Cezary Skrzyński

* fix index type

* improve comments

* address PR comments

* fix comments per CI suggestions

* revert is_sort_until
  • Loading branch information
fnrizzi committed May 4, 2023
1 parent 7a166d2 commit a45cc1e
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 122 deletions.
11 changes: 6 additions & 5 deletions algorithms/src/std_algorithms/impl/Kokkos_AdjacentFind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexType>::min()};
// FIXME_NVHPC using a ternary operator causes problems
red_value_type value = {::Kokkos::reduction_identity<IndexType>::min()};
if (are_equal) {
value.min_loc_true = i;
}

m_reducer.join(red_value, rv);
m_reducer.join(red_value, value);
}

KOKKOS_FUNCTION
Expand Down
8 changes: 5 additions & 3 deletions algorithms/src/std_algorithms/impl/Kokkos_FindEnd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ struct StdFindEndFunctor {
}
}

const auto rv =
found ? red_value_type{i}
: red_value_type{::Kokkos::reduction_identity<IndexType>::max()};
// FIXME_NVHPC using a ternary operator causes problems
red_value_type rv = {::Kokkos::reduction_identity<IndexType>::max()};
if (found) {
rv.max_loc_true = i;
}

m_reducer.join(red_value, rv);
}
Expand Down
9 changes: 5 additions & 4 deletions algorithms/src/std_algorithms/impl/Kokkos_FindFirstOf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ struct StdFindFirstOfFunctor {
}
}

const auto rv =
found ? red_value_type{i}
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};

// FIXME_NVHPC using a ternary operator causes problems
red_value_type rv = {::Kokkos::reduction_identity<IndexType>::min()};
if (found) {
rv.min_loc_true = i;
}
m_reducer.join(red_value, rv);
}

Expand Down
9 changes: 5 additions & 4 deletions algorithms/src/std_algorithms/impl/Kokkos_FindIfOrNot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexType>::min()};
// FIXME_NVHPC using a ternary operator causes problems
red_value_type rv = {::Kokkos::reduction_identity<IndexType>::min()};
if (found_condition) {
rv.min_loc_true = i;
}

m_reducer.join(red_value, rv);
}
Expand Down
8 changes: 6 additions & 2 deletions algorithms/src/std_algorithms/impl/Kokkos_IsPartitioned.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ struct StdIsPartitionedFunctor {
::Kokkos::reduction_identity<index_type>::min();
constexpr index_type m_red_id_max =
::Kokkos::reduction_identity<index_type>::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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexType>::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<IndexType>::min()};
if (different) {
rv.min_loc_true = i;
}

m_reducer.join(red_value, rv);
}
Expand Down
9 changes: 5 additions & 4 deletions algorithms/src/std_algorithms/impl/Kokkos_Mismatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexType>::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<IndexType>::min()};
}

m_reducer.join(red_value, rv);
}
Expand Down
11 changes: 7 additions & 4 deletions algorithms/src/std_algorithms/impl/Kokkos_PartitionPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<index_type>::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<index_type>::min()};
}

m_reducer.join(redValue, rv);
}

Expand Down
8 changes: 5 additions & 3 deletions algorithms/src/std_algorithms/impl/Kokkos_Search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ struct StdSearchFunctor {
}
}

const auto rv =
found ? red_value_type{i}
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};
// FIXME_NVHPC using a ternary operator causes problems
red_value_type rv = {::Kokkos::reduction_identity<IndexType>::min()};
if (found) {
rv = {i};
}

m_reducer.join(red_value, rv);
}
Expand Down
8 changes: 5 additions & 3 deletions algorithms/src/std_algorithms/impl/Kokkos_SearchN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ struct StdSearchNFunctor {
}
}

const auto rv =
found ? red_value_type{i}
: red_value_type{::Kokkos::reduction_identity<IndexType>::min()};
// FIXME_NVHPC using a ternary operator causes problems
red_value_type rv = {::Kokkos::reduction_identity<IndexType>::min()};
if (found) {
rv.min_loc_true = i;
}

m_reducer.join(red_value, rv);
}
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsAdjacentFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, int>();
run_all_scenarios<DynamicTag, double>();
run_all_scenarios<StridedThreeTag, int>();
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsAllAnyNoneOf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, double>();
run_all_scenarios<StridedTwoTag, int>();
run_all_scenarios<StridedThreeTag, unsigned>();
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, double>();
run_all_scenarios<StridedTwoTag, int>();
run_all_scenarios<StridedThreeTag, unsigned>();
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsFindEnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, int>();
run_all_scenarios<StridedThreeTag, int>();
}
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsFindFirstOf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, int>();
run_all_scenarios<StridedThreeTag, int>();
}
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_is_sorted_until_all_scenarios<DynamicTag, double>();
run_is_sorted_until_all_scenarios<StridedTwoTag, double>();
run_is_sorted_until_all_scenarios<StridedThreeTag, double>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
// FIXME: should this disable only custom comparator tests?
#if !defined KOKKOS_ENABLE_OPENMPTARGET
run_all_scenarios<DynamicTag, double>();
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsMismatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, double>();
run_all_scenarios<StridedThreeTag, int>();
}
Expand Down
24 changes: 0 additions & 24 deletions algorithms/unit_tests/TestStdAlgorithmsPartitioningOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
IsNegativeFunctor<value_type> p;
const auto result1 = KE::is_partitioned(exespace(), KE::cbegin(m_static_view),
KE::cbegin(m_static_view), p);
Expand All @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
const IsNegativeFunctor<value_type> p;

for (int id = 0; id < FixtureViews::Count; ++id) {
Expand All @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
const IsNegativeFunctor<value_type> p;

for (int id = 0; id < FixtureViews::Count; ++id) {
Expand All @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
const IsNegativeFunctor<value_type> p;

for (int id = 0; id < FixtureViews::Count; ++id) {
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, int>();
run_all_scenarios<StridedThreeTag, int>();
}
Expand Down
6 changes: 0 additions & 6 deletions algorithms/unit_tests/TestStdAlgorithmsSearch_n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<exespace, Kokkos::Cuda>) {
GTEST_SKIP() << "FIXME wrong result";
}
#endif
run_all_scenarios<DynamicTag, int>();
run_all_scenarios<StridedThreeTag, int>();
}
Expand Down

0 comments on commit a45cc1e

Please sign in to comment.