Skip to content

Commit

Permalink
Fix missing initialization of AccumulatorCaches in Eval::trace
Browse files Browse the repository at this point in the history
Add a constructor to `AccumulatorCaches` instead of just calling
`clear(networks)` to prevent similar issues from appearing in the
future.

fixes #5190

closes #5191

No functional change
  • Loading branch information
Disservin committed Apr 28, 2024
1 parent 886ed90 commit 3502c8a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks,
// Trace scores are from white's point of view
std::string Eval::trace(Position& pos, const Eval::NNUE::Networks& networks) {

auto caches = std::make_unique<Eval::NNUE::AccumulatorCaches>();
auto caches = std::make_unique<Eval::NNUE::AccumulatorCaches>(networks);

if (pos.checkers())
return "Final evaluation: none (in check)";
Expand Down
5 changes: 5 additions & 0 deletions src/nnue/nnue_accumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ struct alignas(CacheLineSize) Accumulator {
// is commonly referred to as "Finny Tables".
struct AccumulatorCaches {

template<typename Networks>
AccumulatorCaches(const Networks& networks) {
clear(networks);
}

template<IndexType Size>
struct alignas(CacheLineSize) Cache {

Expand Down
4 changes: 2 additions & 2 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ Search::Worker::Worker(SharedState& sharedState,
// Unpack the SharedState struct into member variables
thread_idx(thread_id),
manager(std::move(sm)),
refreshTable(),
options(sharedState.options),
threads(sharedState.threads),
tt(sharedState.tt),
networks(sharedState.networks) {
networks(sharedState.networks),
refreshTable(networks) {
clear();
}

Expand Down
7 changes: 3 additions & 4 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,14 @@ class Worker {

Tablebases::Config tbConfig;

// Used by NNUE

Eval::NNUE::AccumulatorCaches refreshTable;

const OptionsMap& options;
ThreadPool& threads;
TranspositionTable& tt;
const Eval::NNUE::Networks& networks;

// Used by NNUE
Eval::NNUE::AccumulatorCaches refreshTable;

friend class Stockfish::ThreadPool;
friend class SearchManager;
};
Expand Down

0 comments on commit 3502c8a

Please sign in to comment.