LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
profiling.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 // profiling .hpp .cpp - Various routines for interfacing with profilers
28 #ifndef LBANN_UTILS_PROFILING_HPP
29 #define LBANN_UTILS_PROFILING_HPP
30 
31 #include <lbann_config.hpp>
32 
33 #if defined(LBANN_HAS_CALIPER)
34 #include <caliper/cali.h>
35 #include <caliper/cali_macros.h>
36 
37 #define LBANN_CALIPER_MARK_SCOPE(x) \
38  CALI_CXX_MARK_SCOPE(x)
39 
40 #define LBANN_CALIPER_MARK_FUNCTION \
41  CALI_CXX_MARK_FUNCTION
42 
43 #define LBANN_CALIPER_MARK_BEGIN(x) \
44  CALI_MARK_BEGIN(x)
45 
46 #define LBANN_CALIPER_MARK_END(x) \
47  CALI_MARK_END(x)
48 
49 #define LBANN_CALIPER_LOOP_BEGIN(label, desc) CALI_CXX_MARK_LOOP_BEGIN(label, desc)
50 #define LBANN_CALIPER_LOOP_END(label) CALI_CXX_MARK_LOOP_END(label)
51 #define LBANN_CALIPER_LOOP_ITER(label, id) CALI_CXX_MARK_LOOP_ITERATION(label, id)
52 
53 #else
54 #define LBANN_CALIPER_MARK_SCOPE(x) ((void)0)
55 #define LBANN_CALIPER_MARK_FUNCTION ((void)0)
56 #define LBANN_CALIPER_MARK_BEGIN(x) ((void)0)
57 #define LBANN_CALIPER_MARK_END(x) ((void)0)
58 #define LBANN_CALIPER_LOOP_BEGIN(...) ((void)0)
59 #define LBANN_CALIPER_LOOP_END(...) ((void)0)
60 #define LBANN_CALIPER_LOOP_ITER(...) ((void)0)
61 #endif
62 
63 namespace lbann {
64 
65 #if defined(LBANN_HAS_CALIPER)
66 void initialize_caliper();
67 void finalize_caliper();
68 bool is_caliper_initialized() noexcept;
69 #endif
70 
71 // Colors to use for profiling.
72 constexpr int num_prof_colors = 20;
73 // http://there4.io/2012/05/02/google-chart-color-list/
74 constexpr int prof_colors[num_prof_colors] = {
75  0x3366CC, 0xDC3912, 0xFF9900, 0x109618, 0x990099, 0x3B3EAC, 0x0099C6,
76  0xDD4477, 0x66AA00, 0xB82E2E, 0x316395, 0x994499, 0x22AA99, 0xAAAA11,
77  0x6633CC, 0xE67300, 0x8B0707, 0x329262, 0x5574A6, 0x3B3EAC};
78 
79 void prof_start();
80 void prof_stop();
81 void prof_region_begin(const char* s, int c, bool sync);
82 void prof_region_end(const char* s, bool sync);
83 
86 {
87 public:
89  ProfRegion(char const* name, bool sync = false);
91  ProfRegion(char const* name, int color, bool sync = false);
92 
93  ~ProfRegion();
94 
95 private:
96  char const* m_name;
97  bool m_sync;
98 }; // class ProfRegion
99 
100 // Using a macro so it's easy to remove if needed.
101 #define BASIC_PROF_REGION(NAME) ProfRegion _(NAME)
102 
103 } // namespace lbann
104 #endif // LBANN_UTILS_PROFILING_HPP
void prof_start()
void prof_stop()
RAII class for a prof region.
Definition: profiling.hpp:85
constexpr int num_prof_colors
Definition: profiling.hpp:72
void prof_region_end(const char *s, bool sync)
char const * m_name
Definition: profiling.hpp:96
void prof_region_begin(const char *s, int c, bool sync)
constexpr int prof_colors[num_prof_colors]
Definition: profiling.hpp:74
ProfRegion(char const *name, bool sync=false)
Create a prof region using an automatic color.