diff --git a/sparse/unit_test/Test_Sparse_Controls.hpp b/sparse/unit_test/Test_Sparse_Controls.hpp index 7da8e19e97..79679f8173 100644 --- a/sparse/unit_test/Test_Sparse_Controls.hpp +++ b/sparse/unit_test/Test_Sparse_Controls.hpp @@ -38,7 +38,25 @@ void test_controls_set() { EXPECT_EQ(c.getParameter("", "default"), "default"); } +void test_controls_il() { + { + KokkosKernels::Experimental::Controls c({{"key1", "val1"}}); + EXPECT_EQ(c.isParameter("blah"), false); + EXPECT_EQ(c.getParameter("blah"), ""); + EXPECT_EQ(c.getParameter("key1"), "val1"); + } + { + KokkosKernels::Experimental::Controls c( + {{"key1", "val1"}, {"key2", "val2"}}); + EXPECT_EQ(c.isParameter("blah"), false); + EXPECT_EQ(c.getParameter("blah"), ""); + EXPECT_EQ(c.getParameter("key1"), "val1"); + EXPECT_EQ(c.getParameter("key2"), "val2"); + } +} + TEST_F(TestCategory, controls_empty) { test_controls_empty(); } TEST_F(TestCategory, controls_set) { test_controls_set(); } +TEST_F(TestCategory, controls_il) { test_controls_il(); } #endif // TEST_SPARSE_CONTROLS_HPP diff --git a/sparse/unit_test/Test_Sparse_spmv_bsr.hpp b/sparse/unit_test/Test_Sparse_spmv_bsr.hpp index 164c87b8df..5b823a22f7 100644 --- a/sparse/unit_test/Test_Sparse_spmv_bsr.hpp +++ b/sparse/unit_test/Test_Sparse_spmv_bsr.hpp @@ -53,6 +53,29 @@ using kokkos_complex_double = Kokkos::complex; using kokkos_complex_float = Kokkos::complex; +/* Poor-man's std::optional since CUDA 11.0 seems to have an ICE + https://github.com/kokkos/kokkos-kernels/issues/1943 +*/ +struct OptCtrls { + bool present_; + KokkosKernels::Experimental::Controls ctrls_; + + OptCtrls() : present_(false) {} + OptCtrls(const KokkosKernels::Experimental::Controls &ctrls) + : present_(true), ctrls_(ctrls) {} + + operator bool() const { return present_; } + + constexpr const KokkosKernels::Experimental::Controls &operator*() + const &noexcept { + return ctrls_; + } + constexpr const KokkosKernels::Experimental::Controls *operator->() const + noexcept { + return &ctrls_; + } +}; + namespace Test_Spmv_Bsr { /*! \brief Maximum value used to fill A */ @@ -151,10 +174,9 @@ Bsr bsr_random(const int blockSize, const int blockRows, const int blockCols) { template -void test_spmv( - const std::optional &controls, - const char *mode, const Alpha &alpha, const Beta &beta, const Bsr &a, - const Crs &acrs, size_t maxNnzPerRow, const XVector &x, const YVector &y) { +void test_spmv(const OptCtrls &controls, const char *mode, const Alpha &alpha, + const Beta &beta, const Bsr &a, const Crs &acrs, + size_t maxNnzPerRow, const XVector &x, const YVector &y) { using scalar_type = typename Bsr::non_const_value_type; using ordinal_type = typename Bsr::non_const_ordinal_type; using KATS = Kokkos::ArithTraits; @@ -369,21 +391,19 @@ void test_spmv_combos(const char *mode, const Bsr &a, const Crs &acrs, // cover a variety of controls using Ctrls = KokkosKernels::Experimental::Controls; - using OptCtrls = std::optional; - std::vector ctrls = { - std::nullopt, // no controls - OptCtrls(std::in_place, Ctrls()), - OptCtrls(std::in_place, Ctrls({{"algorithm", "tpl"}})), - OptCtrls(std::in_place, Ctrls({{"algorithm", "v4.1"}}))}; + std::vector ctrls = {OptCtrls(), // no controls + OptCtrls(Ctrls()), // empty controls + OptCtrls(Ctrls({{"algorithm", "tpl"}})), + OptCtrls(Ctrls({{"algorithm", "v4.1"}}))}; if constexpr (KokkosKernels::Impl::kk_is_gpu_exec_space()) { #if defined(KOKKOS_ENABLE_CUDA) if constexpr (std::is_same_v) { #if defined(KOKKOS_ARCH_AMPERE) || defined(KOKKOS_ARCH_VOLTA) - ctrls.push_back(Ctrls({{"algorithm", "experimental_tc"}})); + ctrls.push_back(OptCtrls(Ctrls({{"algorithm", "experimental_tc"}}))); #if defined(KOKKOS_ARCH_AMPERE) - ctrls.push_back(Ctrls( - {{"algorithm", "experimental_tc"}, {"tc_precision", "double"}})); + ctrls.push_back(OptCtrls(Ctrls( + {{"algorithm", "experimental_tc"}, {"tc_precision", "double"}}))); #endif // AMPERE #endif // AMPERE || VOLTA } @@ -481,10 +501,9 @@ void test_spmv() { // it's for A. template -void test_spm_mv( - const std::optional &controls, - const char *mode, const Alpha &alpha, const Beta &beta, const Bsr &a, - const Crs &acrs, size_t maxNnzPerRow, const XVector &x, const YVector &y) { +void test_spm_mv(const OptCtrls &controls, const char *mode, const Alpha &alpha, + const Beta &beta, const Bsr &a, const Crs &acrs, + size_t maxNnzPerRow, const XVector &x, const YVector &y) { using scalar_type = typename Bsr::non_const_value_type; using ordinal_type = typename Bsr::non_const_ordinal_type; using KATS = Kokkos::ArithTraits; @@ -607,21 +626,19 @@ void test_spm_mv_combos(const char *mode, const Bsr &a, const Crs &acrs, // cover a variety of controls using Ctrls = KokkosKernels::Experimental::Controls; - using OptCtrls = std::optional; - std::vector ctrls = { - std::nullopt, // no controls - OptCtrls(std::in_place, Ctrls()), - OptCtrls(std::in_place, Ctrls({{"algorithm", "tpl"}})), - OptCtrls(std::in_place, Ctrls({{"algorithm", "v4.1"}}))}; + std::vector ctrls = {OptCtrls(), // no controls + OptCtrls(Ctrls()), // empty controls + OptCtrls(Ctrls({{"algorithm", "tpl"}})), + OptCtrls(Ctrls({{"algorithm", "v4.1"}}))}; if constexpr (KokkosKernels::Impl::kk_is_gpu_exec_space()) { #if defined(KOKKOS_ENABLE_CUDA) if constexpr (std::is_same_v) { #if defined(KOKKOS_ARCH_AMPERE) || defined(KOKKOS_ARCH_VOLTA) - ctrls.push_back(Ctrls({{"algorithm", "experimental_tc"}})); + ctrls.push_back(OptCtrls(Ctrls({{"algorithm", "experimental_tc"}}))); #if defined(KOKKOS_ARCH_AMPERE) - ctrls.push_back(Ctrls( - {{"algorithm", "experimental_tc"}, {"tc_precision", "double"}})); + ctrls.push_back(OptCtrls(Ctrls( + {{"algorithm", "experimental_tc"}, {"tc_precision", "double"}}))); #endif // AMPERE #endif // AMPERE || VOLTA }