From 70c58ccc63ebaf5438515de1f0c53afb882baa16 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Fri, 29 Oct 2021 10:45:47 +0200 Subject: [PATCH] Make configuration library backwards compatible It's now possible to either directly insert the configuration objects into the main config json (new format) or just to enter the json file names to the configurations (old format). --- DRAMSys/library/CMakeLists.txt | 1 + .../common/configuration/AddressMapping.cpp | 26 +-- .../src/common/configuration/AddressMapping.h | 4 +- .../src/common/configuration/CMakeLists.txt | 3 + .../common/configuration/Configuration.cpp | 19 ++- .../src/common/configuration/Configuration.h | 4 +- .../src/common/configuration/McConfig.cpp | 32 ++-- .../src/common/configuration/McConfig.h | 4 +- .../src/common/configuration/SimConfig.cpp | 35 ++-- .../src/common/configuration/SimConfig.h | 4 +- .../common/configuration/ThermalConfig.cpp | 37 ++-- .../src/common/configuration/ThermalConfig.h | 4 +- .../src/common/configuration/TraceSetup.cpp | 22 +-- .../src/common/configuration/TraceSetup.h | 2 +- .../memspec/MemArchitectureSpec.cpp | 2 +- .../memspec/MemArchitectureSpec.h | 2 +- .../configuration/memspec/MemPowerSpec.cpp | 2 +- .../configuration/memspec/MemPowerSpec.h | 2 +- .../common/configuration/memspec/MemSpec.cpp | 16 +- .../common/configuration/memspec/MemSpec.h | 4 +- .../configuration/memspec/MemTimingSpec.cpp | 2 +- .../configuration/memspec/MemTimingSpec.h | 2 +- .../common/configuration/tests/simpletest.cpp | 159 ++++++++---------- .../library/src/common/configuration/util.cpp | 60 +++++++ .../library/src/common/configuration/util.h | 6 +- 25 files changed, 271 insertions(+), 183 deletions(-) create mode 100644 DRAMSys/library/src/common/configuration/util.cpp diff --git a/DRAMSys/library/CMakeLists.txt b/DRAMSys/library/CMakeLists.txt index 61b4756b..391b6179 100644 --- a/DRAMSys/library/CMakeLists.txt +++ b/DRAMSys/library/CMakeLists.txt @@ -322,4 +322,5 @@ endif() target_link_libraries(DRAMSysLibrary PUBLIC ${SYSTEMC_LIBRARY} PRIVATE DRAMPower + PRIVATE DRAMSysConfiguration ) diff --git a/DRAMSys/library/src/common/configuration/AddressMapping.cpp b/DRAMSys/library/src/common/configuration/AddressMapping.cpp index cceea826..b3277d89 100644 --- a/DRAMSys/library/src/common/configuration/AddressMapping.cpp +++ b/DRAMSys/library/src/common/configuration/AddressMapping.cpp @@ -38,7 +38,7 @@ #include -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const AddressMapping &m) @@ -51,26 +51,32 @@ void to_json(json &j, const AddressMapping &m) {"BANK_BIT", m.bankBits}, {"ROW_BIT", m.rowBits}}; - Util::from_optional("CHANNEL_BIT", congen, m.channelBits); - Util::from_optional("BYTE_BIT", congen, m.byteBits); - Util::from_optional("BANKGROUP_BIT", congen, m.bankGroupBits); - Util::from_optional("XOR", congen, m.xorBits); + from_optional("CHANNEL_BIT", congen, m.channelBits); + from_optional("BYTE_BIT", congen, m.byteBits); + from_optional("BANKGROUP_BIT", congen, m.bankGroupBits); + from_optional("XOR", congen, m.xorBits); j["CONGEN"] = congen; } void from_json(const json &j, AddressMapping &m) { - json congen = j.at("CONGEN"); + json j_addressmapping = get_config_json(j, addressMappingPath, "CONGEN"); + + json congen; + if (j_addressmapping["CONGEN"].is_null()) + congen = j_addressmapping; + else + congen = j_addressmapping["CONGEN"]; congen.at("COLUMN_BIT").get_to(m.coloumnBits); congen.at("BANK_BIT").get_to(m.bankBits); congen.at("ROW_BIT").get_to(m.rowBits); - Util::get_optional("CHANNEL_BIT", congen, m.channelBits); - Util::get_optional("BYTE_BIT", congen, m.byteBits); - Util::get_optional("BANKGROUP_BIT", congen, m.bankGroupBits); - Util::get_optional("XOR", congen, m.xorBits); + get_optional("CHANNEL_BIT", congen, m.channelBits); + get_optional("BYTE_BIT", congen, m.byteBits); + get_optional("BANKGROUP_BIT", congen, m.bankGroupBits); + get_optional("XOR", congen, m.xorBits); } void to_json(json &j, const XorPair &x) diff --git a/DRAMSys/library/src/common/configuration/AddressMapping.h b/DRAMSys/library/src/common/configuration/AddressMapping.h index dd3f9c91..07c4cda0 100644 --- a/DRAMSys/library/src/common/configuration/AddressMapping.h +++ b/DRAMSys/library/src/common/configuration/AddressMapping.h @@ -39,10 +39,12 @@ #include #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; +const std::string addressMappingPath = "configs/amconfigs"; + struct XorPair { unsigned int first; diff --git a/DRAMSys/library/src/common/configuration/CMakeLists.txt b/DRAMSys/library/src/common/configuration/CMakeLists.txt index 87c02b92..d62c5fdc 100644 --- a/DRAMSys/library/src/common/configuration/CMakeLists.txt +++ b/DRAMSys/library/src/common/configuration/CMakeLists.txt @@ -51,7 +51,10 @@ add_library(DRAMSysConfiguration STATIC memspec/MemArchitectureSpec.cpp memspec/MemPowerSpec.cpp memspec/MemTimingSpec.cpp + util.cpp ) +target_compile_definitions(DRAMSysConfiguration PRIVATE DRAMSysResourceDirectory="${CMAKE_SOURCE_DIR}/library/resources") + target_link_libraries(DRAMSysConfiguration PRIVATE nlohmann_json::nlohmann_json) target_include_directories(DRAMSysConfiguration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/DRAMSys/library/src/common/configuration/Configuration.cpp b/DRAMSys/library/src/common/configuration/Configuration.cpp index 24cd663f..006db6f2 100644 --- a/DRAMSys/library/src/common/configuration/Configuration.cpp +++ b/DRAMSys/library/src/common/configuration/Configuration.cpp @@ -36,9 +36,9 @@ #include "Configuration.h" #include "util.h" -#include +#include -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const Configuration &c) @@ -49,8 +49,8 @@ void to_json(json &j, const Configuration &c) {"simulationid", c.simulationId}, {"simconfig", c.simConfig}}; - Util::from_optional("thermalconfig", j, c.thermalConfig); - Util::from_optional("tracesetup", j, c.traceSetup); + from_optional("thermalconfig", j, c.thermalConfig); + from_optional("tracesetup", j, c.traceSetup); } void from_json(const json &j, Configuration &c) @@ -61,8 +61,15 @@ void from_json(const json &j, Configuration &c) j.at("simulationid").get_to(c.simulationId); j.at("simconfig").get_to(c.simConfig); - Util::get_optional("thermalconfig", j, c.thermalConfig); - Util::get_optional("tracesetup", j, c.traceSetup); + get_optional("thermalconfig", j, c.thermalConfig); + get_optional("tracesetup", j, c.traceSetup); +} + +Configuration from_path(const std::string &path) +{ + std::ifstream file(path); + json simulation = json::parse(file).at("simulation"); + return simulation.get(); } } // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/Configuration.h b/DRAMSys/library/src/common/configuration/Configuration.h index 069a5147..9385d13a 100644 --- a/DRAMSys/library/src/common/configuration/Configuration.h +++ b/DRAMSys/library/src/common/configuration/Configuration.h @@ -57,7 +57,7 @@ * Consider also switching to std::variant to achieve static polymorphism. */ -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; @@ -75,6 +75,8 @@ struct Configuration void to_json(json &j, const Configuration &p); void from_json(const json &j, Configuration &p); +Configuration from_path(const std::string &path); + } // namespace Configuration #endif // CONFIGURATION_H diff --git a/DRAMSys/library/src/common/configuration/McConfig.cpp b/DRAMSys/library/src/common/configuration/McConfig.cpp index b0ad41ec..daaf66d0 100644 --- a/DRAMSys/library/src/common/configuration/McConfig.cpp +++ b/DRAMSys/library/src/common/configuration/McConfig.cpp @@ -36,7 +36,7 @@ #include "McConfig.h" #include "util.h" -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const McConfig &c) @@ -54,25 +54,27 @@ void to_json(json &j, const McConfig &c) {"Arbiter", c.arbiter}, {"MaxActiveTransactions", c.maxActiveTransactions}}; - Util::from_optional("RefreshManagment", j, c.refreshManagement); + from_optional("RefreshManagment", j, c.refreshManagement); } void from_json(const json &j, McConfig &c) { - j.at("PagePolicy").get_to(c.pagePolicy); - j.at("Scheduler").get_to(c.scheduler); - j.at("SchedulerBuffer").get_to(c.schedulerBuffer); - j.at("RequestBufferSize").get_to(c.requestBufferSize); - j.at("CmdMux").get_to(c.cmdMux); - j.at("RespQueue").get_to(c.respQueue); - j.at("RefreshPolicy").get_to(c.refreshPolicy); - j.at("RefreshMaxPostponed").get_to(c.refreshMaxPostponed); - j.at("RefreshMaxPulledin").get_to(c.refreshMaxPulledin); - j.at("PowerDownPolicy").get_to(c.powerDownPolicy); - j.at("Arbiter").get_to(c.arbiter); - j.at("MaxActiveTransactions").get_to(c.maxActiveTransactions); + json j_mcconfig = get_config_json(j, mcConfigPath, "mcconfig"); - Util::get_optional("RefreshManagment", j, c.refreshManagement); + j_mcconfig.at("PagePolicy").get_to(c.pagePolicy); + j_mcconfig.at("Scheduler").get_to(c.scheduler); + j_mcconfig.at("SchedulerBuffer").get_to(c.schedulerBuffer); + j_mcconfig.at("RequestBufferSize").get_to(c.requestBufferSize); + j_mcconfig.at("CmdMux").get_to(c.cmdMux); + j_mcconfig.at("RespQueue").get_to(c.respQueue); + j_mcconfig.at("RefreshPolicy").get_to(c.refreshPolicy); + j_mcconfig.at("RefreshMaxPostponed").get_to(c.refreshMaxPostponed); + j_mcconfig.at("RefreshMaxPulledin").get_to(c.refreshMaxPulledin); + j_mcconfig.at("PowerDownPolicy").get_to(c.powerDownPolicy); + j_mcconfig.at("Arbiter").get_to(c.arbiter); + j_mcconfig.at("MaxActiveTransactions").get_to(c.maxActiveTransactions); + + get_optional("RefreshManagment", j_mcconfig, c.refreshManagement); } } // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/McConfig.h b/DRAMSys/library/src/common/configuration/McConfig.h index d265e022..363a06b8 100644 --- a/DRAMSys/library/src/common/configuration/McConfig.h +++ b/DRAMSys/library/src/common/configuration/McConfig.h @@ -40,10 +40,12 @@ #include #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; +const std::string mcConfigPath = "configs/mcconfigs"; + enum class PagePolicy { Open, diff --git a/DRAMSys/library/src/common/configuration/SimConfig.cpp b/DRAMSys/library/src/common/configuration/SimConfig.cpp index 91acde69..77903e0b 100644 --- a/DRAMSys/library/src/common/configuration/SimConfig.cpp +++ b/DRAMSys/library/src/common/configuration/SimConfig.cpp @@ -34,8 +34,9 @@ */ #include "SimConfig.h" +#include "util.h" -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const SimConfig &c) @@ -59,21 +60,23 @@ void to_json(json &j, const SimConfig &c) void from_json(const json &j, SimConfig &c) { - j.at("AddressOffset").get_to(c.addressOffset); - j.at("CheckTLM2Protocol").get_to(c.checkTLM2Protocol); - j.at("DatabaseRecording").get_to(c.databaseRecording); - j.at("Debug").get_to(c.debug); - j.at("ECCControllerMode").get_to(c.eccControllerMode); - j.at("EnableWindowing").get_to(c.enableWindowing); - j.at("ErrorCSVFile").get_to(c.errorCsvFile); - j.at("ErrorChipSeed").get_to(c.errorChipSeed); - j.at("PowerAnalysis").get_to(c.powerAnalysis); - j.at("SimulationName").get_to(c.simulationName); - j.at("SimulationProgressBar").get_to(c.simulationProgressBar); - j.at("StoreMode").get_to(c.storeMode); - j.at("ThermalSimulation").get_to(c.thermalSimulation); - j.at("UseMalloc").get_to(c.useMalloc); - j.at("WindowSize").get_to(c.windowSize); + json j_simconfig = get_config_json(j, simConfigPath, "simconfig"); + + j_simconfig.at("AddressOffset").get_to(c.addressOffset); + j_simconfig.at("CheckTLM2Protocol").get_to(c.checkTLM2Protocol); + j_simconfig.at("DatabaseRecording").get_to(c.databaseRecording); + j_simconfig.at("Debug").get_to(c.debug); + j_simconfig.at("ECCControllerMode").get_to(c.eccControllerMode); + j_simconfig.at("EnableWindowing").get_to(c.enableWindowing); + j_simconfig.at("ErrorCSVFile").get_to(c.errorCsvFile); + j_simconfig.at("ErrorChipSeed").get_to(c.errorChipSeed); + j_simconfig.at("PowerAnalysis").get_to(c.powerAnalysis); + j_simconfig.at("SimulationName").get_to(c.simulationName); + j_simconfig.at("SimulationProgressBar").get_to(c.simulationProgressBar); + j_simconfig.at("StoreMode").get_to(c.storeMode); + j_simconfig.at("ThermalSimulation").get_to(c.thermalSimulation); + j_simconfig.at("UseMalloc").get_to(c.useMalloc); + j_simconfig.at("WindowSize").get_to(c.windowSize); } } // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/SimConfig.h b/DRAMSys/library/src/common/configuration/SimConfig.h index 7d23ff75..b28d131d 100644 --- a/DRAMSys/library/src/common/configuration/SimConfig.h +++ b/DRAMSys/library/src/common/configuration/SimConfig.h @@ -38,10 +38,12 @@ #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; +const std::string simConfigPath = "configs/simulator"; + enum class ECCControllerMode { Disabled, diff --git a/DRAMSys/library/src/common/configuration/ThermalConfig.cpp b/DRAMSys/library/src/common/configuration/ThermalConfig.cpp index e593fcbe..6c69daec 100644 --- a/DRAMSys/library/src/common/configuration/ThermalConfig.cpp +++ b/DRAMSys/library/src/common/configuration/ThermalConfig.cpp @@ -34,8 +34,9 @@ */ #include "ThermalConfig.h" +#include "util.h" -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const ThermalConfig &c) @@ -55,17 +56,19 @@ void to_json(json &j, const ThermalConfig &c) void from_json(const json &j, ThermalConfig &c) { - j.at("TemperatureScale").get_to(c.temperatureScale); - j.at("StaticTemperatureDefaultValue").get_to(c.staticTemperatureDefaultValue); - j.at("ThermalSimPeriod").get_to(c.thermalSimPeriod); - j.at("ThermalSimUnit").get_to(c.thermalSimUnit); - j.at("PowerInfoFile").get_to(c.powerInfo); - j.at("IceServerIp").get_to(c.iceServerIp); - j.at("IceServerPort").get_to(c.iceServerPort); - j.at("SimPeriodAdjustFactor").get_to(c.simPeriodAdjustFactor); - j.at("NPowStableCyclesToIncreasePeriod").get_to(c.nPowStableCyclesToIncreasePeriod); - j.at("GenerateTemperatureMap").get_to(c.generateTemperatureMap); - j.at("GeneratePowerMap").get_to(c.generatePowerMap); + json j_thermalsim = get_config_json(j, thermalConfigPath, "thermalsimconfig"); + + j_thermalsim.at("TemperatureScale").get_to(c.temperatureScale); + j_thermalsim.at("StaticTemperatureDefaultValue").get_to(c.staticTemperatureDefaultValue); + j_thermalsim.at("ThermalSimPeriod").get_to(c.thermalSimPeriod); + j_thermalsim.at("ThermalSimUnit").get_to(c.thermalSimUnit); + j_thermalsim.at("PowerInfoFile").get_to(c.powerInfo); + j_thermalsim.at("IceServerIp").get_to(c.iceServerIp); + j_thermalsim.at("IceServerPort").get_to(c.iceServerPort); + j_thermalsim.at("SimPeriodAdjustFactor").get_to(c.simPeriodAdjustFactor); + j_thermalsim.at("NPowStableCyclesToIncreasePeriod").get_to(c.nPowStableCyclesToIncreasePeriod); + j_thermalsim.at("GenerateTemperatureMap").get_to(c.generateTemperatureMap); + j_thermalsim.at("GeneratePowerMap").get_to(c.generatePowerMap); } void to_json(json &j, const DramDieChannel &c) @@ -89,10 +92,12 @@ void to_json(json &j, const PowerInfo &c) void from_json(const json &j, PowerInfo &c) { - j.at("dram_die_channel0").get_to(c.channel0); - j.at("dram_die_channel1").get_to(c.channel1); - j.at("dram_die_channel2").get_to(c.channel2); - j.at("dram_die_channel3").get_to(c.channel3); + json j_powerinfo = get_config_json(j, thermalConfigPath, "powerInfo"); + + j_powerinfo.at("dram_die_channel0").get_to(c.channel0); + j_powerinfo.at("dram_die_channel1").get_to(c.channel1); + j_powerinfo.at("dram_die_channel2").get_to(c.channel2); + j_powerinfo.at("dram_die_channel3").get_to(c.channel3); } } // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/ThermalConfig.h b/DRAMSys/library/src/common/configuration/ThermalConfig.h index a6e6fd34..02c905b6 100644 --- a/DRAMSys/library/src/common/configuration/ThermalConfig.h +++ b/DRAMSys/library/src/common/configuration/ThermalConfig.h @@ -38,10 +38,12 @@ #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; +const std::string thermalConfigPath = "configs/thermalsim"; + enum class TemperatureScale { Celsius, diff --git a/DRAMSys/library/src/common/configuration/TraceSetup.cpp b/DRAMSys/library/src/common/configuration/TraceSetup.cpp index e39452fc..39b76790 100644 --- a/DRAMSys/library/src/common/configuration/TraceSetup.cpp +++ b/DRAMSys/library/src/common/configuration/TraceSetup.cpp @@ -36,7 +36,7 @@ #include "TraceSetup.h" #include "util.h" -namespace Configuration +namespace DRAMSysConfiguration { TrafficInitiator::~TrafficInitiator() @@ -62,11 +62,11 @@ void to_json(json &j, const TraceSetup &c) inititator_j["rwRatio"] = generator->rwRatio; inititator_j["addressDistribution"] = generator->addressDistribution; - Util::from_optional("seed", inititator_j, generator->seed); - Util::from_optional("maxPendingReadRequests", inititator_j, generator->maxPendingReadRequests); - Util::from_optional("maxPendingWriteRequests", inititator_j, generator->maxPendingWriteRequests); - Util::from_optional("minAddress", inititator_j, generator->minAddress); - Util::from_optional("maxAddress", inititator_j, generator->maxAddress); + from_optional("seed", inititator_j, generator->seed); + from_optional("maxPendingReadRequests", inititator_j, generator->maxPendingReadRequests); + from_optional("maxPendingWriteRequests", inititator_j, generator->maxPendingWriteRequests); + from_optional("minAddress", inititator_j, generator->minAddress); + from_optional("maxAddress", inititator_j, generator->maxAddress); } else if (const auto hammer = dynamic_cast(initiator.get())) { @@ -103,11 +103,11 @@ void from_json(const json &j, TraceSetup &c) initiator_j.at("rwRatio").get_to(generator->rwRatio); initiator_j.at("addressDistribution").get_to(generator->addressDistribution); - Util::get_optional("seed", initiator_j, generator->seed); - Util::get_optional("maxPendingReadRequests", initiator_j, generator->maxPendingReadRequests); - Util::get_optional("maxPendingWriteRequests", initiator_j, generator->maxPendingWriteRequests); - Util::get_optional("minAddress", initiator_j, generator->minAddress); - Util::get_optional("maxAddress", initiator_j, generator->maxAddress); + get_optional("seed", initiator_j, generator->seed); + get_optional("maxPendingReadRequests", initiator_j, generator->maxPendingReadRequests); + get_optional("maxPendingWriteRequests", initiator_j, generator->maxPendingWriteRequests); + get_optional("minAddress", initiator_j, generator->minAddress); + get_optional("maxAddress", initiator_j, generator->maxAddress); initiator = std::unique_ptr(generator); } diff --git a/DRAMSys/library/src/common/configuration/TraceSetup.h b/DRAMSys/library/src/common/configuration/TraceSetup.h index d3974ec6..61361bc2 100644 --- a/DRAMSys/library/src/common/configuration/TraceSetup.h +++ b/DRAMSys/library/src/common/configuration/TraceSetup.h @@ -40,7 +40,7 @@ #include #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; diff --git a/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp index 5de2684b..ce2b33d2 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp +++ b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp @@ -35,7 +35,7 @@ #include "MemArchitectureSpec.h" -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const MemArchitectureSpec &c) diff --git a/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h index cd516ad2..80a18ecc 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h +++ b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h @@ -39,7 +39,7 @@ #include #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; diff --git a/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp index 6621fabc..0cdb3059 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp +++ b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp @@ -35,7 +35,7 @@ #include "MemPowerSpec.h" -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const MemPowerSpec &c) diff --git a/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h index 5c201580..8d125a44 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h +++ b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h @@ -39,7 +39,7 @@ #include #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; diff --git a/DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp index 8bdcf0ef..29def6d8 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp +++ b/DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp @@ -36,7 +36,7 @@ #include "MemSpec.h" #include "util.h" -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const MemSpec &c) @@ -46,17 +46,19 @@ void to_json(json &j, const MemSpec &c) {"memoryType", c.memoryType}, {"memtimingspec", c.memTimingSpec}}; - Util::from_optional("mempowerspec", j, c.memPowerSpec); + from_optional("mempowerspec", j, c.memPowerSpec); } void from_json(const json &j, MemSpec &c) { - j.at("memarchitecturespec").get_to(c.memArchitectureSpec); - j.at("memoryId").get_to(c.memoryId); - j.at("memoryType").get_to(c.memoryType); - j.at("memtimingspec").get_to(c.memTimingSpec); + json j_memspecs = get_config_json(j, memSpecPath, "memspec"); - Util::get_optional("mempowerspec", j, c.memPowerSpec); + j_memspecs.at("memarchitecturespec").get_to(c.memArchitectureSpec); + j_memspecs.at("memoryId").get_to(c.memoryId); + j_memspecs.at("memoryType").get_to(c.memoryType); + j_memspecs.at("memtimingspec").get_to(c.memTimingSpec); + + get_optional("mempowerspec", j, c.memPowerSpec); } } // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/memspec/MemSpec.h b/DRAMSys/library/src/common/configuration/memspec/MemSpec.h index 5d716963..248709b4 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemSpec.h +++ b/DRAMSys/library/src/common/configuration/memspec/MemSpec.h @@ -42,10 +42,12 @@ #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; +const std::string memSpecPath = "configs/memspecs"; + struct MemSpec { MemArchitectureSpec memArchitectureSpec; diff --git a/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp index 0b41f8cf..27414e57 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp +++ b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp @@ -35,7 +35,7 @@ #include "MemTimingSpec.h" -namespace Configuration +namespace DRAMSysConfiguration { void to_json(json &j, const MemTimingSpec &c) diff --git a/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h index 6203803b..61ba7308 100644 --- a/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h +++ b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h @@ -39,7 +39,7 @@ #include #include -namespace Configuration +namespace DRAMSysConfiguration { using json = nlohmann::json; diff --git a/DRAMSys/library/src/common/configuration/tests/simpletest.cpp b/DRAMSys/library/src/common/configuration/tests/simpletest.cpp index 4c7f2b1a..1be7c5e5 100644 --- a/DRAMSys/library/src/common/configuration/tests/simpletest.cpp +++ b/DRAMSys/library/src/common/configuration/tests/simpletest.cpp @@ -4,126 +4,105 @@ using json = nlohmann::json; -Configuration::AddressMapping getAddressMapping() +DRAMSysConfiguration::AddressMapping getAddressMapping() { - // Configuration::ConGen *mycongen = new Configuration::ConGen; - // mycongen->byteBits = {{0, 1}, true}; - // mycongen->bankBits = {16}; - // mycongen->bankGroupBits = {{13, 14, 15}, true}; - // mycongen->coloumnBits = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - // mycongen->channelBits = {{33}, true}; - // mycongen->rowBits = {17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}; - // return std::unique_ptr(mycongen); - - return Configuration::AddressMapping{{{0, 1}, true}, - {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, - {16}, - {{13, 14, 15}, true}, - {17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}, - {{33}, true}, - {{}, false}}; + return DRAMSysConfiguration::AddressMapping{{{0, 1}, true}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, + {16}, + {{13, 14, 15}, true}, + {17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}, + {{33}, true}, + {{}, false}}; } -Configuration::McConfig getMcConfig() +DRAMSysConfiguration::McConfig getMcConfig() { - return Configuration::McConfig{Configuration::PagePolicy::Open, - Configuration::Scheduler::FrFcfs, - Configuration::SchedulerBuffer::Bankwise, - 8, - Configuration::CmdMux::Oldest, - Configuration::RespQueue::Fifo, - Configuration::RefreshPolicy::AllBank, - 0, - 0, - Configuration::PowerDownPolicy::NoPowerDown, - Configuration::Arbiter::Simple, - 128, - std::pair{false, true}}; + return DRAMSysConfiguration::McConfig{DRAMSysConfiguration::PagePolicy::Open, + DRAMSysConfiguration::Scheduler::FrFcfs, + DRAMSysConfiguration::SchedulerBuffer::Bankwise, + 8, + DRAMSysConfiguration::CmdMux::Oldest, + DRAMSysConfiguration::RespQueue::Fifo, + DRAMSysConfiguration::RefreshPolicy::AllBank, + 0, + 0, + DRAMSysConfiguration::PowerDownPolicy::NoPowerDown, + DRAMSysConfiguration::Arbiter::Simple, + 128, + std::pair{false, true}}; } -Configuration::SimConfig getSimConfig() +DRAMSysConfiguration::SimConfig getSimConfig() { - return Configuration::SimConfig { - 0, - false, + return DRAMSysConfiguration::SimConfig{ + 0, false, true, false, DRAMSysConfiguration::ECCControllerMode::Disabled, false, "error.csv", + 42, false, "ddr5", true, DRAMSysConfiguration::StoreMode::NoStorage, false, false, + 1000}; +} + +DRAMSysConfiguration::ThermalConfig getThermalConfig() +{ + return DRAMSysConfiguration::ThermalConfig{ + DRAMSysConfiguration::TemperatureScale::Celsius, + 89, + 100, + DRAMSysConfiguration::ThermalSimUnit::Microseconds, + DRAMSysConfiguration::PowerInfo{{0.0, 1.0}, {0.0, 1.0}, {0.0, 1.0}, {0.0, 1.0}}, + "127.0.0.1", + 118800, + 10, + 5, true, - false, - Configuration::ECCControllerMode::Disabled, - false, - "error.csv", - 42, - false, - "ddr5", - true, - Configuration::StoreMode::NoStorage, - false, - false, - 1000 - }; + true}; } -Configuration::ThermalConfig getThermalConfig() +std::unique_ptr getTracePlayer() { - return Configuration::ThermalConfig{Configuration::TemperatureScale::Celsius, - 89, - 100, - Configuration::ThermalSimUnit::Microseconds, - Configuration::PowerInfo{{0.0, 1.0}, {0.0, 1.0}, {0.0, 1.0}, {0.0, 1.0}}, - "127.0.0.1", - 118800, - 10, - 5, - true, - true}; -} - -std::unique_ptr getTracePlayer() -{ - Configuration::TracePlayer *player = new Configuration::TracePlayer; + DRAMSysConfiguration::TracePlayer *player = new DRAMSysConfiguration::TracePlayer; player->clkMhz = 100; player->name = "mytrace.stl"; - return std::unique_ptr(player); + return std::unique_ptr(player); } -std::unique_ptr getTraceGeneratorRandom() +std::unique_ptr getTraceGeneratorRandom() { - Configuration::TraceGenerator *gen = new Configuration::TraceGenerator; + DRAMSysConfiguration::TraceGenerator *gen = new DRAMSysConfiguration::TraceGenerator; gen->clkMhz = 100; gen->name = "MyTestGen"; - gen->addressDistribution = Configuration::AddressDistribution::Random; + gen->addressDistribution = DRAMSysConfiguration::AddressDistribution::Random; gen->maxAddress = {1000, true}; gen->maxPendingReadRequests = {8, true}; gen->rwRatio = 0.5; gen->seed = {1337, true}; gen->numRequests = 1000; - return std::unique_ptr(gen); + return std::unique_ptr(gen); } -std::unique_ptr getTraceGeneratorSequential() +std::unique_ptr getTraceGeneratorSequential() { - Configuration::TraceGenerator *gen = new Configuration::TraceGenerator; + DRAMSysConfiguration::TraceGenerator *gen = new DRAMSysConfiguration::TraceGenerator; gen->clkMhz = 100; gen->name = "MyTestGen"; - gen->addressDistribution = Configuration::AddressDistribution::Sequential; + gen->addressDistribution = DRAMSysConfiguration::AddressDistribution::Sequential; gen->addressIncrement = {64, true}; gen->maxAddress = {1000, true}; gen->maxPendingReadRequests = {8, true}; gen->rwRatio = 0.5; gen->numRequests = 1000; - return std::unique_ptr(gen); + return std::unique_ptr(gen); } -std::unique_ptr getTraceHammer() +std::unique_ptr getTraceHammer() { - Configuration::TraceHammer *hammer = new Configuration::TraceHammer; + DRAMSysConfiguration::TraceHammer *hammer = new DRAMSysConfiguration::TraceHammer; hammer->clkMhz = 100; hammer->name = "MyTestHammer"; @@ -131,23 +110,23 @@ std::unique_ptr getTraceHammer() hammer->numRequests = 4000; hammer->rowIncrement = 2097152; - return std::unique_ptr(hammer); + return std::unique_ptr(hammer); } -Configuration::TraceSetup getTraceSetup() +DRAMSysConfiguration::TraceSetup getTraceSetup() { - std::unordered_set> initiators; + std::unordered_set> initiators; initiators.emplace(getTracePlayer()); initiators.emplace(getTraceGeneratorRandom()); initiators.emplace(getTraceGeneratorSequential()); initiators.emplace(getTraceHammer()); - return Configuration::TraceSetup{std::move(initiators)}; + return DRAMSysConfiguration::TraceSetup{std::move(initiators)}; } -Configuration::Configuration getConfig(const Configuration::MemSpec &memSpec) +DRAMSysConfiguration::Configuration getConfig(const DRAMSysConfiguration::MemSpec &memSpec) { - return Configuration::Configuration{ + return DRAMSysConfiguration::Configuration{ getAddressMapping(), getMcConfig(), memSpec, @@ -161,10 +140,7 @@ Configuration::Configuration getConfig(const Configuration::MemSpec &memSpec) int main() { - std::ifstream file("ddr5.json"); - json ddr5_j = json::parse(file, nullptr, false); - json config = ddr5_j.at("simulation"); - Configuration::Configuration conf = config.get(); + DRAMSysConfiguration::Configuration conf = DRAMSysConfiguration::from_path("ddr5.json"); std::ofstream fileout("myjson.json"); json j_my; j_my["simulation"] = getConfig(conf.memSpec); // just copy memspec over @@ -173,9 +149,18 @@ int main() std::ifstream file2("hbm2.json"); json hbm2_j = json::parse(file2, nullptr, false); json hbm2_config = hbm2_j.at("simulation"); - Configuration::Configuration hbm2conf = hbm2_config.get(); + DRAMSysConfiguration::Configuration hbm2conf = hbm2_config.get(); std::ofstream filehbm2("myhbm2.json"); json j_myhbm2; j_myhbm2["simulation"] = hbm2conf; filehbm2 << j_myhbm2.dump(4); + + std::ifstream file3("old_conf.json"); + json ddr5_old = json::parse(file3, nullptr, false); + json ddr5_old_conf = ddr5_old.at("simulation"); + DRAMSysConfiguration::Configuration ddr5_old_config = ddr5_old_conf.get(); + std::ofstream fileoldout("old_conf_converted.json"); + json j_oldconfconv; + j_oldconfconv["simulation"] = ddr5_old_config; + fileoldout << j_oldconfconv.dump(4); } diff --git a/DRAMSys/library/src/common/configuration/util.cpp b/DRAMSys/library/src/common/configuration/util.cpp new file mode 100644 index 00000000..d4d3ef29 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/util.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, Technische Universität Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Derek Christ + */ + +#include "util.h" + +#include + +namespace DRAMSysConfiguration +{ + +json get_config_json(const json &j, const std::string &configPath, const std::string &objectName) +{ + if (j.is_object()) + { + return j; + } + else // j should be a string path to the real json file + { + std::string jsonFileName; + j.get_to(jsonFileName); + + std::ifstream file(std::string(DRAMSysResourceDirectory) + "/" + configPath + "/" + jsonFileName); + json j_object = json::parse(file); + return j_object.at(objectName); + } +} + +} // namespace DRAMSysConfiguration diff --git a/DRAMSys/library/src/common/configuration/util.h b/DRAMSys/library/src/common/configuration/util.h index 1f25489c..113c3265 100644 --- a/DRAMSys/library/src/common/configuration/util.h +++ b/DRAMSys/library/src/common/configuration/util.h @@ -39,7 +39,7 @@ #include #include -namespace Util +namespace DRAMSysConfiguration { using json = nlohmann::json; @@ -70,6 +70,8 @@ void from_optional(const std::string &name, json &j, const std::pair &v } } -} // namespace Util +json get_config_json(const json &j, const std::string &configPath, const std::string &objectName); + +} // namespace DRAMSysConfiguration #endif