kokkos-utils 0.0.1
 
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
29class ManagerTest : public ::testing::Test,
31 public scoped::ExecutionSpace<execution_space>
32{};
33
35TEST(Manager, singleton_traits)
36{
37 static_assert( ! std::is_copy_constructible_v<Manager>);
38 static_assert( ! std::is_copy_assignable_v <Manager>);
39
40 static_assert( ! std::is_move_constructible_v<Manager>);
41 static_assert( ! std::is_move_assignable_v <Manager>);
42}
43
51template <Event... EventTypes>
53{
54 template <Kokkos::utils::impl::IsTypeOneOf<EventTypes...> EventType>
55 void operator()(const EventType& event) {
56 std::get<std::vector<EventType>>(events).push_back(event);
57 }
58
59 std::tuple<std::vector<EventTypes>...> events {};
60};
61
63TEST_F(ManagerTest, dispatch_to_call_operators_of_single_listener)
64{
65 const auto tester_listener = std::make_shared<TesterListener<BeginParallelForEvent, EndParallelForEvent, BeginFenceEvent>>();
66
68
70
72
73 const auto& [begin_parallel_for_events, end_parallel_for_events, begin_fence_events] = tester_listener->events;
74
76 ASSERT_EQ(begin_parallel_for_events.size(), 1);
77 ASSERT_EQ(begin_parallel_for_events[0].name, "computation - level 0 - pfor");
78
80 ASSERT_EQ(end_parallel_for_events.size(), 1);
81 ASSERT_EQ(begin_parallel_for_events[0].event_id, end_parallel_for_events[0].event_id);
82
84 ASSERT_GT(begin_fence_events.size(), 2);
85 ASSERT_THAT(
86 begin_fence_events,
87 ::testing::Contains(::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("computation - level 0 - fence after pfor")))
88 );
89 ASSERT_THAT(
90 begin_fence_events,
91 ::testing::Contains(::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("other fence after stopping the profile section")))
92 );
93}
94
96TEST_F(ManagerTest, dispatch_to_call_operators_of_multiple_listeners)
97{
98 const auto tester_listener_a = std::make_shared<TesterListener<BeginParallelForEvent>>();
99 const auto tester_listener_b = std::make_shared<TesterListener<BeginParallelForEvent, EndParallelForEvent>>();
100
103
105
108
109 const auto& [begin_parallel_for_events_listener_a] = tester_listener_a->events;
110 const auto& [begin_parallel_for_events_listener_b, end_parallel_for_events_listener_b] = tester_listener_b->events;
111
113 ASSERT_EQ(begin_parallel_for_events_listener_a.size(), 1);
114 ASSERT_EQ(begin_parallel_for_events_listener_a[0].name, "computation - level 0 - pfor");
115 ASSERT_EQ(begin_parallel_for_events_listener_b.size(), 1);
116 ASSERT_EQ(begin_parallel_for_events_listener_b[0].name, "computation - level 0 - pfor");
117
119 ASSERT_EQ(end_parallel_for_events_listener_b.size(), 1);
120 ASSERT_EQ(begin_parallel_for_events_listener_b[0].event_id, end_parallel_for_events_listener_b[0].event_id);
121}
122
124TEST_F(ManagerTest, listener_from_lambda)
125{
126 bool matched = false;
127
128 using view_t = Kokkos::View<int, execution_space>;
129
130 const view_t my_src_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, exec, "my rank-0 src view"));
131 const view_t my_dst_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, exec, "my rank-0 dst view"));
132
134 [&](const BeginDeepCopyEvent& event) {
135 if (event.dst.size == sizeof(int) && event.src.ptr == my_src_view.data()
136 && event.dst.ptr == my_dst_view.data()) matched = true;
137 }
138 );
139
140 Kokkos::deep_copy(exec, my_dst_view, my_src_view);
141
142 ASSERT_TRUE(matched);
143
145}
146
147} // 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:194
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:171
Check if T is the same as one of the types Ts.
TEST_F(EnqueuedEventTimerTest, duration)
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