Introduce an own optional type for configuration lib
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
*/
|
||||
|
||||
#include "AddressMapping.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -49,12 +48,11 @@ void to_json(json &j, const AddressMapping &m)
|
||||
{"COLUMN_BIT", m.coloumnBits},
|
||||
{"BANKGROUP_BIT", m.bankGroupBits},
|
||||
{"BANK_BIT", m.bankBits},
|
||||
{"ROW_BIT", m.rowBits}};
|
||||
|
||||
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);
|
||||
{"ROW_BIT", m.rowBits},
|
||||
{"CHANNEL_BIT", m.channelBits},
|
||||
{"BYTE_BIT", m.byteBits},
|
||||
{"BANKGROUP_BIT", m.bankGroupBits},
|
||||
{"XOR", m.xorBits}};
|
||||
|
||||
j["CONGEN"] = congen;
|
||||
}
|
||||
@@ -73,10 +71,17 @@ void from_json(const json &j, AddressMapping &m)
|
||||
congen.at("BANK_BIT").get_to(m.bankBits);
|
||||
congen.at("ROW_BIT").get_to(m.rowBits);
|
||||
|
||||
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);
|
||||
if (congen.contains("CHANNEL_BIT"))
|
||||
congen.at("CHANNEL_BIT").get_to(m.channelBits);
|
||||
|
||||
if (congen.contains("BYTE_BIT"))
|
||||
congen.at("BYTE_BIT").get_to(m.byteBits);
|
||||
|
||||
if (congen.contains("BANKGROUP_BIT"))
|
||||
congen.at("BANKGROUP_BIT").get_to(m.bankGroupBits);
|
||||
|
||||
if (congen.contains("XOR"))
|
||||
congen.at("XOR").get_to(m.xorBits);
|
||||
}
|
||||
|
||||
void to_json(json &j, const XorPair &x)
|
||||
@@ -90,4 +95,4 @@ void from_json(const json &j, XorPair &x)
|
||||
j.at("SECOND").get_to(x.second);
|
||||
}
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
@@ -33,8 +33,10 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef ADDRESSMAPPING_H
|
||||
#define ADDRESSMAPPING_H
|
||||
#ifndef DRAMSYSCONFIGURATION_ADDRESSMAPPING_H
|
||||
#define DRAMSYSCONFIGURATION_ADDRESSMAPPING_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <unordered_set>
|
||||
@@ -56,13 +58,13 @@ void from_json(const json &j, XorPair &x);
|
||||
|
||||
struct AddressMapping
|
||||
{
|
||||
std::pair<std::unordered_set<unsigned int>, bool> byteBits;
|
||||
Optional<std::unordered_set<unsigned int>> byteBits;
|
||||
std::unordered_set<unsigned int> coloumnBits;
|
||||
std::unordered_set<unsigned int> bankBits;
|
||||
std::pair<std::unordered_set<unsigned int>, bool> bankGroupBits;
|
||||
Optional<std::unordered_set<unsigned int>> bankGroupBits;
|
||||
std::unordered_set<unsigned int> rowBits;
|
||||
std::pair<std::unordered_set<unsigned int>, bool> channelBits;
|
||||
std::pair<std::vector<XorPair>, bool> xorBits;
|
||||
Optional<std::unordered_set<unsigned int>> channelBits;
|
||||
Optional<std::vector<XorPair>> xorBits;
|
||||
};
|
||||
|
||||
void to_json(json &j, const AddressMapping &m);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
# Derek Christ
|
||||
|
||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||
set(JSON_ImplicitConversions OFF CACHE INTERNAL "")
|
||||
add_subdirectory(${CMAKE_SOURCE_DIR}/library/src/common/third_party/nlohmann ${CMAKE_CURRENT_BINARY_DIR}/nlohmann)
|
||||
|
||||
option(DRAMSYS_CONFIGURATION_TESTS "Build the unit tests for configuration." OFF)
|
||||
@@ -56,5 +57,6 @@ add_library(DRAMSysConfiguration STATIC
|
||||
|
||||
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})
|
||||
|
||||
target_link_libraries(DRAMSysConfiguration PRIVATE nlohmann_json::nlohmann_json)
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
*/
|
||||
|
||||
#include "Configuration.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@@ -43,14 +42,11 @@ namespace DRAMSysConfiguration
|
||||
|
||||
void to_json(json &j, const Configuration &c)
|
||||
{
|
||||
j = json{{"addressmapping", c.addressMapping},
|
||||
{"mcconfig", c.mcConfig},
|
||||
{"memspec", c.memSpec},
|
||||
{"simulationid", c.simulationId},
|
||||
{"simconfig", c.simConfig}};
|
||||
j = json{{"addressmapping", c.addressMapping}, {"mcconfig", c.mcConfig}, {"memspec", c.memSpec},
|
||||
{"simulationid", c.simulationId}, {"simconfig", c.simConfig}, {"thermalconfig", c.thermalConfig},
|
||||
{"tracesetup", c.traceSetup}};
|
||||
|
||||
from_optional("thermalconfig", j, c.thermalConfig);
|
||||
from_optional("tracesetup", j, c.traceSetup);
|
||||
remove_null_values(j);
|
||||
}
|
||||
|
||||
void from_json(const json &j, Configuration &c)
|
||||
@@ -61,8 +57,11 @@ void from_json(const json &j, Configuration &c)
|
||||
j.at("simulationid").get_to(c.simulationId);
|
||||
j.at("simconfig").get_to(c.simConfig);
|
||||
|
||||
get_optional("thermalconfig", j, c.thermalConfig);
|
||||
get_optional("tracesetup", j, c.traceSetup);
|
||||
if (j.contains("thermalconfig"))
|
||||
j.at("thermalconfig").get_to(c.thermalConfig);
|
||||
|
||||
if (j.contains("tracesetup"))
|
||||
j.at("tracesetup").get_to(c.traceSetup);
|
||||
}
|
||||
|
||||
Configuration from_path(const std::string &path)
|
||||
@@ -72,4 +71,4 @@ Configuration from_path(const std::string &path)
|
||||
return simulation.get<DRAMSysConfiguration::Configuration>();
|
||||
}
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef CONFIGURATION_H
|
||||
#define CONFIGURATION_H
|
||||
#ifndef DRAMSYSCONFIGURATION_CONFIGURATION_H
|
||||
#define DRAMSYSCONFIGURATION_CONFIGURATION_H
|
||||
|
||||
#include "AddressMapping.h"
|
||||
#include "McConfig.h"
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "ThermalConfig.h"
|
||||
#include "TraceSetup.h"
|
||||
#include "memspec/MemSpec.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <memory>
|
||||
#include <nlohmann/json.hpp>
|
||||
@@ -68,8 +69,8 @@ struct Configuration
|
||||
MemSpec memSpec;
|
||||
SimConfig simConfig;
|
||||
std::string simulationId;
|
||||
std::pair<ThermalConfig, bool> thermalConfig;
|
||||
std::pair<TraceSetup, bool> traceSetup;
|
||||
Optional<ThermalConfig> thermalConfig;
|
||||
Optional<TraceSetup> traceSetup;
|
||||
};
|
||||
|
||||
void to_json(json &j, const Configuration &p);
|
||||
@@ -77,6 +78,6 @@ void from_json(const json &j, Configuration &p);
|
||||
|
||||
Configuration from_path(const std::string &path);
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
#endif // CONFIGURATION_H
|
||||
#endif // DRAMSYSCONFIGURATION_CONFIGURATION_H
|
||||
|
||||
@@ -34,8 +34,7 @@
|
||||
*/
|
||||
|
||||
#include "McConfig.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <iostream>
|
||||
namespace DRAMSysConfiguration
|
||||
{
|
||||
|
||||
@@ -52,29 +51,64 @@ void to_json(json &j, const McConfig &c)
|
||||
{"RefreshMaxPulledin", c.refreshMaxPulledin},
|
||||
{"PowerDownPolicy", c.powerDownPolicy},
|
||||
{"Arbiter", c.arbiter},
|
||||
{"MaxActiveTransactions", c.maxActiveTransactions}};
|
||||
{"MaxActiveTransactions", c.maxActiveTransactions},
|
||||
{"RefreshManagment", c.refreshManagement}};
|
||||
|
||||
from_optional("RefreshManagment", j, c.refreshManagement);
|
||||
remove_null_values(j);
|
||||
}
|
||||
|
||||
void from_json(const json &j, McConfig &c)
|
||||
{
|
||||
json j_mcconfig = get_config_json(j, mcConfigPath, "mcconfig");
|
||||
|
||||
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);
|
||||
if (j_mcconfig.contains("PagePolicy"))
|
||||
j_mcconfig.at("PagePolicy").get_to(c.pagePolicy);
|
||||
|
||||
get_optional("RefreshManagment", j_mcconfig, c.refreshManagement);
|
||||
if (j_mcconfig.contains("PagePolicy"))
|
||||
j_mcconfig.at("Scheduler").get_to(c.scheduler);
|
||||
|
||||
if (j_mcconfig.contains("SchedulerBuffer"))
|
||||
j_mcconfig.at("SchedulerBuffer").get_to(c.schedulerBuffer);
|
||||
|
||||
if (j_mcconfig.contains("RequestBufferSize"))
|
||||
j_mcconfig.at("RequestBufferSize").get_to(c.requestBufferSize);
|
||||
|
||||
if (j_mcconfig.contains("CmdMux"))
|
||||
j_mcconfig.at("CmdMux").get_to(c.cmdMux);
|
||||
|
||||
if (j_mcconfig.contains("RespQueue"))
|
||||
j_mcconfig.at("RespQueue").get_to(c.respQueue);
|
||||
|
||||
if (j_mcconfig.contains("RefreshPolicy"))
|
||||
j_mcconfig.at("RefreshPolicy").get_to(c.refreshPolicy);
|
||||
|
||||
if (j_mcconfig.contains("RefreshMaxPostponed"))
|
||||
j_mcconfig.at("RefreshMaxPostponed").get_to(c.refreshMaxPostponed);
|
||||
|
||||
if (j_mcconfig.contains("RefreshMaxPulledin"))
|
||||
j_mcconfig.at("RefreshMaxPulledin").get_to(c.refreshMaxPulledin);
|
||||
|
||||
if (j_mcconfig.contains("PowerDownPolicy"))
|
||||
j_mcconfig.at("PowerDownPolicy").get_to(c.powerDownPolicy);
|
||||
|
||||
if (j_mcconfig.contains("Arbiter"))
|
||||
j_mcconfig.at("Arbiter").get_to(c.arbiter);
|
||||
|
||||
if (j_mcconfig.contains("MaxActiveTransactions"))
|
||||
j_mcconfig.at("MaxActiveTransactions").get_to(c.maxActiveTransactions);
|
||||
|
||||
if (j_mcconfig.contains("RefreshManagment"))
|
||||
j_mcconfig.at("RefreshManagment").get_to(c.refreshManagement);
|
||||
|
||||
invalidateEnum(c.pagePolicy);
|
||||
invalidateEnum(c.scheduler);
|
||||
invalidateEnum(c.schedulerBuffer);
|
||||
invalidateEnum(c.cmdMux);
|
||||
invalidateEnum(c.respQueue);
|
||||
invalidateEnum(c.refreshPolicy);
|
||||
invalidateEnum(c.respQueue);
|
||||
invalidateEnum(c.powerDownPolicy);
|
||||
invalidateEnum(c.arbiter);
|
||||
}
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
@@ -33,8 +33,10 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef MCCONFIG_H
|
||||
#define MCCONFIG_H
|
||||
#ifndef DRAMSYSCONFIGURATION_MCCONFIG_H
|
||||
#define DRAMSYSCONFIGURATION_MCCONFIG_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <memory>
|
||||
#include <nlohmann/json.hpp>
|
||||
@@ -150,19 +152,19 @@ NLOHMANN_JSON_SERIALIZE_ENUM(Arbiter, {{Arbiter::Invalid, nullptr},
|
||||
|
||||
struct McConfig
|
||||
{
|
||||
PagePolicy pagePolicy;
|
||||
Scheduler scheduler;
|
||||
SchedulerBuffer schedulerBuffer;
|
||||
unsigned int requestBufferSize;
|
||||
CmdMux cmdMux;
|
||||
RespQueue respQueue;
|
||||
RefreshPolicy refreshPolicy;
|
||||
unsigned int refreshMaxPostponed;
|
||||
unsigned int refreshMaxPulledin;
|
||||
PowerDownPolicy powerDownPolicy;
|
||||
Arbiter arbiter;
|
||||
unsigned int maxActiveTransactions;
|
||||
std::pair<bool, bool> refreshManagement;
|
||||
Optional<PagePolicy> pagePolicy;
|
||||
Optional<Scheduler> scheduler;
|
||||
Optional<SchedulerBuffer> schedulerBuffer;
|
||||
Optional<unsigned int> requestBufferSize;
|
||||
Optional<CmdMux> cmdMux;
|
||||
Optional<RespQueue> respQueue;
|
||||
Optional<RefreshPolicy> refreshPolicy;
|
||||
Optional<unsigned int> refreshMaxPostponed;
|
||||
Optional<unsigned int> refreshMaxPulledin;
|
||||
Optional<PowerDownPolicy> powerDownPolicy;
|
||||
Optional<Arbiter> arbiter;
|
||||
Optional<unsigned int> maxActiveTransactions;
|
||||
Optional<bool> refreshManagement;
|
||||
};
|
||||
|
||||
void to_json(json &j, const McConfig &c);
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
*/
|
||||
|
||||
#include "SimConfig.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace DRAMSysConfiguration
|
||||
{
|
||||
@@ -62,21 +61,53 @@ void from_json(const json &j, SimConfig &c)
|
||||
{
|
||||
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);
|
||||
if (j_simconfig.contains("AddressOffset"))
|
||||
j_simconfig.at("AddressOffset").get_to(c.addressOffset);
|
||||
|
||||
if (j_simconfig.contains("CheckTLM2Protocol"))
|
||||
j_simconfig.at("CheckTLM2Protocol").get_to(c.checkTLM2Protocol);
|
||||
|
||||
if (j_simconfig.contains("DatabaseRecording"))
|
||||
j_simconfig.at("DatabaseRecording").get_to(c.databaseRecording);
|
||||
|
||||
if (j_simconfig.contains("Debug"))
|
||||
j_simconfig.at("Debug").get_to(c.debug);
|
||||
|
||||
if (j_simconfig.contains("ECCControllerMode"))
|
||||
j_simconfig.at("ECCControllerMode").get_to(c.eccControllerMode);
|
||||
|
||||
if (j_simconfig.contains("EnableWindowing"))
|
||||
j_simconfig.at("EnableWindowing").get_to(c.enableWindowing);
|
||||
|
||||
if (j_simconfig.contains("ErrorCSVFile"))
|
||||
j_simconfig.at("ErrorCSVFile").get_to(c.errorCsvFile);
|
||||
|
||||
if (j_simconfig.contains("ErrorChipSeed"))
|
||||
j_simconfig.at("ErrorChipSeed").get_to(c.errorChipSeed);
|
||||
|
||||
if (j_simconfig.contains("PowerAnalysis"))
|
||||
j_simconfig.at("PowerAnalysis").get_to(c.powerAnalysis);
|
||||
|
||||
if (j_simconfig.contains("SimulationName"))
|
||||
j_simconfig.at("SimulationName").get_to(c.simulationName);
|
||||
|
||||
if (j_simconfig.contains("SimulationProgressBar"))
|
||||
j_simconfig.at("SimulationProgressBar").get_to(c.simulationProgressBar);
|
||||
|
||||
if (j_simconfig.contains("StoreMode"))
|
||||
j_simconfig.at("StoreMode").get_to(c.storeMode);
|
||||
|
||||
if (j_simconfig.contains("ThermalSimulation"))
|
||||
j_simconfig.at("ThermalSimulation").get_to(c.thermalSimulation);
|
||||
|
||||
if (j_simconfig.contains("UseMalloc"))
|
||||
j_simconfig.at("UseMalloc").get_to(c.useMalloc);
|
||||
|
||||
if (j_simconfig.contains("WindowSize"))
|
||||
j_simconfig.at("WindowSize").get_to(c.windowSize);
|
||||
|
||||
invalidateEnum(c.eccControllerMode);
|
||||
invalidateEnum(c.storeMode);
|
||||
}
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
@@ -33,8 +33,10 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef SIMCONFIG_H
|
||||
#define SIMCONFIG_H
|
||||
#ifndef DRAMSYSCONFIGURATION_SIMCONFIG_H
|
||||
#define DRAMSYSCONFIGURATION_SIMCONFIG_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -64,26 +66,27 @@ enum class StoreMode
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(StoreMode, {{StoreMode::Invalid, nullptr},
|
||||
{StoreMode::NoStorage, "NoStorage"},
|
||||
{StoreMode::Store, "Store"},
|
||||
{StoreMode::ErrorModel, "ErrorModel"}})
|
||||
|
||||
struct SimConfig
|
||||
{
|
||||
unsigned int addressOffset;
|
||||
bool checkTLM2Protocol;
|
||||
bool databaseRecording;
|
||||
bool debug;
|
||||
ECCControllerMode eccControllerMode;
|
||||
bool enableWindowing;
|
||||
std::string errorCsvFile;
|
||||
unsigned int errorChipSeed;
|
||||
bool powerAnalysis;
|
||||
std::string simulationName;
|
||||
bool simulationProgressBar;
|
||||
StoreMode storeMode;
|
||||
bool thermalSimulation;
|
||||
bool useMalloc;
|
||||
unsigned int windowSize;
|
||||
Optional<unsigned int> addressOffset;
|
||||
Optional<bool> checkTLM2Protocol;
|
||||
Optional<bool> databaseRecording;
|
||||
Optional<bool> debug;
|
||||
Optional<ECCControllerMode> eccControllerMode;
|
||||
Optional<bool> enableWindowing;
|
||||
Optional<std::string> errorCsvFile;
|
||||
Optional<unsigned int> errorChipSeed;
|
||||
Optional<bool> powerAnalysis;
|
||||
Optional<std::string> simulationName;
|
||||
Optional<bool> simulationProgressBar;
|
||||
Optional<StoreMode> storeMode;
|
||||
Optional<bool> thermalSimulation;
|
||||
Optional<bool> useMalloc;
|
||||
Optional<unsigned int> windowSize;
|
||||
};
|
||||
|
||||
void to_json(json &j, const SimConfig &c);
|
||||
|
||||
@@ -100,4 +100,4 @@ void from_json(const json &j, PowerInfo &c)
|
||||
j_powerinfo.at("dram_die_channel3").get_to(c.channel3);
|
||||
}
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef THERMALCONFIG_H
|
||||
#define THERMALCONFIG_H
|
||||
#ifndef DRAMSYSCONFIGURATION_THERMALCONFIG_H
|
||||
#define DRAMSYSCONFIGURATION_THERMALCONFIG_H
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
*/
|
||||
|
||||
#include "TraceSetup.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace DRAMSysConfiguration
|
||||
{
|
||||
@@ -61,12 +60,11 @@ void to_json(json &j, const TraceSetup &c)
|
||||
inititator_j["numRequests"] = generator->numRequests;
|
||||
inititator_j["rwRatio"] = generator->rwRatio;
|
||||
inititator_j["addressDistribution"] = generator->addressDistribution;
|
||||
|
||||
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);
|
||||
inititator_j["seed"] = generator->seed;
|
||||
inititator_j["maxPendingReadRequests"] = generator->maxPendingReadRequests;
|
||||
inititator_j["maxPendingWriteRequests"] = generator->maxPendingWriteRequests;
|
||||
inititator_j["minAddress"] = generator->minAddress;
|
||||
inititator_j["maxAddress"] = generator->maxAddress;
|
||||
}
|
||||
else if (const auto hammer = dynamic_cast<TraceHammer *>(initiator.get()))
|
||||
{
|
||||
@@ -79,6 +77,7 @@ void to_json(json &j, const TraceSetup &c)
|
||||
inititator_j["type"] = "player";
|
||||
}
|
||||
|
||||
remove_null_values(inititator_j);
|
||||
j.insert(j.end(), inititator_j);
|
||||
}
|
||||
}
|
||||
@@ -103,11 +102,20 @@ void from_json(const json &j, TraceSetup &c)
|
||||
initiator_j.at("rwRatio").get_to(generator->rwRatio);
|
||||
initiator_j.at("addressDistribution").get_to(generator->addressDistribution);
|
||||
|
||||
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);
|
||||
if (initiator_j.contains("seed"))
|
||||
initiator_j.at("seed").get_to(generator->seed);
|
||||
|
||||
if (initiator_j.contains("maxPendingReadRequests"))
|
||||
initiator_j.at("maxPendingReadRequests").get_to(generator->maxPendingReadRequests);
|
||||
|
||||
if (initiator_j.contains("maxPendingWriteRequests"))
|
||||
initiator_j.at("maxPendingWriteRequests").get_to(generator->maxPendingWriteRequests);
|
||||
|
||||
if (initiator_j.contains("minAddress"))
|
||||
initiator_j.at("minAddress").get_to(generator->minAddress);
|
||||
|
||||
if (initiator_j.contains("maxAddress"))
|
||||
initiator_j.at("maxAddress").get_to(generator->maxAddress);
|
||||
|
||||
initiator = std::unique_ptr<TraceGenerator>(generator);
|
||||
}
|
||||
@@ -128,4 +136,4 @@ void from_json(const json &j, TraceSetup &c)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Configuration
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
@@ -33,8 +33,10 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef TRACESETUP_H
|
||||
#define TRACESETUP_H
|
||||
#ifndef DRAMSYSCONFIGURATION_TRACESETUP_H
|
||||
#define DRAMSYSCONFIGURATION_TRACESETUP_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <memory>
|
||||
#include <nlohmann/json.hpp>
|
||||
@@ -85,12 +87,12 @@ struct TraceGenerator : public TrafficInitiator
|
||||
unsigned int numRequests;
|
||||
double rwRatio;
|
||||
AddressDistribution addressDistribution;
|
||||
std::pair<unsigned int, bool> addressIncrement;
|
||||
std::pair<unsigned int, bool> seed;
|
||||
std::pair<unsigned int, bool> maxPendingReadRequests;
|
||||
std::pair<unsigned int, bool> maxPendingWriteRequests;
|
||||
std::pair<unsigned int, bool> minAddress;
|
||||
std::pair<unsigned int, bool> maxAddress;
|
||||
Optional<unsigned int> addressIncrement;
|
||||
Optional<unsigned int> seed;
|
||||
Optional<unsigned int> maxPendingReadRequests;
|
||||
Optional<unsigned int> maxPendingWriteRequests;
|
||||
Optional<unsigned int> minAddress;
|
||||
Optional<unsigned int> maxAddress;
|
||||
};
|
||||
|
||||
struct TraceHammer : public TrafficInitiator
|
||||
@@ -101,7 +103,7 @@ struct TraceHammer : public TrafficInitiator
|
||||
|
||||
struct TraceSetup
|
||||
{
|
||||
std::unordered_set<std::unique_ptr<TrafficInitiator>> initiators;
|
||||
std::unordered_set<std::shared_ptr<TrafficInitiator>> initiators;
|
||||
};
|
||||
|
||||
void to_json(json &j, const TraceSetup &c);
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef MEMARCHITECTURESPEC_H
|
||||
#define MEMARCHITECTURESPEC_H
|
||||
#ifndef DRAMSYSCONFIGURATION_MEMARCHITECTURESPEC_H
|
||||
#define DRAMSYSCONFIGURATION_MEMARCHITECTURESPEC_H
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef MEMPOWERSPEC_H
|
||||
#define MEMPOWERSPEC_H
|
||||
#ifndef DRAMSYSCONFIGURATION_MEMPOWERSPEC_H
|
||||
#define DRAMSYSCONFIGURATION_MEMPOWERSPEC_H
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
*/
|
||||
|
||||
#include "MemSpec.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace DRAMSysConfiguration
|
||||
{
|
||||
@@ -44,9 +43,10 @@ void to_json(json &j, const MemSpec &c)
|
||||
j = json{{"memarchitecturespec", c.memArchitectureSpec},
|
||||
{"memoryId", c.memoryId},
|
||||
{"memoryType", c.memoryType},
|
||||
{"memtimingspec", c.memTimingSpec}};
|
||||
{"memtimingspec", c.memTimingSpec},
|
||||
{"mempowerspec", c.memPowerSpec}};
|
||||
|
||||
from_optional("mempowerspec", j, c.memPowerSpec);
|
||||
remove_null_values(j);
|
||||
}
|
||||
|
||||
void from_json(const json &j, MemSpec &c)
|
||||
@@ -58,7 +58,8 @@ void from_json(const json &j, MemSpec &c)
|
||||
j_memspecs.at("memoryType").get_to(c.memoryType);
|
||||
j_memspecs.at("memtimingspec").get_to(c.memTimingSpec);
|
||||
|
||||
get_optional("mempowerspec", j, c.memPowerSpec);
|
||||
if (j_memspecs.contains("mempowerspec"))
|
||||
j_memspecs.at("mempowerspec").get_to(c.memPowerSpec);
|
||||
}
|
||||
|
||||
} // namespace Configuration
|
||||
|
||||
@@ -33,12 +33,13 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef MEMSPEC_H
|
||||
#define MEMSPEC_H
|
||||
#ifndef DRAMSYSCONFIGURATION_MEMSPEC_H
|
||||
#define DRAMSYSCONFIGURATION_MEMSPEC_H
|
||||
|
||||
#include "MemArchitectureSpec.h"
|
||||
#include "MemPowerSpec.h"
|
||||
#include "MemTimingSpec.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -54,7 +55,7 @@ struct MemSpec
|
||||
std::string memoryId;
|
||||
std::string memoryType;
|
||||
MemTimingSpec memTimingSpec;
|
||||
std::pair<MemPowerSpec, bool> memPowerSpec;
|
||||
Optional<MemPowerSpec> memPowerSpec;
|
||||
};
|
||||
|
||||
void to_json(json &j, const MemSpec &c);
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef MEMTIMINGSPEC_H
|
||||
#define MEMTIMINGSPEC_H
|
||||
#ifndef DRAMSYSCONFIGURATION_MEMTIMINGSPEC_H
|
||||
#define DRAMSYSCONFIGURATION_MEMTIMINGSPEC_H
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -6,13 +6,13 @@ using json = nlohmann::json;
|
||||
|
||||
DRAMSysConfiguration::AddressMapping getAddressMapping()
|
||||
{
|
||||
return DRAMSysConfiguration::AddressMapping{{{0, 1}, true},
|
||||
return DRAMSysConfiguration::AddressMapping{{{0, 1}},
|
||||
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
|
||||
{16},
|
||||
{{13, 14, 15}, true},
|
||||
{{13, 14, 15}},
|
||||
{17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32},
|
||||
{{33}, true},
|
||||
{{}, false}};
|
||||
{{33}},
|
||||
{{}}};
|
||||
}
|
||||
|
||||
DRAMSysConfiguration::McConfig getMcConfig()
|
||||
@@ -29,14 +29,14 @@ DRAMSysConfiguration::McConfig getMcConfig()
|
||||
DRAMSysConfiguration::PowerDownPolicy::NoPowerDown,
|
||||
DRAMSysConfiguration::Arbiter::Simple,
|
||||
128,
|
||||
std::pair<bool, bool>{false, true}};
|
||||
{}};
|
||||
}
|
||||
|
||||
DRAMSysConfiguration::SimConfig getSimConfig()
|
||||
{
|
||||
return DRAMSysConfiguration::SimConfig{
|
||||
0, false, true, false, DRAMSysConfiguration::ECCControllerMode::Disabled, false, "error.csv",
|
||||
42, false, "ddr5", true, DRAMSysConfiguration::StoreMode::NoStorage, false, false,
|
||||
0, false, true, false, DRAMSysConfiguration::ECCControllerMode::Disabled, false, {"error.csv"},
|
||||
42, false, {"ddr5"}, true, DRAMSysConfiguration::StoreMode::NoStorage, false, false,
|
||||
1000};
|
||||
}
|
||||
|
||||
@@ -74,10 +74,10 @@ std::unique_ptr<DRAMSysConfiguration::TraceGenerator> getTraceGeneratorRandom()
|
||||
gen->name = "MyTestGen";
|
||||
|
||||
gen->addressDistribution = DRAMSysConfiguration::AddressDistribution::Random;
|
||||
gen->maxAddress = {1000, true};
|
||||
gen->maxPendingReadRequests = {8, true};
|
||||
gen->maxAddress = 1000;
|
||||
gen->maxPendingReadRequests = 8;
|
||||
gen->rwRatio = 0.5;
|
||||
gen->seed = {1337, true};
|
||||
gen->seed = 1337;
|
||||
gen->numRequests = 1000;
|
||||
|
||||
return std::unique_ptr<DRAMSysConfiguration::TraceGenerator>(gen);
|
||||
@@ -91,9 +91,9 @@ std::unique_ptr<DRAMSysConfiguration::TraceGenerator> getTraceGeneratorSequentia
|
||||
gen->name = "MyTestGen";
|
||||
|
||||
gen->addressDistribution = DRAMSysConfiguration::AddressDistribution::Sequential;
|
||||
gen->addressIncrement = {64, true};
|
||||
gen->maxAddress = {1000, true};
|
||||
gen->maxPendingReadRequests = {8, true};
|
||||
gen->addressIncrement = 64;
|
||||
gen->maxAddress = 1000;
|
||||
gen->maxPendingReadRequests = 8;
|
||||
gen->rwRatio = 0.5;
|
||||
gen->numRequests = 1000;
|
||||
|
||||
@@ -115,13 +115,13 @@ std::unique_ptr<DRAMSysConfiguration::TraceHammer> getTraceHammer()
|
||||
|
||||
DRAMSysConfiguration::TraceSetup getTraceSetup()
|
||||
{
|
||||
std::unordered_set<std::unique_ptr<DRAMSysConfiguration::TrafficInitiator>> initiators;
|
||||
std::unordered_set<std::shared_ptr<DRAMSysConfiguration::TrafficInitiator>> initiators;
|
||||
initiators.emplace(getTracePlayer());
|
||||
initiators.emplace(getTraceGeneratorRandom());
|
||||
initiators.emplace(getTraceGeneratorSequential());
|
||||
initiators.emplace(getTraceHammer());
|
||||
|
||||
return DRAMSysConfiguration::TraceSetup{std::move(initiators)};
|
||||
return DRAMSysConfiguration::TraceSetup{initiators};
|
||||
}
|
||||
|
||||
DRAMSysConfiguration::Configuration getConfig(const DRAMSysConfiguration::MemSpec &memSpec)
|
||||
@@ -132,9 +132,9 @@ DRAMSysConfiguration::Configuration getConfig(const DRAMSysConfiguration::MemSpe
|
||||
memSpec,
|
||||
getSimConfig(),
|
||||
"std::string_simulationId",
|
||||
{getThermalConfig(), true},
|
||||
getThermalConfig(),
|
||||
// {{}, false}, works too
|
||||
{getTraceSetup(), true},
|
||||
getTraceSetup(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
#ifndef DRAMSYSCONFIGURATION_UTIL_H
|
||||
#define DRAMSYSCONFIGURATION_UTIL_H
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <utility>
|
||||
@@ -43,35 +43,91 @@ namespace DRAMSysConfiguration
|
||||
{
|
||||
using json = nlohmann::json;
|
||||
|
||||
/**
|
||||
* Inspired from https://github.com/nlohmann/json/issues/1749#issuecomment-770748811
|
||||
*/
|
||||
template <typename T>
|
||||
void get_optional(const std::string &name, const json &j, std::pair<T, bool> &val)
|
||||
class Optional : public std::pair<T, bool>
|
||||
{
|
||||
auto it = j.find(name);
|
||||
if (it != j.end())
|
||||
public:
|
||||
Optional() : std::pair<T, bool>{{}, false}
|
||||
{
|
||||
val.first = it->template get<T>();
|
||||
val.second = true;
|
||||
}
|
||||
else
|
||||
Optional(const T &v) : std::pair<T, bool>{v, true}
|
||||
{
|
||||
val.second = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return this->second;
|
||||
}
|
||||
|
||||
const T &getValue() const
|
||||
{
|
||||
assert(this->second == true);
|
||||
return this->first;
|
||||
}
|
||||
|
||||
void setValue(const T &v)
|
||||
{
|
||||
this->first = v;
|
||||
this->second = true;
|
||||
}
|
||||
|
||||
void invalidate()
|
||||
{
|
||||
this->second = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void from_optional(const std::string &name, json &j, const std::pair<T, bool> &val)
|
||||
void invalidateEnum(T &value)
|
||||
{
|
||||
if (val.second)
|
||||
{
|
||||
j[name] = val.first;
|
||||
}
|
||||
if (value.isValid() && value.getValue() == T::first_type::Invalid)
|
||||
value.invalidate();
|
||||
}
|
||||
|
||||
json get_config_json(const json &j, const std::string &configPath, const std::string &objectName);
|
||||
|
||||
inline void remove_null_values(json &j)
|
||||
{
|
||||
std::vector<std::string> keysToRemove;
|
||||
|
||||
for (const auto &element : j.items())
|
||||
{
|
||||
if (element.value() == nullptr)
|
||||
keysToRemove.emplace_back(element.key());
|
||||
}
|
||||
|
||||
std::for_each(keysToRemove.begin(), keysToRemove.end(), [&](const std::string &key) { j.erase(key); });
|
||||
}
|
||||
|
||||
} // namespace DRAMSysConfiguration
|
||||
|
||||
/**
|
||||
* Inspired from
|
||||
* https://json.nlohmann.me/features/arbitrary_types/#how-can-i-use-get-for-non-default-constructiblenon-copyable-types
|
||||
*/
|
||||
namespace nlohmann
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
void to_json(nlohmann::json &j, const DRAMSysConfiguration::Optional<T> &v)
|
||||
{
|
||||
if (v.isValid())
|
||||
j = v.getValue();
|
||||
else
|
||||
j = nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void from_json(const nlohmann::json &j, DRAMSysConfiguration::Optional<T> &v)
|
||||
{
|
||||
if (j.is_null())
|
||||
v = {};
|
||||
else
|
||||
{
|
||||
v = {j.get<T>()};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nlohmann
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user