LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
accumulating_timer.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
25 //
26 // lbann_timer .hpp - Wrapper around time functionality
28 
29 #ifndef LBANN_UTILS_ACCUMULATING_TIMER_INCLUDED
30 #define LBANN_UTILS_ACCUMULATING_TIMER_INCLUDED
31 
33 #include "lbann/utils/timer.hpp"
34 
35 namespace lbann {
36 
42 {
43 public:
45 
51  void start() noexcept;
52 
62  double stop() noexcept;
63 
67  double check() const noexcept;
68 
72  void reset() noexcept;
73 
75  bool running() const noexcept;
76 
78 
79 
82  size_t samples() const noexcept;
83 
85  double mean() const noexcept;
86 
88  double stddev() const noexcept;
89 
91  double min() const noexcept;
92 
94  double max() const noexcept;
95 
102  double total_time() const noexcept;
103 
105  void reset_statistics() noexcept;
106 
108 private:
111 }; // class AccumulatingTimer
112 
113 inline void AccumulatingTimer::start() noexcept { m_timer.start(); }
114 
115 inline double AccumulatingTimer::stop() noexcept
116 {
117  if (running()) {
118  auto elapsed_time = m_timer.stop();
119  m_stats.insert(elapsed_time);
120  return elapsed_time;
121  }
122  return 0.;
123 }
124 
125 inline double AccumulatingTimer::check() const noexcept
126 {
127  return m_timer.check();
128 }
129 
130 inline void AccumulatingTimer::reset() noexcept { m_timer.reset(); }
131 
132 inline bool AccumulatingTimer::running() const noexcept
133 {
134  return m_timer.running();
135 }
136 
137 inline size_t AccumulatingTimer::samples() const noexcept
138 {
139  return m_stats.samples();
140 }
141 
142 inline double AccumulatingTimer::mean() const noexcept
143 {
144  return m_stats.mean();
145 }
146 
147 inline double AccumulatingTimer::stddev() const noexcept
148 {
149  return m_stats.stddev();
150 }
151 
152 inline double AccumulatingTimer::min() const noexcept
153 {
154  return m_stats.samples() ? m_stats.min() : 0.;
155 }
156 
157 inline double AccumulatingTimer::max() const noexcept
158 {
159  return m_stats.samples() ? m_stats.max() : 0.;
160 }
161 
162 inline double AccumulatingTimer::total_time() const noexcept
163 {
164  return m_stats.total();
165 }
166 
167 inline void AccumulatingTimer::reset_statistics() noexcept { m_stats.reset(); }
168 
169 } // namespace lbann
170 #endif // LBANN_UTILS_ACCUMULATING_TIMER_INCLUDED
void reset() noexcept
All values return to their defaults.
Timer that accumulates mean and variance of timer durations as it goes.
void reset_statistics() noexcept
Clear the running history of durations.
void reset() noexcept
Clear any internal state in the timer.
double mean() const noexcept
Running mean of observed samples.
double total_time() const noexcept
The total time observed by this timer.
double max() const noexcept
The largest observed duration.
double check() const noexcept
Get the current elapsed time (seconds) without stopping.
Definition: utils/timer.hpp:97
double stop() noexcept
Get the elapsed time for this duration in seconds.
double min() const noexcept
Get the minimum observed value.
void start() noexcept
Start counting time for this duration sample.
bool running() const noexcept
Check if the timer is running.
double min() const noexcept
The smallest observed duration.
size_t samples() const noexcept
Number of observed samples.
double check() const noexcept
Get the current elapsed time in this duration (in seconds) without stopping the timer.
Accumulate mean, stddev, min, and max over a streaming data set.
double stddev() const noexcept
Running (unbiased) sample standard deviation of the observed samples.
void insert(double val) noexcept
Add a new value to the data set.
double stddev() const noexcept
The standard deviation of observed durations.
double mean() const noexcept
The mean observed duration.
bool running() const noexcept
Determine whether there is an active duration sample running.
size_t samples() const noexcept
The number of durations observed in this timer.
double total() const noexcept
Running sum of observed samples.
double max() const noexcept
Get the minimum observed value.
void reset() noexcept
Reset this duration without caching it in the running statistics.
An exceedingly simple duration calculator.
Definition: utils/timer.hpp:52
double stop() noexcept
Get the total elapsed time in seconds.
Definition: utils/timer.hpp:89
void start() noexcept
Start counting time.
Definition: utils/timer.hpp:80