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
30// Reuse hash<pair<string,string>>
31#include "sparta/report/format/DetailInfoData.hpp"
32
33namespace sparta {
34namespace app {
35
36constexpr char NoPipelineCollectionStr[] = "NOPREFIX_";
37
43{
44public:
48 std::vector<std::string> arch_search_dirs = {""};
49
55 std::string arch_arg_default = "";
56
61
66 std::string run_time_clock = "";
67
72 std::string inst_counter = "";
73
78 std::list<ParameterTemplate> other_meta_params = {};
79
87 std::string auto_summary_default = "off";
88
101 Strict, Relaxed
102 };
103 std::pair<std::string, RetiredInstPathStrictness> path_to_retired_inst_counter =
104 std::make_pair("rob.stats.total_number_retired",
105 RetiredInstPathStrictness::Relaxed);
106};
107
122{
123private:
124
126 const DefaultValues defaults_;
127
128public:
129
132
137 void processParameter(const std::string & pattern, const std::string & value,
138 bool optional = false);
139
144 void processConfigFile(const std::string & pattern, const std::string & filename,
145 bool is_final = false);
146
149 void processArch(const std::string & pattern,
150 const std::string & filename);
151
154 void enableLogging(const std::string & pattern,
155 const std::string & category,
156 const std::string & destination);
157
159 bool hasFinalConfig() const { return !final_config_file_.empty(); }
160
162 void processExtensionFile(const std::string & filename);
163
165 void setStateTrackingFile(const std::string & filename);
166
168 const std::string& getStateTrackingFilename() const;
169
171 void addControlFile(const std::string & filename);
172
174 const std::set<std::string> & getControlFiles() const;
175
177 void addRunMetadata(const std::string & name,
178 const std::string & value);
179
181 const std::vector<std::pair<std::string, std::string>> & getRunMetadata() const;
182
184 std::string stringizeRunMetadata() const;
185
187 std::string getFinalConfigFile() const { return final_config_file_; }
188
190 void setMemoryUsageDefFile(const std::string & def_file);
191
193 const std::string & getMemoryUsageDefFile() const;
194
197
200
205 void disablePrettyPrintReports(const std::string & format);
206
208 const std::set<std::string> & getDisabledPrettyPrintFormats() const;
209
214 void omitStatsWithValueZeroForReportFormat(const std::string & format);
215
217 const std::set<utils::lowercase_string> &
219
226
231
239
246 const ParameterTree& getUnboundParameterTree() const { return ptree_; }
247
254
260 const ParameterTree& getArchUnboundParameterTree() const { return arch_ptree_; }
261
267 return extensions_ptree_;
268 }
269
276 return extensions_ptree_;
277 }
278
282 bool archFileProvided() const { return arch_applicator_ != nullptr; }
283
285 void printArchConfigurations(std::ostream & os) const {
286 if(archFileProvided()) {
287 os << arch_applicator_->stringize();
288 }
289 else {
290 os << "<not provided>";
291 }
292 }
293
298 void addArchSearchPath(const std::string & dir) {
299 arch_search_paths_.emplace(arch_search_paths_.begin(), dir);
300 }
301
306 const std::vector<std::string> &getArchSearchPath() const {
307 return arch_search_paths_;
308 }
309
314 void addConfigSearchPath(const std::string & dir) {
315 config_search_paths_.emplace(config_search_paths_.begin(), dir);
316 }
317
322 const std::vector<std::string> & getConfigSearchPath() const {
323 return config_search_paths_;
324 }
325
330 void addReportDefnSearchPath(const std::string & dir) {
331 report_defn_search_paths_.emplace(report_defn_search_paths_.begin(), dir);
332 }
333
338 const std::vector<std::string> & getReportDefnSearchPaths() const {
339 return report_defn_search_paths_;
340 }
341
343 void printGenericConfigurations(std::ostream & os) const {
344 for(auto & cp : config_applicators_) {
345 os << " " << cp->stringize() << '\n';
346 }
347 }
348
352 enum class SignalMode
353 {
354 DISABLE_BACKTRACE_SIGNALS,
355 ENABLE_BACKTRACE_SIGNALS
356 };
357
363 DEBUG_DUMP_NEVER = 1,
364 DEBUG_DUMP_ERROR = 2,
365 DEBUG_DUMP_MAX = 3
366 };
367
372 DEBUG_DUMP_EVERYTHING,
373 DEBUG_DUMP_NOTHING,
374 DEBUG_DUMP_BACKTRACE_ONLY
375 };
376
380 enum class AutoSummaryState {
381 AUTO_SUMMARY_OFF = 0,
385 };
386
391 enum class TriggerSource {
392 TRIGGER_ON_NONE = 0,
393 TRIGGER_ON_CYCLE,
394 TRIGGER_ON_INSTRUCTION,
395 TRIGGER_ON_ROI
396 };
397
402 bool warn_stderr = true;
403
408 bool verbose_cfg = false;
409
414
418 bool debug_sim = false;
419
423 bool report_on_error = true;
424
431 SignalMode signal_mode{SignalMode::ENABLE_BACKTRACE_SIGNALS};
432
439
444
448 PostRunDebugDumpOptions debug_dump_options{PostRunDebugDumpOptions::DEBUG_DUMP_EVERYTHING};
449
453 std::string dump_debug_filename{"error-dump.dbg"};
454
458 uint64_t trigger_on_value = 0;
459
462 TriggerSource trigger_on_type{TriggerSource::TRIGGER_ON_NONE};
463
466 std::string trigger_clock;
467
471 bool validate_post_run = false;
472
476 std::string warnings_file{""};
477
481 bool show_dag = false;
482
487
492 std::string pipeline_collection_file_prefix = NoPipelineCollectionStr;
493
497 ReportDescVec reports;
498
503 {
504 public:
505 void setGlobalDatabaseFile(const std::string & db_file)
506 {
507 global_simdb_file_ = db_file;
508 }
509
510 void disableLegacyReports()
511 {
512 if (!appEnabled("simdb-reports")) {
513 throw SpartaException()
514 << "Cannot disable legacy reports when simdb-reports app is not enabled";
515 }
516 legacy_reports_enabled_ = false;
517 }
518
519 bool legacyReportsEnabled() const
520 {
521 return legacy_reports_enabled_;
522 }
523
524 void enableApp(const std::string & app_name, const std::string & db_file, size_t num_instances = 1)
525 {
526 enabled_apps_[db_file].insert(app_name);
527 app_db_files_[app_name].insert(db_file);
528 enabled_app_counts_[std::make_pair(app_name, db_file)] = num_instances;
529 }
530
531 bool appEnabled(const std::string & app_name) const
532 {
533 return app_db_files_.count(app_name) > 0;
534 }
535
536 std::vector<std::string> getEnabledApps() const
537 {
538 std::vector<std::string> apps;
539 for (const auto& [app_name, db_files] : app_db_files_)
540 {
541 apps.emplace_back(app_name);
542 }
543 return apps;
544 }
545
546 size_t getAppInstances(const std::string & app_name, const std::string & db_file) const
547 {
548 auto key = std::make_pair(app_name, db_file);
549 auto it = enabled_app_counts_.find(key);
550 if (it == enabled_app_counts_.end()) {
551 return 0;
552 }
553 return it->second;
554 }
555
556 std::vector<std::string> getAppDatabases(const std::string & app_name) const
557 {
558 auto it = app_db_files_.find(app_name);
559 if (it != app_db_files_.end()) {
560 return {it->second.begin(), it->second.end()};
561 } else {
562 return {};
563 }
564 }
565
566 //Call this once prior to calling Simulation::configure()
567 void finalize()
568 {
569 if (global_simdb_file_.empty())
570 {
571 return;
572 }
573
574 //Try to set the global SimDB file.
575 // --simdb-apps test.db app1 --simdb-file out.db
576 // >> send app1 to out.db
577 // --simdb-apps test.db app1 --enable-simdb-reports reports.db --simdb-file out.db
578 // >> send app1 to out.db
579 // >> send 'simdb-reports' (ReportStatsCollector) to out.db
580 // --simdb-apps foo.db app1 --simdb-apps bar.db app1 --simdb-file out.db
581 // >> THROW:
582 // >>>> one instance of app1 was to go to foo.db, the other to bar.db
583 // >>>> if we use only out.db, not clear if there should be two app1
584 // instances or just one
585 std::ostringstream errors;
586 for (const auto & [app_name, db_files] : app_db_files_) {
587 if (db_files.size() > 1) {
588 if (errors.str().empty()) {
589 errors << "Cannot use --simdb-file if any app is sent to two "
590 << "different databases:\n";
591 }
592 errors << " " << app_name << " is sent to:\n";
593 for (const auto & db_file : db_files) {
594 errors << " " << db_file << "\n";
595 }
596 }
597 }
598
599 const auto error = errors.str();
600 if (!error.empty()) {
601 throw SpartaException(error);
602 }
603
604 for (const auto & [app_name, db_files] : app_db_files_) {
605 for (const auto & db_file : db_files) {
606 auto key = std::make_pair(app_name, db_file);
607 const auto num_instances = enabled_app_counts_.at(key);
608 if (db_file != global_simdb_file_) {
609 std::cout << "Redirecting " << num_instances << " instance"
610 << (num_instances == 1 ? "" : "s") << " of the '"
611 << app_name << "' app from " << db_file << " to "
612 << global_simdb_file_ << "\n";
613 enableApp(app_name, global_simdb_file_, num_instances);
614 }
615 }
616 }
617
618 std::vector<std::string> old_db_files;
619 for (const auto & [db_file, _] : enabled_apps_) {
620 if (db_file != global_simdb_file_) {
621 old_db_files.push_back(db_file);
622 }
623 }
624
625 for (const auto & db_file : old_db_files) {
626 enabled_apps_.erase(db_file);
627 }
628
629 for (auto & [app_name, db_files] : app_db_files_) {
630 db_files.clear();
631 db_files.insert(global_simdb_file_);
632 }
633
634 std::vector<std::pair<std::string, std::string>> old_counts_kvps;
635 for (const auto & [key, num_instances] : enabled_app_counts_) {
636 if (key.second != global_simdb_file_) {
637 old_counts_kvps.push_back(key);
638 }
639 }
640
641 for (const auto & key : old_counts_kvps) {
642 enabled_app_counts_.erase(key);
643 }
644 }
645
646 //SQLite3 PRAGMA's to execute on database creation.
647 // "PRAGMA <name> = <val>"
648 void addPragmaOnOpen(const std::string& name, const std::string& val)
649 {
650 dbmgr_pragmas_[name] = val;
651 }
652
653 std::vector<std::pair<std::string, std::string>> getPragmas() const
654 {
655 std::vector<std::pair<std::string, std::string>> pragmas;
656 for (const auto & [name, val] : dbmgr_pragmas_)
657 {
658 pragmas.emplace_back(name, val);
659 }
660 return pragmas;
661 }
662
663 private:
664 std::string global_simdb_file_;
665 std::map<std::string, std::set<std::string>> enabled_apps_;
666 std::map<std::string, std::set<std::string>> app_db_files_;
667 std::unordered_map<std::pair<std::string, std::string>, size_t> enabled_app_counts_;
668 bool legacy_reports_enabled_ = true;
669 std::map<std::string, std::string> dbmgr_pragmas_;
670 } simdb_config;
671
686
694
698 std::pair<std::string, app::DefaultValues::RetiredInstPathStrictness> path_to_retired_inst_counter =
699 std::make_pair(defaults_.path_to_retired_inst_counter.first,
700 app::DefaultValues::RetiredInstPathStrictness::Relaxed);
701
703 const DefaultValues & getDefaults() const { return defaults_; }
704
706 const log::TapDescVec & getTaps() const { return taps_; }
707
711 void setConsumed() const { is_consumed_ = true; }
712
713private:
714
716 mutable bool is_consumed_ = false;
717
719 // Simulation configuration, your -c, -p, --arch flags from Command line
720
722 std::string final_config_file_ = "";
723
725 std::string memory_usage_def_file_;
726
729 bool generate_stats_mapping_ = false;
730
733 std::set<std::string> disabled_pretty_print_report_formats_;
734
737 std::set<utils::lowercase_string> zero_values_omitted_report_formats_;
738
740 ParameterTree arch_ptree_;
741
743 ParameterTree ptree_;
744
746 ParameterTree extensions_ptree_;
747
749 std::vector<std::string> arch_search_paths_;
750
752 std::vector<std::string> config_search_paths_ = {"./"};
753
755 std::vector<std::string> report_defn_search_paths_;
756
758 std::set<std::string> simulation_control_filenames_;
759
761 std::vector<std::pair<std::string, std::string>> run_metadata_;
762
764 std::unique_ptr<ArchNodeConfigFileApplicator> arch_applicator_;
765
767 ConfigVec config_applicators_;
768
769 //
771
773 // Simulation logging
777 log::TapDescVec taps_;
778
780 std::string state_tracking_file_;
781
782 //
784};
785
786} // namespace app
787} // namespace sparta
Configuration Applicators.
Describes reports to instantiate and tracks their instantiations.
Set of macros for Sparta assertions. Caught by the framework.
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
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 an extension (.yaml) file.
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.
const ParameterTree & getExtensionsUnboundParameterTree() const
Returns a ParameterTree (const version) containing an unbound set of named tree node extensions and t...
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)
ParameterTree & getExtensionsUnboundParameterTree()
Returns a ParameterTree containing an unbound set of named tree node extensions and their parameter v...
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.