kokkos-utils 0.0.4
 
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
80 ASSERT_FALSE(Manager::is_initialized());
81
83}
84
102
103class ManagerTest : public ::testing::Test,
105 public scoped::ExecutionSpace<execution_space>
106{};
107
115template <Event... EventTypes>
117{
118 template <Kokkos::utils::impl::IsTypeOneOf<EventTypes...> EventType>
119 void operator()(const EventType& event) {
120 std::get<std::vector<EventType>>(events).push_back(event);
121 }
122
123 std::tuple<std::vector<EventTypes>...> events {};
124};
125
127TEST_F(ManagerTest, dispatch_to_call_operators_of_single_listener)
128{
129 const auto tester_listener = std::make_shared<TesterListener<BeginParallelForEvent, EndParallelForEvent, BeginFenceEvent>>();
130
132
134
136
137 const auto& [begin_parallel_for_events, end_parallel_for_events, begin_fence_events] = tester_listener->events;
138
140 ASSERT_EQ(begin_parallel_for_events.size(), 1);
141 ASSERT_EQ(begin_parallel_for_events[0].name, "computation - level 0 - pfor");
142
144 ASSERT_EQ(end_parallel_for_events.size(), 1);
145 ASSERT_EQ(begin_parallel_for_events[0].event_id, end_parallel_for_events[0].event_id);
146
148 ASSERT_GT(begin_fence_events.size(), 2);
149 ASSERT_THAT(
150 begin_fence_events,
151 ::testing::Contains(::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("computation - level 0 - fence after pfor")))
152 );
153 ASSERT_THAT(
154 begin_fence_events,
155 ::testing::Contains(::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("other fence after stopping the profile section")))
156 );
157}
158
160TEST_F(ManagerTest, dispatch_to_call_operators_of_multiple_listeners)
161{
162 const auto tester_listener_a = std::make_shared<TesterListener<BeginParallelForEvent>>();
163 const auto tester_listener_b = std::make_shared<TesterListener<BeginParallelForEvent, EndParallelForEvent>>();
164
167
169
172
173 const auto& [begin_parallel_for_events_listener_a] = tester_listener_a->events;
174 const auto& [begin_parallel_for_events_listener_b, end_parallel_for_events_listener_b] = tester_listener_b->events;
175
177 ASSERT_EQ(begin_parallel_for_events_listener_a.size(), 1);
178 ASSERT_EQ(begin_parallel_for_events_listener_a[0].name, "computation - level 0 - pfor");
179 ASSERT_EQ(begin_parallel_for_events_listener_b.size(), 1);
180 ASSERT_EQ(begin_parallel_for_events_listener_b[0].name, "computation - level 0 - pfor");
181
183 ASSERT_EQ(end_parallel_for_events_listener_b.size(), 1);
184 ASSERT_EQ(begin_parallel_for_events_listener_b[0].event_id, end_parallel_for_events_listener_b[0].event_id);
185}
186
188TEST_F(ManagerTest, listener_from_lambda)
189{
190 bool matched = false;
191
192 using view_t = Kokkos::View<int, execution_space>;
193
194 const view_t my_src_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, exec, "my rank-0 src view"));
195 const view_t my_dst_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, exec, "my rank-0 dst view"));
196
198 [&](const BeginDeepCopyEvent& event) {
199 if (event.dst.size == sizeof(int) && event.src.ptr == my_src_view.data()
200 && event.dst.ptr == my_dst_view.data()) matched = true;
201 }
202 );
203
204 Kokkos::deep_copy(exec, my_dst_view, my_src_view);
205
206 ASSERT_TRUE(matched);
207
209}
210
211} // namespace Kokkos::utils::tests::callbacks
Class to manage Kokkos profiling callback calls.
Definition Manager.hpp:141
static void unregister_listener(const Callable *const callable)
Unregister a callable object as a listener.
Definition Manager.hpp:197
static Manager & get_instance()
Definition Manager.hpp:166
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:174
Check if T is the same as one of the types Ts.
auto get_next_event_id() noexcept
If the Manager is initialized, return Manager::get_next_event_id. Otherwise, return EventTraits::inva...
Definition Manager.hpp:492
void dispatch(const EventType &event)
If the Manager is initialized, call Manager::dispatch with event.
Definition Manager.hpp:486
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:136
static constexpr event_id_t invalid_event_id
Definition Events.hpp:17
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:198
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