The Sparta Modeling Framework
Loading...
Searching...
No Matches
main.cpp
1// <main.cpp> -*- C++ -*-
2
3
4#include <iostream>
5
6#include "ExampleSimulation.hpp" // Core model example simulator
7
8#include "sparta/parsers/ConfigEmitterYAML.hpp"
11#include "sparta/sparta.hpp"
12
13// User-friendly usage that correspond with sparta::app::CommandLineSimulator
14// options
15const char USAGE[] =
16 "Usage:\n"
17 " [-i insts] [-r RUNTIME] [--show-tree] [--show-dag]\n"
18 " [-p PATTERN VAL] [-c FILENAME]\n"
19 " [--node-config-file PATTERN FILENAME]\n"
20 " [-l PATTERN CATEGORY DEST]\n"
21 " [-h]\n"
22 "\n";
23
24constexpr char VERSION_VARNAME[] = "version";
25
26
27int main(int argc, char **argv)
28{
29 uint64_t ilimit = 0;
30 uint32_t num_cores = 1;
31
33 DEFAULTS.auto_summary_default = "on";
34
36 argc, argv, "", "", {});
37
38 // try/catch block to ensure proper destruction of the cls/sim classes in
39 // the event of an error
40 try{
41 // Helper class for parsing command line arguments, setting up the
42 // simulator, and running the simulator. All of the things done by this
43 // classs can be done manually if desired. Use the source for the
44 // CommandLineSimulator class as a starting point
45 sparta::app::CommandLineSimulator cls(USAGE, DEFAULTS);
46 auto& app_opts = cls.getApplicationOptions();
47 app_opts.add_options()
48 (VERSION_VARNAME,
49 "produce version message",
50 "produce version message") // Brief
51 ("instruction-limit,i",
52 sparta::app::named_value<uint64_t>("LIMIT", &ilimit)->default_value(ilimit),
53 "Limit the simulation to retiring a specific number of instructions. 0 (default) "
54 "means no limit. If -r is also specified, the first limit reached ends the simulation",
55 "End simulation after a number of instructions. Note that if set to 0, this may be "
56 "overridden by a node parameter within the simulator")
57 ("num-cores",
58 sparta::app::named_value<uint32_t>("CORES", &num_cores)->default_value(1),
59 "The number of cores in simulation", "The number of cores in simulation")
60 ("show-factories",
61 "Show the registered factories");
62
63 // Add any positional command-line options
64 // po::positional_options_description& pos_opts = cls.getPositionalOptions();
65 // (void)pos_opts;
66 // pos_opts.add(TRACE_POS_VARNAME, -1); // example
67
68 // Parse command line options and configure simulator
69 int err_code = 0;
70 if(!cls.parse(argc, argv, err_code)){
71 return err_code; // Any errors already printed to cerr
72 }
73
74 bool show_factories = false;
75 auto& vm = cls.getVariablesMap();
76 if(vm.count("show-factories") != 0) {
77 show_factories = true;
78 }
79
80 // Create the simulator
81 sparta::Scheduler scheduler;
82 ExampleSimulator sim("core_topology_1",
83 scheduler,
84 num_cores, // cores
85 ilimit,
86 show_factories); // run for ilimit instructions
87
88 cls.populateSimulation(&sim);
89
90 cls.runSimulator(&sim);
91
92 cls.postProcess(&sim);
93
94 }catch(...){
95 // Could still handle or log the exception here
96 throw;
97 }
98 return 0;
99}
Class for creating a simulator based on command-line arguments.
Wrapper for boost program_options option_description that allows multiple levels of detail.
ExampleSimulator which builds the model and configures it.
A class that lets you schedule events now and in the future.
Contains information describing the simulation instance for the purpose of identifying the simulation...
static SimulationInfo & getInstance()
Gets the SimulationInfo singleton instance.
Command line simulator front-end class with argument parsing Works in conjunction with sparta::app::S...
Optional default values for the simulator which can be customized and provided by anyone instantiatin...