Skip to content

Commit

Permalink
feat: checkpoint-working-paraflex
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgioajmone committed Jul 29, 2024
1 parent 629b984 commit 879ea09
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 63 deletions.
98 changes: 49 additions & 49 deletions components/BranchPredictor/BTB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ BTB::BTB(int32_t aBTBSets, int32_t aBTBAssoc)
{
// aBTBSize must be a power of 2
DBG_Assert(((aBTBSets - 1) & (aBTBSets)) == 0);
theBTB.resize(aBTBSets);
theBTB.resize(aBTBSets, BTBSet(aBTBAssoc));

theIndexMask = aBTBSets - 1; // ! Shouldn't it be log2(aBTBSets) ?
}

Expand Down Expand Up @@ -123,57 +124,56 @@ BTB::saveState() const {
//DBG_Assert(false, (<< "Don't know how to save type " << block->theBranchType));
break;
}
checkpoint[i][j] = {{"PC", (uint64_t)block->thePC}, {"target", (uint64_t)block->theTarget}, {"type", (uint8_t)type}};
if(block->valid){
checkpoint[i][j] = {{"PC", (uint64_t)block->thePC}, {"target", (uint64_t)block->theTarget}, {"type", (uint8_t)type}};
}
}
}

return checkpoint;

}
// void
// BTB::loadState(json checkpoint)
//{
//
// for (size_t set = 0; set < (size_t)theBTBSets; set++) {
//
// size_t blockSize = checkpoint.at(set).size();
//
// theBTB[set].get<by_baddr>().clear();
//
// for (size_t block = 0; block < blockSize; block++) {
// uint64_t aPC = checkpoint.at(set).at(block)["PC"];
// uint64_t aTarget = checkpoint.at(set).at(block)["target"];
// uint64_t aType = checkpoint.at(set).at(block)["type"];
//
// switch (aType) {
// case 0:
// theBTB[set].push_back(
// BTBEntry(VirtualMemoryAddress(aPC), kNonBranch, VirtualMemoryAddress(aTarget)));
// break;
// case 1:
// theBTB[set].push_back(
// BTBEntry(VirtualMemoryAddress(aPC), kConditional, VirtualMemoryAddress(aTarget)));
// break;
// case 2:
// theBTB[set].push_back(
// BTBEntry(VirtualMemoryAddress(aPC), kUnconditional, VirtualMemoryAddress(aTarget)));
// break;
// case 3:
// theBTB[set].push_back(BTBEntry(VirtualMemoryAddress(aPC), kCall, VirtualMemoryAddress(aTarget)));
// break;
// case 4:
// theBTB[set].push_back(
// BTBEntry(VirtualMemoryAddress(aPC), kIndirectReg, VirtualMemoryAddress(aTarget)));
// break;
// case 5:
// theBTB[set].push_back(
// BTBEntry(VirtualMemoryAddress(aPC), kIndirectCall, VirtualMemoryAddress(aTarget)));
// break;
// case 6:
// theBTB[set].push_back(BTBEntry(VirtualMemoryAddress(aPC), kReturn,
// VirtualMemoryAddress(aTarget))); break;
// default: DBG_Assert(false, (<< "Don't know how to load type" << aType)); break;
// }
// }
// }
// }

void
BTB::loadState(json checkpoint) {

for (size_t set = 0; set < (size_t)theBTBSets; set++) {

size_t blockSize = checkpoint.at(set).size();

theBTB[set].invalidateAll();

for (size_t block = 0; block < blockSize; block++) {
uint64_t aPC = checkpoint.at(set).at(block)["PC"];
uint64_t aTarget = checkpoint.at(set).at(block)["target"];
uint8_t aType = checkpoint.at(set).at(block)["type"];

switch (aType) {
case 0:
theBTB[set].insert(BTBEntry(VirtualMemoryAddress(aPC), kNonBranch, VirtualMemoryAddress(aTarget)));
break;
case 1:
theBTB[set].insert(BTBEntry(VirtualMemoryAddress(aPC), kConditional, VirtualMemoryAddress(aTarget)));
break;
case 2:
theBTB[set].insert(BTBEntry(VirtualMemoryAddress(aPC), kUnconditional, VirtualMemoryAddress(aTarget)));
break;
case 3:
theBTB[set].insert(BTBEntry(VirtualMemoryAddress(aPC), kCall, VirtualMemoryAddress(aTarget)));
break;
case 4:
theBTB[set].insert(BTBEntry(VirtualMemoryAddress(aPC), kIndirectReg, VirtualMemoryAddress(aTarget)));
break;
case 5:
theBTB[set].insert(BTBEntry(VirtualMemoryAddress(aPC), kIndirectCall, VirtualMemoryAddress(aTarget)));
break;
case 6:
theBTB[set].insert(BTBEntry(VirtualMemoryAddress(aPC), kReturn, VirtualMemoryAddress(aTarget)));
break;
default:
//DBG_Assert(false, (<< "Don't know how to load type" << aType));
break;
}
}
}
};
1 change: 1 addition & 0 deletions components/BranchPredictor/BTB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BTB
bool update(BranchFeedback const& aFeedback);

