User Guide
perf_stat.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 /**
11  * \file
12  * \brief Implement class for performance statistics
13  */
14 
15 #include <sstream>
16 #include <string>
17 #include <vector>
18 
19 namespace nmodl {
20 namespace utils {
21 
22 /**
23  * @addtogroup utils
24  * @{
25  */
26 
27 /**
28  * \struct PerfStat
29  * \brief Helper class to collect performance statistics
30  *
31  * For code generation it is useful to know the performance
32  * characteristics of every block in nmodl. The PerfStat class
33  * groups performance characteristics of a single block in
34  * nmodl.
35  */
36 struct PerfStat {
37  /// name for pretty-printing
38  std::string title;
39 
40  /// write ops
41  int n_assign = 0;
42 
43  /// basic ops (<= 1 cycle)
44  int n_add = 0;
45  int n_sub = 0;
46  int n_mul = 0;
47 
48  /// expensive ops
49  int n_div = 0;
50 
51  /// expensive functions : commonly
52  /// used functions in mod files
53  int n_exp = 0;
54  int n_log = 0;
55  int n_pow = 0;
56 
57  /// could be external math funcs
58  int n_ext_func_call = 0;
59 
60  /// mod functions (before/after inlining)
61  int n_int_func_call = 0;
62 
63  /// bitwise ops
64  int n_and = 0;
65  int n_or = 0;
66 
67  /// comparisons ops
68  int n_gt = 0;
69  int n_lt = 0;
70  int n_ge = 0;
71  int n_le = 0;
72  int n_ne = 0;
73  int n_ee = 0;
74 
75  /// unary ops
76  int n_not = 0;
77  int n_neg = 0;
78 
79  /// conditional ops
80  int n_if = 0;
81  int n_elif = 0;
82 
83  /// expensive : typically access to dynamically allocated memory
84  int n_global_read = 0;
85  int n_global_write = 0;
88 
89  /// cheap : typically local variables in mod file means registers
90  int n_local_read = 0;
91  int n_local_write = 0;
92 
93  /// could be optimized : access to variables that could be read-only
94  /// in this case write counts are typically from initialization
95  int n_constant_read = 0;
99 
100  friend PerfStat operator+(const PerfStat& first, const PerfStat& second);
101 
102  void print(std::stringstream& stream) const;
103 
104  static std::vector<std::string> keys();
105 
106  std::vector<std::string> values() const;
107 };
108 
109 /** @} */ // end of utils
110 
111 } // namespace utils
112 } // namespace nmodl
nmodl::utils::PerfStat::n_pow
int n_pow
Definition: perf_stat.hpp:55
nmodl::utils::PerfStat::n_sub
int n_sub
Definition: perf_stat.hpp:45
nmodl::utils::PerfStat::n_ext_func_call
int n_ext_func_call
could be external math funcs
Definition: perf_stat.hpp:58
nmodl::utils::PerfStat::values
std::vector< std::string > values() const
Definition: perf_stat.cpp:82
nmodl::utils::PerfStat::n_assign
int n_assign
write ops
Definition: perf_stat.hpp:41
nmodl::utils::PerfStat::n_not
int n_not
unary ops
Definition: perf_stat.hpp:76
nmodl::utils::PerfStat::n_neg
int n_neg
Definition: perf_stat.hpp:77
nmodl::utils::PerfStat::n_elif
int n_elif
Definition: perf_stat.hpp:81
nmodl::utils::PerfStat::n_le
int n_le
Definition: perf_stat.hpp:71
nmodl::utils::PerfStat::n_unique_global_read
int n_unique_global_read
Definition: perf_stat.hpp:86
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::utils::PerfStat::n_constant_write
int n_constant_write
Definition: perf_stat.hpp:96
nmodl::utils::PerfStat::keys
static std::vector< std::string > keys()
Definition: perf_stat.cpp:76
nmodl::utils::PerfStat::n_if
int n_if
conditional ops
Definition: perf_stat.hpp:80
nmodl::utils::PerfStat::n_ee
int n_ee
Definition: perf_stat.hpp:73
nmodl::utils::PerfStat::n_global_read
int n_global_read
expensive : typically access to dynamically allocated memory
Definition: perf_stat.hpp:84
nmodl::utils::PerfStat::n_unique_constant_write
int n_unique_constant_write
Definition: perf_stat.hpp:98
nmodl::utils::PerfStat::n_ge
int n_ge
Definition: perf_stat.hpp:70
nmodl::utils::PerfStat::n_lt
int n_lt
Definition: perf_stat.hpp:69
nmodl::utils::PerfStat::n_ne
int n_ne
Definition: perf_stat.hpp:72
nmodl::utils::PerfStat::n_log
int n_log
Definition: perf_stat.hpp:54
nmodl::utils::PerfStat::print
void print(std::stringstream &stream) const
Definition: perf_stat.cpp:66
nmodl::utils::PerfStat::n_local_read
int n_local_read
cheap : typically local variables in mod file means registers
Definition: perf_stat.hpp:90
nmodl::utils::PerfStat::n_constant_read
int n_constant_read
could be optimized : access to variables that could be read-only in this case write counts are typica...
Definition: perf_stat.hpp:95
nmodl::utils::PerfStat::n_or
int n_or
Definition: perf_stat.hpp:65
nmodl::utils::PerfStat::n_gt
int n_gt
comparisons ops
Definition: perf_stat.hpp:68
nmodl::utils::PerfStat::n_local_write
int n_local_write
Definition: perf_stat.hpp:91
nmodl::utils::PerfStat::n_global_write
int n_global_write
Definition: perf_stat.hpp:85
nmodl::utils::PerfStat::operator+
friend PerfStat operator+(const PerfStat &first, const PerfStat &second)
Definition: perf_stat.cpp:18
nmodl::utils::PerfStat::n_div
int n_div
expensive ops
Definition: perf_stat.hpp:49
nmodl::utils::PerfStat::n_and
int n_and
bitwise ops
Definition: perf_stat.hpp:64
nmodl::utils::PerfStat::n_int_func_call
int n_int_func_call
mod functions (before/after inlining)
Definition: perf_stat.hpp:61
nmodl::utils::PerfStat
Helper class to collect performance statistics.
Definition: perf_stat.hpp:36
nmodl::utils::PerfStat::n_mul
int n_mul
Definition: perf_stat.hpp:46
nmodl::utils::PerfStat::n_unique_global_write
int n_unique_global_write
Definition: perf_stat.hpp:87
nmodl::utils::PerfStat::title
std::string title
name for pretty-printing
Definition: perf_stat.hpp:38
nmodl::utils::PerfStat::n_exp
int n_exp
expensive functions : commonly used functions in mod files
Definition: perf_stat.hpp:53
nmodl::utils::PerfStat::n_unique_constant_read
int n_unique_constant_read
Definition: perf_stat.hpp:97
nmodl::utils::PerfStat::n_add
int n_add
basic ops (<= 1 cycle)
Definition: perf_stat.hpp:44