Skip to content

Commit

Permalink
Add "clear_cache" command.
Browse files Browse the repository at this point in the history
No lz- prefix as this command existed in GNU Go as well.

Pull request leela-zero#2344.
  • Loading branch information
TFiFiE authored and gcp committed Apr 23, 2019
1 parent 4f1290a commit e542dd0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/GTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ const std::string GTP::s_commands[] = {
"fixed_handicap",
"last_move",
"move_history",
"clear_cache",
"place_free_handicap",
"set_free_handicap",
"loadsgf",
Expand Down Expand Up @@ -918,6 +919,10 @@ void GTP::execute(GameState & game, const std::string& xinput) {
}
gtp_printf_raw("\n");
return;
} else if (command.find("clear_cache") == 0) {
s_network->nncache_clear();
gtp_printf(id, "");
return;
} else if (command.find("place_free_handicap") == 0) {
std::istringstream cmdstream(command);
std::string tmp;
Expand Down
5 changes: 5 additions & 0 deletions src/NNCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ void NNCache::resize(int size) {
}
}

void NNCache::clear() {
m_cache.clear();
m_order.clear();
}

void NNCache::set_size_from_playouts(int max_playouts) {
// cache hits are generally from last several moves so setting cache
// size based on playouts increases the hit rate while balancing memory
Expand Down
1 change: 1 addition & 0 deletions src/NNCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class NNCache {

// Resize NNCache
void resize(int size);
void clear();

// Try and find an existing entry.
bool lookup(std::uint64_t hash, Netresult & result);
Expand Down
4 changes: 4 additions & 0 deletions src/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,3 +1033,7 @@ size_t Network::get_estimated_cache_size() {
void Network::nncache_resize(int max_count) {
return m_nncache.resize(max_count);
}

void Network::nncache_clear() {
m_nncache.clear();
}
1 change: 1 addition & 0 deletions src/Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Network {
size_t get_estimated_size();
size_t get_estimated_cache_size();
void nncache_resize(int max_count);
void nncache_clear();

private:
std::pair<int, int> load_v1_network(std::istream& wtfile);
Expand Down

0 comments on commit e542dd0

Please sign in to comment.