Skip to content

Commit

Permalink
fix: rename to saveState and delete old save mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
branylagaffe committed Aug 7, 2024
1 parent 9530944 commit 98716c5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 263 deletions.
4 changes: 0 additions & 4 deletions components/FastCMPCache/AbstractCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ class AbstractCache {
virtual void saveState(std::ostream &s) = 0;

virtual bool loadState(std::istream &s) = 0;

virtual void saveStateJSON(std::ostream &s) = 0;

virtual bool loadStateJSON(std::istream &s) = 0;
};

} // namespace nFastCMPCache
Expand Down
84 changes: 6 additions & 78 deletions components/FastCMPCache/FastCMPCacheImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,24 +815,24 @@ class FLEXUS_COMPONENT(FastCMPCache)
theCacheStats->update();
}

void saveStateJSON(std::string const &aDirName) {
void saveState(std::string const &aDirName) {
std::string fname(aDirName);
fname += "/" + statName() + "-dir.json";
std::ofstream ofs(fname.c_str(), std::ios::out);

theDirectory->saveStateJSON(ofs, aDirName);
theDirectory->saveState(ofs, aDirName);

fname = aDirName;
fname += "/" + statName() + "-cache.json";
std::ofstream c_ofs(fname.c_str(), std::ios::out);

theCache->saveStateJSON(c_ofs);
theCache->saveState(c_ofs);

ofs.close();
c_ofs.close();
}

void loadStateJSON(std::string const &aDirName)
void loadState(std::string const &aDirName)
{
std::string fname(aDirName);
fname += "/" + statName() + "-dir.json";
Expand All @@ -841,7 +841,7 @@ class FLEXUS_COMPONENT(FastCMPCache)
DBG_(Dev,
(<< " saved checkpoint state " << fname << " not found. Resetting to empty cache. "));
} else {
if (!theDirectory->loadStateJSON(ifs, aDirName)) {
if (!theDirectory->loadState(ifs, aDirName)) {
DBG_(Dev, (<< "Error loading checkpoint state from file: " << fname
<< ". Make sure your checkpoints match your current cache "
"configuration."));
Expand All @@ -857,7 +857,7 @@ class FLEXUS_COMPONENT(FastCMPCache)
DBG_(Dev,
(<< " saved checkpoint state " << c_fname << " not found. Resetting to empty cache. "));
} else {
if (!theCache->loadStateJSON(c_ifs)) {
if (!theCache->loadState(c_ifs)) {
DBG_(Dev, (<< "Error loading checkpoint state from file: " << c_fname
<< ". Make sure your checkpoints match your current cache "
"configuration."));
Expand All @@ -870,78 +870,6 @@ class FLEXUS_COMPONENT(FastCMPCache)
c_ifs.close();
}

void saveState(std::string const& aDirName)
{
std::string fname(aDirName);
fname += "/" + statName() + "-dir.gz";
std::ofstream ofs(fname.c_str(), std::ios::binary);

boost::iostreams::filtering_stream<boost::iostreams::output> out;
out.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params(9)));
out.push(ofs);

theDirectory->saveState(out, aDirName);

fname = aDirName;
fname += "/" + statName() + "-cache.gz";
std::ofstream c_ofs(fname.c_str(), std::ios::binary);

boost::iostreams::filtering_stream<boost::iostreams::output> c_out;
c_out.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params(9)));
c_out.push(c_ofs);

theCache->saveState(c_out);
saveStateJSON(aDirName);
}

void loadState(std::string const &aDirName)
{
std::string fname(aDirName);
fname += "/" + statName() + "-dir.gz";
std::ifstream ifs(fname.c_str(), std::ios::binary);
if (!ifs.good()) {
DBG_(Dev,
(<< " saved checkpoint state " << fname << " not found. Resetting to empty cache. "));
} else {
// ifs >> std::skipws;

boost::iostreams::filtering_stream<boost::iostreams::input> in;
in.push(boost::iostreams::gzip_decompressor());
in.push(ifs);

if (!theDirectory->loadState(in, aDirName)) {
DBG_(Dev, (<< "Error loading checkpoint state from file: " << fname
<< ". Make sure your checkpoints match your current cache "
"configuration."));
DBG_Assert(false);
}
loadStateJSON(aDirName);
}
DBG_(Dev, (<< " Directory state loaded"));
std::string c_fname(aDirName);
c_fname += "/" + statName() + "-cache.gz";
std::ifstream c_ifs(c_fname.c_str(), std::ios::binary);
if (!c_ifs.good()) {
DBG_(Dev,
(<< " saved checkpoint state " << c_fname << " not found. Resetting to empty cache. "));
} else {
// ifs >> std::skipws;

boost::iostreams::filtering_stream<boost::iostreams::input> c_in;
c_in.push(boost::iostreams::gzip_decompressor());
c_in.push(c_ifs);

if (!theCache->loadState(c_in)) {
DBG_(Dev,
(<< "Error loading checkpoint state from file: " << c_fname
<< ". Make sure your checkpoints match your current cache "
"configuration."));
DBG_Assert(false);
}
}
DBG_(Dev, (<< " Cache state loaded"));
}

}; // end class FastCMPCache

} // end Namespace nFastCMPCache
Expand Down
39 changes: 2 additions & 37 deletions components/FastCMPCache/InfiniteDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class InfiniteDirectory : public AbstractDirectory {
}
}

