From d5862e55eabd96dbe467179065e9773f76f19a27 Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Tue, 25 Feb 2025 14:05:34 +0100 Subject: [PATCH] Moved DramRecordable logic to Dram --- src/libdramsys/DRAMSys/simulation/DRAMSys.cpp | 14 ++--- src/libdramsys/DRAMSys/simulation/Dram.cpp | 58 ++++++++++++++++++- src/libdramsys/DRAMSys/simulation/Dram.h | 13 ++++- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp index a505e5d1..a7d3a282 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp +++ b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp @@ -114,18 +114,16 @@ DRAMSys::DRAMSys(const sc_core::sc_module_name& name, const Config::Configuratio *addressDecoder, tlmRecorders[i])); - // drams.emplace_back(std::make_unique( - // ("dram" + std::to_string(i)).c_str(), simConfig, *memSpec, tlmRecorders[i])); - - drams.emplace_back( - std::make_unique(("dram" + std::to_string(i)).c_str(), simConfig, *memSpec)); + drams.emplace_back(std::make_unique( + ("dram" + std::to_string(i)).c_str(), simConfig, *memSpec, tlmRecorders[i])); if (simConfig.checkTLM2Protocol) controllersTlmCheckers.emplace_back( std::make_unique>( ("TLMCheckerController" + std::to_string(i)).c_str())); - tlmWrappers.emplace_back(std::make_unique(("TlmRecorderWrapper" + std::to_string(i)).c_str(), tlmRecorders[i])); + tlmWrappers.emplace_back(std::make_unique( + ("TlmRecorderWrapper" + std::to_string(i)).c_str(), tlmRecorders[i])); } } else @@ -135,8 +133,8 @@ DRAMSys::DRAMSys(const sc_core::sc_module_name& name, const Config::Configuratio controllers.emplace_back(std::make_unique( ("controller" + std::to_string(i)).c_str(), mcConfig, *memSpec, *addressDecoder)); - drams.emplace_back( - std::make_unique(("dram" + std::to_string(i)).c_str(), simConfig, *memSpec)); + drams.emplace_back(std::make_unique( + ("dram" + std::to_string(i)).c_str(), simConfig, *memSpec, tlmRecorders[i])); if (simConfig.checkTLM2Protocol) { diff --git a/src/libdramsys/DRAMSys/simulation/Dram.cpp b/src/libdramsys/DRAMSys/simulation/Dram.cpp index 6f767fe4..5b1e7d4c 100644 --- a/src/libdramsys/DRAMSys/simulation/Dram.cpp +++ b/src/libdramsys/DRAMSys/simulation/Dram.cpp @@ -41,7 +41,9 @@ #include "Dram.h" #include "DRAMSys/common/DebugManager.h" +#include "DRAMSys/common/TlmRecorder.h" #include "DRAMSys/config/SimConfig.h" +#include #ifdef DRAMPOWER #include "LibDRAMPower.h" @@ -67,13 +69,18 @@ using namespace DRAMPower; namespace DRAMSys { -Dram::Dram(const sc_module_name& name, const SimConfig& simConfig, const MemSpec& memSpec) : +Dram::Dram(const sc_module_name& name, + const SimConfig& simConfig, + const MemSpec& memSpec, + TlmRecorder& tlmRecorder) : sc_module(name), memSpec(memSpec), storeMode(simConfig.storeMode), powerAnalysis(simConfig.powerAnalysis), channelSize(memSpec.getSimMemSizeInBytes() / memSpec.numberOfChannels), - useMalloc(simConfig.useMalloc) + useMalloc(simConfig.useMalloc), + tlmRecorder(tlmRecorder), + powerWindowSize(memSpec.tCK * simConfig.windowSize) { if (storeMode == Config::StoreModeType::Store) { @@ -109,6 +116,9 @@ Dram::Dram(const sc_module_name& name, const SimConfig& simConfig, const MemSpec { DRAMPower = std::make_unique(memSpec.toDramPowerMemSpec(), false); } + + if (simConfig.powerAnalysis && simConfig.enableWindowing) + SC_THREAD(powerWindow); #endif } @@ -132,6 +142,10 @@ void Dram::reportPower() std::cout << name() << std::string(" Average Power: ") << std::fixed << std::setprecision(2) << DRAMPower->getPower().average_power * memSpec.devicesPerRank << std::string(" mW") << std::endl; + + tlmRecorder.recordPower(sc_time_stamp().to_seconds(), + this->DRAMPower->getPower().window_average_power * + this->memSpec.devicesPerRank); #endif } @@ -267,4 +281,44 @@ void Dram::deserialize(std::istream& stream) stream.read(reinterpret_cast(memory), channelSize); } +#ifdef DRAMPOWER +// This Thread is only triggered when Power Simulation is enabled. +// It estimates the current average power which will be stored in the trace database for +// visualization purposes. +void Dram::powerWindow() +{ + int64_t clkCycles = 0; + + while (true) + { + // At the very beginning (zero clock cycles) the energy is 0, so we wait first + sc_module::wait(powerWindowSize); + + clkCycles = std::lround(sc_time_stamp() / this->memSpec.tCK); + + this->DRAMPower->calcWindowEnergy(clkCycles); + + // During operation the energy should never be zero since the device is always consuming + assert(!this->DRAMPower->getEnergy().window_energy < 1e-05); + + // Store the time (in seconds) and the current average power (in mW) into the database + tlmRecorder.recordPower(sc_time_stamp().to_seconds(), + this->DRAMPower->getPower().window_average_power * + this->memSpec.devicesPerRank); + + // Here considering that DRAMPower provides the energy in pJ and the power in mW + PRINTDEBUGMESSAGE(this->name(), + std::string("\tWindow Energy: \t") + + std::to_string(this->DRAMPower->getEnergy().window_energy * + this->memSpec.devicesPerRank) + + std::string("\t[pJ]")); + PRINTDEBUGMESSAGE(this->name(), + std::string("\tWindow Average Power: \t") + + std::to_string(this->DRAMPower->getPower().window_average_power * + this->memSpec.devicesPerRank) + + std::string("\t[mW]")); + } +} +#endif + } // namespace DRAMSys diff --git a/src/libdramsys/DRAMSys/simulation/Dram.h b/src/libdramsys/DRAMSys/simulation/Dram.h index d8c7125a..add46abe 100644 --- a/src/libdramsys/DRAMSys/simulation/Dram.h +++ b/src/libdramsys/DRAMSys/simulation/Dram.h @@ -43,6 +43,7 @@ #include "DRAMSys/common/Deserialize.h" #include "DRAMSys/common/Serialize.h" +#include "DRAMSys/common/TlmRecorder.h" #include "DRAMSys/configuration/memspec/MemSpec.h" #include "DRAMSys/simulation/SimConfig.h" @@ -68,8 +69,15 @@ protected: const uint64_t channelSize; const bool useMalloc; + TlmRecorder& tlmRecorder; + sc_core::sc_time powerWindowSize; + #ifdef DRAMPOWER std::unique_ptr DRAMPower; + // This Thread is only triggered when Power Simulation is enabled. + // It estimates the current average power which will be stored in the trace database for + // visualization purposes. + void powerWindow(); #endif virtual tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload& trans, @@ -82,7 +90,10 @@ protected: void executeWrite(const tlm::tlm_generic_payload& trans); public: - Dram(const sc_core::sc_module_name& name, const SimConfig& simConfig, const MemSpec& memSpec); + Dram(const sc_core::sc_module_name& name, + const SimConfig& simConfig, + const MemSpec& memSpec, + TlmRecorder& tlmRecorder); SC_HAS_PROCESS(Dram); Dram(const Dram&) = delete;