diff --git a/DRAMSys/dramSys/src/error/errormodel.cpp b/DRAMSys/dramSys/src/error/errormodel.cpp index 8d7fda5a..e0b731d2 100644 --- a/DRAMSys/dramSys/src/error/errormodel.cpp +++ b/DRAMSys/dramSys/src/error/errormodel.cpp @@ -34,6 +34,8 @@ */ #include "errormodel.h" +#include +#include errorModel::errorModel() { @@ -50,6 +52,9 @@ errorModel::errorModel() { lastRowAccess[i] = SC_ZERO_TIME; } + + // Parse data input: + parseInputData(); } errorModel::~errorModel() @@ -64,6 +69,9 @@ errorModel::~errorModel() // Remove all data from the lastRowAccess delete [] lastRowAccess; + + // Clean errorMap + errorMap.clear(); } void errorModel::store(tlm::tlm_generic_payload &trans) @@ -153,3 +161,72 @@ void errorModel::setTemperature(double t) { temperature = t; } + +void errorModel::parseInputData() +{ + std::string fileName = Configuration::getInstance().ErrorCSVFile; + std::ifstream inputFile(fileName); + + std::cout << "Parsing Error File: " << fileName << std::endl; + + if(inputFile.is_open()) + { + std::string line; + while(std::getline(inputFile,line)) + { + std::istringstream iss(line); + std::string str_temperature; + std::string str_retentionTime; + std::string str_mu_independent; + std::string str_sigma_independent; + std::string str_mu_dependent; + std::string str_sigma_dependent; + + // Parse file: + iss >> str_temperature + >> str_retentionTime + >> str_mu_independent + >> str_sigma_independent + >> str_mu_dependent + >> str_sigma_dependent; + + unsigned int temperature = std::stoi(str_temperature.c_str(), 0, 10); + sc_time retentionTime = sc_time(std::stod(str_retentionTime.c_str(),0),SC_MS); + + unsigned int mu_independent = std::stod(str_mu_independent.c_str(),0); + unsigned int sigma_independent = std::stod(str_sigma_independent.c_str(),0); + unsigned int mu_dependent = std::stod(str_mu_dependent.c_str(),0); + unsigned int sigma_dependent = std::stod(str_sigma_dependent.c_str(),0); + + errors e; + + //calculate normal distribution of # of independent errors + unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); + std::default_random_engine generator(seed); + std::normal_distribution distribution(mu_independent,sigma_independent); + e.independent = ceil(distribution(generator)); + + // calculate normal distribution of # of dependent errors + unsigned seed2 = std::chrono::system_clock::now().time_since_epoch().count(); + std::default_random_engine generator2(seed2); + std::normal_distribution distribution2(mu_dependent,sigma_dependent); + e.dependent = ceil(distribution2(generator2)); + + // Store parsed data to the errorMap: + errorMap[temperature][retentionTime] = e; + + std::cout << "Temperature = " << temperature + << " Time = " << retentionTime + << " independent = " << errorMap[temperature][retentionTime].independent + << " dependent = " << errorMap[temperature][retentionTime].dependent + << std::endl; + } + inputFile.close(); + + // Get the + } + else + { + SC_REPORT_FATAL("errormodel","Cannot open ErrorCSVFile"); + } +} diff --git a/DRAMSys/dramSys/src/error/errormodel.h b/DRAMSys/dramSys/src/error/errormodel.h index 4dd7e501..0dd9dd2f 100644 --- a/DRAMSys/dramSys/src/error/errormodel.h +++ b/DRAMSys/dramSys/src/error/errormodel.h @@ -38,6 +38,7 @@ #include "../controller/core/configuration/Configuration.h" #include "../common/xmlAddressdecoder.h" #include +#include class errorModel { @@ -63,7 +64,16 @@ class errorModel // Online Parameters: double temperature; - // Input data structures: + // Input data related things: + void parseInputData(); + + struct errors + { + double independent; + double dependent; + }; + + std::map > errorMap; // To use a map for storing the data a comparing function must be defined struct DecodedAddressComparer