NEURON
perf_stat.cpp
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 #include <iostream>
9 
10 #include <vector>
11 
12 #include "utils/perf_stat.hpp"
13 #include "utils/table_data.hpp"
14 
15 namespace nmodl {
16 namespace utils {
17 
18 PerfStat operator+(const PerfStat& first, const PerfStat& second) {
20 
21  result.n_assign = first.n_assign + second.n_assign;
22 
23  result.n_add = first.n_add + second.n_add;
24  result.n_sub = first.n_sub + second.n_sub;
25  result.n_mul = first.n_mul + second.n_mul;
26  result.n_div = first.n_div + second.n_div;
27 
28  result.n_exp = first.n_exp + second.n_exp;
29  result.n_log = first.n_log + second.n_log;
30  result.n_pow = first.n_pow + second.n_pow;
31 
32  result.n_ext_func_call = first.n_ext_func_call + second.n_ext_func_call;
33  result.n_int_func_call = first.n_int_func_call + second.n_int_func_call;
34 
35  result.n_and = first.n_and + second.n_and;
36  result.n_or = first.n_or + second.n_or;
37 
38  result.n_gt = first.n_gt + second.n_gt;
39  result.n_lt = first.n_lt + second.n_lt;
40  result.n_ge = first.n_ge + second.n_ge;
41  result.n_le = first.n_le + second.n_le;
42  result.n_ne = first.n_ne + second.n_ne;
43  result.n_ee = first.n_ee + second.n_ee;
44 
45  result.n_not = first.n_not + second.n_not;
46  result.n_neg = first.n_neg + second.n_neg;
47 
48  result.n_if = first.n_if + second.n_if;
49  result.n_elif = first.n_elif + second.n_elif;
50 
51  result.n_global_read = first.n_global_read + second.n_global_read;
52  result.n_global_write = first.n_global_write + second.n_global_write;
53  result.n_unique_global_read = first.n_unique_global_read + second.n_unique_global_read;
54  result.n_unique_global_write = first.n_unique_global_write + second.n_unique_global_write;
55 
56  result.n_local_read = first.n_local_read + second.n_local_read;
57  result.n_local_write = first.n_local_write + second.n_local_write;
58 
59  result.n_constant_read = first.n_constant_read + second.n_constant_read;
60  result.n_constant_write = first.n_constant_write + second.n_constant_write;
61  result.n_unique_constant_read = first.n_unique_constant_read + second.n_unique_constant_read;
62  result.n_unique_constant_write = first.n_unique_constant_write + second.n_unique_constant_write;
63  return result;
64 }
65 
66 void PerfStat::print(std::stringstream& stream) const {
68  table.headers = keys();
69  table.rows.push_back(values());
70  if (!title.empty()) {
71  table.title = title;
72  }
73  table.print(stream);
74 }
75 
76 std::vector<std::string> PerfStat::keys() {
77  return {"+", "-", "x", "/", "exp", "log", "GM-R(T)",
78  "GM-R(U)", "GM-W(T)", "GM-W(U)", "CM-R(T)", "CM-R(U)", "CM-W(T)", "CM-W(U)",
79  "LM-R(T)", "LM-W(T)", "calls(ext)", "calls(int)", "compare", "unary", "conditional"};
80 }
81 
82 std::vector<std::string> PerfStat::values() const {
83  std::vector<std::string> row;
84 
85  int compares = n_gt + n_lt + n_ge + n_le + n_ne + n_ee;
86  int conditionals = n_if + n_elif;
87 
88  row.push_back(std::to_string(n_add));
89  row.push_back(std::to_string(n_sub));
90  row.push_back(std::to_string(n_mul));
91  row.push_back(std::to_string(n_div));
92  row.push_back(std::to_string(n_exp));
93  row.push_back(std::to_string(n_log));
94 
95  row.push_back(std::to_string(n_global_read));
97  row.push_back(std::to_string(n_global_write));
99 
100  row.push_back(std::to_string(n_constant_read));
102  row.push_back(std::to_string(n_constant_write));
104 
105  row.push_back(std::to_string(n_local_read));
106  row.push_back(std::to_string(n_local_write));
107 
108  row.push_back(std::to_string(n_ext_func_call));
109  row.push_back(std::to_string(n_int_func_call));
110 
111  row.push_back(std::to_string(compares));
112  row.push_back(std::to_string(n_not + n_neg));
113  row.push_back(std::to_string(conditionals));
114 
115  return row;
116 }
117 
118 } // namespace utils
119 } // namespace nmodl
std::string to_string(const T &obj)
PerfStat operator+(const PerfStat &first, const PerfStat &second)
Definition: perf_stat.cpp:18
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
static unsigned row
Definition: nonlin.cpp:78
Implement class for performance statistics.
static struct table * table
Helper class to collect performance statistics.
Definition: perf_stat.hpp:36
int n_and
bitwise ops
Definition: perf_stat.hpp:64
int n_assign
write ops
Definition: perf_stat.hpp:41
void print(std::stringstream &stream) const
Definition: perf_stat.cpp:66
int n_div
expensive ops
Definition: perf_stat.hpp:49
std::vector< std::string > values() const
Definition: perf_stat.cpp:82
int n_int_func_call
mod functions (before/after inlining)
Definition: perf_stat.hpp:61
int n_local_read
cheap : typically local variables in mod file means registers
Definition: perf_stat.hpp:90
int n_global_read
expensive : typically access to dynamically allocated memory
Definition: perf_stat.hpp:84
int n_if
conditional ops
Definition: perf_stat.hpp:80
int n_ext_func_call
could be external math funcs
Definition: perf_stat.hpp:58
int n_add
basic ops (<= 1 cycle)
Definition: perf_stat.hpp:44
int n_gt
comparisons ops
Definition: perf_stat.hpp:68
int n_not
unary ops
Definition: perf_stat.hpp:76
std::string title
name for pretty-printing
Definition: perf_stat.hpp:38
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
static std::vector< std::string > keys()
Definition: perf_stat.cpp:76
int n_exp
expensive functions : commonly used functions in mod files
Definition: perf_stat.hpp:53
Class to construct and pretty-print tabular data.
Definition: table_data.hpp:36
Definition: units.cpp:71
Implement generic table data structure.