The Sparta Modeling Framework
Loading...
Searching...
No Matches
CommandLineSimulator.hpp
Go to the documentation of this file.
1// <CommandLineSimulator> -*- C++ -*-
2
3
9#pragma once
10
11#include <boost/program_options.hpp>
12#include <boost/program_options/cmdline.hpp>
13#include <boost/program_options/errors.hpp>
14#include <boost/program_options/options_description.hpp>
15#include <boost/program_options/positional_options.hpp>
16#include <boost/program_options/variables_map.hpp>
17#include <cstdint>
18#include <vector>
19#include <set>
20#include <memory>
21#include <string>
22#include <unordered_map>
23
24#include "sparta/report/Report.hpp"
30#include "sparta/trigger/Trigger.hpp"
31#include "sparta/trigger/Triggerable.hpp"
32#include "sparta/pevents/PeventTrigger.hpp"
33#include "sparta/pevents/PeventController.hpp"
36
37namespace boost::program_options {
38template <class charT> class basic_parsed_options;
39} // namespace boost::program_options
40
41namespace sparta::app {
42class Simulation;
43} // namespace sparta::app
44
45namespace sparta::trigger {
46class Trigger;
47class Triggerable;
48} // namespace sparta::trigger
49
50namespace po = boost::program_options;
51namespace pocls = boost::program_options::command_line_style;
52
53namespace sparta {
54class InformationWriter;
55
56namespace app {
57
58const constexpr char DefaultHeartbeat[] = "0";
59
60
85{
86public:
87
92
95
103 CommandLineSimulator(const std::string& usage,
104 const DefaultValues& defs=DEFAULTS);
105
110
116 bool isParsed() const {
117 return is_parsed_;
118 }
119
125 bool isSetup() const {
126 return is_setup_;
127 }
128
133 const std::string& getUsage() const { return usage_; }
134
144 return sparta_opts_;
145 }
146
151 return app_opts_;
152 }
153
158 return advanced_opts_;
159 }
160
165 po::positional_options_description& getPositionalOptions() {
166 return positional_opts_;
167 }
168
173 const po::variables_map& getVariablesMap() const {
174 return vm_;
175 }
176
195 bool parse(int argc,
196 char** argv,
197 int& err_code);
198
204 int parse(int argc,
205 char** argv);
206
215
220
224 void runSimulator(Simulation* sim, uint64_t ticks);
225
231
236 bool isRuntimeFinite() const {
237
239 (run_time_ticks_ != sparta::Scheduler::INDEFINITE);
240 return retval;
241 }
242
249
256
257protected:
258
263
267 void runSimulator_(Simulation* sim, uint64_t ticks);
268
273
279 (void) opts;
280 }
281
284
287
291 const std::string usage_;
292
296 int argc_ = 0;
297
301 char **argv_ = nullptr;
302
306 ReportDescVec reports_;
307
311 std::vector<std::string> report_descriptor_def_files_;
312
317 app::ReportYamlReplacements report_yaml_placeholder_replacements_;
318
327 std::unordered_map<std::string, app::ReportYamlReplacements>
329
334 bool is_parsed_ = false;
335
339 bool is_setup_ = false;
340
345 uint64_t run_time_ticks_ = sparta::Scheduler::INDEFINITE;
346
351 bool no_run_mode_ = false;
352
358
362 std::string read_final_config_ = "";
368
374
381
386 bool no_show_config_ = false;
387
391 bool show_tree_ = false;
392
396 bool show_parameters_ = false;
397
401 bool show_ports_ = false;
402
407 bool show_counters_ = false;
408
412 bool show_clocks_ = false;
413
417 bool show_pevents_ = false;
423
428 bool show_loggers_ = false;
429
433 bool show_hidden_ = false;
434
438 bool disable_colors_ = false;
439
444 std::string dump_debug_type_{"error"};
445
453 std::string debug_dump_options_{"all"};
454
458 std::unique_ptr<sparta::trigger::Triggerable> pipeline_collection_triggerable_;
459 std::unique_ptr<sparta::trigger::Trigger> pipeline_trigger_;
460 std::unique_ptr<sparta::InformationWriter> info_out_;
461
466 std::string pipeline_heartbeat_ = DefaultHeartbeat;
467
469 std::set<std::string> pipeline_enabled_node_names_;
470
474 std::unique_ptr<sparta::trigger::Triggerable> pevent_trigger_;
475
483 bool run_pevents_ = false;
484
486 std::string runtime_clock_;
487
492 std::string auto_summary_;
493
497 std::string help_topic_;
498
499private:
500
504 bool use_pyshell_ = false;
505
509 void printUsageHelp_() const;
510
514 void printOptionsHelp_(uint32_t level) const;
515
519 void showVerboseHelp_() const;
520
524 void showBriefHelp_() const;
525
529 void showHelpTopics_() const;
530
536 bool openALFAndFindPipelineNodes_(const std::string & alf_filename);
537
541 MultiDetailOptions sparta_opts_;
542
546 MultiDetailOptions param_opts_;
547
551 MultiDetailOptions debug_opts_;
552
556 MultiDetailOptions run_time_opts_;
557
561 MultiDetailOptions pipeout_opts_;
562
566 MultiDetailOptions log_opts_;
567
571 MultiDetailOptions report_opts_;
572
576 MultiDetailOptions simdb_opts_;
577
583 MultiDetailOptions simdb_internal_opts_;
584
589 MultiDetailOptions app_opts_;
590
595 MultiDetailOptions feature_opts_;
596
601 MultiDetailOptions advanced_opts_;
602
606 po::options_description all_opts_;
607
611 po::positional_options_description positional_opts_;
612
616 po::variables_map vm_;
617
622 std::vector<std::string> unrecognized_opts_;
623
629 std::unique_ptr<trigger::Trigger> debug_trigger_;
630
631};
632
633 } // namespace app
634} // namespace sparta
Application-infrastructure triggers.
Wrapper for boost program_options option_description that allows multiple levels of detail.
Describes reports to instantiate and tracks their instantiations.
A simple time-based, event precedence based scheduler.
Simulation setup base class.
static const Tick INDEFINITE
Constant for infinite tick count.
Command line simulator front-end class with argument parsing Works in conjunction with sparta::app::S...
app::ReportYamlReplacements report_yaml_placeholder_replacements_
Vector of yaml placeholder key-value pairs. These will be applied to the yamls given by "--report my_...
bool parse(int argc, char **argv, int &err_code)
Parse command line options.
void populateSimulation_(Simulation *sim)
Implements populateSimulation.
std::string pipeline_heartbeat_
Heartbeat period of pipeline collection file (before lexical cast or validation)
bool is_parsed_
Have the command line options been parsed yet by this class through the parse method.
virtual void postParse_(po::basic_parsed_options< char > &opts)
Callback before interpreting command parsed command line tokens.
void runSimulator(Simulation *sim, uint64_t ticks)
Run the simulator for the specified number of ticks.
std::string final_config_file_verbose_
Destination to which final configuration (before running) will be written ("" if not written)....
virtual ~CommandLineSimulator()
Destructor.
std::unique_ptr< sparta::trigger::Triggerable > pipeline_collection_triggerable_
Instance of the pipeline collector if collection enabled.
std::string read_final_config_
The file to read from for reading in a final config file.
SimulationConfiguration sim_config_
Simulation configuration including default values.
std::string debug_dump_options_
When a simulation error occurs and error logging is enabled, what content should the error log contai...
ReportDescVec reports_
Vector of Report descriptors to instantiate on the simulator.
po::positional_options_description & getPositionalOptions()
Gets the boost positional options for the parser owned by this simulator.
std::string dump_debug_type_
Under what conditions should the debug content be dumped at simulator destruction....
std::string auto_summary_
Automatic summary state. Determines what to do with the automatic summary after running.
void runSimulator(Simulation *sim)
Run the simulator.
bool show_counters_
Display all counters and stats in the device tree after finalization.
bool show_notifications_
Display all notifications in the device tree after finalization excluding log messages.
MultiDetailOptions & getAdvancedOptions()
Gets the advanced options for this simulator.
uint64_t run_time_cycles_
Run-time user parameter.
CommandLineSimulator(const std::string &usage, const DefaultValues &defs=DEFAULTS)
Construct.
const std::string usage_
Usage string specified at construction.
std::unique_ptr< sparta::trigger::Triggerable > pevent_trigger_
The filename to log pevents too.
void postProcess_(Simulation *sim)
Implements postProcess.
std::vector< std::string > report_descriptor_def_files_
Vector of report descriptor definition files (YAML)
std::string final_config_file_
Destination to which final configuration (before running) will be written ("" if not written)
FeatureConfiguration feature_config_
Simulation feature configuration.
bool show_clocks_
Display all the clocks in the tree.
const po::variables_map & getVariablesMap() const
Variables map populated by command-line parsing. This map is populated within the parse() method.
bool show_loggers_
Display all notifications in the device tree after finalization excluding log messages.
uint32_t config_applicators_used_
number of non-final configuration applications used to modify parameters. A tally of all -p,...
void postProcess(Simulation *sim)
Post-process the results of the simulation if applicable.
std::set< std::string > pipeline_enabled_node_names_
The names of the nodes to be enabled.
bool show_pevents_
Display all the pevent types in the tree.
MultiDetailOptions & getApplicationOptions()
Gets the application-specific options for this simulator.
int parse(int argc, char **argv)
DEPRECATED Shorthand version of other parse method,.
bool isParsed() const
Has this simulator parsed the command line yet Being parsed is required to call for populateSimulatio...
SimulationConfiguration & getSimulationConfiguration()
bool show_parameters_
Display all parameters in the device tree after building.
std::string help_topic_
Help topic to show.
const MultiDetailOptions & getSpartaOptions() const
Gets the sparta-specific options for this simulator.
bool isSetup() const
Has this simulator been setup yet? Being set up is required to call runSimulator.
bool show_tree_
Display the device tree at every opportunity.
const SimulationConfiguration & getSimulationConfiguration() const
static DefaultValues DEFAULTS
Static DefaultValues for a SPARTA CommandLineSimulator.
const std::string & getUsage() const
Gets the usage string specified for this simulator at construction. This string is printed when usage...
std::unordered_map< std::string, app::ReportYamlReplacements > report_specific_yaml_placeholder_replacements_
Map to hold report-specific yaml placeholder key-value pairs. An example usage might be: <sim> –repor...
pevents::PeventCollectorController pevent_controller_
a pevent controller is used to parse in pevent on and off commands, and prepare collection for the sp...
bool no_run_mode_
Is this simulator in no-run mode where it quits just before finalization.
bool show_hidden_
Show hidden treenodes when displaying the device tree.
bool is_setup_
Has the simulator been setup through the populateSimulation method.
std::string runtime_clock_
The runtime clock to use for -r option.
bool no_show_config_
Should the trivialities of simulator configuration (e.g what command line options were specified) be ...
bool show_ports_
Display all ports in the device tree after finalization.
void runSimulator_(Simulation *sim, uint64_t ticks)
Implements runSimulator.
bool disable_colors_
Show hidden treenodes when displaying the device tree.
std::string power_config_file_
Destination to which power configuration (to be read by power model) will be written ("" if not writt...
void populateSimulation(Simulation *sim)
Builds the content of the simulator making it ready to run.
CommandLineSimulator()=delete
Not default constructable.
Optional default values for the simulator which can be customized and provided by anyone instantiatin...
Collection of named feature values.
Class for containing multiple levels of boost program options.
Configuration applicator class that is used for configuring a simulator. Works in conjunction with sp...
Simulator which builds a sparta DeviceTree.
Simple class for recursively adding taps to pevents. There is probably a more efficient way than each...
Sparta Application framework.
Macros for handling exponential backoff.