kokkos-utils
0.0.5
Toggle main menu visibility
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
5
#include "
kokkos-utils/callbacks/EventNameMatcher.hpp
"
6
#include "
kokkos-utils/callbacks/SequenceOfRegionTimerListener.hpp
"
7
8
#include "
kokkos-utils/tests/scoped/callbacks/Manager.hpp
"
9
20
21
namespace
Kokkos::utils::tests::callbacks
22
{
23
24
using namespace
Kokkos::utils::callbacks;
25
26
class
SequenceOfRegionTimerListenerTest
:
public
::testing::Test,
27
public
scoped::callbacks::Manager
28
{};
29
34
TEST_F
(
SequenceOfRegionTimerListenerTest
, reset)
35
{
36
using
event_matcher_t =
EventNameMatcher
;
37
using
sequence_t =
SequenceOfRegionTimerListener<event_matcher_t>
;
38
using
region_timer_t
=
typename
sequence_t::region_timer_t;
39
using
region_matcher_t =
typename
region_timer_t::matcher_t
;
40
using
unit_t =
Kokkos::utils::timer::nanoseconds
;
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
50
Kokkos::utils::callbacks::Manager::register_listener
(seq);
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
62
DO_A_REGION
(A)
63
DO_A_REGION
(B)
64
DO_A_REGION
(C)
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
85
Kokkos::utils::callbacks::Manager::unregister_listener
(seq.get());
86
}
87
88
}
// namespace Kokkos::utils::tests::callbacks
EventNameMatcher.hpp
SequenceOfRegionTimerListener.hpp
Kokkos::utils::callbacks::Manager::unregister_listener
static void unregister_listener(const Callable *const callable)
Unregister a callable object as a listener.
Definition
Manager.hpp:197
Kokkos::utils::callbacks::Manager::register_listener
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
Kokkos::utils::tests::callbacks::SequenceOfRegionTimerListenerTest
Definition
test_SequenceOfRegionTimerListener.cpp:28
Kokkos::utils::tests::callbacks
Definition
Helpers.hpp:7
Kokkos::utils::tests::callbacks::region_timer_t
RegionTimerListener< EventRegexMatcher > region_timer_t
Listener to time regions whose name matches a regex.
Definition
test_TimerListener.cpp:178
Kokkos::utils::tests::callbacks::TEST_F
TEST_F(EnqueuedEventTimerTest, duration)
Definition
test_EnqueuedEventTimer.cpp:47
Kokkos::utils::timer::nanoseconds
std::chrono::duration< double, std::nano > nanoseconds
Definition
Duration.hpp:12
Kokkos::utils::callbacks::EventNameMatcher
Matcher to select events whose name matches name.
Definition
EventNameMatcher.hpp:11
Kokkos::utils::callbacks::RegionTimerListener< EventRegexMatcher >::matcher_t
EventTypeMatcher< region_matcher_t, PushRegionEvent, PopRegionEvent > matcher_t
Definition
RegionTimerListener.hpp:28
Kokkos::utils::callbacks::SequenceOfRegionTimerListener
Time a sequence of push/pop regions.
Definition
SequenceOfRegionTimerListener.hpp:19
Kokkos::utils::tests::scoped::callbacks::Manager
Initializing and finalizing Kokkos::utils::callbacks::Manager in a RAII manner.
Definition
Manager.hpp:10
CHECK_TIMER
#define CHECK_TIMER(_index_, _name_)
DO_A_REGION
#define DO_A_REGION(_name_)
Manager.hpp
tests
callbacks
test_SequenceOfRegionTimerListener.cpp
Generated on
for kokkos-utils by
1.18.0