kokkos-utils
0.0.7
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_Macros.hpp"
4
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
5
import
kokkos.core;
6
#else
7
#include "Kokkos_Core.hpp"
8
#endif
9
10
#include "
kokkos-utils/callbacks/EventNameMatcher.hpp
"
11
#include "
kokkos-utils/callbacks/SequenceOfRegionTimerListener.hpp
"
12
13
#include "
kokkos-utils/tests/scoped/callbacks/Manager.hpp
"
14
25
26
namespace
Kokkos::utils::tests::callbacks
27
{
28
29
using namespace
Kokkos::utils::callbacks;
30
31
class
SequenceOfRegionTimerListenerTest
:
public
::testing::Test,
32
public
scoped::callbacks::Manager
33
{};
34
39
TEST_F
(
SequenceOfRegionTimerListenerTest
, reset)
40
{
41
using
event_matcher_t =
EventNameMatcher
;
42
using
sequence_t =
SequenceOfRegionTimerListener<event_matcher_t>
;
43
using
region_timer_t
=
typename
sequence_t::region_timer_t;
44
using
region_matcher_t =
typename
region_timer_t::matcher_t
;
45
using
unit_t =
Kokkos::utils::timer::nanoseconds
;
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
55
Kokkos::utils::callbacks::Manager::register_listener
(seq);
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
67
DO_A_REGION
(A)
68
DO_A_REGION
(B)
69
DO_A_REGION
(C)
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
90
Kokkos::utils::callbacks::Manager::unregister_listener
(seq.get());
91
}
92
93
}
// 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:33
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:183
Kokkos::utils::tests::callbacks::TEST_F
TEST_F(EnqueuedEventTimerTest, duration)
Definition
test_EnqueuedEventTimer.cpp:52
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