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
155 void processExtensionFile(const std::string & filename);
156
159 void enableLogging(const std::string & pattern,
160 const std::string & category,
161 const std::string & destination);
162
164 bool hasFinalConfig() const { return !final_config_file_.empty(); }
165
167 void setStateTrackingFile(const std::string & filename);
168
170 const std::string& getStateTrackingFilename() const;
171
173 void addControlFile(const std::string & filename);
174
176 const std::set<std::string> & getControlFiles() const;
177
179 void addRunMetadata(const std::string & name,
180 const std::string & value);
181
183 const std::vector<std::pair<std::string, std::string>> & getRunMetadata() const;
184
186 std::string stringizeRunMetadata() const;
187
189 std::string getFinalConfigFile() const { return final_config_file_; }
190
192 void setMemoryUsageDefFile(const std::string & def_file);
193
195 const std::string & getMemoryUsageDefFile() const;
196
199
202
207 void disablePrettyPrintReports(const std::string & format);
208
210 const std::set<std::string> & getDisabledPrettyPrintFormats() const;
211
216 void omitStatsWithValueZeroForReportFormat(const std::string & format);
217
219 const std::set<utils::lowercase_string> &
221
228
236
243 const ParameterTree& getUnboundParameterTree() const { return ptree_; }
244
251
257 const ParameterTree& getArchUnboundParameterTree() const { return arch_ptree_; }
258
262 bool archFileProvided() const { return arch_applicator_ != nullptr; }
263
265 void printArchConfigurations(std::ostream & os) const {
266 if(archFileProvided()) {
267 os << arch_applicator_->stringize();
268 }
269 else {
270 os << "<not provided>";
271 }
272 }
273
278 void addArchSearchPath(const std::string & dir) {
279 arch_search_paths_.emplace(arch_search_paths_.begin(), dir);
280 }
281
286 const std::vector<std::string> &getArchSearchPath() const {
287 return arch_search_paths_;
288 }
289
294 void addConfigSearchPath(const std::string & dir) {
295 config_search_paths_.emplace(config_search_paths_.begin(), dir);
296 }
297
302 const std::vector<std::string> & getConfigSearchPath() const {
303 return config_search_paths_;
304 }
305
310 void addReportDefnSearchPath(const std::string & dir) {
311 report_defn_search_paths_.emplace(report_defn_search_paths_.begin(), dir);
312 }
313
318 const std::vector<std::string> & getReportDefnSearchPaths() const {
319 return report_defn_search_paths_;
320 }
321
323 void printGenericConfigurations(std::ostream & os) const {
324 for(auto & cp : config_applicators_) {
325 os << " " << cp->stringize() << '\n';
326 }
327 }
328
332 enum class SignalMode
333 {
334 DISABLE_BACKTRACE_SIGNALS,
335 ENABLE_BACKTRACE_SIGNALS
336 };
337
343 DEBUG_DUMP_NEVER = 1,
344 DEBUG_DUMP_ERROR = 2,
345 DEBUG_DUMP_MAX = 3
346 };
347
352 DEBUG_DUMP_EVERYTHING,
353 DEBUG_DUMP_NOTHING,
354 DEBUG_DUMP_BACKTRACE_ONLY
355 };
356
360 enum class AutoSummaryState {
361 AUTO_SUMMARY_OFF = 0,
365 };
366
371 enum class TriggerSource {
372 TRIGGER_ON_NONE = 0,
373 TRIGGER_ON_CYCLE,
374 TRIGGER_ON_INSTRUCTION,
375 TRIGGER_ON_ROI
376 };
377
382 bool warn_stderr = true;
383
388 bool verbose_cfg = false;
389
394
398 bool debug_sim = false;
399
403 bool report_on_error = true;
404
411 SignalMode signal_mode{SignalMode::ENABLE_BACKTRACE_SIGNALS};
412
419
424
428 PostRunDebugDumpOptions debug_dump_options{PostRunDebugDumpOptions::DEBUG_DUMP_EVERYTHING};
429
433 std::string dump_debug_filename{"error-dump.dbg"};
434
438 uint64_t trigger_on_value = 0;
439
442 TriggerSource trigger_on_type{TriggerSource::TRIGGER_ON_NONE};
443
446 std::string trigger_clock;
447
451 bool validate_post_run = false;
452
456 std::string warnings_file{""};
457
461 bool show_dag = false;
462
467
472 std::string pipeline_collection_filepath = NoPipelineCollectionStr;
473
479
483 ReportDescVec reports;
484
489 {
490 public:
495 void setSimExecutable(const std::string & exe_name)
496 {
497 sim_exec_db_filename_ = exe_name + ".db";
498 }
499
507 void enableApp(const std::string & app_name)
508 {
509 sparta_assert(!appEnabled(app_name));
510 sparta_assert(!sim_exec_db_filename_.empty());
511
512 enabled_apps_.insert(app_name);
513 setAppCount(app_name, 1);
514 setAppDatabase(app_name, sim_exec_db_filename_);
515 }
516
520 bool appEnabled(const std::string & app_name) const
521 {
522 return enabled_apps_.count(app_name) > 0;
523 }
524
528 std::vector<std::string> getEnabledApps() const
529 {
530 return {enabled_apps_.begin(), enabled_apps_.end()};
531 }
532
536 void setAppCount(const std::string & app_name, size_t count)
537 {
538 sparta_assert(count > 0);
539 sparta_assert(appEnabled(app_name));
540 concrete_app_counts_[app_name] = count;
541 inferred_app_counts_.erase(app_name);
542 }
543
550 void inferAppCountFromTreePattern(const std::string & app_name, const std::string & pattern)
551 {
552 sparta_assert(!pattern.empty());
553 sparta_assert(appEnabled(app_name));
554 concrete_app_counts_.erase(app_name);
555 inferred_app_counts_[app_name] = pattern;
556 }
557
562 std::string getTreePatternForInferredAppCount(const std::string & app_name) const
563 {
564 if (!appEnabled(app_name)) {
565 throw SpartaException("App '") << app_name << "' is not enabled.";
566 }
567
568 auto it = inferred_app_counts_.find(app_name);
569 if (it != inferred_app_counts_.end()) {
570 return it->second;
571 }
572 return "";
573 }
574
579 size_t getAppCount(const std::string & app_name) const
580 {
581 if (!appEnabled(app_name)) {
582 return 0;
583 }
584
585 auto it = concrete_app_counts_.find(app_name);
586 if (it == concrete_app_counts_.end()) {
587 throw SpartaException("We do not know the app count yet. Has the tree been built?");
588 }
589 return it->second;
590 }
591
595 void setAppDatabase(const std::string & app_name, const std::string & db_file)
596 {
597 sparta_assert(appEnabled(app_name));
598 app_databases_[app_name] = db_file;
599 }
600
604 std::string getAppDatabase(const std::string & app_name) const
605 {
606 sparta_assert(appEnabled(app_name));
607 return app_databases_.at(app_name);
608 }
609
613 void reuseDatabase(const std::string & db_file)
614 {
615 reused_db_files_.insert(db_file);
616 }
617
621 bool shouldOverwriteDatabase(const std::string & db_file) const
622 {
623 return reused_db_files_.count(db_file) == 0;
624 }
625
634 {
635 if (!appEnabled("simdb-reports")) {
636 throw SpartaException()
637 << "Cannot disable legacy reports when simdb-reports app is not enabled";
638 }
639 legacy_reports_enabled_ = false;
640 }
641
648 {
649 return legacy_reports_enabled_;
650 }
651
655 void enableVerboseMode(bool enable = true)
656 {
657 verbose_ = enable;
658 }
659
663 bool verboseMode() const
664 {
665 return verbose_;
666 }
667
672 void addPragmaOnOpen(const std::string& name, const std::string& val)
673 {
674 dbmgr_pragmas_[name] = val;
675 }
676
681 std::vector<std::pair<std::string, std::string>> getPragmas() const
682 {
683 std::vector<std::pair<std::string, std::string>> pragmas;
684 for (const auto & [name, val] : dbmgr_pragmas_)
685 {
686 pragmas.emplace_back(name, val);
687 }
688 return pragmas;
689 }
690
691 private:
692 std::string sim_exec_db_filename_;
693 std::set<std::string> enabled_apps_;
694 std::map<std::string, size_t> concrete_app_counts_;
695 std::map<std::string, std::string> inferred_app_counts_;
696 std::map<std::string, std::string> app_databases_;
697 std::set<std::string> reused_db_files_;
698 std::map<std::string, std::string> dbmgr_pragmas_;
699 bool legacy_reports_enabled_ = true;
700 bool verbose_ = false;
701 } simdb_config;
702
709 TreeNodeExtensionManager extension_mgr;
710
725
733
737 std::pair<std::string, app::DefaultValues::RetiredInstPathStrictness> path_to_retired_inst_counter =
738 std::make_pair(defaults_.path_to_retired_inst_counter.first,
739 app::DefaultValues::RetiredInstPathStrictness::Relaxed);
740
742 const DefaultValues & getDefaults() const { return defaults_; }
743
745 const log::TapDescVec & getTaps() const { return taps_; }
746
750 void setConsumed() const { is_consumed_ = true; }
751
752private:
753
755 mutable bool is_consumed_ = false;
756
758 // Simulation configuration, your -c, -p, --arch flags from Command line
759
761 std::string final_config_file_ = "";
762
764 std::string memory_usage_def_file_;
765
768 bool generate_stats_mapping_ = false;
769
772 std::set<std::string> disabled_pretty_print_report_formats_;
773
776 std::set<utils::lowercase_string> zero_values_omitted_report_formats_;
777
779 ParameterTree arch_ptree_;
780
782 ParameterTree ptree_;
783
790 enum ExtensionsOrderOfOps : uint32_t
791 {
792 FROM_ARCH_YAML_WITH_WILDCARDS = 0,
793 FROM_CONFIG_YAML_OR_PARAM_WITH_WILDCARDS,
794 FROM_EXT_YAML_WITH_WILDCARDS,
795 FROM_ARCH_YAML_WITHOUT_WILDCARDS,
796 FROM_CONFIG_YAML_OR_PARAM_WITHOUT_WILDCARDS,
797 FROM_EXT_YAML_WITHOUT_WILDCARDS,
798 __N
799 };
800
803 std::array<ParameterTree, ExtensionsOrderOfOps::__N> extension_ptrees_;
804
807 static void extractPTreeExtensions_(
808 const ParameterTree & source_ptree,
809 ParameterTree & no_extensions,
810 ParameterTree & only_extensions);
811
815 static void splitExtensionPTree_(
816 const ParameterTree & source_ptree,
817 ParameterTree & wildcard_extensions,
818 ParameterTree & concrete_extensions);
819
821 std::vector<std::string> arch_search_paths_;
822
824 std::vector<std::string> config_search_paths_ = {"./"};
825
827 std::vector<std::string> report_defn_search_paths_;
828
830 std::set<std::string> simulation_control_filenames_;
831
833 std::vector<std::pair<std::string, std::string>> run_metadata_;
834
836 std::unique_ptr<ArchNodeConfigFileApplicator> arch_applicator_;
837
839 ConfigVec config_applicators_;
840
841 //
843
845 // Simulation logging
849 log::TapDescVec taps_;
850
852 std::string state_tracking_file_;
853
854 //
856};
857
858} // namespace app
859} // 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...
void enableVerboseMode(bool enable=true)
Call the setVerbose() method for all SimDB apps once created.
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.
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 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.
utils::ValidValue< size_t > pipeline_collection_heartbeat
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 processExtensionFile(const std::string &filename)
Consume a yaml file with extensions (–extension-file(s))
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)
Provides a wrapper around a value to ensure that the value is assigned.
Macros for handling exponential backoff.