7#include "ExampleSimulation.hpp"
9#include "CPUFactory.hpp"
12#include "sparta/utils/TimeManager.hpp"
15#include "sparta/trigger/ContextCounterTrigger.hpp"
21#include "sparta/report/DatabaseInterface.hpp"
22#include "simdb/schema/Schema.hpp"
23#include "simdb/TableProxy.hpp"
24#include "simdb/async/AsyncTaskEval.hpp"
25#include "simdb/impl/sqlite/SQLiteConnProxy.hpp"
26#include "simdb/impl/hdf5/HDF5ConnProxy.hpp"
27#include "simdb/utils/uuids.hpp"
28#include "simdb/utils/ObjectQuery.hpp"
33#include "Dispatch.hpp"
37#include "FlushManager.hpp"
38#include "Preloader.hpp"
39#include "CustomHistogramStats.hpp"
49 struct TestSQLiteSchemaA {
62 static TestSQLiteSchemaA createRandom() {
64 s.numbers.First = rand() / 1000 * 3.14;
65 s.numbers.Second = rand() / 1000 * 3.14;
66 s.metadata.Name = simdb::generateUUID();
67 s.metadata.Value = rand() / 1000 * 3.14;
74 struct TestSQLiteSchemaB {
87 static TestSQLiteSchemaB createRandom() {
89 s.strings.First = simdb::generateUUID();
90 s.strings.Second = simdb::generateUUID();
91 s.metadata.Name = simdb::generateUUID();
92 s.metadata.Value = simdb::generateUUID();
98 struct TestHDF5SchemaC {
103 static TestHDF5SchemaC createRandom() {
105 s.x = rand() / 1000 * 3.14;
106 s.y = rand() / 1000 * 3.14;
113namespace sparta_simdb {
126 const TestSQLiteSchemaA & createAndStoreRecordForSQLiteSchemaA() {
127 if (records_schemaA_.size() < 100) {
128 indices_schemaA_.emplace_back(records_schemaA_.size());
129 records_schemaA_.emplace_back(TestSQLiteSchemaA::createRandom());
130 return records_schemaA_.back();
132 indices_schemaA_.emplace_back(rand() % records_schemaA_.size());
133 return records_schemaA_[indices_schemaA_.back()];
137 const TestSQLiteSchemaB & createAndStoreRecordForSQLiteSchemaB() {
138 if (records_schemaB_.size() < 100) {
139 indices_schemaB_.emplace_back(records_schemaB_.size());
140 records_schemaB_.emplace_back(TestSQLiteSchemaB::createRandom());
141 return records_schemaB_.back();
143 indices_schemaB_.emplace_back(rand() % records_schemaB_.size());
144 return records_schemaB_[indices_schemaB_.back()];
148 const TestHDF5SchemaC & createAndStoreRecordForHDF5SchemaC() {
149 records_schemaC_.emplace_back(TestHDF5SchemaC::createRandom());
150 return records_schemaC_.back();
153 const std::vector<TestSQLiteSchemaA> & getWrittenRecordsForSchemaA()
const {
154 return records_schemaA_;
157 const std::vector<TestSQLiteSchemaB> & getWrittenRecordsForSchemaB()
const {
158 return records_schemaB_;
161 const std::vector<TestHDF5SchemaC> & getWrittenRecordsForSchemaC()
const {
162 return records_schemaC_;
165 void verifyRecords(
const std::string & db_file)
const {
166 simdb::ObjectManager obj_mgr(
".");
167 if (!obj_mgr.connectToExistingDatabase(db_file)) {
171 auto numeric_db = GET_DB_FROM_CURRENT_SIMULATION(NumericMeta);
174 numeric_db->createObjectQueryForTable(
"Numbers");
177 double first = 0, second = 0;
178 values_query->writeResultIterationsTo(
179 "First", &first,
"Second", &second);
181 if (values_query->countMatches() != indices_schemaA_.size()) {
185 auto result_iter = values_query->executeQuery();
186 size_t record_idx = 0;
187 while (result_iter->getNext()) {
188 const auto & expected = records_schemaA_[indices_schemaA_[record_idx]];
189 if (first != expected.numbers.First) {
192 if (second != expected.numbers.Second) {
200 numeric_db->createObjectQueryForTable(
"Metadata");
204 meta_query->writeResultIterationsTo(
"Name", &name,
"Value", &value);
206 if (meta_query->countMatches() != indices_schemaA_.size()) {
210 auto result_iter = meta_query->executeQuery();
211 size_t record_idx = 0;
212 while (result_iter->getNext()) {
213 const auto & expected = records_schemaA_[indices_schemaA_[record_idx]];
214 if (name != expected.metadata.Name) {
217 if (value != expected.metadata.Value) {
227 std::vector<TestSQLiteSchemaA> records_schemaA_;
228 std::vector<TestSQLiteSchemaB> records_schemaB_;
229 std::vector<TestHDF5SchemaC> records_schemaC_;
230 std::vector<uint16_t> indices_schemaA_;
231 std::vector<uint16_t> indices_schemaB_;
232 std::vector<uint16_t> indices_schemaC_;
262 void buildSchemaA(simdb::Schema & schema)
264 using dt = simdb::ColumnDataType;
266 schema.addTable(
"Numbers")
267 .addColumn(
"First", dt::double_t)
268 .addColumn(
"Second", dt::double_t);
270 schema.addTable(
"Metadata")
271 .addColumn(
"Name", dt::string_t)
272 .addColumn(
"Value", dt::double_t);
275 void buildSchemaB(simdb::Schema & schema)
277 using dt = simdb::ColumnDataType;
279 schema.addTable(
"Strings")
280 .addColumn(
"First", dt::string_t)
281 .addColumn(
"Second", dt::string_t);
283 schema.addTable(
"Metadata")
284 .addColumn(
"Name", dt::string_t)
285 .addColumn(
"Value", dt::string_t);
288 void buildSchemaC(simdb::Schema & schema)
290 using dt = simdb::ColumnDataType;
292 schema.addTable(
"Numbers")
293 .addField(
"x", dt::double_t, FOFFSET(TestHDF5SchemaC,x))
294 .addField(
"y", dt::double_t, FOFFSET(TestHDF5SchemaC,y))
295 .addField(
"z", dt::uint16_t, FOFFSET(TestHDF5SchemaC,z));
298 simdb::DbConnProxy * createSQLiteProxy()
300 return new simdb::SQLiteConnProxy;
303 simdb::DbConnProxy * createHDF5Proxy()
305 return new simdb::HDF5ConnProxy;
317 "baz", 0,
"Example parameter set to reproduce bug"))
322 uint32_t read()
const {
323 return int_param_->getValue();
327 std::unique_ptr<Parameter<uint32_t>> int_param_;
335 const std::string & desc) :
336 TreeNode(parent,
"baz_node",
"BazGroup", 0, desc)
342 void checkDbAccess(
const bool stop_checking =
false) {
343 if (stop_checking_db_access_) {
346 if (
auto dbconn = GET_DB_FOR_COMPONENT(Stats,
this)) {
349 (void) dbconn->findObject(
"ObjectManagersInDatabase", 1);
350 stop_checking_db_access_ = stop_checking;
356 <<
"' has parameter 'baz' with a value set to "
357 << baz_->read() << std::endl;
360 std::cout <<
"That's the ticket: "
361 << ext->getParameters()->getParameterValueAs<std::string>(
"ticket_") << std::endl;
366 std::unique_ptr<IntParameterSet> baz_;
367 bool stop_checking_db_access_ =
false;
372template <
typename DataT>
374 const std::string & param_name,
375 const DataT & expected_value)
381 if (actual_value != expected_value) {
383 <<
"\tParameter name: " << param_name
384 <<
"\nParameter value (actual): " << actual_value
385 <<
"\nParameter value (expected): " << expected_value;
389template <
typename DataT>
391 const std::string & param_name,
392 const std::set<DataT> & expected_values)
395 for (
const auto & expected : expected_values) {
398 validateParameter<DataT>(params, param_name, expected);
407 "encountered for '") << param_name <<
"'";
417 void doSomethingElse()
const {
418 std::cout <<
"Invoking a method that is unknown to the sparta::TreeNode object, "
419 "even though 'this' object was created by, and currently owned by, "
420 "a specific tree node.";
429 std::unique_ptr<sparta::Parameter<double>> degrees_;
434 virtual void postCreate()
override {
437 "degrees_", 360.0,
"Number of degrees in a circle", ps));
441double calculateAverageOfInternalCounters(
442 const std::vector<const sparta::CounterBase*> & counters)
445 for (
const auto & ctr : counters) {
448 return agg / counters.size();
453 if (
auto dbconn = GET_DB_FROM_CURRENT_SIMULATION(Stats)) {
456 (void) dbconn->findObject(
"ObjectManagersInDatabase", 1);
463 uint64_t instruction_limit,
464 bool show_factories) :
465 sparta::app::Simulation(
"sparta_core_example", &scheduler),
466 cpu_topology_(topology),
467 num_cores_(num_cores),
468 instruction_limit_(instruction_limit),
469 show_factories_(show_factories),
470 simdb_tester_(std::make_shared<sparta_simdb::DatabaseTester>())
482 controller_.reset(
new ExampleSimulator::ExampleController(
this));
489 sparta::trigger::ContextCounterTrigger::registerContextCounterCalcFunction(
490 "avg", &calculateAverageOfInternalCounters);
493 REGISTER_SIMDB_NAMESPACE(NumericMeta, SQLite);
494 REGISTER_SIMDB_SCHEMA_BUILDER(NumericMeta, buildSchemaA);
496 REGISTER_SIMDB_NAMESPACE(StringMeta, SQLite);
497 REGISTER_SIMDB_SCHEMA_BUILDER(StringMeta, buildSchemaB);
500 REGISTER_SIMDB_NAMESPACE(NumericVals, HDF5);
501 REGISTER_SIMDB_SCHEMA_BUILDER(NumericVals, buildSchemaC);
504 REGISTER_SIMDB_PROXY_CREATE_FUNCTION(HDF5, createHDF5Proxy);
507void ExampleSimulator::registerStatCalculationFcns_()
525ExampleSimulator::~ExampleSimulator()
528 if (on_triggered_notifier_registered_) {
529 getRoot()->DEREGISTER_FOR_NOTIFICATION(
530 onTriggered_, std::string,
"sparta_expression_trigger_fired");
533 if (simdb_perf_async_ctrl_enabled_) {
534 std::set<std::string> simdb_files;
535 if (
auto dbconn = GET_DB_FOR_COMPONENT(NumericMeta,
this)) {
536 simdb_files.insert(dbconn->getDatabaseFile());
539 for (
const auto & db_file : simdb_files) {
540 simdb_tester_->verifyRecords(db_file);
547 auto sparta_res_factory = getResourceSet()->getResourceFactory(
"cpu");
552void ExampleSimulator::buildTree_()
556 registerStatCalculationFcns_();
558 auto cpu_factory = getCPUFactory_();
561 cpu_factory->setTopology(cpu_topology_, num_cores_);
573 cpu_factory->buildTree(
getRoot());
577 std::cout <<
"Registered factories: \n";
578 for(
const auto& f : getCPUFactory_()->getResourceNames()){
579 std::cout <<
"\t" << f << std::endl;
584 for(uint32_t i = 0; i < num_cores_; ++i){
590 if (extensions !=
nullptr) {
593 validateParameter<std::string>(*dispatch_prms,
"when_",
"buildTree_");
594 validateParameter<std::string>(*dispatch_prms,
"why_",
"checkAvailability");
601 if (extensions !=
nullptr) {
604 validateParameter<std::string>(*dispatch_prms,
"edges_",
"4");
613 if (extensions !=
nullptr) {
617 validateParameter<std::string>(*alu0_prms,
"color_",
"black");
618 validateParameter<std::string>(*alu0_prms,
"shape_",
"diamond");
623 if (extensions !=
nullptr) {
627 validateParameter<std::string>(*alu1_prms,
"color_",
"green");
628 validateParameter<std::string>(*alu1_prms,
"shape_",
"circle");
640 if (extensions !=
nullptr) {
644 validateParameter<std::string>(*fpu_prms,
"color_",
"green");
645 validateParameter<std::string>(*fpu_prms,
"shape_",
"round");
646 validateParameter<double> (*fpu_prms,
"degrees_", 360.0);
650 validateParameter<std::string>(*fpu_prms,
"edges_",
"0");
655 circle_subclass->doSomethingElse();
680 dispatch,
"Dummy node under top.cpu.core0.dispatch (to reproduce a SPARTA bug)"));
683 fpu,
"Dummy node under top.cpu.core0.fpu (to reproduce a SPARTA bug)"));
686void ExampleSimulator::configureTree_()
689 std::pair<std::string, std::string> sqlite_db_files;
690 if (
auto dbconn = GET_DB_FOR_COMPONENT(NumericMeta,
this)) {
691 const TestSQLiteSchemaA data = simdb_tester_->
692 createAndStoreRecordForSQLiteSchemaA();
694 const double first = data.numbers.First;
695 const double second = data.numbers.Second;
696 dbconn->getTable(
"Numbers")->createObjectWithArgs(
697 "First", first,
"Second", second);
699 const std::string meta_name = data.metadata.Name;
700 const double meta_value = data.metadata.Value;
701 dbconn->getTable(
"Metadata")->createObjectWithArgs(
702 "Name", meta_name,
"Value", meta_value);
704 sqlite_db_files.first = dbconn->getDatabaseFile();
710 if (
auto dbconn = GET_DB_FOR_COMPONENT(StringMeta,
this)) {
711 const TestSQLiteSchemaB data = simdb_tester_->
712 createAndStoreRecordForSQLiteSchemaB();
714 const std::string first = data.strings.First;
715 const std::string second = data.strings.Second;
716 dbconn->getTable(
"Strings")->createObjectWithArgs(
717 "First", first,
"Second", second);
719 const std::string meta_name = data.metadata.Name;
720 const std::string meta_value = data.metadata.Value;
721 dbconn->getTable(
"Metadata")->createObjectWithArgs(
722 "Name", meta_name,
"Value", meta_value);
724 sqlite_db_files.second = dbconn->getDatabaseFile();
732 sparta_assert(sqlite_db_files.first == sqlite_db_files.second);
737 validateTreeNodeExtensions_();
745 dispatch_baz_->readParams();
746 fpu_baz_->readParams();
753 if(instruction_limit_ != 0){
758 this->
getRoot()->getSearchScope()->getChild(
"top.cpu.core0.rob"),
759 "testing_notif_channel",
760 "Notification channel for testing purposes only",
761 "testing_notif_channel"));
764 getRoot()->getSearchScope()->getChild(
"top.cpu.core0.rob"),
766 "Notification channel for testing report toggling on/off (statistics profiling)",
771 "all_threads_warmup_instruction_count_retired_re4",
772 "Legacy notificiation channel for testing purposes only",
773 "all_threads_warmup_instruction_count_retired_re4"));
775 getRoot()->REGISTER_FOR_NOTIFICATION(
776 onTriggered_, std::string,
"sparta_expression_trigger_fired");
777 on_triggered_notifier_registered_ =
true;
783void ExampleSimulator::bindTree_()
790 auto cpu_factory = getCPUFactory_();
791 cpu_factory->bindTree(
getRoot());
793 sparta::SpartaHandler cb = sparta::SpartaHandler::from_member<
795 this,
"ExampleSimulator::postRandomNumber_");
797 random_number_trigger_.reset(
new sparta::trigger::ExpressionCounterTrigger(
798 "RandomNumber", cb,
"cpu.core0.rob.stats.total_number_retired 7500",
false, this->
getRoot()));
800 toggle_notif_trigger_.reset(
new sparta::trigger::ExpressionTimeTrigger(
806 lazy_table_create_trigger_.reset(
new sparta::trigger::ExpressionTrigger(
807 "DelayedTableCreate",
809 "top.cpu.core0.rob.stats.total_number_retired >= 12000",
813 if (
auto db_root = GET_DB_FROM_CURRENT_SIMULATION(Stats)) {
814 lazy_table_proxy_ = db_root->getConditionalTable(
"Lazy");
819 static const uint32_t warmup_multiplier = 1000;
820 auto gen_expression = [](
const uint32_t core_idx) {
821 std::ostringstream oss;
822 oss <<
"cpu.core" << core_idx <<
".rob.stats.total_number_retired >= "
823 << ((core_idx+1) * warmup_multiplier);
827 num_cores_still_warming_up_ = num_cores_;
828 core_warmup_listeners_.reserve(num_cores_);
830 for (uint32_t core_idx = 0; core_idx < num_cores_; ++core_idx) {
831 core_warmup_listeners_.emplace_back(
832 new sparta::trigger::ExpressionTrigger(
833 "LegacyWarmupNotifications",
835 gen_expression(core_idx),
841void ExampleSimulator::onLegacyWarmupNotification_()
844 --num_cores_still_warming_up_;
845 if (num_cores_still_warming_up_ == 0) {
846 legacy_warmup_report_starter_->postNotification(1);
850const sparta::CounterBase* ExampleSimulator::findSemanticCounter_(CounterSemantic sem)
const {
860void ExampleSimulator::postRandomNumber_()
862 const size_t random = rand() % 25;
863 testing_notification_source_->postNotification(random);
864 random_number_trigger_->reschedule();
867 dispatch_baz_->checkDbAccess(
true);
870 if (!simdb_perf_async_ctrl_enabled_) {
874 using ObjectDatabase = simdb::ObjectManager::ObjectDatabase;
895 if (
auto obj_db = GET_DB_FOR_COMPONENT(NumericMeta,
this)) {
897 class TestWriter :
public simdb::WorkerTask
900 TestWriter(ObjectDatabase * obj_db,
903 simdb_tester_(db_tester)
906 void completeTask()
override {
907 const TestSQLiteSchemaA data = simdb_tester_->
908 createAndStoreRecordForSQLiteSchemaA();
910 obj_db_->getTable(
"Numbers")->createObjectWithArgs(
911 "First", data.numbers.First,
912 "Second", data.numbers.Second);
914 obj_db_->getTable(
"Metadata")->createObjectWithArgs(
915 "Name", data.metadata.Name,
916 "Value", data.metadata.Value);
920 ObjectDatabase * obj_db_ =
nullptr;
924 std::unique_ptr<simdb::WorkerTask> task(
new TestWriter(
925 obj_db, simdb_tester_.get()));
926 obj_db->getTaskQueue()->addWorkerTask(std::move(task));
929 if (
auto obj_db = GET_DB_FOR_COMPONENT(StringMeta,
this)) {
931 class TestWriter :
public simdb::WorkerTask
934 TestWriter(ObjectDatabase * obj_db,
937 simdb_tester_(db_tester)
940 void completeTask()
override {
941 const TestSQLiteSchemaB data = simdb_tester_->
942 createAndStoreRecordForSQLiteSchemaB();
944 obj_db_->getTable(
"Strings")->createObjectWithArgs(
945 "First", data.strings.First,
946 "Second", data.strings.Second);
948 obj_db_->getTable(
"Metadata")->createObjectWithArgs(
949 "Name", data.metadata.Name,
950 "Value", data.metadata.Value);
954 ObjectDatabase * obj_db_ =
nullptr;
958 std::unique_ptr<simdb::WorkerTask> task(
new TestWriter(
959 obj_db, simdb_tester_.get()));
960 obj_db->getTaskQueue()->addWorkerTask(std::move(task));
963 if (
auto obj_db = GET_DB_FOR_COMPONENT(NumericVals,
this)) {
965 class TestWriter :
public simdb::WorkerTask
968 TestWriter(ObjectDatabase * obj_db,
971 simdb_tester_(db_tester)
974 void completeTask()
override {
975 const TestHDF5SchemaC data = simdb_tester_->
976 createAndStoreRecordForHDF5SchemaC();
978 obj_db_->getTable(
"Numbers")->createObjectWithVals(
979 data.x, data.y, data.z);
983 ObjectDatabase * obj_db_ =
nullptr;
987 std::unique_ptr<simdb::WorkerTask> task(
new TestWriter(
988 obj_db, simdb_tester_.get()));
989 obj_db->getTaskQueue()->addWorkerTask(std::move(task));
993void ExampleSimulator::postToToggleTrigger_()
995 typedef std::pair<uint64_t,uint64_t> ValueCount;
996 static std::queue<ValueCount> values;
998 if (values.empty()) {
1000 values.push({1,25});
1001 values.push({0,15});
1002 values.push({1,25});
1003 values.push({0,15});
1005 ValueCount tmp = values.front();
1009 if (values.front().second == 0) {
1011 ValueCount tmp = values.front();
1014 --values.front().second;
1017 const ValueCount & current_value = values.front();
1018 const uint64_t value_to_post = current_value.first;
1019 toggle_trigger_notification_source_->postNotification(value_to_post);
1020 toggle_notif_trigger_->reschedule();
1023void ExampleSimulator::addToStatsSchema_()
1026 if (
auto db_namespace = db_root->getNamespace(
"Stats")) {
1027 db_namespace->addToSchema([&](simdb::Schema & schema) {
1028 using dt = simdb::ColumnDataType;
1030 schema.addTable(
"Lazy")
1031 .addColumn(
"Foo", dt::string_t)
1032 .addColumn(
"Bar", dt::int32_t);
1035 lazy_table_create_trigger_.reset(
new sparta::trigger::ExpressionTrigger(
1036 "DelayedTableCreate",
1038 "top.cpu.core0.rob.stats.total_number_retired >= 40000",
1045void ExampleSimulator::addToLazySchemaTable_()
1047 if (lazy_table_proxy_->isWritable()) {
1048 const std::string foo =
"hello_world";
1051 auto recordA = lazy_table_proxy_->getTable()->createObjectWithArgs(
1052 "Foo", foo,
"Bar", bar);
1054 auto db_root = GET_DB_FROM_CURRENT_SIMULATION(Stats);
1057 auto recordB = db_root->getTable(
"Lazy")->createObjectWithArgs(
1058 "Foo", foo,
"Bar", bar);
1061 recordB->getPropertyString(
"Foo"));
1064 recordB->getPropertyInt32(
"Bar"));
1068void ExampleSimulator::onTriggered_(
const std::string & msg)
1070 std::cout <<
" [trigger] " << msg << std::endl;
1073void ExampleSimulator::validateTreeNodeExtensions_()
1077 if (core_tn ==
nullptr) {
1081 if (cat_base ==
nullptr) {
1086 validateParameter<std::string>(*cat_prms,
"name_",
"Tom");
1090 validateParameter<std::string>(*cat_prms,
"language_", {
"meow",
"grrr"});
1094 if (mouse_base ==
nullptr) {
1099 validateParameter<std::string>(*mouse_prms,
"name_",
"Jerry");
1100 validateParameter<std::string>(*mouse_prms,
"language_",
"squeak");
1104 if (fpu_tn ==
nullptr) {
1108 if (circle_base ==
nullptr) {
1114 validateParameter<std::string>(*circle_prms,
"color_",
"green");
1115 validateParameter<std::string>(*circle_prms,
"shape_",
"round");
1118 validateParameter<double>(*circle_prms,
"degrees_", 360.0);
1123 circle_subclass->doSomethingElse();
1127 if (top_node ==
nullptr) {
1131 if (top_extensions ==
nullptr) {
1135 validateParameter<std::string>(*top_prms,
"color_",
"red");
1142 "call to TreeNode::getExtension()");
1149 circle_prms = circle_base_by_default->getParameters();
1151 validateParameter<std::string>(*circle_prms,
"color_",
"green");
1152 validateParameter<std::string>(*circle_prms,
"shape_",
"round");
1153 validateParameter<double>(*circle_prms,
"degrees_", 360.0);
1158 if (circle_prms->getNumParameters() > 3) {
1159 validateParameter<std::string>(*circle_prms,
"edges_",
"0");
1170 validateParameter<std::string>(*baz_prms,
"ticket_",
"663");
1175ExampleSimulator::ExampleController::ExampleController(
1177 sparta::app::Simulation::SimulationController(sim)
1179 sparta::app::Simulation::SimulationController::addNamedCallback_(
1182 sparta::app::Simulation::SimulationController::addNamedCallback_(
1188 std::cout <<
" [control] Controller PAUSE method has been called for simulation '"
1194 std::cout <<
" [control] Controller RESUME method has been called for simulation '"
1200 std::cout <<
" [control] Controller TERMINATE method has been called for simulation '"
1205void ExampleSimulator::ExampleController::customEatCallback_()
1207 std::cout <<
" [control] Controller CUSTOM method has been called ('eat')" << std::endl;
1210void ExampleSimulator::ExampleController::customSleepCallback_()
1212 std::cout <<
" [control] Controller CUSTOM method has been called ('sleep')" << std::endl;
File that defines the Clock class.
CycleHistogram implementation using sparta CycleCounter.
Definition of the CoreModel Fetch unit.
#define REGISTER_HISTOGRAM_STAT_CALC_FCN(histogram_type, fcn_name)
Function Registration Macro for Histogram/CycleHistogram. This macro is called by the users in their ...
Histogram implementation using sparta Counters.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#define CREATE_SPARTA_HANDLER(clname, meth)
File that defines the SpartaTester class and testing Macros.
Basic Node framework in sparta device tree composite pattern.
ExampleSimulator which builds the model and configures it.
ExampleSimulator(const std::string &topology, sparta::Scheduler &scheduler, uint32_t num_cores=1, uint64_t instruction_limit=0, bool show_factories=false)
Construct ExampleSimulator.
The base class for all Counters.
Helper class used to trivially extend TreeNode parameter sets (but not any additional functionality b...
A TreeNode that generates a specific type of notification which propagates up a tree of TreeNodes (us...
Non-templated base class for generic parameter access and iteration.
void setValueFromString(const std::string &str, bool poke=false)
Attempts to assign a value to this non-vector Parameter from a string.
Generic container of Parameters.
ParameterSet()=delete
Default constructor disabled.
const T getParameterValueAs(const std::string &name) const
Finds a parameter and gets its value as the templated type.
void addParameter_(sparta::ParameterBase *p)
Add a parameter to the parameter set. \temp This will be removed.
bool hasParameter(const std::string &name) const
Determines whether this ParameterSet has the parameter with the given name.
Parameter instance, templated to contain only a specific type.
void addResourceFactory()
Add a resource factory by its template type.
TreeNode subclass representing a node in the device tree which contains a single ResourceFactory and ...
void enterTeardown()
Places this tree into TREE_TEARDOWN phase so that nodes may be deleted without errors.
A class that lets you schedule events now and in the future.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Base class used to extend TreeNode parameter sets.
Node in a composite tree representing a sparta Tree item.
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
std::string getLocation() const override final
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
TreeNode()=delete
Not default-constructable.
ExtensionsBase * getExtension()
Get an extension without needing to specify any particular type string. If no extensions exist,...
ExtensionsBase * getExtension(const std::string &extension_name)
Get an extension object by type string. Returns nullptr if not found (unrecognized).
const ConstT getChildAs(const std::string &name, bool must_exist=true) const
Retrieves a child that is castable to T with the given dotted path.
TreeNode * getChild(const std::string &name, bool must_exist=true)
Retrieves a child with this dotted path name.
Simulator which builds a sparta DeviceTree.
std::vector< std::unique_ptr< sparta::TreeNode > > to_delete_
Vector of TreeNodes to delete automatically at destruction. Add any nodes allocated to this list to a...
@ CSEM_INSTRUCTIONS
Instruction count semantic (usually core0)
std::shared_ptr< SimulationController > controller_
Custom controller to handle various simulation events.
simdb::DatabaseRoot * getDatabaseRoot() const
Get the database root for this simulation.
sparta::RootTreeNode * getRoot() noexcept
Returns the tree root.
const FeatureConfiguration * getFeatureConfiguration() const
Returns this simulator's feature configuration.
void addTreeNodeExtensionFactory_(const std::string &extension_name, std::function< TreeNode::ExtensionsBase *()> creator)
Include an extension factory for this simulation's device tree nodes. They will be given to specific ...
void setSimulationController_(std::shared_ptr< SimulationController > controller)
Set a controller to handle custom simulation events.
sparta::ResourceSet * getResourceSet() noexcept
Returns the resource set for this Simulation.
const std::string & getSimName() const noexcept
Returns this simulator's name.
sparta::Scheduler * getScheduler()
Returns the simulation's scheduler.
Macros for handling exponential backoff.
std::enable_if< std::is_same< T, app::FeatureConfiguration >::value, bool >::type IsFeatureValueEnabled(const T &cfg, const std::string &feature_name)