Merge branch 'work/simulator_library' into 'develop'
Introduce Simulator class See merge request ems/astdm/modeling.dram/dram.sys.5!35
This commit is contained in:
@@ -246,7 +246,7 @@ void SimulationDialog::loadConfigurationFromTextFields()
|
||||
MemSpec memSpec;
|
||||
SimConfig simConfig;
|
||||
std::string simulationId;
|
||||
TraceSetup traceSetup;
|
||||
std::vector<Initiator> traceSetup;
|
||||
|
||||
simulationId = ui->simulationIdLineEdit->text().toStdString();
|
||||
|
||||
@@ -266,12 +266,14 @@ void SimulationDialog::loadConfigurationFromTextFields()
|
||||
return;
|
||||
}
|
||||
|
||||
configuration = DRAMSys::Config::Configuration{addressMapping,
|
||||
mcConfig,
|
||||
memSpec,
|
||||
simConfig,
|
||||
simulationId,
|
||||
std::make_optional<TraceSetup>(std::move(traceSetup))};
|
||||
configuration = DRAMSys::Config::Configuration{
|
||||
addressMapping,
|
||||
mcConfig,
|
||||
memSpec,
|
||||
simConfig,
|
||||
simulationId,
|
||||
std::make_optional<std::vector<Initiator>>(std::move(traceSetup))
|
||||
};
|
||||
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ namespace DRAMSys::Config {
|
||||
struct Configuration
|
||||
{
|
||||
static constexpr std::string_view KEY = "simulation";
|
||||
|
||||
|
||||
AddressMapping addressmapping;
|
||||
McConfig mcconfig;
|
||||
MemSpec memspec;
|
||||
SimConfig simconfig;
|
||||
std::string simulationid;
|
||||
std::optional<TraceSetup> tracesetup;
|
||||
std::optional<std::vector<Initiator>> tracesetup;
|
||||
};
|
||||
|
||||
NLOHMANN_JSONIFY_ALL_THINGS(Configuration,
|
||||
|
||||
@@ -129,7 +129,7 @@ struct TrafficGenerator
|
||||
std::optional<uint64_t> maxTransactions;
|
||||
std::optional<unsigned> dataLength;
|
||||
std::optional<unsigned> dataAlignment;
|
||||
|
||||
|
||||
uint64_t numRequests;
|
||||
double rwRatio;
|
||||
AddressDistribution addressDistribution;
|
||||
@@ -201,8 +201,7 @@ struct TraceSetupConstants
|
||||
static constexpr std::string_view SUB_DIR = "tracesetup";
|
||||
};
|
||||
|
||||
using TraceSetup = std::vector<
|
||||
std::variant<TracePlayer, TrafficGenerator, TrafficGeneratorStateMachine, RowHammer>>;
|
||||
using Initiator = std::variant<TracePlayer, TrafficGenerator, TrafficGeneratorStateMachine, RowHammer>;
|
||||
|
||||
} // namespace Configuration
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ enum sc_time_unit string2TimeUnit(const std::string &s)
|
||||
}
|
||||
|
||||
void Configuration::loadSimConfig(const DRAMSys::Config::SimConfig &simConfig)
|
||||
{
|
||||
{
|
||||
addressOffset = simConfig.AddressOffset.value_or(addressOffset);
|
||||
checkTLM2Protocol = simConfig.CheckTLM2Protocol.value_or(checkTLM2Protocol);
|
||||
databaseRecording = simConfig.DatabaseRecording.value_or(databaseRecording);
|
||||
|
||||
@@ -33,28 +33,13 @@
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#include "simulator/Initiator.h"
|
||||
#include "simulator/MemoryManager.h"
|
||||
#include "simulator/SimpleInitiator.h"
|
||||
#include "simulator/generator/TrafficGenerator.h"
|
||||
#include "simulator/hammer/RowHammer.h"
|
||||
#include "simulator/player/StlPlayer.h"
|
||||
#include "simulator/util.h"
|
||||
#include "simulator/Simulator.h"
|
||||
|
||||
#include <DRAMSys/simulation/DRAMSysRecordable.h>
|
||||
|
||||
#include <systemc>
|
||||
#include <tlm>
|
||||
#include <tlm_utils/peq_with_cb_and_phase.h>
|
||||
#include <tlm_utils/simple_initiator_socket.h>
|
||||
#include <DRAMSys/config/DRAMSysConfiguration.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
|
||||
static constexpr std::string_view TRACE_DIRECTORY = "traces";
|
||||
|
||||
int sc_main(int argc, char **argv)
|
||||
int sc_main(int argc, char** argv)
|
||||
{
|
||||
std::filesystem::path resourceDirectory = DRAMSYS_RESOURCE_DIR;
|
||||
if (argc >= 3)
|
||||
@@ -71,131 +56,8 @@ int sc_main(int argc, char **argv)
|
||||
DRAMSys::Config::Configuration configuration =
|
||||
DRAMSys::Config::from_path(baseConfig.c_str(), resourceDirectory.c_str());
|
||||
|
||||
if (!configuration.tracesetup.has_value())
|
||||
SC_REPORT_FATAL("Simulator", "No traffic initiators specified");
|
||||
|
||||
std::unique_ptr<DRAMSys::DRAMSys> dramSys;
|
||||
if (configuration.simconfig.DatabaseRecording.value_or(false))
|
||||
{
|
||||
dramSys = std::make_unique<DRAMSys::DRAMSysRecordable>("DRAMSys", configuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
dramSys = std::make_unique<DRAMSys::DRAMSys>("DRAMSys", configuration);
|
||||
}
|
||||
|
||||
bool storageEnabled = dramSys->getConfig().storeMode == DRAMSys::Configuration::StoreMode::Store;
|
||||
MemoryManager memoryManager(storageEnabled);
|
||||
|
||||
std::vector<std::unique_ptr<Initiator>> initiators;
|
||||
|
||||
unsigned int terminatedInitiators = 0;
|
||||
auto termianteInitiator = [&initiators, &terminatedInitiators]()
|
||||
{
|
||||
terminatedInitiators++;
|
||||
|
||||
if (terminatedInitiators == initiators.size())
|
||||
sc_core::sc_stop();
|
||||
};
|
||||
|
||||
uint64_t totalTransactions{};
|
||||
uint64_t transactionsFinished = 0;
|
||||
auto transactionFinished = [&totalTransactions, &transactionsFinished, &configuration]()
|
||||
{
|
||||
transactionsFinished++;
|
||||
|
||||
if (configuration.simconfig.SimulationProgressBar.value_or(false))
|
||||
loadBar(transactionsFinished, totalTransactions);
|
||||
};
|
||||
|
||||
for (auto const &initiator_config : configuration.tracesetup.value())
|
||||
{
|
||||
uint64_t memorySize = dramSys->getConfig().memSpec->getSimMemSizeInBytes();
|
||||
unsigned int defaultDataLength = dramSys->getConfig().memSpec->defaultBytesPerBurst;
|
||||
|
||||
auto initiator = std::visit(
|
||||
[=, &memoryManager](auto &&config) -> std::unique_ptr<Initiator>
|
||||
{
|
||||
using T = std::decay_t<decltype(config)>;
|
||||
if constexpr (std::is_same_v<T, DRAMSys::Config::TrafficGenerator> ||
|
||||
std::is_same_v<T, DRAMSys::Config::TrafficGeneratorStateMachine>)
|
||||
{
|
||||
return std::make_unique<TrafficGenerator>(config,
|
||||
memoryManager,
|
||||
memorySize,
|
||||
defaultDataLength,
|
||||
transactionFinished,
|
||||
termianteInitiator);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, DRAMSys::Config::TracePlayer>)
|
||||
{
|
||||
std::filesystem::path tracePath =
|
||||
resourceDirectory / TRACE_DIRECTORY / config.name;
|
||||
|
||||
StlPlayer::TraceType traceType;
|
||||
|
||||
auto extension = tracePath.extension();
|
||||
if (extension == ".stl")
|
||||
traceType = StlPlayer::TraceType::Absolute;
|
||||
else if (extension == ".rstl")
|
||||
traceType = StlPlayer::TraceType::Relative;
|
||||
else
|
||||
{
|
||||
std::string report = extension.string() + " is not a valid trace format.";
|
||||
SC_REPORT_FATAL("Simulator", report.c_str());
|
||||
}
|
||||
|
||||
StlPlayer player(
|
||||
tracePath.c_str(), config.clkMhz, defaultDataLength, traceType, false);
|
||||
|
||||
return std::make_unique<SimpleInitiator<StlPlayer>>(config.name.c_str(),
|
||||
memoryManager,
|
||||
config.clkMhz,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
transactionFinished,
|
||||
termianteInitiator,
|
||||
std::move(player));
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, DRAMSys::Config::RowHammer>)
|
||||
{
|
||||
RowHammer hammer(
|
||||
config.numRequests, config.rowIncrement, defaultDataLength);
|
||||
|
||||
return std::make_unique<SimpleInitiator<RowHammer>>(config.name.c_str(),
|
||||
memoryManager,
|
||||
config.clkMhz,
|
||||
1,
|
||||
1,
|
||||
transactionFinished,
|
||||
termianteInitiator,
|
||||
std::move(hammer));
|
||||
}
|
||||
},
|
||||
initiator_config);
|
||||
|
||||
totalTransactions += initiator->totalRequests();
|
||||
|
||||
initiator->bind(dramSys->tSocket);
|
||||
initiators.push_back(std::move(initiator));
|
||||
}
|
||||
|
||||
// Store the starting of the simulation in wall-clock time:
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Start the SystemC simulation
|
||||
sc_set_stop_mode(sc_core::SC_STOP_FINISH_DELTA);
|
||||
sc_core::sc_start();
|
||||
|
||||
if (!sc_core::sc_end_of_simulation_invoked())
|
||||
{
|
||||
SC_REPORT_WARNING("sc_main", "Simulation stopped without explicit sc_stop()");
|
||||
sc_core::sc_stop();
|
||||
}
|
||||
|
||||
auto finish = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = finish - start;
|
||||
std::cout << "Simulation took " + std::to_string(elapsed.count()) + " seconds." << std::endl;
|
||||
Simulator simulator(std::move(configuration), std::move(resourceDirectory));
|
||||
Simulator::run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
171
src/simulator/simulator/Simulator.cpp
Normal file
171
src/simulator/simulator/Simulator.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2023, RPTU Kaiserslautern-Landau
|
||||
* 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 "Simulator.h"
|
||||
|
||||
#include "SimpleInitiator.h"
|
||||
#include "generator/TrafficGenerator.h"
|
||||
#include "hammer/RowHammer.h"
|
||||
#include "player/StlPlayer.h"
|
||||
#include "util.h"
|
||||
|
||||
Simulator::Simulator(DRAMSys::Config::Configuration configuration,
|
||||
std::filesystem::path resourceDirectory) :
|
||||
configuration(std::move(configuration)),
|
||||
resourceDirectory(std::move(resourceDirectory)),
|
||||
memoryManager(configuration.simconfig.StoreMode == DRAMSys::Config::StoreModeType::Store)
|
||||
{
|
||||
if (this->configuration.simconfig.DatabaseRecording.value_or(false))
|
||||
{
|
||||
dramSys = std::make_unique<DRAMSys::DRAMSysRecordable>("DRAMSys", this->configuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
dramSys = std::make_unique<DRAMSys::DRAMSys>("DRAMSys", this->configuration);
|
||||
}
|
||||
|
||||
terminateInitiator = [this]()
|
||||
{
|
||||
terminatedInitiators++;
|
||||
|
||||
if (terminatedInitiators == initiators.size())
|
||||
sc_core::sc_stop();
|
||||
};
|
||||
|
||||
finishTransaction = [this]()
|
||||
{
|
||||
transactionsFinished++;
|
||||
|
||||
if (this->configuration.simconfig.SimulationProgressBar.value_or(false))
|
||||
loadBar(transactionsFinished, totalTransactions);
|
||||
};
|
||||
|
||||
if (!configuration.tracesetup.has_value())
|
||||
SC_REPORT_FATAL("Simulator", "No traffic initiators specified");
|
||||
|
||||
for (const auto& initiatorConfig : *this->configuration.tracesetup)
|
||||
{
|
||||
auto initiator = instantiateInitiator(initiatorConfig);
|
||||
totalTransactions += initiator->totalRequests();
|
||||
initiator->bind(dramSys->tSocket);
|
||||
initiators.push_back(std::move(initiator));
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Initiator>
|
||||
Simulator::instantiateInitiator(const DRAMSys::Config::Initiator& initiator)
|
||||
{
|
||||
uint64_t memorySize = dramSys->getConfig().memSpec->getSimMemSizeInBytes();
|
||||
unsigned int defaultDataLength = dramSys->getConfig().memSpec->defaultBytesPerBurst;
|
||||
|
||||
return std::visit(
|
||||
[=](auto&& config) -> std::unique_ptr<Initiator>
|
||||
{
|
||||
using T = std::decay_t<decltype(config)>;
|
||||
if constexpr (std::is_same_v<T, DRAMSys::Config::TrafficGenerator> ||
|
||||
std::is_same_v<T, DRAMSys::Config::TrafficGeneratorStateMachine>)
|
||||
{
|
||||
return std::make_unique<TrafficGenerator>(config,
|
||||
memoryManager,
|
||||
memorySize,
|
||||
defaultDataLength,
|
||||
finishTransaction,
|
||||
terminateInitiator);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, DRAMSys::Config::TracePlayer>)
|
||||
{
|
||||
std::filesystem::path tracePath = resourceDirectory / TRACE_DIRECTORY / config.name;
|
||||
|
||||
std::optional<StlPlayer::TraceType> traceType;
|
||||
|
||||
auto extension = tracePath.extension();
|
||||
if (extension == ".stl")
|
||||
traceType = StlPlayer::TraceType::Absolute;
|
||||
else if (extension == ".rstl")
|
||||
traceType = StlPlayer::TraceType::Relative;
|
||||
|
||||
if (!traceType.has_value())
|
||||
{
|
||||
std::string report = extension.string() + " is not a valid trace format.";
|
||||
SC_REPORT_FATAL("Simulator", report.c_str());
|
||||
}
|
||||
|
||||
StlPlayer player(
|
||||
tracePath.c_str(), config.clkMhz, defaultDataLength, *traceType, false);
|
||||
|
||||
return std::make_unique<SimpleInitiator<StlPlayer>>(config.name.c_str(),
|
||||
memoryManager,
|
||||
config.clkMhz,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
finishTransaction,
|
||||
terminateInitiator,
|
||||
std::move(player));
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, DRAMSys::Config::RowHammer>)
|
||||
{
|
||||
RowHammer hammer(config.numRequests, config.rowIncrement, defaultDataLength);
|
||||
|
||||
return std::make_unique<SimpleInitiator<RowHammer>>(config.name.c_str(),
|
||||
memoryManager,
|
||||
config.clkMhz,
|
||||
1,
|
||||
1,
|
||||
finishTransaction,
|
||||
terminateInitiator,
|
||||
std::move(hammer));
|
||||
}
|
||||
},
|
||||
initiator);
|
||||
}
|
||||
|
||||
void Simulator::run()
|
||||
{
|
||||
// Store the starting of the simulation in wall-clock time:
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Start the SystemC simulation
|
||||
sc_core::sc_start();
|
||||
|
||||
if (!sc_core::sc_end_of_simulation_invoked())
|
||||
{
|
||||
SC_REPORT_WARNING("Simulator", "Simulation stopped without explicit sc_stop()");
|
||||
sc_core::sc_stop();
|
||||
}
|
||||
|
||||
auto finish = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = finish - start;
|
||||
std::cout << "Simulation took " + std::to_string(elapsed.count()) + " seconds." << std::endl;
|
||||
}
|
||||
71
src/simulator/simulator/Simulator.h
Normal file
71
src/simulator/simulator/Simulator.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2023, RPTU Kaiserslautern-Landau
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Initiator.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
#include <DRAMSys/config/DRAMSysConfiguration.h>
|
||||
#include <DRAMSys/simulation/DRAMSysRecordable.h>
|
||||
|
||||
static constexpr std::string_view TRACE_DIRECTORY = "traces";
|
||||
|
||||
class Simulator
|
||||
{
|
||||
public:
|
||||
Simulator(DRAMSys::Config::Configuration configuration,
|
||||
std::filesystem::path resourceDirectory);
|
||||
|
||||
static void run();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Initiator> instantiateInitiator(const DRAMSys::Config::Initiator& initiator);
|
||||
|
||||
MemoryManager memoryManager;
|
||||
|
||||
DRAMSys::Config::Configuration configuration;
|
||||
std::filesystem::path resourceDirectory;
|
||||
|
||||
std::unique_ptr<DRAMSys::DRAMSys> dramSys;
|
||||
std::vector<std::unique_ptr<Initiator>> initiators;
|
||||
|
||||
std::function<void()> terminateInitiator;
|
||||
std::function<void()> finishTransaction;
|
||||
|
||||
unsigned int terminatedInitiators = 0;
|
||||
uint64_t totalTransactions{};
|
||||
uint64_t transactionsFinished = 0;
|
||||
};
|
||||
@@ -110,7 +110,7 @@ protected:
|
||||
DRAMSys::Config::TrafficGenerator traceGeneratorOneState;
|
||||
DRAMSys::Config::TrafficGeneratorStateMachine traceGeneratorMultipleStates;
|
||||
DRAMSys::Config::RowHammer traceHammer;
|
||||
DRAMSys::Config::TraceSetup traceSetup{{tracePlayer, traceGeneratorOneState, traceGeneratorMultipleStates, traceHammer}};
|
||||
std::vector<DRAMSys::Config::Initiator> traceSetup{{tracePlayer, traceGeneratorOneState, traceGeneratorMultipleStates, traceHammer}};
|
||||
|
||||
DRAMSys::Config::Configuration configuration{
|
||||
addressMapping,
|
||||
@@ -302,7 +302,7 @@ TEST(RefreshPolicyType, BackwardsCompatibility)
|
||||
TEST_F(ConfigurationTest, SimConfig)
|
||||
{
|
||||
std::string_view simconfig_string = R"(
|
||||
{
|
||||
{
|
||||
"simconfig": {
|
||||
"AddressOffset": 0,
|
||||
"CheckTLM2Protocol": false,
|
||||
|
||||
Reference in New Issue
Block a user