kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
test_SequenceOfRegionTimerListener.cpp
Go to the documentation of this file.
1#include "gmock/gmock.h"
2
3#include "Kokkos_Core.hpp"
4
7
9
20
22{
23
24using namespace Kokkos::utils::callbacks;
25
26class SequenceOfRegionTimerListenerTest : public ::testing::Test,
28{};
29
35{
36 using event_matcher_t = EventNameMatcher;
38 using region_timer_t = typename sequence_t::region_timer_t;
39 using region_matcher_t = typename region_timer_t::matcher_t;
41
42 constexpr unit_t sleep_for{500.};
43
44 const auto seq = std::make_shared<sequence_t>(
45 region_matcher_t{{{"region A"}}},
46 region_matcher_t{{{"region B"}}},
47 region_matcher_t{{{"region C"}}}
48 );
49
51
52 for(unsigned short int irep = 0; irep < 3; ++irep)
53 {
54 #define DO_A_REGION(_name_) \
55 Kokkos::Timer region_##_name_##_outer; \
56 region_##_name_##_outer.reset(); \
57 Kokkos::Profiling::pushRegion("region " #_name_); \
58 std::this_thread::sleep_for(sleep_for); \
59 Kokkos::Profiling::popRegion(); \
60 const auto region_##_name_##_elapsed = region_##_name_##_outer.seconds();
61
65
66 #undef DO_A_REGION
67
68 #define CHECK_TIMER(_index_, _name_) \
69 { \
70 auto& timer = seq->timers.at(_index_); \
71 const auto duration = timer.template duration<unit_t>(); \
72 ASSERT_GT(duration, sleep_for) << #_name_; \
73 ASSERT_LT(duration, Kokkos::utils::timer::seconds{region_##_name_##_elapsed}); \
74 }
75
76 CHECK_TIMER(0, A)
77 CHECK_TIMER(1, B)
78 CHECK_TIMER(2, C)
79
80 #undef CHECK_TIMER
81
82 seq->reset();
83 }
84
86}
87
88} // 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
RegionTimerListener< EventRegexMatcher > region_timer_t
Listener to time regions whose name matches a regex.
TEST_F(EnqueuedEventTimerTest, duration)
std::chrono::duration< double, std::nano > nanoseconds
Definition Duration.hpp:12
Matcher to select events whose name matches name.
EventTypeMatcher< region_matcher_t, PushRegionEvent, PopRegionEvent > matcher_t
Initializing and finalizing Kokkos::utils::callbacks::Manager in a RAII manner.
Definition Manager.hpp:10
#define CHECK_TIMER(_index_, _name_)
#define DO_A_REGION(_name_)