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_file_prefix = NoPipelineCollectionStr;
473
477 ReportDescVec reports;
478
483 {
484 public:
489 void setSimExecutable(const std::string & exe_name)
490 {
491 sim_exec_db_filename_ = exe_name + ".db";
492 }
493
499 void useAppFileLogger(const std::string & filename)
500 {
501 app_file_logger_filename_ = filename;
502 }
503
507 std::string getAppLoggerFilename() const
508 {
509 return app_file_logger_filename_;
510 }
511
519 void enableApp(const std::string & app_name)
520 {
521 sparta_assert(!appEnabled(app_name));
522 sparta_assert(!sim_exec_db_filename_.empty());
523
524 enabled_apps_.insert(app_name);
525 setAppCount(app_name, 1);
526 setAppDatabase(app_name, sim_exec_db_filename_);
527 }
528
532 bool appEnabled(const std::string & app_name) const
533 {
534 return enabled_apps_.count(app_name) > 0;
535 }
536
540 std::vector<std::string> getEnabledApps() const
541 {
542 return {enabled_apps_.begin(), enabled_apps_.end()};
543 }
544
548 void setAppCount(const std::string & app_name, size_t count)
549 {
550 sparta_assert(count > 0);
551 sparta_assert(appEnabled(app_name));
552 concrete_app_counts_[app_name] = count;
553 inferred_app_counts_.erase(app_name);
554 }
555
562 void inferAppCountFromTreePattern(const std::string & app_name, const std::string & pattern)
563 {
564 sparta_assert(!pattern.empty());
565 sparta_assert(appEnabled(app_name));
566 concrete_app_counts_.erase(app_name);
567 inferred_app_counts_[app_name] = pattern;
568 }
569
574 std::string getTreePatternForInferredAppCount(const std::string & app_name) const
575 {
576 if (!appEnabled(app_name)) {
577 throw SpartaException("App '") << app_name << "' is not enabled.";
578 }
579
580 auto it = inferred_app_counts_.find(app_name);
581 if (it != inferred_app_counts_.end()) {
582 return it->second;
583 }
584 return "";
585 }
586
591 size_t getAppCount(const std::string & app_name) const
592 {
593 if (!appEnabled(app_name)) {
594 return 0;
595 }
596
597 auto it = concrete_app_counts_.find(app_name);
598 if (it == concrete_app_counts_.end()) {
599 throw SpartaException("We do not know the app count yet. Has the tree been built?");
600 }
601 return it->second;
602 }
603
607 void setAppDatabase(const std::string & app_name, const std::string & db_file)
608 {
609 sparta_assert(appEnabled(app_name));
610 app_databases_[app_name] = db_file;
611 }
612
616 std::string getAppDatabase(const std::string & app_name) const
617 {
618 sparta_assert(appEnabled(app_name));
619 return app_databases_.at(app_name);
620 }
621
625 void reuseDatabase(const std::string & db_file)
626 {
627 reused_db_files_.insert(db_file);
628 }
629
633 bool shouldOverwriteDatabase(const std::string & db_file) const
634 {
635 return reused_db_files_.count(db_file) == 0;
636 }
637
646 {
647 if (!appEnabled("simdb-reports")) {
648 throw SpartaException()
649 << "Cannot disable legacy reports when simdb-reports app is not enabled";
650 }
651 legacy_reports_enabled_ = false;
652 }
653
660 {
661 return legacy_reports_enabled_;
662 }
663
668 void addPragmaOnOpen(const std::string& name, const std::string& val)
669 {
670 dbmgr_pragmas_[name] = val;
671 }
672
677 std::vector<std::pair<std::string, std::string>> getPragmas() const
678 {
679 std::vector<std::pair<std::string, std::string>> pragmas;
680 for (const auto & [name, val] : dbmgr_pragmas_)
681 {
682 pragmas.emplace_back(name, val);
683 }
684 return pragmas;
685 }
686
687 private:
688 std::string sim_exec_db_filename_;
689 std::string app_file_logger_filename_;
690 std::set<std::string> enabled_apps_;
691 std::map<std::string, size_t> concrete_app_counts_;
692 std::map<std::string, std::string> inferred_app_counts_;
693 std::map<std::string, std::string> app_databases_;
694 std::set<std::string> reused_db_files_;
695 std::map<std::string, std::string> dbmgr_pragmas_;
696 bool legacy_reports_enabled_ = true;
697 } simdb_config;
698
705 TreeNodeExtensionManager extension_mgr;
706
721
729
733 std::pair<std::string, app::DefaultValues::RetiredInstPathStrictness> path_to_retired_inst_counter =
734 std::make_pair(defaults_.path_to_retired_inst_counter.first,
735 app::DefaultValues::RetiredInstPathStrictness::Relaxed);
736
738 const DefaultValues & getDefaults() const { return defaults_; }
739
741 const log::TapDescVec & getTaps() const { return taps_; }
742
746 void setConsumed() const { is_consumed_ = true; }
747
748private:
749
751 mutable bool is_consumed_ = false;
752
754 // Simulation configuration, your -c, -p, --arch flags from Command line
755
757 std::string final_config_file_ = "";
758
760 std::string memory_usage_def_file_;
761
764 bool generate_stats_mapping_ = false;
765
768 std::set<std::string> disabled_pretty_print_report_formats_;
769
772 std::set<utils::lowercase_string> zero_values_omitted_report_formats_;
773
775 ParameterTree arch_ptree_;
776
778 ParameterTree ptree_;
779
786 enum ExtensionsOrderOfOps : uint32_t
787 {
788 FROM_ARCH_YAML_WITH_WILDCARDS = 0,
789 FROM_CONFIG_YAML_OR_PARAM_WITH_WILDCARDS,
790 FROM_EXT_YAML_WITH_WILDCARDS,
791 FROM_ARCH_YAML_WITHOUT_WILDCARDS,
792 FROM_CONFIG_YAML_OR_PARAM_WITHOUT_WILDCARDS,
793 FROM_EXT_YAML_WITHOUT_WILDCARDS,
794 __N
795 };
796
799 std::array<ParameterTree, ExtensionsOrderOfOps::__N> extension_ptrees_;
800
803 static void extractPTreeExtensions_(
804 const ParameterTree & source_ptree,
805 ParameterTree & no_extensions,
806 ParameterTree & only_extensions);
807
811 static void splitExtensionPTree_(
812 const ParameterTree & source_ptree,
813 ParameterTree & wildcard_extensions,
814 ParameterTree & concrete_extensions);
815
817 std::vector<std::string> arch_search_paths_;
818
820 std::vector<std::string> config_search_paths_ = {"./"};
821
823 std::vector<std::string> report_defn_search_paths_;
824
826 std::set<std::string> simulation_control_filenames_;
827
829 std::vector<std::pair<std::string, std::string>> run_metadata_;
830
832 std::unique_ptr<ArchNodeConfigFileApplicator> arch_applicator_;
833
835 ConfigVec config_applicators_;
836
837 //
839
841 // Simulation logging
845 log::TapDescVec taps_;
846
848 std::string state_tracking_file_;
849
850 //
852};
853
854} // namespace app
855} // 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 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)
Macros for handling exponential backoff.