LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
profiler.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 // timer .hpp .cpp - Callback hooks to time training
28 
29 #ifndef LBANN_CALLBACKS_PROFILER_HPP_INCLUDED
30 #define LBANN_CALLBACKS_PROFILER_HPP_INCLUDED
31 
33 
34 namespace lbann {
35 namespace callback {
36 
39 class profiler : public callback_base
40 {
41 public:
42  profiler(bool sync = false, bool skip_init = false);
43  profiler(const profiler&) = default;
44  profiler& operator=(const profiler&) = default;
45  ~profiler();
46  profiler* copy() const override { return new profiler(*this); }
47  void on_epoch_begin(model* m) override;
48  void on_epoch_end(model* m) override;
49  void on_validation_begin(model* m) override;
50  void on_validation_end(model* m) override;
51  void on_test_begin(model* m) override;
52  void on_test_end(model* m) override;
53  void on_batch_begin(model* m) override;
54  void on_batch_end(model* m) override;
55  void on_batch_evaluate_begin(model* m) override;
56  void on_batch_evaluate_end(model* m) override;
57  void on_forward_prop_begin(model* m) override;
58  void on_forward_prop_end(model* m) override;
59  void on_evaluate_forward_prop_begin(model* m) override;
60  void on_evaluate_forward_prop_end(model* m) override;
61  void on_backward_prop_begin(model* m) override;
62  void on_backward_prop_end(model* m) override;
63  void on_forward_prop_begin(model* m, Layer* l) override;
64  void on_forward_prop_end(model* m, Layer* l) override;
65  void on_evaluate_forward_prop_begin(model* m, Layer* l) override;
66  void on_evaluate_forward_prop_end(model* m, Layer* l) override;
67  void on_backward_prop_begin(model* m, Layer* l) override;
68  void on_backward_prop_end(model* m, Layer* l) override;
69  void on_optimize_begin(model* m) override;
70  void on_optimize_end(model* m) override;
71  void on_optimize_begin(model* m, weights* w) override;
72  void on_optimize_end(model* m, weights* w) override;
73  std::string name() const override { return "profiler"; }
74 
76 
79  template <class Archive>
80  void serialize(Archive& ar);
81 
83 
84 private:
86  void write_specific_proto(lbann_data::Callback& proto) const final;
87 
89  int get_color(Layer* l);
91  bool m_sync;
94 };
95 
96 // Builder function
97 std::unique_ptr<callback_base>
98 build_profiler_callback_from_pbuf(const google::protobuf::Message&,
99  std::shared_ptr<lbann_summary> const&);
100 
101 } // namespace callback
102 } // namespace lbann
103 
104 #endif // LBANN_CALLBACKS_PROFILER_HPP_INCLUDED
std::unique_ptr< callback_base > build_profiler_callback_from_pbuf(const google::protobuf::Message &, std::shared_ptr< lbann_summary > const &)
void on_epoch_begin(model *m) override
Called at the beginning of each epoch.
void on_batch_end(model *m) override
Called immediately after the end of a (mini-)batch.
void on_optimize_end(model *m) override
Called when a model ends optimization.
std::string name() const override
Return this callback&#39;s name.
Definition: profiler.hpp:73
void on_validation_begin(model *m) override
Called at the beginning of validation.
Neural network tensor operation.
Definition: layer.hpp:285
void on_batch_evaluate_end(model *m) override
Called at the end of a (mini-)batch evaluation (validation / testing).
profiler * copy() const override
Definition: profiler.hpp:46
void serialize(Archive &ar)
Store state to archive for checkpoint and restart.
void on_evaluate_forward_prop_end(model *m) override
Called when a model ends forward propagation for evaluation (validation / testing).
Base class for callbacks during training/testing.
Definition: callback.hpp:76
Abstract base class for neural network models.
Definition: model.hpp:83
void write_specific_proto(lbann_data::Callback &proto) const final
void on_backward_prop_end(model *m) override
Called when a model ends backward propagation.
void on_forward_prop_end(model *m) override
Called when a model ends forward propagation.
void on_batch_begin(model *m) override
Called at the beginning of a (mini-)batch.
profiler & operator=(const profiler &)=default
void on_forward_prop_begin(model *m) override
Called when a model begins forward propagation.
void on_evaluate_forward_prop_begin(model *m) override
Called when a model begins forward propagation for evaluation (validation / testing).
void on_backward_prop_begin(model *m) override
Called when a model begins backward propagation.
profiler(bool sync=false, bool skip_init=false)
void on_batch_evaluate_begin(model *m) override
Called at the beginning of a (mini-)batch evaluation (validation / testing).
void on_epoch_end(model *m) override
Called immediate after the end of each epoch.
void on_validation_end(model *m) override
Called immediately after the end of validation.
void on_test_end(model *m) override
Called immediately after the end of testing.
void on_test_begin(model *m) override
Called at the beginning of testing.
void on_optimize_begin(model *m) override
Called when a model begins optimization.