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
13
16
25
26using execution_space = Kokkos::DefaultExecutionSpace;
27
29{
30
31using namespace Kokkos::utils::callbacks;
32
35
36class RecorderListenerTest : public ::testing::Test,
38 public scoped::ExecutionSpace<execution_space>
39{};
40
43{
45 static_assert(std::same_as<
48 >);
49
50 static_assert(Listener <event_in_profile_section_recorder_t>);
51 static_assert(ListenerFor<event_in_profile_section_recorder_t, EventTypeList>);
52 static_assert(ListenerFor<event_in_profile_section_recorder_t, PushRegionEvent, PopRegionEvent>);
53}
54
55template <Event EvenType>
56class RecorderListenerSingleEventTypeTest : public ::testing::Test,
58
60
63{
64 using recorder_listener_t = RecorderListener<TypeParam>;
65 static_assert(std::same_as<typename recorder_listener_t::event_type_list_t, Kokkos::Impl::type_list<TypeParam>>);
66 static_assert(std::same_as<typename recorder_listener_t::matcher_t, AnyEventMatcher>);
67
68 const auto recorder = std::make_shared<recorder_listener_t>();
69
71 Manager::unregister_listener(recorder.get());
72
73 ASSERT_EQ(recorder->recorded_events.size(), 0);
74}
75
78{
79 EventInProfileSectionMatcher matcher{.matcher = EventRegexMatcher{.regex = std::regex("profile section")}};
80 const auto recorder = std::make_shared<event_in_profile_section_recorder_t>(std::move(matcher));
81
82 const auto any_event_recorder = std::make_shared<RecorderListener<EventTypeList>>();
83
86
88
90 ASSERT_THAT(
91 recorder->recorded_events,
92 ::testing::Contains(ABeginParallelForEventWithName(::testing::StrEq("computation - level 0 - pfor")))
93 );
94
95 ASSERT_THAT(
96 recorder->recorded_events,
97 ContainsInOrder<typename decltype(recorder->recorded_events)::value_type>(
98 APushRegionEventWithName(::testing::StrEq("computation - level 0")),
99 ABeginParallelForEventWithName(::testing::StrEq("computation - level 0 - pfor")),
101 ABeginFenceEventWithName(::testing::StrEq("computation - level 0 - fence after pfor")),
103 AProfileEventWithName(::testing::StrEq("buried marker")),
104 APushRegionEventWithName(::testing::StrEq("computation - level 1")),
105 ABeginParallelReduceEventWithName(::testing::StrEq("computation - level 1 - preduce on default exec")),
107 ABeginFenceEventWithName(::testing::StrEq("Kokkos::parallel_reduce: fence due to result being value, not view")),
111 )
112 );
113
114 ASSERT_GT(any_event_recorder->recorded_events.size(), recorder->recorded_events.size());
115
116 const auto fence_event_outside_profile_section = ABeginFenceEventWithName(::testing::StrEq("other fence after stopping the profile section"));
117
118 ASSERT_THAT(
119 recorder->recorded_events,
120 ::testing::Not(::testing::Contains(fence_event_outside_profile_section))
121 );
122
123 ASSERT_THAT(
124 any_event_recorder->recorded_events,
125 ::testing::Contains(fence_event_outside_profile_section)
126 );
127
128 const auto output = [&recorder] () -> std::string {
129 std::ostringstream oss;
130 recorder->report(oss);
131 return oss.str();
132 }();
133
134 ASSERT_THAT(output, ::testing::HasSubstr("computation - level 0 - pfor"));
135 ASSERT_THAT(output, ::testing::HasSubstr("computation - level 0 - fence after pfor"));
136
139}
140
143{
144 ASSERT_THAT(
146 ::testing::Contains(
148 ::testing::Field(&BeginParallelForEvent::name, ::testing::StrEq("computation - level 0 - pfor")),
149 ::testing::Field(&BeginParallelForEvent::dev_id, ::testing::Eq(Kokkos::Tools::Experimental::device_id(this->exec)))
150 )
151 )
152 );
153
155 ASSERT_THAT(
157 ::testing::Contains(
159 ::testing::FieldsAre(::testing::StrEq("computation - level 0 - pfor"), ::testing::Eq(Kokkos::Tools::Experimental::device_id(this->exec)), ::testing::_)
160 )
161 )
162 );
163}
164
167
169TEST(FenceFinder, traits)
170{
172 static_assert(std::same_as<
174 Kokkos::Impl::type_list<BeginFenceEvent>
175 >);
176
177 static_assert(Listener<fence_finder_t>);
178}
179
181TEST_F_WITH_CB_MGR(FenceFinderTest, recorded_events)
182{
183 const auto exec = Kokkos::Experimental::partition_space(execution_space{}, 1)[0];
184
185 const auto fence_finder = std::make_shared<fence_finder_t>(EventRegexMatcher(std::regex("computation - level 0 - fence after pfor")));
186
188
190
192 ASSERT_THAT(
193 fence_finder->recorded_events,
194 ::testing::Contains(
196 ::testing::Field(&BeginFenceEvent::name, ::testing::StrEq("computation - level 0 - fence after pfor")),
197 ::testing::Field(&BeginFenceEvent::dev_id, ::testing::Eq(Kokkos::Tools::Experimental::device_id(exec)))
198 )
199 )
200 );
201
203}
204
205} // 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:11
auto APopRegionEvent(Matchers &&... matchers)
Definition Helpers.hpp:42
auto AEndParallelReduceEvent(Matchers &&... matchers)
Definition Helpers.hpp:30
auto ABeginParallelForEvent(Matchers &&... matchers)
Definition Helpers.hpp:27
auto ABeginParallelForEventWithName(Matcher &&matcher)
Definition Helpers.hpp:53
Kokkos::Impl::filter_type_list_t< impl::IsListenerFor< Callable >::template type, EventTypeList > listener_event_type_list_t
Type list holding the event types that Callable can be a listener for.
Definition Listener.hpp:39
auto APushRegionEventWithName(Matcher &&matcher)
Definition Helpers.hpp:58
auto AEndFenceEvent(Matchers &&... matchers)
Definition Helpers.hpp:34
auto ABeginParallelReduceEventWithName(Matcher &&matcher)
Definition Helpers.hpp:54
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:199
auto AProfileEventWithName(Matcher &&matcher)
Definition Helpers.hpp:59
auto ABeginFenceEventWithName(Matcher &&matcher)
Definition Helpers.hpp:56
auto ABeginFenceEvent(Matchers &&... matchers)
Definition Helpers.hpp:33
auto ContainsInOrder(Matchers &&... matchers)
Definition Helpers.hpp:136
auto AEndParallelForEvent(Matchers &&... matchers)
Definition Helpers.hpp:28
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
TEST_F(EnqueuedEventTimerTest, duration)
TYPED_TEST(TimerTest, start_aborts_for_wrongly_enqueued_event)
RecorderListener< EventInProfileSectionMatcher< EventRegexMatcher >, EventTypeList > event_in_profile_section_recorder_t
Listener to record events that occur in a profile section.
TYPED_TEST_SUITE(TimerTest, TimerTypes)
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.
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