Skip to content

Commit

Permalink
TAGE checkpointing fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur19171 committed Jul 8, 2024
1 parent 70f66a9 commit 81f0a28
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1,272 deletions.
6 changes: 4 additions & 2 deletions components/BranchPredictor/BranchPredictor.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "BranchPredictor.hpp"

#include <core/boost_extensions/padded_string_cast.hpp>
#include <components/uFetch/uFetchTypes.hpp>
#include "core/debug/debug.hpp"
#include "core/types.hpp"
#include <fstream>

#include <core/checkpoint/json.hpp>
using json = nlohmann::json;
Expand Down Expand Up @@ -158,13 +160,13 @@ BranchPredictor::feedback(VirtualMemoryAddress anAddress,
void BranchPredictor::loadState(std::string const& aDirName) {}

void BranchPredictor::saveState(std::string const& aDirName) {
std::string fname(dirname);
std::string fname(aDirName);
fname += "/bpred-" + boost::padded_string_cast<2, '0'>(theIndex) + ".json";
std::ofstream ofs(fname.c_str());

json checkpoint;

checkpoint["BTB"] = theBTB.saveState();
// checkpoint["BTB"] = theBTB.saveState();
checkpoint["TAGE"] = theTage.saveState();

ofs << std::setw(4) << checkpoint << std::endl;
Expand Down
79 changes: 39 additions & 40 deletions components/BranchPredictor/TAGEImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,60 +874,59 @@ class PREDICTOR {

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

btable_json["hyst"] = (int)btable[i].hyst;
btable_json["pred"] = (int)btable[i].pred;

checkpoint["btable"].push_back(btable_json);
}

for (int i = 0; i < NHIST; i++) {
json gtable_array_json;

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

gtable_json["ctr"] = (int)gtable[i][j].ctr;
gtable_json["tag"] = (int)gtable[i][j].tag;
gtable_json["ubit"] = (int)gtable[i][j].ubit;

gtable_array_json.push_back(gtable_json);
}

checkpoint["gtable"].push_back(gtable_array_json);
};

for (int i = 0; i < NHIST; i++) {
checkpoint["ch_i"].emplace_back(
{
(uint32_t)ch_i[i].comp,
ch_i[i].CLENGTH,
ch_i[i].OLENGTH
}
);
}
json ch_i_json;

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

checkpoint["ch_i"].push_back(ch_i_json);
}

for (int i = 0; i < NHIST; i++) {
checkpoint["ch_t"].emplace_back(
{
(uint32_t)ch_t[1][i].comp,
ch_t[1][i].CLENGTH,
ch_t[1][i].OLENGTH,
ch_t[1][i].OUTPOINT
}
);

for (int j = 0; j < 2; j++) {
json ch_t_array_json;

for (int i = 0; i < NHIST; i++) {
json ch_t_json;

ch_t_json["comp"] = (uint32_t)ch_t[j][i].comp;
ch_t_json["o_length"] = (uint32_t)ch_t[j][i].OLENGTH;
ch_t_json["out_point"] = (uint32_t)ch_t[j][i].OUTPOINT;

ch_t_array_json.push_back(ch_t_json);
}

checkpoint["ch_t"].push_back(ch_t_array_json);
}

for (int i = 0; i < NHIST; i++) {
checkpoint["m"].emplace_back(m[i]);
checkpoint["m"].push_back(m[i]);
};

return checkpoint;
Expand Down
Loading

0 comments on commit 81f0a28

Please sign in to comment.