json saveState() const;
void loadState(json checkpoint);
};

#endif
8 changes: 8 additions & 0 deletions components/BranchPredictor/BTBSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ BTBSet::invalidate(VirtualMemoryAddress anAddress)
// TODO: Update replacementQueue for invalidation
}
}
}

void
BTBSet::invalidateAll()
{
for (uint32_t i = 0; i < blocks.size(); ++i) {
blocks[i].valid = false;
}
}
2 changes: 2 additions & 0 deletions components/BranchPredictor/BTBSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class BTBSet

// [MADHUR] Invalidate entry if present
void invalidate(VirtualMemoryAddress anAddress);

void invalidateAll();
};

#endif
13 changes: 12 additions & 1 deletion components/BranchPredictor/BranchPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,18 @@ BranchPredictor::feedback(VirtualMemoryAddress anAddress,
}


void BranchPredictor::loadState(std::string const& aDirName) {}
void BranchPredictor::loadState(std::string const& aDirName) {
std::string fname(aDirName);
fname += "/bpred-" + boost::padded_string_cast<2, '0'>(theIndex) + ".json";
std::ifstream ifs(fname.c_str());

json checkpoint;
ifs >> checkpoint;

theBTB.loadState(checkpoint["btb"]);
theTage.loadState(checkpoint["tage"]);
ifs.close();
}

void BranchPredictor::saveState(std::string const& aDirName) {
std::string fname(aDirName);
Expand Down
59 changes: 52 additions & 7 deletions components/BranchPredictor/TAGEImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,10 @@ class PREDICTOR {
json checkpoint;

checkpoint["PWIN"] = PWIN;
checkpoint["tick"] = TICK;
checkpoint["seed"] = Seed;
checkpoint["phist"] = phist;
checkpoint["ghist"] = ghist.to_string();
checkpoint["TICK"] = TICK;
checkpoint["SEED"] = Seed;
checkpoint["PHIST"] = phist;
checkpoint["GHIST"] = ghist.to_string();
checkpoint["LOGB"] = LOGB;
checkpoint["NHIST"] = NHIST;
checkpoint["LOGG"] = LOGG;
Expand Down Expand Up @@ -930,9 +930,54 @@ class PREDICTOR {
}

void loadState(json checkpoint) {
}

};
} // namespace SharedTypes
DBG_Assert(LOGB == checkpoint["LOGB"]);
DBG_Assert(NHIST == checkpoint["NHIST"]);
DBG_Assert(LOGG == checkpoint["LOGG"]);
DBG_Assert(TBITS == checkpoint["TBITS"]);
DBG_Assert(MAXHIST == checkpoint["MAXHIST"]);
DBG_Assert(MINHIST == checkpoint["MINHIST"]);
DBG_Assert(CBITS == checkpoint["CBITS"]);

PWIN = checkpoint["PWIN"];
TICK = checkpoint["TICK"];
Seed = checkpoint["SEED"];
phist = checkpoint["PHIST"];
ghist = history_t(checkpoint["GHIST"].get<std::string>());

// bimodal table
for (int i = 0; i < (1 << LOGB); i++) {
btable[i].hyst = checkpoint["btable"][i]["hyst"];
btable[i].pred = checkpoint["btable"][i]["pred"];
}

