diff --git a/DRAMSys/library/library.pro b/DRAMSys/library/library.pro index 20a1eb2d..df48ed98 100644 --- a/DRAMSys/library/library.pro +++ b/DRAMSys/library/library.pro @@ -51,6 +51,7 @@ INCLUDEPATH += $${systemc_home}/include INCLUDEPATH += src/common/third_party/DRAMPower/src INCLUDEPATH += src/common/third_party/DRAMPower/src/libdrampower +INCLUDEPATH += src/common/third_party/json/include DEFINES += TIXML_USE_STL DEFINES += SC_INCLUDE_DYNAMIC_PROCESSES @@ -194,7 +195,8 @@ HEADERS += \ src/controller/scheduler/Fr_Fcfs_read_priority.h \ src/controller/scheduler/Fr_Fcfs_grouper.h \ src/common/AddressDecoder.h \ - src/common/jsonAddressDecoder.h + src/common/jsonAddressDecoder.h \ + src/common/third_party/json/include/nlohmann/json.hpp thermalsim = $$(THERMALSIM) isEmpty(thermalsim) { diff --git a/DRAMSys/library/resources/configs/amconfigs/am_test_congen_output.json b/DRAMSys/library/resources/configs/amconfigs/am_test_congen_output.json index 74d8c492..3aca28c7 100644 --- a/DRAMSys/library/resources/configs/amconfigs/am_test_congen_output.json +++ b/DRAMSys/library/resources/configs/amconfigs/am_test_congen_output.json @@ -9,30 +9,31 @@ "Name": "merged_sorted", "Solutions": [ { - "XOR": [], + "XOR": [ + ], "Banks Rows": [ { "bank_bits": [ - 18, - 12, - 11 + 27, + 28, + 29 ], "rows": { "row_bits": [ - 24, 13, - 17, 14, 15, 16, - 25, + 17, + 18, 19, - 21, 20, - 26, + 21, + 22, 23, - 29, - 28 + 24, + 25, + 26 ], "costs": 477468 }, @@ -41,4 +42,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/DRAMSys/library/resources/resources.pri b/DRAMSys/library/resources/resources.pri index cd77f0c8..cb6615b2 100644 --- a/DRAMSys/library/resources/resources.pri +++ b/DRAMSys/library/resources/resources.pri @@ -172,4 +172,5 @@ DISTFILES += \ $$PWD/configs/simulator/lpddr4.xml \ $$PWD/simulations/lpddr4-single-device.xml \ $$PWD/configs/amconfigs/am_lpddr4.xml \ - $$PWD/configs/memspecs/MICRON_6Gb_LPDDR4-3200_NDA_NDA_NDA.xml + $$PWD/configs/memspecs/MICRON_6Gb_LPDDR4-3200_NDA_NDA_NDA.xml \ + $$PWD/configs/amconfigs/am_test_congen_output.json diff --git a/DRAMSys/library/src/common/jsonAddressDecoder.cpp b/DRAMSys/library/src/common/jsonAddressDecoder.cpp index d82f41bf..dd9c8b62 100644 --- a/DRAMSys/library/src/common/jsonAddressDecoder.cpp +++ b/DRAMSys/library/src/common/jsonAddressDecoder.cpp @@ -1,4 +1,5 @@ #include "jsonAddressDecoder.h" +#include "Utils.h" #include @@ -6,6 +7,14 @@ using std::ifstream; using std::cout; using std::endl; +#include + +using json = nlohmann::json; + +#include + +using std::set; + JSONAddressDecoder::JSONAddressDecoder() { @@ -23,22 +32,173 @@ void JSONAddressDecoder::setConfiguration(std::string url) return; } + // parse json file + json data; + file >> data; + file.close(); + + // extract data + // For simplicity takethe first solution of one or more available ones. + auto sol = data["Solutions"].begin(); + assert(sol != data["Solutions"].end()); + + // Set for connected bits + set sUsed; + + // get XOR connections + unsigned num = (*sol)["XOR"].size()>>1; + + for(unsigned i = 0; i < num; i++) + { + m_vXor.push_back(pair ((*sol)["XOR"].at(i), (*sol)["XOR"].at(i+num))); + } + + // get all bank bits + unsigned counter = 0; + for(auto it = (*sol)["Banks Rows"][0]["bank_bits"].begin(); it != (*sol)["Banks Rows"][0]["bank_bits"].end(); it++) + { + m_vBankBits.push_back(pair(counter++, (*it))); + sUsed.insert((unsigned)(*it)); + } + + // get all row bits bits + counter = 0; + for(auto it = (*sol)["Banks Rows"][0]["rows"]["row_bits"].begin(); it != (*sol)["Banks Rows"][0]["rows"]["row_bits"].end(); it++) + { + m_vRowBits.push_back(pair(counter++, (*it))); + sUsed.insert((unsigned)(*it)); + } + + // Add byte bits (fixed) + sUsed.insert(0); + sUsed.insert(1); + sUsed.insert(2); + + // Theset bits are ignored + sUsed.insert(30); + sUsed.insert(31); + + // Create Column mapping + counter = 0; + for(unsigned i = 0; i < 32; i++) + { + if(sUsed.find(i) != sUsed.end()) + continue; // Already mapped + + m_vColumnBits.push_back(pair(counter++, i)); + } + + amount["channel"] = 1; + amount["bank"] = pow(2.0, m_vBankBits.size()); + amount["row"] = pow(2.0, m_vRowBits.size()); + amount["column"] = pow(2.0, m_vColumnBits.size()); + amount["bytes"] = pow(2.0, 3); } DecodedAddress JSONAddressDecoder::decodeAddress(sc_dt::uint64 addr) { DecodedAddress result; + // Apply XOR + for(auto it = m_vXor.begin(); it != m_vXor.end(); it++) + { + addr &= ~(1 << it->first); + addr |= (((addr >> it->first) & 1) ^ ((addr >> it->second) & 1)) << it->first; + } + + // Unsed + result.bankgroup = 0; + result.channel = 0; + result.rank = 0; + + // Pass through of the three byte bits + result.bytes = addr & 0x7; + + // Bank + result.bank = 0; + for(auto it = m_vBankBits.begin(); it != m_vBankBits.end(); it++) + { + result.bank |= ((addr >> it->second) & 1) << it->first; + } + + // Row + result.row = 0; + for(auto it = m_vRowBits.begin(); it != m_vRowBits.end(); it++) + { + result.row |= ((addr >> it->second) & 1) << it->first; + } + + // Column + result.column = 0; + for(auto it = m_vColumnBits.begin(); it != m_vColumnBits.end(); it++) + { + result.column |= ((addr >> it->second) & 1) << it->first; + } + return result; } sc_dt::uint64 JSONAddressDecoder::encodeAddress(DecodedAddress n) { - return 0; + sc_dt::uint64 address = 0; + for(auto it = m_vBankBits.begin(); it != m_vBankBits.end(); it++) + { + address |= ((n.bank >> it->first) & 1) << it->second; + } + for(auto it = m_vRowBits.begin(); it != m_vRowBits.end(); it++) + { + address |= ((n.row >> it->first) & 1) << it->second; + } + for(auto it = m_vColumnBits.begin(); it != m_vColumnBits.end(); it++) + { + address |= ((n.column >> it->first) & 1) << it->second; + } + + address |= n.bytes; + + // Apply XOR + for(auto it = m_vXor.begin(); it != m_vXor.end(); it++) + { + address &= ~(1 << it->first); + address |= (((address >> it->first) & 1) ^ ((address >> it->second) & 1)) << it->first; + } + + return address; } void JSONAddressDecoder::print() { + map> output; + for(auto it = m_vBankBits.begin(); it != m_vBankBits.end(); it++) + { + output[it->second] = pair(it->first , 'B'); + } + for(auto it = m_vRowBits.begin(); it != m_vRowBits.end(); it++) + { + output[it->second] = pair(it->first , 'R'); + } + for(auto it = m_vColumnBits.begin(); it != m_vColumnBits.end(); it++) + { + output[it->second] = pair(it->first , 'C'); + } + + // add byte bits + output[0] = pair(0 , 'b'); + output[1] = pair(1 , 'b'); + output[2] = pair(2 , 'b'); + + cout << "Used addressmapping:" << endl; + cout << headline << endl; + for(unsigned i = 0; i < 32; i++) + { + cout << " " << i << " "; + } + cout << endl; + for(unsigned i = 0; i < 32; i++) + { + cout << " " << output[i].second << "(" << output[i].first << ") "; + } + cout << endl; } diff --git a/DRAMSys/library/src/common/jsonAddressDecoder.h b/DRAMSys/library/src/common/jsonAddressDecoder.h index bc5eb8df..354b7513 100644 --- a/DRAMSys/library/src/common/jsonAddressDecoder.h +++ b/DRAMSys/library/src/common/jsonAddressDecoder.h @@ -38,6 +38,13 @@ #include "AddressDecoder.h" +#include +#include + +using std::vector; +using std::pair; +using std::map; + class JSONAddressDecoder : public CAddressDecoder { @@ -46,6 +53,11 @@ class JSONAddressDecoder private: JSONAddressDecoder(); + vector> m_vXor; + vector> m_vBankBits; + vector> m_vRowBits; + vector> m_vColumnBits; + public: virtual void setConfiguration(std::string url); diff --git a/DRAMSys/library/src/common/xmlAddressdecoder.h b/DRAMSys/library/src/common/xmlAddressdecoder.h index ed300670..03ade6c5 100644 --- a/DRAMSys/library/src/common/xmlAddressdecoder.h +++ b/DRAMSys/library/src/common/xmlAddressdecoder.h @@ -50,7 +50,6 @@ class xmlAddressDecoder friend class CAddressDecoder; private: - xmlAddressDecoder(); std::map masks; @@ -59,16 +58,13 @@ private: tinyxml2::XMLElement* addressmapping; public: - DecodedAddress decodeAddress(sc_dt::uint64 addr); - sc_dt::uint64 encodeAddress(DecodedAddress n); + virtual DecodedAddress decodeAddress(sc_dt::uint64 addr); + virtual sc_dt::uint64 encodeAddress(DecodedAddress n); void setConfiguration(std::string url); -private: - void setConfiguration(tinyxml2::XMLElement* addressMap); -public: - void print(); - std::map amount; +public: + virtual void print(); }; #endif diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index 403435d4..245b4aca 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -94,7 +94,9 @@ DRAMSys::DRAMSys(sc_module_name __attribute__((unused)) name, else if(amconfig.find(".json") != string::npos) { CAddressDecoder::createInstance(CAddressDecoder::Type::JSON); - CAddressDecoder::getInstance().setConfiguration(pathToResources + amconfig); + CAddressDecoder::getInstance().setConfiguration(pathToResources + + "configs/amconfigs/" + + amconfig); } else {