The Sparta Modeling Framework
Loading...
Searching...
No Matches
SimulationConfiguration.hpp
Go to the documentation of this file.
1// <SimulationConfiguration> -*- C++ -*-
2
3
9#pragma once
10
11#include <cstdint>
12#include <vector>
13#include <set>
14#include <string>
15#include <memory>
16#include <list>
17#include <ostream>
18#include <type_traits>
19#include <utility>
20
21#include "sparta/sparta.hpp"
22#include "sparta/simulation/ParameterTree.hpp"
24#include "sparta/log/Tap.hpp"
29#include "sparta/utils/Utils.hpp"
30#include "sparta/extensions/TreeNodeExtensionManager.hpp"
31
32// Reuse hash<pair<string,string>>
33#include "sparta/report/format/DetailInfoData.hpp"
34
35namespace sparta {
36namespace app {
37
38constexpr char NoPipelineCollectionStr[] = "NOPREFIX_";
39
45{
46public:
50 std::vector<std::string> arch_search_dirs = {""};
51
57 std::string arch_arg_default = "";
58
63
68 std::string run_time_clock = "";
69
74 std::string inst_counter = "";
75
80 std::list<ParameterTemplate> other_meta_params = {};
81
89 std::string auto_summary_default = "off";
90
103 Strict, Relaxed
104 };
105 std::pair<std::string, RetiredInstPathStrictness> path_to_retired_inst_counter =
106 std::make_pair("rob.stats.total_number_retired",
107 RetiredInstPathStrictness::Relaxed);
108};
109
124{
125private:
126
128 const DefaultValues defaults_;
129
130public:
131
134
139 void processParameter(const std::string & pattern, const std::string & value,
140 bool optional = false);
141
146 void processConfigFile(const std::string & pattern, const std::string & filename,
147 bool is_final = false);
148
151 void processArch(const std::string & pattern,
152 const std::string & filename);
153
156 void enableLogging(const std::string & pattern,
157 const std::string & category,
158 const std::string & destination);
159
161 bool hasFinalConfig() const { return !final_config_file_.empty(); }
162
164 void setStateTrackingFile(const std::string & filename);
165
167 const std::string& getStateTrackingFilename() const;
168
170 void addControlFile(const std::string & filename);
171
173 const std::set<std::string> & getControlFiles() const;
174
176 void addRunMetadata(const std::string & name,
177 const std::string & value);
178
180 const std::vector<std::pair<std::string, std::string>> & getRunMetadata() const;
181
183 std::string stringizeRunMetadata() const;
184
186 std::string getFinalConfigFile() const { return final_config_file_; }
187
189 void setMemoryUsageDefFile(const std::string & def_file);
190
192 const std::string & getMemoryUsageDefFile() const;
193
196
199
204 void disablePrettyPrintReports(const std::string & format);
205
207 const std::set<std::string> & getDisabledPrettyPrintFormats() const;
208
213 void omitStatsWithValueZeroForReportFormat(const std::string & format);
214
216 const std::set<utils::lowercase_string> &
218
225
233
240 const ParameterTree& getUnboundParameterTree() const { return ptree_; }
241
248
254 const ParameterTree& getArchUnboundParameterTree() const { return arch_ptree_; }
255
259 bool archFileProvided() const { return arch_applicator_ != nullptr; }
260
262 void printArchConfigurations(std::ostream & os) const {
263 if(archFileProvided()) {
264 os << arch_applicator_->stringize();
265 }
266 else {
267 os << "<not provided>";
268 }
269 }
270
275 void addArchSearchPath(const std::string & dir) {
276 arch_search_paths_.emplace(arch_search_paths_.begin(), dir);
277 }
278
283 const std::vector<std::string> &getArchSearchPath() const {
284 return arch_search_paths_;
285 }
286
291 void addConfigSearchPath(const std::string & dir) {
292 config_search_paths_.emplace(config_search_paths_.begin(), dir);
293 }
294
299 const std::vector<std::string> & getConfigSearchPath() const {
300 return config_search_paths_;
301 }
302
307 void addReportDefnSearchPath(const std::string & dir) {
308 report_defn_search_paths_.emplace(report_defn_search_paths_.begin(), dir);
309 }
310
315 const std::vector<std::string> & getReportDefnSearchPaths() const {
316 return report_defn_search_paths_;
317 }
318
320 void printGenericConfigurations(std::ostream & os) const {
321 for(auto & cp : config_applicators_) {
322 os << " " << cp->stringize() << '\n';
323 }
324 }
325
329 enum class SignalMode
330 {
331 DISABLE_BACKTRACE_SIGNALS,
332 ENABLE_BACKTRACE_SIGNALS
333 };
334
340 DEBUG_DUMP_NEVER = 1,
341 DEBUG_DUMP_ERROR = 2,
342 DEBUG_DUMP_MAX = 3
343 };
344
349 DEBUG_DUMP_EVERYTHING,
350 DEBUG_DUMP_NOTHING,
351 DEBUG_DUMP_BACKTRACE_ONLY
352 };
353
357 enum class AutoSummaryState {
358 AUTO_SUMMARY_OFF = 0,
362 };
363
368 enum class TriggerSource {
369 TRIGGER_ON_NONE = 0,
370 TRIGGER_ON_CYCLE,
371 TRIGGER_ON_INSTRUCTION,
372 TRIGGER_ON_ROI
373 };
374
379 bool warn_stderr = true;
380
385 bool verbose_cfg = false;
386
391
395 bool debug_sim = false;
396
400 bool report_on_error = true;
401
408 SignalMode signal_mode{SignalMode::ENABLE_BACKTRACE_SIGNALS};
409
416
421
425 PostRunDebugDumpOptions debug_dump_options{PostRunDebugDumpOptions::DEBUG_DUMP_EVERYTHING};
426
430 std::string dump_debug_filename{"error-dump.dbg"};
431
435 uint64_t trigger_on_value = 0;
436
439 TriggerSource trigger_on_type{TriggerSource::TRIGGER_ON_NONE};
440
443 std::string trigger_clock;
444
448 bool validate_post_run = false;
449
453 std::string warnings_file{""};
454
458 bool show_dag = false;
459
464
469 std::string pipeline_collection_file_prefix = NoPipelineCollectionStr;
470
474 ReportDescVec reports;
475
480 {
481 public:
486 void setSimExecutable(const std::string & exe_name)
487 {
488 sim_exec_db_filename_ = exe_name + ".db";
489 }
490
496 void useAppFileLogger(const std::string & filename)
497 {
498 app_file_logger_filename_ = filename;
499 }
500
504 std::string getAppLoggerFilename() const
505 {
506 return app_file_logger_filename_;
507 }
508
516 void enableApp(const std::string & app_name)
517 {
518 sparta_assert(!appEnabled(app_name));
519 sparta_assert(!sim_exec_db_filename_.empty());
520
521 enabled_apps_.insert(app_name);
522 setAppCount(app_name, 1);
523 setAppDatabase(app_name, sim_exec_db_filename_);
524 }
525
529 bool appEnabled(const std::string & app_name) const
530 {
531 return enabled_apps_.count(app_name) > 0;
532 }
533
537 std::vector<std::string> getEnabledApps() const
538 {
539 return {enabled_apps_.begin(), enabled_apps_.end()};
540 }
541
545 void setAppCount(const std::string & app_name, size_t count)
546 {
547 sparta_assert(count > 0);
548 sparta_assert(appEnabled(app_name));
549 concrete_app_counts_[app_name] = count;
550 inferred_app_counts_.erase(app_name);
551 }
552
559 void inferAppCountFromTreePattern(const std::string & app_name, const std::string & pattern)
560 {
561 sparta_assert(!pattern.empty());
562 sparta_assert(appEnabled(app_name));
563 concrete_app_counts_.erase(app_name);
564 inferred_app_counts_[app_name] = pattern;
565 }
566
571 std::string getTreePatternForInferredAppCount(const std::string & app_name) const
572 {
573 if (!appEnabled(app_name)) {
574 throw SpartaException("App '") << app_name << "' is not enabled.";
575 }
576
577 auto it = inferred_app_counts_.find(app_name);
578 if (it != inferred_app_counts_.end()) {
579 return it->second;
580 }
581 return "";
582 }
583
588 size_t getAppCount(const std::string & app_name) const
589 {
590 if (!appEnabled(app_name)) {
591 return 0;
592 }
593
594 auto it = concrete_app_counts_.find(app_name);
595 if (it == concrete_app_counts_.end()) {
596 throw SpartaException("We do not know the app count yet. Has the tree been built?");
597 }
598 return it->second;
599 }
600
604 void setAppDatabase(const std::string & app_name, const std::string & db_file)
605 {
606 sparta_assert(appEnabled(app_name));
607 app_databases_[app_name] = db_file;
608 }
609
613 std::string getAppDatabase(const std::string & app_name) const
614 {
615 sparta_assert(appEnabled(app_name));
616 return app_databases_.at(app_name);
617 }
618
622 void reuseDatabase(const std::string & db_file)
623 {
624 reused_db_files_.insert(db_file);
625 }
626
630 bool shouldOverwriteDatabase(const std::string & db_file) const
631 {
632 return reused_db_files_.count(db_file) == 0;
633 }
634
643 {
644 if (!appEnabled("simdb-reports")) {
645 throw SpartaException()
646 << "Cannot disable legacy reports when simdb-reports app is not enabled";
647 }
648 legacy_reports_enabled_ = false;
649 }
650
657 {
658 return legacy_reports_enabled_;
659 }
660
665 void addPragmaOnOpen(const std::string& name, const std::string& val)
666 {
667 dbmgr_pragmas_[name] = val;
668 }
669
674 std::vector<std::pair<std::string, std::string>> getPragmas() const
675 {
676 std::vector<std::pair<std::string, std::string>> pragmas;
677 for (const auto & [name, val] : dbmgr_pragmas_)
678 {
679 pragmas.emplace_back(name, val);
680 }
681 return pragmas;
682 }
683
684 private:
685 std::string sim_exec_db_filename_;
686 std::string app_file_logger_filename_;
687 std::set<std::string> enabled_apps_;
688 std::map<std::string, size_t> concrete_app_counts_;
689 std::map<std::string, std::string> inferred_app_counts_;
690 std::map<std::string, std::string> app_databases_;
691 std::set<std::string> reused_db_files_;
692 std::map<std::string, std::string> dbmgr_pragmas_;
693 bool legacy_reports_enabled_ = true;
694 } simdb_config;
695
702 TreeNodeExtensionManager extension_mgr;
703
718
726
730 std::pair<std::string, app::DefaultValues::RetiredInstPathStrictness> path_to_retired_inst_counter =
731 std::make_pair(defaults_.path_to_retired_inst_counter.first,
732 app::DefaultValues::RetiredInstPathStrictness::Relaxed);
733
735 const DefaultValues & getDefaults() const { return defaults_; }
736
738 const log::TapDescVec & getTaps() const { return taps_; }
739
743 void setConsumed() const { is_consumed_ = true; }
744
745private:
746
748 mutable bool is_consumed_ = false;
749
751 // Simulation configuration, your -c, -p, --arch flags from Command line
752
754 std::string final_config_file_ = "";
755
757 std::string memory_usage_def_file_;
758
761 bool generate_stats_mapping_ = false;
762
765 std::set<std::string> disabled_pretty_print_report_formats_;
766
769 std::set<utils::lowercase_string> zero_values_omitted_report_formats_;
770
772 ParameterTree arch_ptree_;
773
775 ParameterTree ptree_;
776
778 std::vector<std::string> arch_search_paths_;
779
781 std::vector<std::string> config_search_paths_ = {"./"};
782
784 std::vector<std::string> report_defn_search_paths_;
785
787 std::set<std::string> simulation_control_filenames_;
788
790 std::vector<std::pair<std::string, std::string>> run_metadata_;
791
793 std::unique_ptr<ArchNodeConfigFileApplicator> arch_applicator_;
794
796 ConfigVec config_applicators_;
797
798 //
800
802 // Simulation logging
806 log::TapDescVec taps_;
807
809 std::string state_tracking_file_;
810
811 //
813};
814
815} // namespace app
816} // namespace sparta
Configuration Applicators.
Describes reports to instantiate and tracks their instantiations.
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Cool string utilities.
Virtual Parameter Tree. This represents a tree of parameters read from some source but does not neces...
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Optional default values for the simulator which can be customized and provided by anyone instantiatin...
std::list< ParameterTemplate > other_meta_params
std::vector< std::string > arch_search_dirs
size_t getAppCount(const std::string &app_name) const
Return the number of instances we should create for the given app.
void setAppDatabase(const std::string &app_name, const std::string &db_file)
Direct the given app to go to the provided database file.
void setAppCount(const std::string &app_name, size_t count)
Set the number of instances that should be available for the given app.
void disableLegacyReports()
When used together with –enable-simdb-reports, the option –disable-legacy-reports results in stats re...
std::vector< std::pair< std::string, std::string > > getPragmas() const
Get a list of name-value pairs for SQLite PRAGMA's to execute on database creation.
void useAppFileLogger(const std::string &filename)
Before creating any apps, call this method to enable all apps to have access to a single thread-safe ...
std::string getAppDatabase(const std::string &app_name) const
Get the database file for the given app.
void reuseDatabase(const std::string &db_file)
Tell SimDB to open the given file without overwriting it.
bool shouldOverwriteDatabase(const std::string &db_file) const
See if the given database should be overwritten or reused.
void inferAppCountFromTreePattern(const std::string &app_name, const std::string &pattern)
Set the number of instances that should be available for the given app using a device tree wildcard p...
void addPragmaOnOpen(const std::string &name, const std::string &val)
Add a SQLite PRAGMA to execute on database creation.
bool appEnabled(const std::string &app_name) const
Check if the given app is enabled.
void setSimExecutable(const std::string &exe_name)
Set the simulation executable. This will be used as the default database filename (with a ....
std::vector< std::string > getEnabledApps() const
Return a list of all enabled apps.
bool legacyReportsEnabled() const
See if legacy stats reports are enabled or not.
void enableApp(const std::string &app_name)
Tell the simulation to enable the given app. Unless otherwise specified, the database will be the exe...
std::string getAppLoggerFilename() const
Get the filename of the apps' shared file logger, if enabled.
std::string getTreePatternForInferredAppCount(const std::string &app_name) const
Get the device tree pattern from which to infer the number of instances of the given app we should cr...
Configuration applicator class that is used for configuring a simulator. Works in conjunction with sp...
const DefaultValues & getDefaults() const
Get the defaults this configuration was made with.
const std::vector< std::string > & getArchSearchPath() const
Get the arch search paths.
std::string getFinalConfigFile() const
Get the final config file name.
const std::vector< std::string > & getReportDefnSearchPaths() const
bool hasFinalConfig() const
Was a final configuration file provided?
void omitStatsWithValueZeroForReportFormat(const std::string &format)
const std::vector< std::pair< std::string, std::string > > & getRunMetadata() const
Get run metadata as key-value pairs.
void addReportDefnSearchPath(const std::string &dir)
const std::string & getStateTrackingFilename() const
Get the State Tracking filename.
const ParameterTree & getArchUnboundParameterTree() const
const std::set< std::string > & getDisabledPrettyPrintFormats() const
Get all report file extensions which have had their pretty printing disabled.
void printArchConfigurations(std::ostream &os) const
Print the ArchNodeConfigFileApplicator for informative messages.
void processConfigFile(const std::string &pattern, const std::string &filename, bool is_final=false)
void addRunMetadata(const std::string &name, const std::string &value)
Add run metadata as a string.
const std::vector< std::string > & getConfigSearchPath() const
Get the search paths for the configure files.
void printGenericConfigurations(std::ostream &os) const
Print the generic configurations for informative messages.
const std::set< utils::lowercase_string > & getReportFormatsWhoOmitStatsWithValueZero() const
Get all report formats which are to omit all SI values that are zero.
void setMemoryUsageDefFile(const std::string &def_file)
Set filename which contains heap profiler settings.
void addConfigSearchPath(const std::string &dir)
SignalMode
Controls installation of signal handlers.
void addControlFile(const std::string &filename)
Consume a simulation control file.
const std::string & getMemoryUsageDefFile() const
Get filename for heap profiler configuration.
SimulationConfiguration(const DefaultValues &defaults=DefaultValues())
Create a SimulationConfiguration.
bool shouldGenerateStatsMapping() const
Get statistics mapping "enabled" flag.
std::string stringizeRunMetadata() const
Get run metadata stringized as "name1=value1,name2=value2,...".
void disablePrettyPrintReports(const std::string &format)
const log::TapDescVec & getTaps() const
Get the taps vector.
const ParameterTree & getUnboundParameterTree() const
void setStateTrackingFile(const std::string &filename)
Set the filename for the State Tracking file.
void enableLogging(const std::string &pattern, const std::string &category, const std::string &destination)
@ DEBUG_DUMP_NEVER
Never dump debug data after running.
@ DEBUG_DUMP_ERROR
Dump debug data only if there is an error while running.
@ DEBUG_DUMP_ALWAYS
Dump debug data in all cases after running.
void generateStatsMapping()
Auto-generate mappings from report column headers to statistic names.
void processParameter(const std::string &pattern, const std::string &value, bool optional=false)
const std::set< std::string > & getControlFiles() const
Get all control files for this simulation.
void processArch(const std::string &pattern, const std::string &filename)
Macros for handling exponential backoff.