kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
Timer.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_UTILS_TIMER_TIMER_HPP
2#define KOKKOS_UTILS_TIMER_TIMER_HPP
3
6
8{
15template <typename T>
16requires Kokkos::utils::concepts::ExecutionSpace<T> || std::is_void_v<T>
17class Timer
18{
19public:
21
22public:
24 bool is_valid() const { return tick.has_value() && tock.has_value(); }
25
32 template <typename Duration = milliseconds>
33 Duration duration() { return tick->template duration<Duration>(*tock); }
34
36 template <typename U = T>
37 requires std::is_void_v<U>
38 void start()
39 {
40 if(! tick.has_value()) tick.emplace();
41 tick->record();
42 }
43
44 template <typename Exec = T>
46 void start(const Exec& exec)
47 {
48 if(! tick.has_value()) tick.emplace();
49 tick->record(exec);
50 }
51
53 template <typename U = T>
54 requires std::is_void_v<U>
55 void stop()
56 {
57 if(! tock.has_value()) tock.emplace();
58 tock->record();
59 }
60
61 template <typename Exec = T>
63 void stop(const Exec& exec)
64 {
65 if(! tock.has_value()) tock.emplace();
66 tock->record(exec);
67 }
68
69private:
70 std::optional<event_t> tick = std::nullopt, tock = std::nullopt;
71};
72
73} // namespace Kokkos::utils::timer
74
75#endif // KOKKOS_UTILS_TIMER_TIMER_HPP
Measure elapsed time between events.
Definition Timer.hpp:18
void stop()
Stop the timer.
Definition Timer.hpp:55
bool is_valid() const
Returns true if start and stop have been called.
Definition Timer.hpp:24
void start(const Exec &exec)
Definition Timer.hpp:46
void start()
Start the timer.
Definition Timer.hpp:38
void stop(const Exec &exec)
Definition Timer.hpp:63
Specify that a type is a Kokkos execution space.