kokkos-utils 0.0.7
Loading...
Searching...
No Matches
test_SequenceOfRegionTimerListener.cpp
Go to the documentation of this file.
1#include "gmock/gmock.h"
2
3#include "Kokkos_Macros.hpp"
4#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
5import kokkos.core;
6#else
7#include "Kokkos_Core.hpp"
8#endif
9
12
14
25
27{
28
29using namespace Kokkos::utils::callbacks;
30
31class SequenceOfRegionTimerListenerTest : public ::testing::Test,
33{};
34
40{
41 using event_matcher_t = EventNameMatcher;
43 using region_timer_t = typename sequence_t::region_timer_t;
44 using region_matcher_t = typename region_timer_t::matcher_t;
46
47 constexpr unit_t sleep_for{500.};
48
49 const auto seq = std::make_shared<sequence_t>(
50 region_matcher_t{{{"region A"}}},
51 region_matcher_t{{{"region B"}}},
52 region_matcher_t{{{"region C"}}}
53 );
54
56
57 for(unsigned short int irep = 0; irep < 3; ++irep)
58 {
59 #define DO_A_REGION(_name_) \
60 Kokkos::Timer region_##_name_##_outer; \
61 region_##_name_##_outer.reset(); \
62 Kokkos::Profiling::pushRegion("region " #_name_); \
63 std::this_thread::sleep_for(sleep_for); \
64 Kokkos::Profiling::popRegion(); \
65 const auto region_##_name_##_elapsed = region_##_name_##_outer.seconds();
66
70
71 #undef DO_A_REGION
72
73 #define CHECK_TIMER(_index_, _name_) \
74 { \
75 auto& timer = seq->timers.at(_index_); \
76 const auto duration = timer.template duration<unit_t>(); \
77 ASSERT_GT(duration, sleep_for) << #_name_; \
78 ASSERT_LT(duration, Kokkos::utils::timer::seconds{region_##_name_##_elapsed}); \
79 }
80
81 CHECK_TIMER(0, A)
82 CHECK_TIMER(1, B)
83 CHECK_TIMER(2, C)
84
85 #undef CHECK_TIMER
86
87 seq->reset();
88 }
89
91}
92
93} // namespace Kokkos::utils::tests::callbacks
static void unregister_listener(const Callable *const callable)
Unregister a callable object as a listener.
Definition Manager.hpp:197
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
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_)