kokkos-utils 0.0.2
 
Loading...
Searching...
No Matches
test_Manager.cpp
Go to the documentation of this file.
1#include "gmock/gmock.h"
2#include "gtest/gtest.h"
3
4#include "Kokkos_Core.hpp"
5
10
12
21
22using execution_space = Kokkos::DefaultExecutionSpace;
23
25{
26
27using namespace Kokkos::utils::callbacks;
28
30constexpr bool test_singleton_traits()
31{
32 static_assert( ! std::is_copy_constructible_v<Manager>);
33 static_assert( ! std::is_copy_assignable_v <Manager>);
34
35 static_assert( ! std::is_move_constructible_v<Manager>);
36 static_assert( ! std::is_move_assignable_v <Manager>);
37
38 return true;
39}
40static_assert(test_singleton_traits());
41
46TEST(Manager, initialize_finalize)
47{
48 ASSERT_FALSE(Manager::is_initialized());
49
51 ASSERT_TRUE(Manager::is_initialized());
52
53 const auto* ptr = std::addressof(Manager::get_instance());
54
56 ASSERT_TRUE(Manager::is_initialized());
57
58 ASSERT_EQ(ptr, std::addressof(Manager::get_instance()));
59
61 ASSERT_TRUE(Manager::is_initialized());
62
63 ASSERT_EQ(ptr, std::addressof(Manager::get_instance()));
64
66 ASSERT_FALSE(Manager::is_initialized());
67
69 ASSERT_FALSE(Manager::is_initialized());
70
72 ASSERT_FALSE(Manager::is_initialized());
73}
74
75class ManagerTest : public ::testing::Test,
77 public scoped::ExecutionSpace<execution_space>
78{};
79
87template <Event... EventTypes>
89{
90 template <Kokkos::utils::impl::IsTypeOneOf<EventTypes...> EventType>
91 void operator()(const EventType& event) {
92 std::get<std::vector<EventType>>(events).push_back(event);
93 }
94
95 std::tuple<std::vector<EventTypes>...> events {};
96};
97
99TEST_F(ManagerTest, dispatch_to_call_operators_of_single_listener)
100{
101 const auto tester_listener = std::make_shared<TesterListener<BeginParallelForEvent, EndParallelForEvent, BeginFenceEvent>>();
102
104
106
108
109 const auto& [begin_parallel_for_events, end_parallel_for_events, begin_fence_events] = tester_listener->events;
110
112 ASSERT_EQ(begin_parallel_for_events.size(), 1);
113 ASSERT_EQ(begin_parallel_for_events[0].name, "computation - level 0 - pfor");
114
116 ASSERT_EQ(end_parallel_for_events.size(), 1);
117 ASSERT_EQ(begin_parallel_for_events[0].event_id, end_parallel_for_events[0].event_id);
118
120 ASSERT_GT(begin_fence_events.size(), 2);
121 ASSERT_THAT(
122 begin_fence_events,
123 ::testing::Contains(::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("computation - level 0 - fence after pfor")))
124 );
125 ASSERT_THAT(
126 begin_fence_events,
127 ::testing::Contains(::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("other fence after stopping the profile section")))
128 );
129}
130
132TEST_F(ManagerTest, dispatch_to_call_operators_of_multiple_listeners)
133{
134 const auto tester_listener_a = std::make_shared<TesterListener<BeginParallelForEvent>>();
135 const auto tester_listener_b = std::make_shared<TesterListener<BeginParallelForEvent, EndParallelForEvent>>();
136
139
141
144
145 const auto& [begin_parallel_for_events_listener_a] = tester_listener_a->events;
146 const auto& [begin_parallel_for_events_listener_b, end_parallel_for_events_listener_b] = tester_listener_b->events;
147
149 ASSERT_EQ(begin_parallel_for_events_listener_a.size(), 1);
150 ASSERT_EQ(begin_parallel_for_events_listener_a[0].name, "computation - level 0 - pfor");
151 ASSERT_EQ(begin_parallel_for_events_listener_b.size(), 1);
152 ASSERT_EQ(begin_parallel_for_events_listener_b[0].name, "computation - level 0 - pfor");
153
155 ASSERT_EQ(end_parallel_for_events_listener_b.size(), 1);
156 ASSERT_EQ(begin_parallel_for_events_listener_b[0].event_id, end_parallel_for_events_listener_b[0].event_id);
157}
158
160TEST_F(ManagerTest, listener_from_lambda)
161{
162 bool matched = false;
163
164 using view_t = Kokkos::View<int, execution_space>;
165
166 const view_t my_src_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, exec, "my rank-0 src view"));
167 const view_t my_dst_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, exec, "my rank-0 dst view"));
168
170 [&](const BeginDeepCopyEvent& event) {
171 if (event.dst.size == sizeof(int) && event.src.ptr == my_src_view.data()
172 && event.dst.ptr == my_dst_view.data()) matched = true;
173 }
174 );
175
176 Kokkos::deep_copy(exec, my_dst_view, my_src_view);
177
178 ASSERT_TRUE(matched);
179
181}
182
183} // namespace Kokkos::utils::tests::callbacks
Class to manage Kokkos profiling callback calls.
Definition Manager.hpp:140
static void unregister_listener(const Callable *const callable)
Unregister a callable object as a listener.
Definition Manager.hpp:196
static Manager & get_instance()
Definition Manager.hpp:165
static listener_list_const_iter_t register_listener(std::shared_ptr< Callable > callable)
Register a callable object, passed as a shared pointer, as a listener.
Definition Manager.hpp:173
Check if T is the same as one of the types Ts.
TEST_F(EnqueuedEventTimerTest, duration)
constexpr bool test_singleton_traits()
TEST(EventTest, BeginEvent)
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:129
Listener that stores the events it receives.
std::tuple< std::vector< EventTypes >... > events
Create a new execution space instance with RAII semantics.
Initializing and finalizing Kokkos::utils::callbacks::Manager in a RAII manner.
Definition Manager.hpp:10
Kokkos::DefaultExecutionSpace execution_space