kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
test_RecorderListener.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
7
12
15
24
25using execution_space = Kokkos::DefaultExecutionSpace;
26
28{
29
30using namespace Kokkos::utils::callbacks;
31
34
36{
37public:
38 void SetUp() override {
39 this->exec = Kokkos::Experimental::partition_space(execution_space{}, 1)[0];
40 }
41
42protected:
44};
45
48{
50 static_assert(std::same_as<
53 >);
54
55 static_assert(Listener<event_in_profile_section_recorder_t>);
56}
57
58template <Event EvenType>
60
62
65{
66 using recorder_listener_t = RecorderListener<TypeParam>;
67 static_assert(std::same_as<typename recorder_listener_t::event_type_list_t, Kokkos::Impl::type_list<TypeParam>>);
68 static_assert(std::same_as<typename recorder_listener_t::matcher_t, AnyEventMatcher>);
69
70 const auto recorder = std::make_shared<recorder_listener_t>();
71
73 Manager::unregister_listener(recorder.get());
74
75 ASSERT_EQ(recorder->recorded_events.size(), 0);
76}
77
80{
81 EventInProfileSectionRegexMatcher matcher(std::regex("profile section"));
82 const auto recorder = std::make_shared<event_in_profile_section_recorder_t>(std::move(matcher));
83
84 const auto any_event_recorder = std::make_shared<RecorderListener<EventTypeList>>();
85
87 Manager::register_listener(any_event_recorder);
88
90
92 ASSERT_THAT(
93 recorder->recorded_events,
94 ::testing::Contains(ABeginParallelForEventWithName(::testing::StrEq("computation - level 0 - pfor")))
95 );
96
97 ASSERT_THAT(
98 recorder->recorded_events,
99 ContainsInOrder<typename decltype(recorder->recorded_events)::value_type>(
100 APushRegionEventWithName(::testing::StrEq("computation - level 0")),
101 ABeginParallelForEventWithName(::testing::StrEq("computation - level 0 - pfor")),
103 ABeginFenceEventWithName(::testing::StrEq("computation - level 0 - fence after pfor")),
105 AProfileEventWithName(::testing::StrEq("buried marker")),
106 APushRegionEventWithName(::testing::StrEq("computation - level 1")),
107 ABeginParallelReduceEventWithName(::testing::StrEq("computation - level 1 - preduce on default exec")),
109 ABeginFenceEventWithName(::testing::StrEq("Kokkos::parallel_reduce: fence due to result being value, not view")),
113 )
114 );
115
116 ASSERT_GT(any_event_recorder->recorded_events.size(), recorder->recorded_events.size());
117
118 const auto fence_event_outside_profile_section = ABeginFenceEventWithName(::testing::StrEq("other fence after stopping the profile section"));
119
120 ASSERT_THAT(
121 recorder->recorded_events,
122 ::testing::Not(::testing::Contains(fence_event_outside_profile_section))
123 );
124
125 ASSERT_THAT(
126 any_event_recorder->recorded_events,
127 ::testing::Contains(fence_event_outside_profile_section)
128 );
129
130 const auto output = [&recorder] () -> std::string {
131 std::ostringstream oss;
132 recorder->report(oss);
133 return oss.str();
134 }();
135
136 ASSERT_THAT(output, ::testing::HasSubstr("computation - level 0 - pfor"));
137 ASSERT_THAT(output, ::testing::HasSubstr("computation - level 0 - fence after pfor"));
138
139 Manager::unregister_listener(recorder.get());
140 Manager::unregister_listener(any_event_recorder.get());
141}
142
145{
146 ASSERT_THAT(
148 ::testing::Contains(
150 ::testing::Field(&BeginParallelForEvent::name, ::testing::StrEq("computation - level 0 - pfor")),
151 ::testing::Field(&BeginParallelForEvent::dev_id, ::testing::Eq(Kokkos::Tools::Experimental::device_id(this->exec)))
152 )
153 )
154 );
155
157 ASSERT_THAT(
159 ::testing::Contains(
161 ::testing::FieldsAre(::testing::StrEq("computation - level 0 - pfor"), ::testing::Eq(Kokkos::Tools::Experimental::device_id(this->exec)), ::testing::_)
162 )
163 )
164 );
165}
166
169
171TEST(FenceFinder, traits)
172{
174 static_assert(std::same_as<
176 Kokkos::Impl::type_list<BeginFenceEvent>
177 >);
178
179 static_assert(Listener<fence_finder_t>);
180}
181
183TEST_F_WITH_CB_MGR(FenceFinderTest, recorded_events)
184{
185 const auto exec = Kokkos::Experimental::partition_space(execution_space{}, 1)[0];
186
187 const auto fence_finder = std::make_shared<fence_finder_t>(EventRegexMatcher(std::regex("computation - level 0 - fence after pfor")));
188
189 Manager::register_listener(fence_finder);
190
192
194 ASSERT_THAT(
195 fence_finder->recorded_events,
196 ::testing::Contains(
198 ::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("computation - level 0 - fence after pfor")),
199 ::testing::Field(&BeginFenceEvent::dev_id, ::testing::Eq(Kokkos::Tools::Experimental::device_id(exec)))
200 )
201 )
202 );
203
204 Manager::unregister_listener(fence_finder.get());
205}
206
207} // namespace Kokkos::utils::tests::callbacks
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
#define TEST_F_WITH_CB_MGR(__test_fixture_name__, __test_name__)
Definition Helpers.hpp:18
auto APopRegionEvent(Matchers &&... matchers)
Definition Helpers.hpp:48
auto AEndParallelReduceEvent(Matchers &&... matchers)
Definition Helpers.hpp:36
auto ABeginParallelForEvent(Matchers &&... matchers)
Definition Helpers.hpp:33
auto ABeginParallelForEventWithName(Matcher &&matcher)
Definition Helpers.hpp:59
Kokkos::Impl::filter_type_list_t< impl::IsListenerFor< Callable >::template type, EventTypeList > listener_event_type_list_t
Type list holding the event types that a callable object can be a listener for.
Definition Listener.hpp:24
auto APushRegionEventWithName(Matcher &&matcher)
Definition Helpers.hpp:64
auto AEndFenceEvent(Matchers &&... matchers)
Definition Helpers.hpp:40
auto ABeginParallelReduceEventWithName(Matcher &&matcher)
Definition Helpers.hpp:60
Kokkos::Impl::type_list< BeginParallelForEvent, EndParallelForEvent, BeginParallelReduceEvent, EndParallelReduceEvent, BeginParallelScanEvent, EndParallelScanEvent, BeginFenceEvent, EndFenceEvent, AllocateDataEvent, DeallocateDataEvent, BeginDeepCopyEvent, EndDeepCopyEvent, CreateProfileSectionEvent, DestroyProfileSectionEvent, StartProfileSectionEvent, StopProfileSectionEvent, PushRegionEvent, PopRegionEvent, ProfileEvent > EventTypeList
Type list holding all event types.
Definition Events.hpp:152
auto AProfileEventWithName(Matcher &&matcher)
Definition Helpers.hpp:65
auto ABeginFenceEventWithName(Matcher &&matcher)
Definition Helpers.hpp:62
auto ABeginFenceEvent(Matchers &&... matchers)
Definition Helpers.hpp:39
auto ContainsInOrder(Matchers &&... matchers)
Definition Helpers.hpp:142
auto AEndParallelForEvent(Matchers &&... matchers)
Definition Helpers.hpp:34
typename impl::EventTestTypes< Kokkos::utils::callbacks::EventTypeList >::type EventTestTypes
Useful type for defining a typed test suite over all types in Kokkos::utils::callbacks::EventTypeList...
Definition Helpers.hpp:21
TYPED_TEST_SUITE(EventTest, EventTestTypes)
TEST_F(ManagerTest, dispatch_to_call_operators_of_single_listener)
RecorderListener< EventInProfileSectionRegexMatcher, EventTypeList > event_in_profile_section_recorder_t
Listener to record events that occur in a profile section.
RecorderListener< EventRegexMatcher, BeginFenceEvent > fence_finder_t
Listener to record fence events.
TEST(EventTest, BeginEvent)
Matcher to select events that occur within a profile section.
Matcher to select events whose name matches a regular expression.
Kokkos::DefaultExecutionSpace execution_space