From e96347b41fe1cdecd251a52933aebb69cf625164 Mon Sep 17 00:00:00 2001 From: scorrea Date: Mon, 18 May 2020 15:30:17 +0200 Subject: [PATCH] simulation setup to json --- .../resources/simulations/ddr3-example.json | 4 +- DRAMSys/library/src/simulation/DRAMSys.cpp | 23 +++--- DRAMSys/library/src/simulation/Setup.cpp | 27 +++---- DRAMSys/library/src/simulation/TraceSetup.cpp | 81 +++++++++---------- 4 files changed, 57 insertions(+), 78 deletions(-) diff --git a/DRAMSys/library/resources/simulations/ddr3-example.json b/DRAMSys/library/resources/simulations/ddr3-example.json index 74450f11..06076dd0 100644 --- a/DRAMSys/library/resources/simulations/ddr3-example.json +++ b/DRAMSys/library/resources/simulations/ddr3-example.json @@ -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"} ] } } diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index 32f77bcd..53862040 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -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: diff --git a/DRAMSys/library/src/simulation/Setup.cpp b/DRAMSys/library/src/simulation/Setup.cpp index b2b8ca79..509a8f97 100644 --- a/DRAMSys/library/src/simulation/Setup.cpp +++ b/DRAMSys/library/src/simulation/Setup.cpp @@ -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"]; } diff --git a/DRAMSys/library/src/simulation/TraceSetup.cpp b/DRAMSys/library/src/simulation/TraceSetup.cpp index 778b25ac..5f0fb38d 100644 --- a/DRAMSys/library/src/simulation/TraceSetup.cpp +++ b/DRAMSys/library/src/simulation/TraceSetup.cpp @@ -40,67 +40,60 @@ TraceSetup::TraceSetup(std::string uri, std::vector *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(moduleName.c_str(), stlFile, playerClk, this); + } else if (ext == "rstl") { + player = new StlPlayer(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(moduleName.c_str(), stlFile, playerClk, this); - } else if (ext == "rstl") { - player = new StlPlayer(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(); }