Extract plausability check from AddressDecoder to separate function

This commit is contained in:
2023-12-11 10:32:39 +01:00
parent 0b88161640
commit ed2a675145
6 changed files with 39 additions and 93 deletions

View File

@@ -47,8 +47,7 @@
namespace DRAMSys
{
AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping,
const MemSpec& memSpec)
AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping)
{
if (const auto& channelBits = addressMapping.CHANNEL_BIT)
{
@@ -108,6 +107,23 @@ AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMap
unsigned columns = std::lround(std::pow(2.0, vColumnBits.size()));
unsigned bytes = std::lround(std::pow(2.0, vByteBits.size()));
maximumAddress =
static_cast<uint64_t>(bytes) * columns * rows * banks * bankGroups * ranks * channels - 1;
bankgroupsPerRank = bankGroups;
banksPerGroup = banks;
}
void AddressDecoder::plausibilityCheck(const MemSpec& memSpec)
{
unsigned channels = std::lround(std::pow(2.0, vChannelBits.size()));
unsigned ranks = std::lround(std::pow(2.0, vRankBits.size()));
unsigned bankGroups = std::lround(std::pow(2.0, vBankGroupBits.size()));
unsigned banks = std::lround(std::pow(2.0, vBankBits.size()));
unsigned rows = std::lround(std::pow(2.0, vRowBits.size()));
unsigned columns = std::lround(std::pow(2.0, vColumnBits.size()));
unsigned bytes = std::lround(std::pow(2.0, vByteBits.size()));
maximumAddress =
static_cast<uint64_t>(bytes) * columns * rows * banks * bankGroups * ranks * channels - 1;
@@ -131,7 +147,8 @@ AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMap
{
highestByteBit = static_cast<int>(*std::max_element(vByteBits.begin(), vByteBits.end()));
for (unsigned bitPosition = 0; bitPosition <= static_cast<unsigned>(highestByteBit); bitPosition++)
for (unsigned bitPosition = 0; bitPosition <= static_cast<unsigned>(highestByteBit);
bitPosition++)
{
if (std::find(vByteBits.begin(), vByteBits.end(), bitPosition) == vByteBits.end())
SC_REPORT_FATAL("AddressDecoder", "Byte bits are not continuous starting from 0");
@@ -148,16 +165,13 @@ AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMap
SC_REPORT_FATAL("AddressDecoder", "No continuous column bits for maximum burst length");
}
bankgroupsPerRank = bankGroups;
bankGroups = bankgroupsPerRank * ranks;
banksPerGroup = banks;
banks = banksPerGroup * bankGroups;
unsigned absoluteBankGroups = bankgroupsPerRank * ranks;
unsigned absoluteBanks = banksPerGroup * absoluteBankGroups;
if (memSpec.numberOfChannels != channels || memSpec.ranksPerChannel != ranks ||
memSpec.bankGroupsPerChannel != bankGroups || memSpec.banksPerChannel != banks ||
memSpec.rowsPerBank != rows || memSpec.columnsPerRow != columns ||
memSpec.devicesPerRank * memSpec.bitWidth != bytes * 8)
memSpec.bankGroupsPerChannel != absoluteBankGroups ||
memSpec.banksPerChannel != absoluteBanks || memSpec.rowsPerBank != rows ||
memSpec.columnsPerRow != columns || memSpec.devicesPerRank * memSpec.bitWidth != bytes * 8)
SC_REPORT_FATAL("AddressDecoder", "Memspec and address mapping do not match");
}

View File

@@ -81,11 +81,14 @@ struct DecodedAddress
class AddressDecoder
{
public:
AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping, const MemSpec& memSpec);
AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping);
[[nodiscard]] DecodedAddress decodeAddress(uint64_t encAddr) const;
[[nodiscard]] unsigned decodeChannel(uint64_t encAddr) const;
[[nodiscard]] uint64_t encodeAddress(DecodedAddress decodedAddress) const;
void print() const;
void plausibilityCheck(const MemSpec &memSpec);
private:
unsigned banksPerGroup;

View File

