mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
avoid modify_and_replicate for first load
We call modify_and_replicate in load_networks, but this is quite inefficient. closes https://github.com/official-stockfish/Stockfish/pull/6574 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
b248d689a8
commit
b808fd3d55
+13
-12
@@ -63,10 +63,7 @@ Engine::Engine(std::optional<std::string> path) :
|
|||||||
numaContext(NumaConfig::from_system(DefaultNumaPolicy)),
|
numaContext(NumaConfig::from_system(DefaultNumaPolicy)),
|
||||||
states(new std::deque<StateInfo>(1)),
|
states(new std::deque<StateInfo>(1)),
|
||||||
threads(),
|
threads(),
|
||||||
networks(numaContext,
|
networks(numaContext, get_default_networks()) {
|
||||||
// Heap-allocate because sizeof(NN::Networks) is large
|
|
||||||
std::make_unique<NN::Networks>(NN::EvalFile{EvalFileDefaultNameBig, "None", ""},
|
|
||||||
NN::EvalFile{EvalFileDefaultNameSmall, "None", ""})) {
|
|
||||||
|
|
||||||
pos.set(StartFEN, false, &states->back());
|
pos.set(StartFEN, false, &states->back());
|
||||||
|
|
||||||
@@ -147,7 +144,8 @@ Engine::Engine(std::optional<std::string> path) :
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
load_networks();
|
threads.clear();
|
||||||
|
threads.ensure_network_replicated();
|
||||||
resize_threads();
|
resize_threads();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,13 +292,16 @@ void Engine::verify_networks() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::load_networks() {
|
std::unique_ptr<Eval::NNUE::Networks> Engine::get_default_networks() const {
|
||||||
networks.modify_and_replicate([this](NN::Networks& networks_) {
|
|
||||||
networks_.big.load(binaryDirectory, options["EvalFile"]);
|
auto networks_ =
|
||||||
networks_.small.load(binaryDirectory, options["EvalFileSmall"]);
|
std::make_unique<NN::Networks>(NN::EvalFile{EvalFileDefaultNameBig, "None", ""},
|
||||||
});
|
NN::EvalFile{EvalFileDefaultNameSmall, "None", ""});
|
||||||
threads.clear();
|
|
||||||
threads.ensure_network_replicated();
|
networks_->big.load(binaryDirectory, "");
|
||||||
|
networks_->small.load(binaryDirectory, "");
|
||||||
|
|
||||||
|
return networks_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::load_big_network(const std::string& file) {
|
void Engine::load_big_network(const std::string& file) {
|
||||||
|
|||||||
+5
-4
@@ -23,6 +23,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -85,10 +86,10 @@ class Engine {
|
|||||||
|
|
||||||
// network related
|
// network related
|
||||||
|
|
||||||
void verify_networks() const;
|
void verify_networks() const;
|
||||||
void load_networks();
|
std::unique_ptr<Eval::NNUE::Networks> get_default_networks() const;
|
||||||
void load_big_network(const std::string& file);
|
void load_big_network(const std::string& file);
|
||||||
void load_small_network(const std::string& file);
|
void load_small_network(const std::string& file);
|
||||||
void save_network(const std::pair<std::optional<std::string>, std::string> files[2]);
|
void save_network(const std::pair<std::optional<std::string>, std::string> files[2]);
|
||||||
|
|
||||||
// utility functions
|
// utility functions
|
||||||
|
|||||||
Reference in New Issue
Block a user