LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
callbacks/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.
26 
27 #ifndef LBANN_CALLBACKS_CALLBACK_TIMER_HPP_INCLUDED
28 #define LBANN_CALLBACKS_CALLBACK_TIMER_HPP_INCLUDED
29 
31 
32 #include <chrono>
33 #include <map>
34 #include <vector>
35 
36 namespace lbann {
37 namespace callback {
38 
44 class timer : public callback_base
45 {
46 public:
47  timer(const std::shared_ptr<lbann_summary>& summarizer = nullptr)
48  : callback_base(1)
49  {}
50  timer(const timer&) = default;
51  timer& operator=(const timer&) = default;
52  timer* copy() const override { return new timer(*this); }
53 
55  void on_epoch_begin(model* m) override { timing_begin(*m); }
57  void on_epoch_end(model* m) override { timing_end(*m); }
59  void on_validation_begin(model* m) override { timing_begin(*m); }
61  void on_validation_end(model* m) override { timing_end(*m); }
63  void on_test_begin(model* m) override { timing_begin(*m); }
65  void on_test_end(model* m) override { timing_end(*m); }
67  void on_batch_begin(model* m) override { batch_timing_begin(*m); }
69  void on_batch_end(model* m) override { batch_timing_end(*m); }
73  void on_batch_evaluate_end(model* m) override { batch_timing_end(*m); }
74 
76  std::string name() const override { return "timer"; }
77 
79 
82  template <class Archive>
83  void serialize(Archive& ar);
84 
86 
87 private:
89  void write_specific_proto(lbann_data::Callback& proto) const final;
90 
92  std::map<execution_mode, EvalType> m_start_times;
94  std::map<execution_mode, EvalType> m_batch_start_times;
96  std::map<execution_mode, std::vector<EvalType>> m_batch_times;
97 
99  void timing_begin(const model& m);
103  void timing_end(model& m);
105  void batch_timing_begin(const model& m);
109  void batch_timing_end(const model& m);
110 
112  std::shared_ptr<lbann_summary> m_summarizer = nullptr;
113 };
114 
115 // Builder function
116 std::unique_ptr<callback_base>
117 build_timer_callback_from_pbuf(const google::protobuf::Message&,
118  std::shared_ptr<lbann_summary> const&);
119 
120 } // namespace callback
121 } // namespace lbann
122 
123 #endif // LBANN_CALLBACKS_CALLBACK_TIMER_HPP_INCLUDED
void on_validation_end(model *m) override
void on_batch_begin(model *m) override
void on_validation_begin(model *m) override
std::shared_ptr< lbann_summary > m_summarizer
lbann_summary
void serialize(Archive &ar)
Store state to archive for checkpoint and restart.
timer * copy() const override
timer & operator=(const timer &)=default
void on_test_begin(model *m) override
std::map< execution_mode, std::vector< EvalType > > m_batch_times
void on_batch_evaluate_begin(model *m) override
void on_batch_end(model *m) override
void write_specific_proto(lbann_data::Callback &proto) const final
void on_epoch_begin(model *m) override
Base class for callbacks during training/testing.
Definition: callback.hpp:76
void timing_end(model &m)
Abstract base class for neural network models.
Definition: model.hpp:83
void timing_begin(const model &m)
void batch_timing_end(const model &m)
std::unique_ptr< callback_base > build_timer_callback_from_pbuf(const google::protobuf::Message &, std::shared_ptr< lbann_summary > const &)
std::map< execution_mode, EvalType > m_batch_start_times
timer(const std::shared_ptr< lbann_summary > &summarizer=nullptr)
std::map< execution_mode, EvalType > m_start_times
void batch_timing_begin(const model &m)
std::string name() const override
void on_epoch_end(model *m) override
void on_test_end(model *m) override
void on_batch_evaluate_end(model *m) override