Address Mapping using json/CONGEN file.

This commit is contained in:
scorrea
2020-05-11 16:23:39 +02:00
parent 20553929fa
commit f92d976552
5 changed files with 123 additions and 163 deletions

View File

@@ -0,0 +1,50 @@
{
"CONGEN": [{
"XOR":[
{
"FIRST":13,
"SECOND":16
}
],
"BYTE_BIT": [
0,
1,
2
],
"COLUMN_BIT": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
],
"BANK_BIT": [
13,
14,
15
],
"ROW_BIT": [
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29
],
"ID": 0
}
]
}

View File

@@ -8,7 +8,7 @@
<!-- Memory Device Specification: Which Device is on the DDR3 DIMM -->
<memspec src="MICRON_1Gb_DDR3-1600_8bit_G.json"></memspec>
<!-- Addressmapping Configuration of the Memory Controller -->
<addressmapping src="congen_extended.xml"></addressmapping>
<addressmapping src="congen_extended.json"></addressmapping>
<!-- Memory Controller Configuration: -->
<mcconfig src="fifoStrict.json"/>
<!--

View File

@@ -1,145 +1,90 @@
/*
* Copyright (c) 2018, University of 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:
* Johannes Feldmann
* Lukas Steiner
*/
#include <cmath>
#include <bitset>
#include "AddressDecoder.h"
#include "utils.h"
#include "../configuration/Configuration.h"
using json = nlohmann::json;
tinyxml2::XMLElement *AddressDecoder::getXMLNode(tinyxml2::XMLElement
*pRoot, std::string strName)
unsigned int AddressDecoder::getUnsignedAttrFromJson(nlohmann::json obj, std::string strName)
{
tinyxml2::XMLElement *pNode = pRoot->FirstChildElement(strName.c_str());
if (pNode == nullptr) {
reportFatal("AddressDecorder",
"XML File corrupted. Missing node " + strName + ".");
if (!obj[strName].empty()){
if (obj[strName].is_number_unsigned()){
return obj[strName];
}
else {
reportFatal("AddressDecoder",
"Attribute " + strName + " is not a number.");
return (unsigned)(-1);
}
}
return pNode;
}
unsigned int AddressDecoder::getUnsignedTextFromXMLNode(
tinyxml2::XMLElement *pRoot)
{
std::string str = pRoot->GetText();
if (str.empty() || std::find_if(str.begin(), str.end(), [](char c) {
return !std::isdigit(c);
}) != str.end()) {
else {
reportFatal("AddressDecoder",
"Node " + std::string(pRoot->Name()) + " is empty or not a number.");
return (unsigned)(-1);
"Attribute " + strName + " is empty or not found");
return (unsigned)(-1);
}
return atol(str.c_str());
}
unsigned int AddressDecoder::getUnsignedAttrFromXMLNode(
tinyxml2::XMLElement *pRoot, std::string strName)
std::vector<unsigned> AddressDecoder::getAttrToVectorFromJson(nlohmann::json obj,
std::string strName)
{
std::string str = pRoot->Attribute(strName.c_str());
if (str.empty() || std::find_if(str.begin(), str.end(), [](char c) {
return !std::isdigit(c);
}) != str.end()) {
reportFatal("AddressDecoder",
"Attribute " + strName + " is empty or not a number.");
return (unsigned)(-1);
}
return atol(str.c_str());
}
std::vector<unsigned> vParameter;
if (!obj[strName].empty()){
for ( auto it: obj[strName].items() ){
auto valor = it.value();
if (valor.is_number_unsigned())
vParameter.push_back(it.value());
else {
reportFatal("AddressDecoder",
"Attribute " + strName + " is not a number.");
}
}
}
return vParameter;
} /// TODO:Rewrite with break instead
AddressDecoder::AddressDecoder(std::string pathToAddressMapping)
{
tinyxml2::XMLDocument doc;
loadXML(pathToAddressMapping, doc);
tinyxml2::XMLElement *pRoot = doc.RootElement();
std::string xmlNodeName(pRoot->Name());
json AddrFile = json::parse(std::ifstream(pathToAddressMapping));
if (xmlNodeName != "CONGEN")
if (AddrFile["CONGEN"].empty())
reportFatal("AddressDecorder",
"Root node name differs from \"CONGEN\". File format not supported.");
// Load address mapping
tinyxml2::XMLElement *pNode;
for ( auto it: AddrFile["CONGEN"].items()){
json j= it.value();
if (getUnsignedAttrFromJson(j, "ID") == 0){
ID=true;
for ( auto xorItem: j["XOR"].items() ){
auto value = xorItem.value();
if (!value.empty())
vXor.push_back(std::pair<unsigned, unsigned>(getUnsignedAttrFromJson(value, "FIRST"),
getUnsignedAttrFromJson(value, "SECOND")));
}
vChannelBits = getAttrToVectorFromJson(j,"CHANNEL_BIT");
vRankBits = getAttrToVectorFromJson(j,"RANK_BIT");
vBankGroupBits = getAttrToVectorFromJson(j,"BANKGROUP_BIT");
vBankBits = getAttrToVectorFromJson(j,"BANK_BIT");
vRowBits = getAttrToVectorFromJson(j,"ROW_BIT");
vColumnBits = getAttrToVectorFromJson(j,"COLUMN_BIT");
vByteBits = getAttrToVectorFromJson(j,"BYTE_BIT");
//if it doesnt have one of them it returns "not a number :("
}
//TODO find a way to generate an error if it doesnt find an object with ID==0.
}
if (ID != true)
SC_REPORT_FATAL("AddressDecoder", "No mapping with ID 0 was found.");
for (pNode = pRoot->FirstChildElement("SOLUTION"); pNode != nullptr;
pNode = pNode->NextSiblingElement("SOLUTION"))
{
if (getUnsignedAttrFromXMLNode(pNode, "ID") == 0)
break;
}
if (pNode == nullptr)
SC_REPORT_FATAL("AddressDecoder", "No mapping with ID 0 was found.");
//Why to have several "SOLUTION" elements if only the one with ID=0 will be used????
// get XOR connections
// An XOR connection needs two parameters: A first bit and a second bit.
for (tinyxml2::XMLElement *pXor = pNode->FirstChildElement("XOR");
pXor != nullptr; pXor = pXor->NextSiblingElement("XOR"))
{
vXor.push_back(std::pair<unsigned, unsigned>(getUnsignedAttrFromXMLNode(pXor, "FIRST"),
getUnsignedAttrFromXMLNode(pXor, "SECOND")));
}
for (tinyxml2::XMLElement *pChannel = pNode->FirstChildElement("CHANNEL_BIT");
pChannel != nullptr; pChannel = pChannel->NextSiblingElement("CHANNEL_BIT"))
vChannelBits.push_back(getUnsignedTextFromXMLNode(pChannel));
for (tinyxml2::XMLElement *pRank = pNode->FirstChildElement("RANK_BIT");
pRank != nullptr; pRank = pRank->NextSiblingElement("RANK_BIT"))
vRankBits.push_back(getUnsignedTextFromXMLNode(pRank));
for (tinyxml2::XMLElement *pBankGroup = pNode->FirstChildElement("BANKGROUP_BIT");
pBankGroup != nullptr; pBankGroup = pBankGroup->NextSiblingElement("BANKGROUP_BIT"))
vBankGroupBits.push_back(getUnsignedTextFromXMLNode(pBankGroup));
for (tinyxml2::XMLElement *pBank = pNode->FirstChildElement("BANK_BIT");
pBank != nullptr; pBank = pBank->NextSiblingElement("BANK_BIT"))
vBankBits.push_back(getUnsignedTextFromXMLNode(pBank));
for (tinyxml2::XMLElement *pRow = pNode->FirstChildElement("ROW_BIT");
pRow != nullptr; pRow = pRow->NextSiblingElement("ROW_BIT"))
vRowBits.push_back(getUnsignedTextFromXMLNode(pRow));
for (tinyxml2::XMLElement *pColumn = pNode->FirstChildElement("COLUMN_BIT");
pColumn != nullptr; pColumn = pColumn->NextSiblingElement("COLUMN_BIT"))
vColumnBits.push_back(getUnsignedTextFromXMLNode(pColumn));
for (tinyxml2::XMLElement *pByte = pNode->FirstChildElement("BYTE_BIT");
pByte != nullptr; pByte = pByte->NextSiblingElement("BYTE_BIT"))
vByteBits.push_back(getUnsignedTextFromXMLNode(pByte));
unsigned channels = pow(2.0, vChannelBits.size());
unsigned ranks = pow(2.0, vRankBits.size());

View File

@@ -1,41 +1,5 @@
/*
* Copyright (c) 2018, University of 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:
* Johannes Feldmann
* Lukas Steiner
*/
#ifndef ADDRESSDECODER_H
#define ADDRESSDECODER_H
#ifndef ADRESSDECODER_H
#define ADRESSDECODER_H
#include <iostream>
#include <sstream>
@@ -43,7 +7,7 @@
#include <map>
#include <vector>
#include "third_party/tinyxml2/tinyxml2.h"
#include "../common/third_party/nlohmann/single_include/nlohmann/json.hpp"
struct DecodedAddress
{
@@ -74,17 +38,18 @@ public:
void print();
private:
tinyxml2::XMLElement *getXMLNode(tinyxml2::XMLElement *pRoot,
std::string strName);
unsigned int getUnsignedTextFromXMLNode(tinyxml2::XMLElement *pRoot);
unsigned int getUnsignedAttrFromXMLNode(tinyxml2::XMLElement *pRoot,
std::string strName);
std::vector<unsigned> getAttrToVectorFromJson(nlohmann::json obj,
std::string strName);
unsigned int getUnsignedAttrFromJson(nlohmann::json obj,
std::string strName);
unsigned banksPerGroup;
unsigned bankgroupsPerRank;
uint64_t maximumAddress;
bool ID;
// This container stores for each used xor gate a pair of address bits, the first bit is overwritten with the result
std::vector<std::pair<unsigned, unsigned>> vXor;
std::vector<unsigned> vChannelBits;

View File

@@ -49,7 +49,7 @@ class ConfigurationLoader
public:
static void loadMCConfig(Configuration &config, std::string amconfigUri);
static void loadMCConfig(Configuration &config, std::string amconfigUri);
static void loadSimConfig(Configuration &config, std::string simconfigUri);