1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 3.0
6 // Copyright (2020) National Technology & Engineering
7 // Solutions of Sandia, LLC (NTESS).
8 //
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40 //
41 // ************************************************************************
42 //@HEADER
43 */
44
45 #ifndef TEST_FUNCTOR_ANALYSIS_HPP
46 #define TEST_FUNCTOR_ANALYSIS_HPP
47
48 #include <gtest/gtest.h>
49 #include <Kokkos_Core.hpp>
50
51 /*--------------------------------------------------------------------------*/
52
53 namespace Test {
54
55 struct TestFunctorAnalysis_03 {
56 struct value_type {
57 double x[2];
58 };
59
60 KOKKOS_INLINE_FUNCTION
operator ()Test::TestFunctorAnalysis_0361 void operator()(int, value_type&) const {}
62
63 KOKKOS_INLINE_FUNCTION
joinTest::TestFunctorAnalysis_0364 void join(value_type volatile&, value_type const volatile&) const {}
65
initTest::TestFunctorAnalysis_0366 KOKKOS_INLINE_FUNCTION static void init(value_type&) {}
67 };
68
69 template <class ExecSpace>
test_functor_analysis()70 void test_functor_analysis() {
71 //------------------------------
72 auto c01 = KOKKOS_LAMBDA(int){};
73 using A01 =
74 Kokkos::Impl::FunctorAnalysis<Kokkos::Impl::FunctorPatternInterface::FOR,
75 Kokkos::RangePolicy<ExecSpace>,
76 decltype(c01)>;
77
78 using R01 = typename A01::template Reducer<typename ExecSpace::memory_space>;
79
80 static_assert(std::is_same<typename A01::value_type, void>::value, "");
81 static_assert(std::is_same<typename A01::pointer_type, void>::value, "");
82 static_assert(std::is_same<typename A01::reference_type, void>::value, "");
83 static_assert(std::is_same<typename R01::functor_type, decltype(c01)>::value,
84 "");
85
86 static_assert(!A01::has_join_member_function, "");
87 static_assert(!A01::has_init_member_function, "");
88 static_assert(!A01::has_final_member_function, "");
89 static_assert(A01::StaticValueSize == 0, "");
90 ASSERT_EQ(R01(&c01).length(), 0);
91
92 //------------------------------
93 auto c02 = KOKKOS_LAMBDA(int, double&){};
94 using A02 = Kokkos::Impl::FunctorAnalysis<
95 Kokkos::Impl::FunctorPatternInterface::REDUCE,
96 Kokkos::RangePolicy<ExecSpace>, decltype(c02)>;
97 using R02 = typename A02::template Reducer<typename ExecSpace::memory_space>;
98
99 static_assert(std::is_same<typename A02::value_type, double>::value, "");
100 static_assert(std::is_same<typename A02::pointer_type, double*>::value, "");
101 static_assert(std::is_same<typename A02::reference_type, double&>::value, "");
102 static_assert(std::is_same<typename R02::functor_type, decltype(c02)>::value,
103 "");
104
105 static_assert(!A02::has_join_member_function, "");
106 static_assert(!A02::has_init_member_function, "");
107 static_assert(!A02::has_final_member_function, "");
108 static_assert(A02::StaticValueSize == sizeof(double), "");
109 ASSERT_EQ(R02(&c02).length(), 1);
110
111 //------------------------------
112
113 TestFunctorAnalysis_03 c03;
114 using A03 = Kokkos::Impl::FunctorAnalysis<
115 Kokkos::Impl::FunctorPatternInterface::REDUCE,
116 Kokkos::RangePolicy<ExecSpace>, TestFunctorAnalysis_03>;
117 using R03 = typename A03::template Reducer<typename ExecSpace::memory_space>;
118
119 static_assert(std::is_same<typename A03::value_type,
120 TestFunctorAnalysis_03::value_type>::value,
121 "");
122 static_assert(std::is_same<typename A03::pointer_type,
123 TestFunctorAnalysis_03::value_type*>::value,
124 "");
125 static_assert(std::is_same<typename A03::reference_type,
126 TestFunctorAnalysis_03::value_type&>::value,
127 "");
128 static_assert(
129 std::is_same<typename R03::functor_type, TestFunctorAnalysis_03>::value,
130 "");
131
132 static_assert(A03::has_join_member_function, "");
133 static_assert(A03::has_init_member_function, "");
134 static_assert(!A03::has_final_member_function, "");
135 static_assert(
136 A03::StaticValueSize == sizeof(TestFunctorAnalysis_03::value_type), "");
137 ASSERT_EQ(R03(&c03).length(), 1);
138
139 //------------------------------
140 }
141
TEST(TEST_CATEGORY,functor_analysis)142 TEST(TEST_CATEGORY, functor_analysis) {
143 test_functor_analysis<TEST_EXECSPACE>();
144 }
145
146 } // namespace Test
147
148 /*--------------------------------------------------------------------------*/
149
150 #endif /* #ifndef TEST_FUNCTOR_ANALYSIS_HPP */
151