simulation setup to json

This commit is contained in:
scorrea
2020-05-18 15:30:17 +02:00
parent 1b9c2802ec
commit e96347b41f
4 changed files with 57 additions and 78 deletions

View File

@@ -7,8 +7,8 @@
"addressmapping": "congen_extended_solution.json",
"mcconfig":"fifoStrict.json",
"tracesetup": [{
"_clkMhz": "800",
"__text": "ddr3_example.stl"}
"clkMhz": 800,
"name": "ddr3_example.stl"}
]
}
}

View File

@@ -45,6 +45,7 @@
#include "DRAMSys.h"
#include "Setup.h"
#include "../common/third_party/tinyxml2/tinyxml2.h"
#include "../common/third_party/nlohmann/single_include/nlohmann/json.hpp"
#include "../common/TlmRecorder.h"
#include "../common/DebugManager.h"
#include "../configuration/ConfigurationLoader.h"
@@ -117,22 +118,16 @@ DRAMSys::DRAMSys(sc_module_name name,
// is prepended to the simulation name if found.
std::string simName;
simName = Configuration::getInstance().simulationName;
tinyxml2::XMLDocument simulationdoc;
loadXML(simulationToRun, simulationdoc);
tinyxml2::XMLElement *simulation =
simulationdoc.FirstChildElement("simulation");
if (simulation != NULL) {
tinyxml2::XMLElement *simid = simulation->FirstChildElement("simulationid");
if (simid != NULL) {
auto r = simid->Attribute("id");
if (r != NULL) {
std::string sid;
sid = r;
simName = sid + '_' + Configuration::getInstance().simulationName;
}
}
nlohmann::json simulationdoc = nlohmann::json::parse(std::ifstream(simulationToRun));
if (!simulationdoc["simulation"]["simulationid"].empty()) {
std::string sid = simulationdoc["simulation"]["simulationid"];
simName = sid + '_' + Configuration::getInstance().simulationName;
}
// Instantiate all internal DRAMSys modules:
instantiateModules(simName, pathToResources, amconfig);
// Connect all internal DRAMSys modules:

View File

@@ -43,33 +43,24 @@ Setup::Setup(std::string uri,
std::string &thermalconfig)
{
// Load Simulation:
tinyxml2::XMLDocument simulationdoc;
loadXML(uri, simulationdoc);
tinyxml2::XMLElement *simulation =
simulationdoc.FirstChildElement("simulation");
nlohmann::json simulationdoc = nlohmann::json::parse(std::ifstream(uri));
std::string xmlNodeName(simulation->Name());
if ( xmlNodeName != "simulation")
if (simulationdoc["simulation"].empty())
reportFatal("SimulationManager",
"Cannot load simulation: simulation node expected");
// Load all sub-configuration XML files:
tinyxml2::XMLElement *s;
s = simulation->FirstChildElement("memspec");
memspec = s->Attribute("src");
// Load all sub-configuration JSON files
s = simulation->FirstChildElement("mcconfig");
mcconfig = s->Attribute("src");
memspec = simulationdoc["simulation"]["memspec"];
s = simulation->FirstChildElement("addressmapping");
amconfig = s->Attribute("src");
mcconfig = simulationdoc["simulation"]["mcconfig"];
s = simulation->FirstChildElement("simconfig");
simconfig = s->Attribute("src");
amconfig = simulationdoc["simulation"]["addressmapping"];
s = simulation->FirstChildElement("thermalconfig");
thermalconfig = s->Attribute("src");
simconfig = simulationdoc["simulation"]["simconfig"];
thermalconfig = simulationdoc["simulation"]["thermalconfig"];
}

View File

@@ -40,67 +40,60 @@ TraceSetup::TraceSetup(std::string uri,
std::vector<TracePlayer *> *devices)
{
// Load Simulation:
tinyxml2::XMLDocument simulationdoc;
loadXML(uri, simulationdoc);
nlohmann::json simulationdoc = nlohmann::json::parse(std::ifstream(uri));
tinyxml2::XMLElement *simulation =
simulationdoc.FirstChildElement("simulation");
std::string xmlNodeName(simulation->Name());
if ( xmlNodeName != "simulation")
if (simulationdoc["simulation"].empty())
reportFatal("traceSetup",
"Cannot load simulation: simulation node expected");
// Load TracePlayers:
tinyxml2::XMLElement *tracesetup =
simulation->FirstChildElement("tracesetup");
for ( auto it: simulationdoc["simulation"]["tracesetup"].items() ){
auto value = it.value();
if (!value.empty()){
sc_time playerClk;
unsigned int frequencyMHz = value["clkMhz"];
for (tinyxml2::XMLElement *device =
tracesetup->FirstChildElement("device");
device != NULL;
device = device->NextSiblingElement("device"))
{
sc_time playerClk;
unsigned int frequencyMHz = device->IntAttribute("clkMhz");
if (frequencyMHz == 0)
reportFatal("traceSetup", "No Frequency Defined");
else
playerClk = sc_time(1.0 / frequencyMHz, SC_US);
if (frequencyMHz == 0)
reportFatal("traceSetup", "No Frequency Defined");
else
playerClk = sc_time(1.0 / frequencyMHz, SC_US);
std::string name = value["name"];
std::string name = device->GetText();
size_t pos = name.rfind('.');
if (pos == std::string::npos) {
throw std::runtime_error("Name of the trace file does not contain a valid extension.");
}
size_t pos = name.rfind('.');
if (pos == std::string::npos) {
throw std::runtime_error("Name of the trace file does not contain a valid extension.");
}
// Get the extension and make it lower case
std::string ext = name.substr(pos + 1);
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
// Get the extension and make it lower case
std::string ext = name.substr(pos + 1);
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
std::string stlFile = pathToResources + std::string("traces/") + name;
std::string moduleName = name;
std::string stlFile = pathToResources + std::string("traces/") + name;
std::string moduleName = name;
// replace all '.' to '_'
std::replace(moduleName.begin(), moduleName.end(), '.', '_');
// replace all '.' to '_'
std::replace(moduleName.begin(), moduleName.end(), '.', '_');
TracePlayer *player;
if (ext == "stl") {
player = new StlPlayer<false>(moduleName.c_str(), stlFile, playerClk, this);
} else if (ext == "rstl") {
player = new StlPlayer<true>(moduleName.c_str(), stlFile, playerClk, this);
} else {
std::string error = "Unsupported file extension in " + name;
throw std::runtime_error(error);
}
devices->push_back(player);
TracePlayer *player;
if (ext == "stl") {
player = new StlPlayer<false>(moduleName.c_str(), stlFile, playerClk, this);
} else if (ext == "rstl") {
player = new StlPlayer<true>(moduleName.c_str(), stlFile, playerClk, this);
} else {
std::string error = "Unsupported file extension in " + name;
throw std::runtime_error(error);
}
devices->push_back(player);
if (Configuration::getInstance().simulationProgressBar) {
totalTransactions += player->getNumberOfLines(stlFile);
if (Configuration::getInstance().simulationProgressBar) {
totalTransactions += player->getNumberOfLines(stlFile);
}
}
}
remainingTransactions = totalTransactions;
numberOfTracePlayers = devices->size();
}