![]() |
User Guide
|
Visitor for measuring performance related information More...
Visitor for measuring performance related information
This visitor used to visit the ast and associated symbol tables to measure the performance of every block in nmodl file. For every symbol in associated symbol table, read/write count is updated which will be used during code generation (to select memory types). Certain statements like useion, valence etc. are not executed in the translated C code and hence need to be skipped (i.e. without visiting children). Note that this pass must be run after symbol table generation pass.
Definition at line 58 of file perf_visitor.hpp.
#include <perf_visitor.hpp>
Private Member Functions | |
void | update_memory_ops (const std::string &name) |
Find symbol in closest scope (up to parent) and update read/write count. More... | |
bool | symbol_to_skip (const std::shared_ptr< symtab::Symbol > &symbol) const |
Certain statements / symbols needs extra check while measuring read/write operations. More... | |
void | count_variables () |
void | measure_performance (const ast::Ast &node) |
Helper function used by all ast nodes : visit all children recursively and performance stats get added on stack. More... | |
void | print_memory_usage () |
void | add_perf_to_printer (const utils::PerfStat &perf) const |
add performance stats to json printer More... | |
Static Private Member Functions | |
static bool | is_local_variable (const std::shared_ptr< symtab::Symbol > &symbol) |
static bool | is_constant_variable (const std::shared_ptr< symtab::Symbol > &symbol) |
Private Attributes | |
symtab::SymbolTable * | current_symtab = nullptr |
symbol table of current block being visited More... | |
std::stack< utils::PerfStat > | blocks_perf |
performance stats of all blocks being visited in recursive chain More... | |
utils::PerfStat | total_perf |
total performance of mod file More... | |
utils::PerfStat | current_block_perf |
performance of current block More... | |
std::stack< utils::PerfStat > | children_blocks_perf |
performance of current all childrens More... | |
bool | start_measurement = false |
whether to measure performance for current block More... | |
bool | visiting_lhs_expression = false |
true while visiting lhs of binary expression (to count write operations) More... | |
bool | under_function_call = false |
whether function call is being visited More... | |
bool | under_solve_block = false |
whether solve block is being visited More... | |
bool | under_net_receive_block = false |
whether net receive block is being visited More... | |
std::unique_ptr< printer::JSONPrinter > | printer |
to print to json file More... | |
std::stringstream | stream |
if not json, all goes to string More... | |
int | num_instance_variables = 0 |
count of per channel instance variables More... | |
int | num_constant_instance_variables = 0 |
subset of instance variables which are constant More... | |
int | num_localized_instance_variables = 0 |
subset of instance variables which are localized More... | |
int | num_global_variables = 0 |
count of global variables More... | |
int | num_constant_global_variables = 0 |
subset of global variables which are constant More... | |
int | num_localized_global_variables = 0 |
subset of global variables which are localized More... | |
int | num_state_variables = 0 |
count of state variables More... | |
int | num_pointer_variables = 0 |
count of pointer / bbcorepointer variables More... | |
int | num_random_variables = 0 |
count of RANDOM variables More... | |
std::string | const_memr_key = "cm_r_u" |
keys used in map to track var usage More... | |
std::string | const_memw_key = "cm_w_u" |
std::string | global_memr_key = "gm_r_u" |
std::string | global_memw_key = "gm_w_u" |
std::map< std::string, std::set< std::string > > | var_usage |
map of variables to count unique read-writes More... | |
|
default |
|
explicit |
Definition at line 26 of file perf_visitor.cpp.
|
private |
add performance stats to json printer
Definition at line 118 of file perf_visitor.cpp.
void nmodl::visitor::PerfVisitor::compact_json | ( | bool | flag | ) |
Definition at line 29 of file perf_visitor.cpp.
|
private |
number of instance variables: range or assigned variables one caveat is that the global variables appearing in assigned block are not treated as range
state variables have state_var property
pointer variables have pointer/bbcorepointer
RANDOM variables have NmodlType::random_var
number of global variables : parameters and pointers could appear also as range variables and hence need to filter out. But if anything declared as global is always global.
Definition at line 228 of file perf_visitor.cpp.
|
inlinenoexcept |
Definition at line 172 of file perf_visitor.hpp.
|
inlinenoexcept |
Definition at line 168 of file perf_visitor.hpp.
|
inlinenoexcept |
Definition at line 176 of file perf_visitor.hpp.
|
inlinenoexcept |
Definition at line 164 of file perf_visitor.hpp.
|
inlinenoexcept |
Definition at line 180 of file perf_visitor.hpp.
|
inlinenoexcept |
Definition at line 160 of file perf_visitor.hpp.
|
staticprivate |
Definition at line 521 of file perf_visitor.cpp.
|
staticprivate |
in the function when we write to function variable then consider it as local variable
Definition at line 511 of file perf_visitor.cpp.
|
private |
Helper function used by all ast nodes : visit all children recursively and performance stats get added on stack.
Once all children visited, we get total performance by summing perfstat of all children.
clear var usage map
Definition at line 133 of file perf_visitor.cpp.
|
inline |
Definition at line 252 of file perf_visitor.hpp.
|
private |
Definition at line 288 of file perf_visitor.cpp.
|
private |
Certain statements / symbols needs extra check while measuring read/write operations.
For example, for expression "exp(a+b)", "exp" is an external math function and we should not increment read count for "exp" symbol. Same for solve statement where name will be derivative block name and neuron solver method.
Definition at line 495 of file perf_visitor.cpp.
|
private |
Find symbol in closest scope (up to parent) and update read/write count.
Also update ops count in current block.
lhs symbols get written
rhs symbols get read
Definition at line 534 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::AfterBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 414 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::BABlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 418 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::BeforeBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 410 of file perf_visitor.cpp.
|
overridevirtual |
count math operations from all binary expressions
if visiting assignment expression, symbols from lhs are written and hence need flag to track
lhs is done (rhs is read only)
Implements nmodl::visitor::ConstVisitor.
Definition at line 35 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::BreakpointBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 406 of file perf_visitor.cpp.
|
inlineoverridevirtual |
certain constructs needs to be excluded from usage counting and hence need to provide empty implementations
Implements nmodl::visitor::ConstVisitor.
Definition at line 242 of file perf_visitor.hpp.
|
overridevirtual |
visit node of type ast::ConstructorBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 364 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::DerivativeBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 372 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::DestructorBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 368 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::DiscreteBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 384 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::ElseIfStatement
Implements nmodl::visitor::ConstVisitor.
Definition at line 221 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::ForNetcon
Implements nmodl::visitor::ConstVisitor.
Definition at line 422 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::FunctionBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 392 of file perf_visitor.cpp.
|
overridevirtual |
count function calls and "most useful" or "commonly used" math functions
Implements nmodl::visitor::ConstVisitor.
Definition at line 176 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::FunctionTableBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 388 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::IfStatement
Implements nmodl::visitor::ConstVisitor.
Definition at line 214 of file perf_visitor.cpp.
|
overridevirtual |
skip initial block under net_receive block
Implements nmodl::visitor::ConstVisitor.
Definition at line 358 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::KineticBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 426 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::LinearBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 376 of file perf_visitor.cpp.
|
inlineoverridevirtual |
visit node of type ast::LocalListStatement
Implements nmodl::visitor::ConstVisitor.
Definition at line 244 of file perf_visitor.hpp.
|
overridevirtual |
every variable used is of type name, update counters
Implements nmodl::visitor::ConstVisitor.
Definition at line 203 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::NetReceiveBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 400 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::NonLinearBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 380 of file perf_visitor.cpp.
|
overridevirtual |
prime name derived from identifier and hence need to be handled here
Implements nmodl::visitor::ConstVisitor.
Definition at line 209 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::ProcedureBlock
Implements nmodl::visitor::ConstVisitor.
Definition at line 396 of file perf_visitor.cpp.
|
overridevirtual |
visit node of type ast::Program
Implements nmodl::visitor::ConstVisitor.
Definition at line 335 of file perf_visitor.cpp.
|
overridevirtual |
solve is not a statement but could have associated block and hence could/should not be skipped completely we can't ignore the block because it could have associated statement block (in theory)
Implements nmodl::visitor::ConstVisitor.
Definition at line 464 of file perf_visitor.cpp.
|
overridevirtual |
Blocks like function can have multiple statement blocks and blocks like net receive has nested initial blocks.
Hence need to maintain separate stack.
starting new block, store current state
new block perf starts from zero
add performance of all visited children
Implements nmodl::visitor::ConstVisitor.
Definition at line 434 of file perf_visitor.cpp.
|
inlineoverridevirtual |
visit node of type ast::Suffix
Implements nmodl::visitor::ConstVisitor.
Definition at line 246 of file perf_visitor.hpp.
|
overridevirtual |
visit node of type ast::UnaryExpression
Implements nmodl::visitor::ConstVisitor.
Definition at line 470 of file perf_visitor.cpp.
|
inlineoverridevirtual |
visit node of type ast::Useion
Implements nmodl::visitor::ConstVisitor.
Definition at line 248 of file perf_visitor.hpp.
|
inlineoverridevirtual |
visit node of type ast::Valence
Implements nmodl::visitor::ConstVisitor.
Definition at line 250 of file perf_visitor.hpp.
|
private |
performance stats of all blocks being visited in recursive chain
Definition at line 65 of file perf_visitor.hpp.
|
private |
performance of current all childrens
Definition at line 74 of file perf_visitor.hpp.
|
private |
keys used in map to track var usage
Definition at line 126 of file perf_visitor.hpp.
|
private |
Definition at line 127 of file perf_visitor.hpp.
|
private |
performance of current block
Definition at line 71 of file perf_visitor.hpp.
|
private |
symbol table of current block being visited
Definition at line 61 of file perf_visitor.hpp.
|
private |
Definition at line 128 of file perf_visitor.hpp.
|
private |
Definition at line 129 of file perf_visitor.hpp.
|
private |
subset of global variables which are constant
Definition at line 111 of file perf_visitor.hpp.
|
private |
subset of instance variables which are constant
Definition at line 102 of file perf_visitor.hpp.
|
private |
count of global variables
Definition at line 108 of file perf_visitor.hpp.
|
private |
count of per channel instance variables
Definition at line 99 of file perf_visitor.hpp.
|
private |
subset of global variables which are localized
Definition at line 114 of file perf_visitor.hpp.
|
private |
subset of instance variables which are localized
Definition at line 105 of file perf_visitor.hpp.
|
private |
count of pointer / bbcorepointer variables
Definition at line 120 of file perf_visitor.hpp.
|
private |
count of RANDOM variables
Definition at line 123 of file perf_visitor.hpp.
|
private |
count of state variables
Definition at line 117 of file perf_visitor.hpp.
|
private |
to print to json file
Definition at line 93 of file perf_visitor.hpp.
|
private |
whether to measure performance for current block
Definition at line 77 of file perf_visitor.hpp.
|
private |
if not json, all goes to string
Definition at line 96 of file perf_visitor.hpp.
|
private |
total performance of mod file
Definition at line 68 of file perf_visitor.hpp.
|
private |
whether function call is being visited
Definition at line 84 of file perf_visitor.hpp.
|
private |
whether net receive block is being visited
Definition at line 90 of file perf_visitor.hpp.
|
private |
whether solve block is being visited
Definition at line 87 of file perf_visitor.hpp.
|
private |
map of variables to count unique read-writes
Definition at line 132 of file perf_visitor.hpp.
|
private |
true while visiting lhs of binary expression (to count write operations)
Definition at line 81 of file perf_visitor.hpp.