for (int i = 0; i < NHIST; i++) {
for (int j = 0; j < (1 << LOGG); j++) {
gtable[i][j].ctr = checkpoint["gtable"][i][j]["ctr"];
gtable[i][j].tag = checkpoint["gtable"][i][j]["tag"];
gtable[i][j].ubit = checkpoint["gtable"][i][j]["ubit"];
}
};

for (int i = 0; i < NHIST; i++) {
ch_i[i].comp = checkpoint["ch_i"][i]["comp"];
ch_i[i].CLENGTH = checkpoint["ch_i"][i]["c_length"];
ch_i[i].OLENGTH = checkpoint["ch_i"][i]["o_length"];
}

for (int j = 0; j < 2; j++) {
for (int i = 0; i < NHIST; i++) {
ch_t[j][i].comp = checkpoint["ch_t"][j][i]["comp"];
ch_t[j][i].OLENGTH = checkpoint["ch_t"][j][i]["o_length"];
ch_t[j][i].OUTPOINT = checkpoint["ch_t"][j][i]["out_point"];
}
}

for (int i = 0; i < NHIST; i++) {
m[i] = checkpoint["m"][i];
}
};
}; // namespace SharedTypes
} // namespace Flexus
}
#endif // PREDICTOR_H_SEEN
4 changes: 3 additions & 1 deletion components/CMPCache/InfiniteDirectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ class InfiniteDirectory : public AbstractDirectory<_State, _EState>
for (uint32_t i{0}; i < cache_size; i++)
{
uint64_t address = checkpoint.at(i)["tag"];
std::bitset<MAX_NUM_SHARERS> sharers ((uint64_t)checkpoint.at(i)["sharers"]);
std::bitset<MAX_NUM_SHARERS> sharers (checkpoint.at(i)["sharers"].get<std::string>());

DBG_Assert(sharers.size() <= theNumSharers, (<< "Sharers size mismatch"));

// It's stupid but that's the only way to workaround this object
SimpleDirectoryState state(theNumSharers);
state = sharers;
Expand Down
4 changes: 2 additions & 2 deletions components/CMPCache/StdArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ class StdArray : public AbstractArray<_State>
json checkpoint;
ifs >> checkpoint;

uint8_t associativity = checkpoint["associativity"];
uint32_t set_count = checkpoint["tags"].size();
DBG_Assert((uint64_t)theAssociativity == checkpoint["associativity"]);
DBG_Assert((uint64_t)theNumSets == checkpoint["tags"].size());

for (int32_t i{0}; i < theNumSets; i++)
{
Expand Down
3 changes: 3 additions & 0 deletions components/Cache/StdArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ class StdArray : public AbstractArray<_State>
json checkpoint;
is >> checkpoint;

DBG_Assert((uint64_t)theAssociativity == checkpoint["associativity"]);
DBG_Assert((uint64_t)setCount == checkpoint["tags"].size());

for (int32_t i{0}; i < setCount; i++) {
theSets[i]->load_set_from_ckpt(checkpoint, theIndex, i, theTagShift, setIndexShift);
}
Expand Down
5 changes: 2 additions & 3 deletions components/FastCMPCache/InfiniteDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ class InfiniteDirectory : public AbstractDirectory {
for (; iter != theDirectory.end(); iter++) {

uint64_t dirAddress = iter->second->address;
uint64_t sharers = iter->second->sharers.getSharers().to_ullong();

checkpoint[i++] = {{"tag", dirAddress}, {"sharers", sharers}};

checkpoint[i++] = {{"tag", dirAddress}, {"sharers", iter->second->sharers.getSharers().to_string()}};

DBG_(Trace, (<< "Directory saving block: " << dirAddress));

Expand Down
3 changes: 3 additions & 0 deletions components/uFetch/uFetchImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ struct SimCache
ifs >> checkpoint;
uint32_t tag_shift = LOG2(theCache.sets());

DBG_Assert((uint64_t)theCacheAssoc == checkpoint["associativity"]);
DBG_Assert((uint64_t)theCache.sets() == checkpoint["tags"].size());

for (std::size_t i{0}; i < theCache.sets(); i++) {
for (uint32_t j = 0; j < checkpoint["tags"].at(i).size(); j++) {
bool dirty = checkpoint["tags"].at(i).at(j)["dirty"];
Expand Down

0 comments on commit 879ea09

Please sign in to comment.