User Guide
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) {
19  PerfStat result;
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;
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;
63  return result;
64 }
65 
66 void PerfStat::print(std::stringstream& stream) const {
67  TableData table;
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));
96  row.push_back(std::to_string(n_unique_global_read));
97  row.push_back(std::to_string(n_global_write));
98  row.push_back(std::to_string(n_unique_global_write));
99 
100  row.push_back(std::to_string(n_constant_read));
101  row.push_back(std::to_string(n_unique_constant_read));
102  row.push_back(std::to_string(n_constant_write));
103  row.push_back(std::to_string(n_unique_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
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::TableData::title
std::string title
title of the table
Definition: table_data.hpp:40
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::TableData::rows
std::vector< TableRowType > rows
data
Definition: table_data.hpp:46
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::operator+
PerfStat operator+(const PerfStat &first, const PerfStat &second)
Definition: perf_stat.cpp:18
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::TableData
Class to construct and pretty-print tabular data.
Definition: table_data.hpp:36
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
table_data.hpp
Implement generic table data structure.
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::symtab::syminfo::to_string
std::string to_string(const T &obj)
Definition: symbol_properties.hpp:282
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::TableData::headers
TableRowType headers
top header/keys
Definition: table_data.hpp:43
nmodl::utils::TableData::print
void print(int indent=0) const
Definition: table_data.cpp:127
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
perf_stat.hpp
Implement class for performance statistics.
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