@@ -151,7 +151,8 @@ void DRAMSys::setupDebugManager([[maybe_unused]] const std::string& traceName) c
void DRAMSys::instantiateModules(const ::DRAMSys::Config::AddressMapping& addressMapping)
{
addressDecoder = std::make_unique<AddressDecoder>(addressMapping, *config.memSpec);
addressDecoder = std::make_unique<AddressDecoder>(addressMapping);
addressDecoder->plausibilityCheck(*config.memSpec);
addressDecoder->print();
// Create arbiter

View File

@@ -106,7 +106,8 @@ void DRAMSysRecordable::setupTlmRecorders(const std::string& traceName,
void DRAMSysRecordable::instantiateModules(const std::string& traceName,
const ::DRAMSys::Config::Configuration& configLib)
{
addressDecoder = std::make_unique<AddressDecoder>(configLib.addressmapping, *config.memSpec);
addressDecoder = std::make_unique<AddressDecoder>(configLib.addressmapping);
addressDecoder->plausibilityCheck(*config.memSpec);
addressDecoder->print();
// Create and properly initialize TLM recorders.

View File

@@ -37,70 +37,6 @@
#include <string>
inline constexpr std::string_view memSpecJsonString = R"(
{
"memspec": {
"memarchitecturespec": {
"burstLength": 16,
"dataRate": 8,
"nbrOfBankGroups": 4,
"nbrOfBanks": 16,
"nbrOfColumns": 1024,
"nbrOfRows": 65536,
"nbrOfRanks": 1,
"nbrOfDevices": 1,
"nbrOfChannels": 1,
"width": 16,
"per2BankOffset": 8
},
"memoryId": "JEDEC_1Gbx16_BG_LPDDR5-6400",
"memoryType": "LPDDR5",
"memtimingspec": {
"RCD_L": 15,
"RCD_S": 15,
"PPD": 2,
"RPab": 17,
"RPpb": 15,
"RAS": 34,
"RCab": 51,
"RCpb": 48,
"FAW": 16,
"RRD": 4,
"RL": 17,
"WCK2CK": 0,
"WCK2DQO": 1,
"RBTP": 4,
"RPRE": 0,
"RPST": 0,
"WL": 9,
"WCK2DQI": 0,
"WPRE": 0,
"WPST": 0,
"WR": 28,
"WTR_L": 10,
"WTR_S": 5,
"CCDMW": 16,
"REFI": 3124,
"REFIpb": 390,
"RFCab": 224,
"RFCpb": 112,
"RTRS": 1,
"BL_n_min_16": 2,
"BL_n_max_16": 4,
"BL_n_L_16": 4,
"BL_n_S_16": 2,
"BL_n_min_32": 6,
"BL_n_max_32": 8,
"BL_n_L_32": 8,
"BL_n_S_32": 2,
"pbR2act": 6,
"pbR2pbR": 72,
"clkMhz": 800
}
}
}
)";
inline constexpr std::string_view addressMappingJsonString = R"(
{
"addressmapping": {

View File

@@ -35,32 +35,23 @@
#include "AddressDecoderConfigs.h"
#include <bitset>
#include <gtest/gtest.h>
#include <DRAMSys/configuration/memspec/MemSpecLPDDR5.h>
#include <DRAMSys/simulation/AddressDecoder.h>
class AddressDecoderFixture : public ::testing::Test
{
protected:
AddressDecoderFixture() :
addressMappingJson(nlohmann::json::parse(addressMappingJsonString).at("addressmapping")),
memSpecJson(nlohmann::json::parse(memSpecJsonString).at("memspec")),
addressMappingConfig(addressMappingJson.get<DRAMSys::Config::AddressMapping>()),
memSpecConfig(memSpecJson.get<DRAMSys::Config::MemSpec>()),
memSpec(memSpecConfig),
addressDecoder(addressMappingConfig, memSpec)
addressMappingConfig(nlohmann::json::parse(addressMappingJsonString)
.at("addressmapping")
.get<DRAMSys::Config::AddressMapping>()),
addressDecoder(addressMappingConfig)
{
}
nlohmann::json addressMappingJson;
nlohmann::json memSpecJson;
// Configs
DRAMSys::Config::AddressMapping addressMappingConfig;
DRAMSys::Config::MemSpec memSpecConfig;
DRAMSys::MemSpecLPDDR5 memSpec;
DRAMSys::AddressDecoder addressDecoder;
};
@@ -116,4 +107,4 @@ TEST_F(AddressDecoderFixture, DeEncoding)
EXPECT_EQ(encodedAddress, address);
}
}
}