mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 20:57:10 +00:00
Pass accumulator caches by reference
closes https://github.com/official-stockfish/Stockfish/pull/6416 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
a191791f46
commit
db824e26be
+4
-4
@@ -59,15 +59,15 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks,
|
|||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
bool smallNet = use_smallnet(pos);
|
bool smallNet = use_smallnet(pos);
|
||||||
auto [psqt, positional] = smallNet ? networks.small.evaluate(pos, accumulators, &caches.small)
|
auto [psqt, positional] = smallNet ? networks.small.evaluate(pos, accumulators, caches.small)
|
||||||
: networks.big.evaluate(pos, accumulators, &caches.big);
|
: networks.big.evaluate(pos, accumulators, caches.big);
|
||||||
|
|
||||||
Value nnue = (125 * psqt + 131 * positional) / 128;
|
Value nnue = (125 * psqt + 131 * positional) / 128;
|
||||||
|
|
||||||
// Re-evaluate the position when higher eval accuracy is worth the time spent
|
// Re-evaluate the position when higher eval accuracy is worth the time spent
|
||||||
if (smallNet && (std::abs(nnue) < 236))
|
if (smallNet && (std::abs(nnue) < 236))
|
||||||
{
|
{
|
||||||
std::tie(psqt, positional) = networks.big.evaluate(pos, accumulators, &caches.big);
|
std::tie(psqt, positional) = networks.big.evaluate(pos, accumulators, caches.big);
|
||||||
nnue = (125 * psqt + 131 * positional) / 128;
|
nnue = (125 * psqt + 131 * positional) / 128;
|
||||||
smallNet = false;
|
smallNet = false;
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ std::string Eval::trace(Position& pos, const Eval::NNUE::Networks& networks) {
|
|||||||
|
|
||||||
ss << std::showpoint << std::showpos << std::fixed << std::setprecision(2) << std::setw(15);
|
ss << std::showpoint << std::showpos << std::fixed << std::setprecision(2) << std::setw(15);
|
||||||
|
|
||||||
auto [psqt, positional] = networks.big.evaluate(pos, *accumulators, &caches->big);
|
auto [psqt, positional] = networks.big.evaluate(pos, *accumulators, caches->big);
|
||||||
Value v = psqt + positional;
|
Value v = psqt + positional;
|
||||||
v = pos.side_to_move() == WHITE ? v : -v;
|
v = pos.side_to_move() == WHITE ? v : -v;
|
||||||
ss << "NNUE evaluation " << 0.01 * UCIEngine::to_cp(v, pos) << " (white side)\n";
|
ss << "NNUE evaluation " << 0.01 * UCIEngine::to_cp(v, pos) << " (white side)\n";
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ template<typename Arch, typename Transformer>
|
|||||||
NetworkOutput
|
NetworkOutput
|
||||||
Network<Arch, Transformer>::evaluate(const Position& pos,
|
Network<Arch, Transformer>::evaluate(const Position& pos,
|
||||||
AccumulatorStack& accumulatorStack,
|
AccumulatorStack& accumulatorStack,
|
||||||
AccumulatorCaches::Cache<FTDimensions>* cache) const {
|
AccumulatorCaches::Cache<FTDimensions>& cache) const {
|
||||||
|
|
||||||
constexpr uint64_t alignment = CacheLineSize;
|
constexpr uint64_t alignment = CacheLineSize;
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ template<typename Arch, typename Transformer>
|
|||||||
NnueEvalTrace
|
NnueEvalTrace
|
||||||
Network<Arch, Transformer>::trace_evaluate(const Position& pos,
|
Network<Arch, Transformer>::trace_evaluate(const Position& pos,
|
||||||
AccumulatorStack& accumulatorStack,
|
AccumulatorStack& accumulatorStack,
|
||||||
AccumulatorCaches::Cache<FTDimensions>* cache) const {
|
AccumulatorCaches::Cache<FTDimensions>& cache) const {
|
||||||
|
|
||||||
constexpr uint64_t alignment = CacheLineSize;
|
constexpr uint64_t alignment = CacheLineSize;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -76,13 +76,13 @@ class Network {
|
|||||||
|
|
||||||
NetworkOutput evaluate(const Position& pos,
|
NetworkOutput evaluate(const Position& pos,
|
||||||
AccumulatorStack& accumulatorStack,
|
AccumulatorStack& accumulatorStack,
|
||||||
AccumulatorCaches::Cache<FTDimensions>* cache) const;
|
AccumulatorCaches::Cache<FTDimensions>& cache) const;
|
||||||
|
|
||||||
|
|
||||||
void verify(std::string evalfilePath, const std::function<void(std::string_view)>&) const;
|
void verify(std::string evalfilePath, const std::function<void(std::string_view)>&) const;
|
||||||
NnueEvalTrace trace_evaluate(const Position& pos,
|
NnueEvalTrace trace_evaluate(const Position& pos,
|
||||||
AccumulatorStack& accumulatorStack,
|
AccumulatorStack& accumulatorStack,
|
||||||
AccumulatorCaches::Cache<FTDimensions>* cache) const;
|
AccumulatorCaches::Cache<FTDimensions>& cache) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void load_user_net(const std::string&, const std::string&);
|
void load_user_net(const std::string&, const std::string&);
|
||||||
|
|||||||
@@ -264,12 +264,12 @@ class FeatureTransformer {
|
|||||||
// Convert input features
|
// Convert input features
|
||||||
std::int32_t transform(const Position& pos,
|
std::int32_t transform(const Position& pos,
|
||||||
AccumulatorStack& accumulatorStack,
|
AccumulatorStack& accumulatorStack,
|
||||||
AccumulatorCaches::Cache<HalfDimensions>* cache,
|
AccumulatorCaches::Cache<HalfDimensions>& cache,
|
||||||
OutputType* output,
|
OutputType* output,
|
||||||
int bucket) const {
|
int bucket) const {
|
||||||
|
|
||||||
using namespace SIMD;
|
using namespace SIMD;
|
||||||
accumulatorStack.evaluate(pos, *this, *cache);
|
accumulatorStack.evaluate(pos, *this, cache);
|
||||||
const auto& accumulatorState = accumulatorStack.latest<PSQFeatureSet>();
|
const auto& accumulatorState = accumulatorStack.latest<PSQFeatureSet>();
|
||||||
const auto& threatAccumulatorState = accumulatorStack.latest<ThreatFeatureSet>();
|
const auto& threatAccumulatorState = accumulatorStack.latest<ThreatFeatureSet>();
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ trace(Position& pos, const Eval::NNUE::Networks& networks, Eval::NNUE::Accumulat
|
|||||||
|
|
||||||
// We estimate the value of each piece by doing a differential evaluation from
|
// We estimate the value of each piece by doing a differential evaluation from
|
||||||
// the current base eval, simulating the removal of the piece from its square.
|
// the current base eval, simulating the removal of the piece from its square.
|
||||||
auto [psqt, positional] = networks.big.evaluate(pos, *accumulators, &caches.big);
|
auto [psqt, positional] = networks.big.evaluate(pos, *accumulators, caches.big);
|
||||||
Value base = psqt + positional;
|
Value base = psqt + positional;
|
||||||
base = pos.side_to_move() == WHITE ? base : -base;
|
base = pos.side_to_move() == WHITE ? base : -base;
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ trace(Position& pos, const Eval::NNUE::Networks& networks, Eval::NNUE::Accumulat
|
|||||||
pos.remove_piece(sq);
|
pos.remove_piece(sq);
|
||||||
|
|
||||||
accumulators->reset();
|
accumulators->reset();
|
||||||
std::tie(psqt, positional) = networks.big.evaluate(pos, *accumulators, &caches.big);
|
std::tie(psqt, positional) = networks.big.evaluate(pos, *accumulators, caches.big);
|
||||||
Value eval = psqt + positional;
|
Value eval = psqt + positional;
|
||||||
eval = pos.side_to_move() == WHITE ? eval : -eval;
|
eval = pos.side_to_move() == WHITE ? eval : -eval;
|
||||||
v = base - eval;
|
v = base - eval;
|
||||||
@@ -157,7 +157,7 @@ trace(Position& pos, const Eval::NNUE::Networks& networks, Eval::NNUE::Accumulat
|
|||||||
ss << '\n';
|
ss << '\n';
|
||||||
|
|
||||||
accumulators->reset();
|
accumulators->reset();
|
||||||
auto t = networks.big.trace_evaluate(pos, *accumulators, &caches.big);
|
auto t = networks.big.trace_evaluate(pos, *accumulators, caches.big);
|
||||||
|
|
||||||
ss << " NNUE network contributions "
|
ss << " NNUE network contributions "
|
||||||
<< (pos.side_to_move() == WHITE ? "(White to move)" : "(Black to move)") << std::endl
|
<< (pos.side_to_move() == WHITE ? "(White to move)" : "(Black to move)") << std::endl
|
||||||
|
|||||||
Reference in New Issue
Block a user