kokkos-utils
0.0.5
Toggle main menu visibility
Loading...
Searching...
No Matches
TimerListener.hpp
Go to the documentation of this file.
1
#ifndef KOKKOS_UTILS_CALLBACKS_TIMERLISTENER_HPP
2
#define KOKKOS_UTILS_CALLBACKS_TIMERLISTENER_HPP
3
4
#include "
kokkos-utils/callbacks/Listener.hpp
"
5
#include "
kokkos-utils/callbacks/Matcher.hpp
"
6
7
namespace
Kokkos::utils::callbacks
8
{
9
10
template
<
typename
TimerType>
11
concept
Startable
=
requires
(TimerType&
timer
) {
12
{
timer
.start() } -> std::same_as<void>;
13
};
14
15
template
<
typename
TimerType,
typename
EventType>
16
concept
StartableWithEvent
=
requires
(TimerType&
timer
,
const
EventType& event) {
17
{
timer
.start(event) } -> std::same_as<void>;
18
};
19
20
template
<
typename
TimerType>
21
concept
Stoppable
=
requires
(TimerType&
timer
) {
22
{
timer
.stop() } -> std::same_as<void>;
23
};
24
25
template
<
typename
TimerType,
typename
EventType>
26
concept
StoppableWithEvent
=
requires
(TimerType&
timer
,
const
EventType& event) {
27
{
timer
.stop(event) } -> std::same_as<void>;
28
};
29
41
template
<
42
Matcher
BeginEndMatcherType,
43
typename
TimerType
44
>
45
struct
TimerListener
46
{
47
template
<Event EventType>
requires
MatcherFor<BeginEndMatcherType, EventType>
48
void
operator()
(
const
EventType& event)
49
{
50
if
(
closed
())
return
;
51
52
const
bool
matching =
matcher
(event);
53
55
if
(!this->
matched_begin
&& matching)
56
{
57
this->
matched_begin
=
true
;
58
59
if
constexpr
(
Startable<TimerType>
) {
60
this->timer.start();
61
}
else
if
constexpr
(
StartableWithEvent<TimerType, EventType>
) {
62
this->timer.start(event);
63
}
64
}
66
else
if
(this->
matched_begin
&& ! this->
matched_end
&& matching)
67
{
68
this->
matched_end
=
true
;
69
70
if
constexpr
(
Stoppable<TimerType>
) {
71
this->timer.stop();
72
}
else
if
constexpr
(
StoppableWithEvent<TimerType, EventType>
) {
73
this->timer.stop(event);
74
}
75
}
76
}
77
79
bool
connected
()
const
{
return
matched_begin
&& !
matched_end
; }
80
82
bool
closed
()
const
{
return
matched_begin
&&
matched_end
; }
83
85
void
reset
() {
86
matched_begin
=
matched_end
=
false
;
87
}
88
89
BeginEndMatcherType
matcher
{};
90
TimerType
timer
{};
91
bool
matched_begin
=
false
;
92
bool
matched_end
=
false
;
93
};
94
95
}
// namespace Kokkos::utils::callbacks
96
97
#endif
// KOKKOS_UTILS_CALLBACKS_TIMERLISTENER_HPP
Listener.hpp
Matcher.hpp
Kokkos::utils::callbacks::MatcherFor
Check that Callable is a matcher for each event in EventTypes.
Definition
Matcher.hpp:35
Kokkos::utils::callbacks::Matcher
Callable is a matcher if it is invocable with at least one event type from Kokkos::utils::callbacks::...
Definition
Matcher.hpp:31
Kokkos::utils::callbacks::StartableWithEvent
Definition
TimerListener.hpp:16
Kokkos::utils::callbacks::Startable
Definition
TimerListener.hpp:11
Kokkos::utils::callbacks::StoppableWithEvent
Definition
TimerListener.hpp:26
Kokkos::utils::callbacks::Stoppable
Definition
TimerListener.hpp:21
Kokkos::utils::callbacks
Definition
BeginEndTimerListener.hpp:12
Kokkos::utils::timer
Definition
Duration.hpp:7
Kokkos::utils::callbacks::TimerListener
Listener that starts a timer when a begin event is received and stops it when a corresponding end eve...
Definition
TimerListener.hpp:46
Kokkos::utils::callbacks::TimerListener::reset
void reset()
Reset the listener so that it can be reused to match a begin event again.
Definition
TimerListener.hpp:85
Kokkos::utils::callbacks::TimerListener< matcher_t, timer_t >::matched_begin
bool matched_begin
Definition
TimerListener.hpp:91
Kokkos::utils::callbacks::TimerListener< matcher_t, timer_t >::matched_end
bool matched_end
Definition
TimerListener.hpp:92
Kokkos::utils::callbacks::TimerListener< matcher_t, timer_t >::timer
timer_t timer
Definition
TimerListener.hpp:90
Kokkos::utils::callbacks::TimerListener::operator()
void operator()(const EventType &event)
Definition
TimerListener.hpp:48
Kokkos::utils::callbacks::TimerListener< matcher_t, timer_t >::closed
bool closed() const
Definition
TimerListener.hpp:82
Kokkos::utils::callbacks::TimerListener::connected
bool connected() const
When the listener has matched the begin, but not yet the end event, it is said to be "connected".
Definition
TimerListener.hpp:79
Kokkos::utils::callbacks::TimerListener< matcher_t, timer_t >::matcher
BeginEndMatcherType matcher
Definition
TimerListener.hpp:89
include
kokkos-utils
callbacks
TimerListener.hpp
Generated on
for kokkos-utils by
1.18.0