void saveStateJSON(std::ostream &s, const std::string &aDirName) {
void saveState(std::ostream &s, const std::string &aDirName) {

json checkpoint;
checkpoint = json::array();
Expand All @@ -325,7 +325,7 @@ class InfiniteDirectory : public AbstractDirectory {

}

bool loadStateJSON(std::istream &s, const std::string &aDirName) {
bool loadState(std::istream &s, const std::string &aDirName) {

json checkpoint;
s >> checkpoint;
Expand Down Expand Up @@ -354,41 +354,6 @@ class InfiniteDirectory : public AbstractDirectory {
return true;
}

void saveState(std::ostream &s, const std::string &aDirName) {
boost::archive::binary_oarchive oa(s);

uint32_t count = (uint32_t)theDirectory.size();
oa << count;
DBG_(Dev, (<< "Saving " << count << " directory entries."));
// StdDirEntrySerializer serializer;
// StdDirEntryExtendedSerializer serializer;
inf_directory_t::iterator iter = theDirectory.begin();
for (; iter != theDirectory.end(); iter++) {
StdDirEntryExtendedSerializer const serializer = iter->second->getSerializer();
DBG_(Trace, (<< "Directory saving block: " << serializer));
oa << serializer;
}
}

bool loadState(std::istream &s, const std::string &aDirName) {
boost::archive::binary_iarchive ia(s);
int32_t count;
ia >> count;
// StdDirEntrySerializer serializer;
StdDirEntryExtendedSerializer serializer;
DBG_(Trace, (<< "Directory loading " << count << " entries."));
for (; count > 0; count--) {
ia >> serializer;
DBG_(Trace, (<< "Directory loading block " << serializer));
InfiniteDirectoryEntry entry(serializer);
if (entry.state != ZeroSharers) {
theDirectory.insert(std::pair<PhysicalMemoryAddress, InfiniteDirectoryEntry *>(
PhysicalMemoryAddress(serializer.tag), new InfiniteDirectoryEntry(serializer)));
}
}
return true;
}

static AbstractDirectory *createInstance(std::list<std::pair<std::string, std::string>> &args) {
InfiniteDirectory *directory = new InfiniteDirectory();

Expand Down
52 changes: 3 additions & 49 deletions components/FastCMPCache/StandardDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class StandardDirectory : public AbstractDirectory
return std::tie(entry->sharers(), entry->state(), wrapper, valid);
}

void saveStateJSON(std::ostream &s, const std::string &aDirName) {
void saveState(std::ostream &s, const std::string &aDirName) {

json checkpoint;

Expand All @@ -277,7 +277,7 @@ class StandardDirectory : public AbstractDirectory
uint64_t dirAddress = theDirectory[set][way].theAddress;

checkpoint[i++] = {{"tag", dirAddress}, {"sharers", theDirectory[set][way].theSharers.getSharers().to_string()}};

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

}
Expand All @@ -287,7 +287,7 @@ class StandardDirectory : public AbstractDirectory

}

bool loadStateJSON(std::istream &s, const std::string &aDirName) {
bool loadState(std::istream &s, const std::string &aDirName) {

json checkpoint;
s >> checkpoint;
Expand Down Expand Up @@ -316,52 +316,6 @@ class StandardDirectory : public AbstractDirectory
return true;
}

void saveState(std::ostream &s, const std::string &aDirName) {
boost::archive::binary_oarchive oa(s);

uint64_t set_count = theNumSets;
uint32_t associativity = theAssociativity;

oa << set_count;
oa << associativity;

StdDirEntrySerializer serializer;
for (int32_t set = 0; set < theNumSets; set++) {
for (int32_t way = 0; way < theAssociativity; way++) {
serializer = theDirectory[set][way].getSerializer();
DBG_(Trace, (<< "Directory saving block " << serializer));
oa << serializer;
}
}
}

bool loadState(std::istream& s, const std::string& aDirName)
{
boost::archive::binary_iarchive ia(s);

uint64_t set_count = 0;
uint32_t associativity = 0;

ia >> set_count;
ia >> associativity;

DBG_Assert(set_count == (uint64_t)theNumSets,
(<< "Error loading directory state. Flexpoint contains " << set_count
<< " sets but simulator configured for " << theNumSets << " sets."));
DBG_Assert(associativity == (uint64_t)theAssociativity,
(<< "Error loading directory state. Flexpoint contains " << associativity
<< "-way sets but simulator configured for " << theAssociativity << "-way sets."));

StdDirEntrySerializer serializer;
for (int32_t set = 0; set < theNumSets; set++) {
for (int32_t way = 0; way < theAssociativity; way++) {
ia >> serializer;
theDirectory[set][way] = serializer;
}
}
return true;
}

static AbstractDirectory* createInstance(std::list<std::pair<std::string, std::string>>& args)
{
StandardDirectory* directory = new StandardDirectory();
Expand Down
Loading

0 comments on commit 98716c5

Please sign in to comment.