From 9935abe28a3de0f699dd5341d46348783d1fdc22 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Thu, 28 Oct 2021 15:44:50 +0200 Subject: [PATCH] Introduce a common json configuration library This new configuration library is capable of parsing DRAMSys config jsons and generating them. The "Configuration" struct contains the complete configuration required for simulation. The library will be used in future in DRAMSys itself and also in the TracePlayer, gem5 player, TraceAnalyzer and all other tools that use DRAMSys as a library. --- DRAMSys/library/CMakeLists.txt | 5 +- .../common/configuration/AddressMapping.cpp | 87 +++++++++ .../src/common/configuration/AddressMapping.h | 71 +++++++ .../src/common/configuration/CMakeLists.txt | 57 ++++++ .../common/configuration/Configuration.cpp | 68 +++++++ .../src/common/configuration/Configuration.h | 80 ++++++++ .../src/common/configuration/McConfig.cpp | 78 ++++++++ .../src/common/configuration/McConfig.h | 171 +++++++++++++++++ .../src/common/configuration/SimConfig.cpp | 79 ++++++++ .../src/common/configuration/SimConfig.h | 92 +++++++++ .../common/configuration/ThermalConfig.cpp | 98 ++++++++++ .../src/common/configuration/ThermalConfig.h | 117 +++++++++++ .../src/common/configuration/TraceSetup.cpp | 131 +++++++++++++ .../src/common/configuration/TraceSetup.h | 112 +++++++++++ .../memspec/MemArchitectureSpec.cpp | 59 ++++++ .../memspec/MemArchitectureSpec.h | 56 ++++++ .../configuration/memspec/MemPowerSpec.cpp | 59 ++++++ .../configuration/memspec/MemPowerSpec.h | 56 ++++++ .../common/configuration/memspec/MemSpec.cpp | 62 ++++++ .../common/configuration/memspec/MemSpec.h | 63 ++++++ .../configuration/memspec/MemTimingSpec.cpp | 59 ++++++ .../configuration/memspec/MemTimingSpec.h | 56 ++++++ .../common/configuration/tests/CMakeLists.txt | 2 + .../common/configuration/tests/simpletest.cpp | 181 ++++++++++++++++++ .../library/src/common/configuration/util.h | 75 ++++++++ 25 files changed, 1971 insertions(+), 3 deletions(-) create mode 100644 DRAMSys/library/src/common/configuration/AddressMapping.cpp create mode 100644 DRAMSys/library/src/common/configuration/AddressMapping.h create mode 100644 DRAMSys/library/src/common/configuration/CMakeLists.txt create mode 100644 DRAMSys/library/src/common/configuration/Configuration.cpp create mode 100644 DRAMSys/library/src/common/configuration/Configuration.h create mode 100644 DRAMSys/library/src/common/configuration/McConfig.cpp create mode 100644 DRAMSys/library/src/common/configuration/McConfig.h create mode 100644 DRAMSys/library/src/common/configuration/SimConfig.cpp create mode 100644 DRAMSys/library/src/common/configuration/SimConfig.h create mode 100644 DRAMSys/library/src/common/configuration/ThermalConfig.cpp create mode 100644 DRAMSys/library/src/common/configuration/ThermalConfig.h create mode 100644 DRAMSys/library/src/common/configuration/TraceSetup.cpp create mode 100644 DRAMSys/library/src/common/configuration/TraceSetup.h create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemSpec.h create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp create mode 100644 DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h create mode 100644 DRAMSys/library/src/common/configuration/tests/CMakeLists.txt create mode 100644 DRAMSys/library/src/common/configuration/tests/simpletest.cpp create mode 100644 DRAMSys/library/src/common/configuration/util.h diff --git a/DRAMSys/library/CMakeLists.txt b/DRAMSys/library/CMakeLists.txt index 8549b70d..61b4756b 100644 --- a/DRAMSys/library/CMakeLists.txt +++ b/DRAMSys/library/CMakeLists.txt @@ -44,9 +44,8 @@ set(DCMAKE_SH="CMAKE_SH-NOTFOUND") # Add DRAMPower: add_subdirectory(src/common/third_party/DRAMPower) -# Add nlohmann: -set(JSON_BuildTests OFF CACHE INTERNAL "") -add_subdirectory(src/common/third_party/nlohmann) +# Add Configuration +add_subdirectory(src/common/configuration) # Add SystemC: if(DEFINED ENV{SYSTEMC_HOME}) diff --git a/DRAMSys/library/src/common/configuration/AddressMapping.cpp b/DRAMSys/library/src/common/configuration/AddressMapping.cpp new file mode 100644 index 00000000..cceea826 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/AddressMapping.cpp @@ -0,0 +1,87 @@ +/* + * 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 "AddressMapping.h" +#include "util.h" + +#include + +namespace Configuration +{ + +void to_json(json &j, const AddressMapping &m) +{ + json congen = json{}; + + congen = json{{"BYTE_BIT", m.byteBits}, + {"COLUMN_BIT", m.coloumnBits}, + {"BANKGROUP_BIT", m.bankGroupBits}, + {"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); + + j["CONGEN"] = congen; +} + +void from_json(const json &j, AddressMapping &m) +{ + json congen = j.at("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); +} + +void to_json(json &j, const XorPair &x) +{ + j = json{{"FIRST", x.first}, {"SECOND", x.second}}; +} + +void from_json(const json &j, XorPair &x) +{ + j.at("FIRST").get_to(x.first); + j.at("SECOND").get_to(x.second); +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/AddressMapping.h b/DRAMSys/library/src/common/configuration/AddressMapping.h new file mode 100644 index 00000000..dd3f9c91 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/AddressMapping.h @@ -0,0 +1,71 @@ +/* + * 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 + */ + +#ifndef ADDRESSMAPPING_H +#define ADDRESSMAPPING_H + +#include +#include + +namespace Configuration +{ +using json = nlohmann::json; + +struct XorPair +{ + unsigned int first; + unsigned int second; +}; + +void to_json(json &j, const XorPair &x); +void from_json(const json &j, XorPair &x); + +struct AddressMapping +{ + std::pair, bool> byteBits; + std::unordered_set coloumnBits; + std::unordered_set bankBits; + std::pair, bool> bankGroupBits; + std::unordered_set rowBits; + std::pair, bool> channelBits; + std::pair, bool> xorBits; +}; + +void to_json(json &j, const AddressMapping &m); +void from_json(const json &j, AddressMapping &m); + +} // namespace Configuration + +#endif // ADDRESSMAPPING_H diff --git a/DRAMSys/library/src/common/configuration/CMakeLists.txt b/DRAMSys/library/src/common/configuration/CMakeLists.txt new file mode 100644 index 00000000..87c02b92 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/CMakeLists.txt @@ -0,0 +1,57 @@ +# 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 + +set(JSON_BuildTests 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) + +if (DRAMSYS_CONFIGURATION_TESTS) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests) +endif() + +add_library(DRAMSysConfiguration STATIC + Configuration.cpp + AddressMapping.cpp + McConfig.cpp + SimConfig.cpp + ThermalConfig.cpp + TraceSetup.cpp + memspec/MemSpec.cpp + memspec/MemArchitectureSpec.cpp + memspec/MemPowerSpec.cpp + memspec/MemTimingSpec.cpp +) + +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 new file mode 100644 index 00000000..24cd663f --- /dev/null +++ b/DRAMSys/library/src/common/configuration/Configuration.cpp @@ -0,0 +1,68 @@ +/* + * 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 "Configuration.h" +#include "util.h" + +#include + +namespace Configuration +{ + +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}}; + + Util::from_optional("thermalconfig", j, c.thermalConfig); + Util::from_optional("tracesetup", j, c.traceSetup); +} + +void from_json(const json &j, Configuration &c) +{ + j.at("addressmapping").get_to(c.addressMapping); + j.at("mcconfig").get_to(c.mcConfig); + j.at("memspec").get_to(c.memSpec); + 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); +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/Configuration.h b/DRAMSys/library/src/common/configuration/Configuration.h new file mode 100644 index 00000000..069a5147 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/Configuration.h @@ -0,0 +1,80 @@ +/* + * 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 + */ + +#ifndef CONFIGURATION_H +#define CONFIGURATION_H + +#include "AddressMapping.h" +#include "McConfig.h" +#include "SimConfig.h" +#include "ThermalConfig.h" +#include "TraceSetup.h" +#include "memspec/MemSpec.h" + +#include +#include +#include + +/** + * To support polymorphic configurations, a Json "type" tag is used + * to determine the correct type before further parsing. + * + * To support optional values, std::pair is used. The first parameter is the value, + * the second parameter specifies if the value is valid. + * Replace with std::optional when this project is updated to C++17. + * Consider also switching to std::variant to achieve static polymorphism. + */ + +namespace Configuration +{ +using json = nlohmann::json; + +struct Configuration +{ + AddressMapping addressMapping; + McConfig mcConfig; + MemSpec memSpec; + SimConfig simConfig; + std::string simulationId; + std::pair thermalConfig; + std::pair traceSetup; +}; + +void to_json(json &j, const Configuration &p); +void from_json(const json &j, Configuration &p); + +} // namespace Configuration + +#endif // CONFIGURATION_H diff --git a/DRAMSys/library/src/common/configuration/McConfig.cpp b/DRAMSys/library/src/common/configuration/McConfig.cpp new file mode 100644 index 00000000..b0ad41ec --- /dev/null +++ b/DRAMSys/library/src/common/configuration/McConfig.cpp @@ -0,0 +1,78 @@ +/* + * 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 "McConfig.h" +#include "util.h" + +namespace Configuration +{ + +void to_json(json &j, const McConfig &c) +{ + j = json{{"PagePolicy", c.pagePolicy}, + {"Scheduler", c.scheduler}, + {"SchedulerBuffer", c.schedulerBuffer}, + {"RequestBufferSize", c.requestBufferSize}, + {"CmdMux", c.cmdMux}, + {"RespQueue", c.respQueue}, + {"RefreshPolicy", c.refreshPolicy}, + {"RefreshMaxPostponed", c.refreshMaxPostponed}, + {"RefreshMaxPulledin", c.refreshMaxPulledin}, + {"PowerDownPolicy", c.powerDownPolicy}, + {"Arbiter", c.arbiter}, + {"MaxActiveTransactions", c.maxActiveTransactions}}; + + Util::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); + + Util::get_optional("RefreshManagment", j, c.refreshManagement); +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/McConfig.h b/DRAMSys/library/src/common/configuration/McConfig.h new file mode 100644 index 00000000..d265e022 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/McConfig.h @@ -0,0 +1,171 @@ +/* + * 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 + */ + +#ifndef MCCONFIG_H +#define MCCONFIG_H + +#include +#include +#include + +namespace Configuration +{ +using json = nlohmann::json; + +enum class PagePolicy +{ + Open, + OpenAdaptive, + Closed, + ClosedAdaptive, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(PagePolicy, { + {PagePolicy::Invalid, nullptr}, + {PagePolicy::Open, "Open"}, + {PagePolicy::OpenAdaptive, "OpenAdaptive"}, + {PagePolicy::Closed, "Closed"}, + {PagePolicy::ClosedAdaptive, "ClosedAdaptive"}, + }) + +enum class Scheduler +{ + Fifo, + FrFcfs, + FrFcfsGrp, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(Scheduler, {{Scheduler::Invalid, nullptr}, + {Scheduler::Fifo, "Fifo"}, + {Scheduler::FrFcfs, "FrFcfs"}, + {Scheduler::FrFcfsGrp, "FrFcfsGrp"}}) + +enum class SchedulerBuffer +{ + Bankwise, + ReadWrite, + Shared, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(SchedulerBuffer, {{SchedulerBuffer::Invalid, nullptr}, + {SchedulerBuffer::Bankwise, "Bankwise"}, + {SchedulerBuffer::ReadWrite, "ReadWrite"}, + {SchedulerBuffer::Shared, "Shared"}}) + +enum class CmdMux +{ + Oldest, + Strict, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(CmdMux, + {{CmdMux::Invalid, nullptr}, {CmdMux::Oldest, "Oldest"}, {CmdMux::Strict, "Strict"}}) + +enum class RespQueue +{ + Fifo, + Reorder, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(RespQueue, {{RespQueue::Invalid, nullptr}, + {RespQueue::Fifo, "Fifo"}, + {RespQueue::Reorder, "Reorder"}}) + +enum class RefreshPolicy +{ + NoRefresh, + AllBank, + PerBank, + SameBank, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(RefreshPolicy, {{RefreshPolicy::Invalid, nullptr}, + {RefreshPolicy::AllBank, "AllBank"}, + {RefreshPolicy::PerBank, "PerBank"}, + {RefreshPolicy::SameBank, "SameBank"}}) + +enum class PowerDownPolicy +{ + NoPowerDown, + Staggered, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(PowerDownPolicy, {{PowerDownPolicy::Invalid, nullptr}, + {PowerDownPolicy::NoPowerDown, "NoPowerDown"}, + {PowerDownPolicy::Staggered, "Staggered"}}) + +enum class Arbiter +{ + Simple, + Fifo, + Reorder, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(Arbiter, {{Arbiter::Invalid, nullptr}, + {Arbiter::Simple, "Simple"}, + {Arbiter::Fifo, "Fifo"}, + {Arbiter::Reorder, "Reorder"}}) + +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 refreshManagement; +}; + +void to_json(json &j, const McConfig &c); +void from_json(const json &j, McConfig &c); + +} // namespace Configuration + +#endif // MCCONFIG_H diff --git a/DRAMSys/library/src/common/configuration/SimConfig.cpp b/DRAMSys/library/src/common/configuration/SimConfig.cpp new file mode 100644 index 00000000..91acde69 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/SimConfig.cpp @@ -0,0 +1,79 @@ +/* + * 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 "SimConfig.h" + +namespace Configuration +{ + +void to_json(json &j, const SimConfig &c) +{ + j = json{{"AddressOffset", c.addressOffset}, + {"CheckTLM2Protocol", c.checkTLM2Protocol}, + {"DatabaseRecording", c.databaseRecording}, + {"Debug", c.debug}, + {"ECCControllerMode", c.eccControllerMode}, + {"EnableWindowing", c.enableWindowing}, + {"ErrorCSVFile", c.errorCsvFile}, + {"ErrorChipSeed", c.errorChipSeed}, + {"PowerAnalysis", c.powerAnalysis}, + {"SimulationName", c.simulationName}, + {"SimulationProgressBar", c.simulationProgressBar}, + {"StoreMode", c.storeMode}, + {"ThermalSimulation", c.thermalSimulation}, + {"UseMalloc", c.useMalloc}, + {"WindowSize", c.windowSize}}; +} + +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); +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/SimConfig.h b/DRAMSys/library/src/common/configuration/SimConfig.h new file mode 100644 index 00000000..7d23ff75 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/SimConfig.h @@ -0,0 +1,92 @@ +/* + * 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 + */ + +#ifndef SIMCONFIG_H +#define SIMCONFIG_H + +#include + +namespace Configuration +{ +using json = nlohmann::json; + +enum class ECCControllerMode +{ + Disabled, + Hamming, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(ECCControllerMode, {{ECCControllerMode::Invalid, nullptr}, + {ECCControllerMode::Disabled, "Disabled"}, + {ECCControllerMode::Hamming, "Hamming"}}) + +enum class StoreMode +{ + NoStorage, + Store, + ErrorModel, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(StoreMode, {{StoreMode::Invalid, nullptr}, + {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; +}; + +void to_json(json &j, const SimConfig &c); +void from_json(const json &j, SimConfig &c); + +} // namespace Configuration + +#endif diff --git a/DRAMSys/library/src/common/configuration/ThermalConfig.cpp b/DRAMSys/library/src/common/configuration/ThermalConfig.cpp new file mode 100644 index 00000000..e593fcbe --- /dev/null +++ b/DRAMSys/library/src/common/configuration/ThermalConfig.cpp @@ -0,0 +1,98 @@ +/* + * 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 "ThermalConfig.h" + +namespace Configuration +{ + +void to_json(json &j, const ThermalConfig &c) +{ + j = json{{"TemperatureScale", c.temperatureScale}, + {"StaticTemperatureDefaultValue", c.staticTemperatureDefaultValue}, + {"ThermalSimPeriod", c.thermalSimPeriod}, + {"ThermalSimUnit", c.thermalSimUnit}, + {"PowerInfoFile", c.powerInfo}, + {"IceServerIp", c.iceServerIp}, + {"IceServerPort", c.iceServerPort}, + {"SimPeriodAdjustFactor", c.simPeriodAdjustFactor}, + {"NPowStableCyclesToIncreasePeriod", c.nPowStableCyclesToIncreasePeriod}, + {"GenerateTemperatureMap", c.generateTemperatureMap}, + {"GeneratePowerMap", c.generatePowerMap}}; +} + +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); +} + +void to_json(json &j, const DramDieChannel &c) +{ + j = json{{"init_pow", c.init_pow}, {"threshold", c.threshold}}; +} + +void from_json(const json &j, DramDieChannel &c) +{ + j.at("init_pow").get_to(c.init_pow); + j.at("threshold").get_to(c.threshold); +} + +void to_json(json &j, const PowerInfo &c) +{ + j = json{{"dram_die_channel0", c.channel0}, + {"dram_die_channel1", c.channel1}, + {"dram_die_channel2", c.channel2}, + {"dram_die_channel3", c.channel3}}; +} + +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); +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/ThermalConfig.h b/DRAMSys/library/src/common/configuration/ThermalConfig.h new file mode 100644 index 00000000..a6e6fd34 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/ThermalConfig.h @@ -0,0 +1,117 @@ +/* + * 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 + */ + +#ifndef THERMALCONFIG_H +#define THERMALCONFIG_H + +#include + +namespace Configuration +{ +using json = nlohmann::json; + +enum class TemperatureScale +{ + Celsius, + Fahrenheit, + Kelvin, + Invalid = -1, +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(TemperatureScale, {{TemperatureScale::Invalid, nullptr}, + {TemperatureScale::Celsius, "Celsius"}, + {TemperatureScale::Fahrenheit, "Fahrenheit"}, + {TemperatureScale::Kelvin, "Kelvin"}}) + +enum class ThermalSimUnit +{ + Seconds, + Milliseconds, + Microseconds, + Nanoseconds, + Picoseconds, + Femtoseconds, + Invalid = -1, +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(ThermalSimUnit, {{ThermalSimUnit::Invalid, nullptr}, + {ThermalSimUnit::Seconds, "s"}, + {ThermalSimUnit::Milliseconds, "ms"}, + {ThermalSimUnit::Microseconds, "us"}, + {ThermalSimUnit::Nanoseconds, "ns"}, + {ThermalSimUnit::Picoseconds, "ps"}, + {ThermalSimUnit::Femtoseconds, "fs"}}) + +struct DramDieChannel +{ + double init_pow; + double threshold; +}; + +void to_json(json &j, const DramDieChannel &c); +void from_json(const json &j, DramDieChannel &c); + +struct PowerInfo +{ + DramDieChannel channel0; + DramDieChannel channel1; + DramDieChannel channel2; + DramDieChannel channel3; +}; + +void to_json(json &j, const PowerInfo &c); +void from_json(const json &j, PowerInfo &c); + +struct ThermalConfig +{ + TemperatureScale temperatureScale; + int staticTemperatureDefaultValue; + double thermalSimPeriod; + ThermalSimUnit thermalSimUnit; + PowerInfo powerInfo; + std::string iceServerIp; + unsigned int iceServerPort; + unsigned int simPeriodAdjustFactor; + unsigned int nPowStableCyclesToIncreasePeriod; + bool generateTemperatureMap; + bool generatePowerMap; +}; + +void to_json(json &j, const ThermalConfig &c); +void from_json(const json &j, ThermalConfig &c); + +} // namespace Configuration + +#endif // THERMALCONFIG_H diff --git a/DRAMSys/library/src/common/configuration/TraceSetup.cpp b/DRAMSys/library/src/common/configuration/TraceSetup.cpp new file mode 100644 index 00000000..e39452fc --- /dev/null +++ b/DRAMSys/library/src/common/configuration/TraceSetup.cpp @@ -0,0 +1,131 @@ +/* + * 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 "TraceSetup.h" +#include "util.h" + +namespace Configuration +{ + +TrafficInitiator::~TrafficInitiator() +{ +} + +void to_json(json &j, const TraceSetup &c) +{ + // Create an empty array + j = json::array(); + + for (const auto &initiator : c.initiators) + { + json inititator_j; + + inititator_j["name"] = initiator->name; + inititator_j["clkMhz"] = initiator->clkMhz; + + if (const auto generator = dynamic_cast(initiator.get())) + { + inititator_j["type"] = "generator"; + inititator_j["numRequests"] = generator->numRequests; + 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); + } + else if (const auto hammer = dynamic_cast(initiator.get())) + { + inititator_j["type"] = "hammer"; + inititator_j["numRequests"] = hammer->numRequests; + inititator_j["rowIncrement"] = hammer->rowIncrement; + } + else if (const auto player = dynamic_cast(initiator.get())) + { + inititator_j["type"] = "player"; + } + + j.insert(j.end(), inititator_j); + } +} + +void from_json(const json &j, TraceSetup &c) +{ + for (const auto &initiator_j : j) + { + // Default to Player, when not specified + TrafficInitiatorType type = initiator_j.value("type", TrafficInitiatorType::Player); + + std::unique_ptr initiator; + if (type == TrafficInitiatorType::Player) + { + initiator = std::unique_ptr(new TracePlayer); + } + else if (type == TrafficInitiatorType::Generator) + { + TraceGenerator *generator = new TraceGenerator; + + initiator_j.at("numRequests").get_to(generator->numRequests); + 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); + + initiator = std::unique_ptr(generator); + } + else if (type == TrafficInitiatorType::Hammer) + { + TraceHammer *hammer = new TraceHammer; + + initiator_j.at("numRequests").get_to(hammer->numRequests); + initiator_j.at("rowIncrement").get_to(hammer->rowIncrement); + + initiator = std::unique_ptr(hammer); + } + + initiator_j.at("name").get_to(initiator->name); + initiator_j.at("clkMhz").get_to(initiator->clkMhz); + + c.initiators.emplace(std::move(initiator)); + } +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/TraceSetup.h b/DRAMSys/library/src/common/configuration/TraceSetup.h new file mode 100644 index 00000000..d3974ec6 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/TraceSetup.h @@ -0,0 +1,112 @@ +/* + * 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 + */ + +#ifndef TRACESETUP_H +#define TRACESETUP_H + +#include +#include +#include + +namespace Configuration +{ +using json = nlohmann::json; + +enum class TrafficInitiatorType +{ + Player, + Generator, + Hammer, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(TrafficInitiatorType, {{TrafficInitiatorType::Invalid, nullptr}, + {TrafficInitiatorType::Player, "player"}, + {TrafficInitiatorType::Hammer, "hammer"}, + {TrafficInitiatorType::Generator, "generator"}}) + +enum class AddressDistribution +{ + Random, + Sequential, + Invalid = -1 +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(AddressDistribution, {{AddressDistribution::Invalid, nullptr}, + {AddressDistribution::Random, "random"}, + {AddressDistribution::Sequential, "sequential"}}) + +struct TrafficInitiator +{ + virtual ~TrafficInitiator() = 0; + + unsigned int clkMhz; + std::string name; +}; + +struct TracePlayer : public TrafficInitiator +{ +}; + +struct TraceGenerator : public TrafficInitiator +{ + unsigned int numRequests; + double rwRatio; + AddressDistribution addressDistribution; + std::pair addressIncrement; + std::pair seed; + std::pair maxPendingReadRequests; + std::pair maxPendingWriteRequests; + std::pair minAddress; + std::pair maxAddress; +}; + +struct TraceHammer : public TrafficInitiator +{ + unsigned int numRequests; + unsigned int rowIncrement; +}; + +struct TraceSetup +{ + std::unordered_set> initiators; +}; + +void to_json(json &j, const TraceSetup &c); +void from_json(const json &j, TraceSetup &c); + +} // namespace Configuration + +#endif diff --git a/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp new file mode 100644 index 00000000..5de2684b --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.cpp @@ -0,0 +1,59 @@ +/* + * 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 "MemArchitectureSpec.h" + +namespace Configuration +{ + +void to_json(json &j, const MemArchitectureSpec &c) +{ + j = json{}; + + for (const auto &entry : c.entries) + { + j[entry.first] = entry.second; + } +} + +void from_json(const json &j, MemArchitectureSpec &c) +{ + for (const auto &entry : j.items()) + { + c.entries[entry.key()] = entry.value(); + } +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h new file mode 100644 index 00000000..cd516ad2 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemArchitectureSpec.h @@ -0,0 +1,56 @@ +/* + * 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 + */ + +#ifndef MEMARCHITECTURESPEC_H +#define MEMARCHITECTURESPEC_H + +#include +#include + +namespace Configuration +{ +using json = nlohmann::json; + +struct MemArchitectureSpec +{ + std::unordered_map entries; +}; + +void to_json(json &j, const MemArchitectureSpec &c); +void from_json(const json &j, MemArchitectureSpec &c); + +} // namespace Configuration + +#endif diff --git a/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp new file mode 100644 index 00000000..6621fabc --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.cpp @@ -0,0 +1,59 @@ +/* + * 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 "MemPowerSpec.h" + +namespace Configuration +{ + +void to_json(json &j, const MemPowerSpec &c) +{ + j = json{}; + + for (const auto &entry : c.entries) + { + j[entry.first] = entry.second; + } +} + +void from_json(const json &j, MemPowerSpec &c) +{ + for (const auto &entry : j.items()) + { + c.entries[entry.key()] = entry.value(); + } +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h new file mode 100644 index 00000000..5c201580 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemPowerSpec.h @@ -0,0 +1,56 @@ +/* + * 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 + */ + +#ifndef MEMPOWERSPEC_H +#define MEMPOWERSPEC_H + +#include +#include + +namespace Configuration +{ +using json = nlohmann::json; + +struct MemPowerSpec +{ + std::unordered_map entries; +}; + +void to_json(json &j, const MemPowerSpec &c); +void from_json(const json &j, MemPowerSpec &c); + +} // namespace Configuration + +#endif diff --git a/DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp new file mode 100644 index 00000000..8bdcf0ef --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemSpec.cpp @@ -0,0 +1,62 @@ +/* + * 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 "MemSpec.h" +#include "util.h" + +namespace Configuration +{ + +void to_json(json &j, const MemSpec &c) +{ + j = json{{"memarchitecturespec", c.memArchitectureSpec}, + {"memoryId", c.memoryId}, + {"memoryType", c.memoryType}, + {"memtimingspec", c.memTimingSpec}}; + + Util::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); + + Util::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 new file mode 100644 index 00000000..5d716963 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemSpec.h @@ -0,0 +1,63 @@ +/* + * 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 + */ + +#ifndef MEMSPEC_H +#define MEMSPEC_H + +#include "MemArchitectureSpec.h" +#include "MemPowerSpec.h" +#include "MemTimingSpec.h" + +#include + +namespace Configuration +{ +using json = nlohmann::json; + +struct MemSpec +{ + MemArchitectureSpec memArchitectureSpec; + std::string memoryId; + std::string memoryType; + MemTimingSpec memTimingSpec; + std::pair memPowerSpec; +}; + +void to_json(json &j, const MemSpec &c); +void from_json(const json &j, MemSpec &c); + +} // namespace Configuration + +#endif // MEMSPEC_H diff --git a/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp new file mode 100644 index 00000000..0b41f8cf --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.cpp @@ -0,0 +1,59 @@ +/* + * 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 "MemTimingSpec.h" + +namespace Configuration +{ + +void to_json(json &j, const MemTimingSpec &c) +{ + j = json{}; + + for (const auto &entry : c.entries) + { + j[entry.first] = entry.second; + } +} + +void from_json(const json &j, MemTimingSpec &c) +{ + for (const auto &entry : j.items()) + { + c.entries[entry.key()] = entry.value(); + } +} + +} // namespace Configuration diff --git a/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h new file mode 100644 index 00000000..6203803b --- /dev/null +++ b/DRAMSys/library/src/common/configuration/memspec/MemTimingSpec.h @@ -0,0 +1,56 @@ +/* + * 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 + */ + +#ifndef MEMTIMINGSPEC_H +#define MEMTIMINGSPEC_H + +#include +#include + +namespace Configuration +{ +using json = nlohmann::json; + +struct MemTimingSpec +{ + std::unordered_map entries; +}; + +void to_json(json &j, const MemTimingSpec &c); +void from_json(const json &j, MemTimingSpec &c); + +} // namespace Configuration + +#endif diff --git a/DRAMSys/library/src/common/configuration/tests/CMakeLists.txt b/DRAMSys/library/src/common/configuration/tests/CMakeLists.txt new file mode 100644 index 00000000..0b9890b0 --- /dev/null +++ b/DRAMSys/library/src/common/configuration/tests/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(simpletest simpletest.cpp) +target_link_libraries(simpletest PRIVATE DRAMSysConfiguration nlohmann_json::nlohmann_json) diff --git a/DRAMSys/library/src/common/configuration/tests/simpletest.cpp b/DRAMSys/library/src/common/configuration/tests/simpletest.cpp new file mode 100644 index 00000000..4c7f2b1a --- /dev/null +++ b/DRAMSys/library/src/common/configuration/tests/simpletest.cpp @@ -0,0 +1,181 @@ +#include +#include +#include + +using json = nlohmann::json; + +Configuration::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}}; +} + +Configuration::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}}; +} + +Configuration::SimConfig getSimConfig() +{ + return Configuration::SimConfig { + 0, + false, + true, + false, + Configuration::ECCControllerMode::Disabled, + false, + "error.csv", + 42, + false, + "ddr5", + true, + Configuration::StoreMode::NoStorage, + false, + false, + 1000 + }; +} + +Configuration::ThermalConfig getThermalConfig() +{ + 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; + + player->clkMhz = 100; + player->name = "mytrace.stl"; + + return std::unique_ptr(player); +} + +std::unique_ptr getTraceGeneratorRandom() +{ + Configuration::TraceGenerator *gen = new Configuration::TraceGenerator; + + gen->clkMhz = 100; + gen->name = "MyTestGen"; + + gen->addressDistribution = Configuration::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); +} + +std::unique_ptr getTraceGeneratorSequential() +{ + Configuration::TraceGenerator *gen = new Configuration::TraceGenerator; + + gen->clkMhz = 100; + gen->name = "MyTestGen"; + + gen->addressDistribution = Configuration::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); +} + +std::unique_ptr getTraceHammer() +{ + Configuration::TraceHammer *hammer = new Configuration::TraceHammer; + + hammer->clkMhz = 100; + hammer->name = "MyTestHammer"; + + hammer->numRequests = 4000; + hammer->rowIncrement = 2097152; + + return std::unique_ptr(hammer); +} + +Configuration::TraceSetup getTraceSetup() +{ + std::unordered_set> initiators; + initiators.emplace(getTracePlayer()); + initiators.emplace(getTraceGeneratorRandom()); + initiators.emplace(getTraceGeneratorSequential()); + initiators.emplace(getTraceHammer()); + + return Configuration::TraceSetup{std::move(initiators)}; +} + +Configuration::Configuration getConfig(const Configuration::MemSpec &memSpec) +{ + return Configuration::Configuration{ + getAddressMapping(), + getMcConfig(), + memSpec, + getSimConfig(), + "std::string_simulationId", + {getThermalConfig(), true}, + // {{}, false}, works too + {getTraceSetup(), true}, + }; +} + +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(); + std::ofstream fileout("myjson.json"); + json j_my; + j_my["simulation"] = getConfig(conf.memSpec); // just copy memspec over + fileout << j_my.dump(4); + + 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(); + std::ofstream filehbm2("myhbm2.json"); + json j_myhbm2; + j_myhbm2["simulation"] = hbm2conf; + filehbm2 << j_myhbm2.dump(4); +} diff --git a/DRAMSys/library/src/common/configuration/util.h b/DRAMSys/library/src/common/configuration/util.h new file mode 100644 index 00000000..1f25489c --- /dev/null +++ b/DRAMSys/library/src/common/configuration/util.h @@ -0,0 +1,75 @@ +/* + * 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 + */ + +#ifndef UTIL_H +#define UTIL_H + +#include +#include + +namespace Util +{ +using json = nlohmann::json; + +/** + * Inspired from https://github.com/nlohmann/json/issues/1749#issuecomment-770748811 + */ +template +void get_optional(const std::string &name, const json &j, std::pair &val) +{ + auto it = j.find(name); + if (it != j.end()) + { + val.first = it->template get(); + val.second = true; + } + else + { + val.second = false; + } +} + +template +void from_optional(const std::string &name, json &j, const std::pair &val) +{ + if (val.second) + { + j[name] = val.first; + } +} + +} // namespace Util + +#endif