mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-23 05:07:14 +00:00
Refactor accumulator storage/updates
Passed Non-regression STC: LLR: 2.93 (-2.94,2.94) <-1.75,0.25> Total: 115840 W: 29983 L: 29854 D: 56003 Ptnml(0-2): 338, 12990, 31149, 13091, 352 https://tests.stockfishchess.org/tests/view/67d0a044166a3e8781d84223 closes https://github.com/official-stockfish/Stockfish/pull/5927 No functional change
This commit is contained in:
+31
-13
@@ -41,7 +41,6 @@
|
||||
#include "movepick.h"
|
||||
#include "nnue/network.h"
|
||||
#include "nnue/nnue_accumulator.h"
|
||||
#include "nnue/nnue_common.h"
|
||||
#include "position.h"
|
||||
#include "syzygy/tbprobe.h"
|
||||
#include "thread.h"
|
||||
@@ -197,6 +196,8 @@ void Search::Worker::ensure_network_replicated() {
|
||||
|
||||
void Search::Worker::start_searching() {
|
||||
|
||||
accumulatorStack.reset(rootPos, networks[numaAccessToken], refreshTable);
|
||||
|
||||
// Non-main threads go directly to iterative_deepening()
|
||||
if (!is_mainthread())
|
||||
{
|
||||
@@ -552,6 +553,26 @@ void Search::Worker::iterative_deepening() {
|
||||
skill.best ? skill.best : skill.pick_best(rootMoves, multiPV)));
|
||||
}
|
||||
|
||||
|
||||
void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st) {
|
||||
do_move(pos, move, st, pos.gives_check(move));
|
||||
}
|
||||
|
||||
void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck) {
|
||||
DirtyPiece dp = pos.do_move(move, st, givesCheck, &tt);
|
||||
accumulatorStack.push(dp);
|
||||
}
|
||||
|
||||
void Search::Worker::do_null_move(Position& pos, StateInfo& st) { pos.do_null_move(st, tt); }
|
||||
|
||||
void Search::Worker::undo_move(Position& pos, const Move move) {
|
||||
pos.undo_move(move);
|
||||
accumulatorStack.pop();
|
||||
}
|
||||
|
||||
void Search::Worker::undo_null_move(Position& pos) { pos.undo_null_move(); }
|
||||
|
||||
|
||||
// Reset histories, usually before a new game
|
||||
void Search::Worker::clear() {
|
||||
mainHistory.fill(66);
|
||||
@@ -614,7 +635,6 @@ Value Search::Worker::search(
|
||||
|
||||
Move pv[MAX_PLY + 1];
|
||||
StateInfo st;
|
||||
ASSERT_ALIGNED(&st, Eval::NNUE::CacheLineSize);
|
||||
|
||||
Key posKey;
|
||||
Move move, excludedMove, bestMove;
|
||||
@@ -859,11 +879,11 @@ Value Search::Worker::search(
|
||||
ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0];
|
||||
ss->continuationCorrectionHistory = &thisThread->continuationCorrectionHistory[NO_PIECE][0];
|
||||
|
||||
pos.do_null_move(st, tt);
|
||||
do_null_move(pos, st);
|
||||
|
||||
Value nullValue = -search<NonPV>(pos, ss + 1, -beta, -beta + 1, depth - R, false);
|
||||
|
||||
pos.undo_null_move();
|
||||
undo_null_move(pos);
|
||||
|
||||
// Do not return unproven mate or TB scores
|
||||
if (nullValue >= beta && !is_win(nullValue))
|
||||
@@ -925,7 +945,7 @@ Value Search::Worker::search(
|
||||
|
||||
movedPiece = pos.moved_piece(move);
|
||||
|
||||
pos.do_move(move, st, &tt);
|
||||
do_move(pos, move, st);
|
||||
thisThread->nodes.fetch_add(1, std::memory_order_relaxed);
|
||||
|
||||
ss->currentMove = move;
|
||||
@@ -943,7 +963,7 @@ Value Search::Worker::search(
|
||||
value = -search<NonPV>(pos, ss + 1, -probCutBeta, -probCutBeta + 1, probCutDepth,
|
||||
!cutNode);
|
||||
|
||||
pos.undo_move(move);
|
||||
undo_move(pos, move);
|
||||
|
||||
if (value >= probCutBeta)
|
||||
{
|
||||
@@ -1165,7 +1185,7 @@ moves_loop: // When in check, search starts here
|
||||
}
|
||||
|
||||
// Step 16. Make the move
|
||||
pos.do_move(move, st, givesCheck, &tt);
|
||||
do_move(pos, move, st, givesCheck);
|
||||
thisThread->nodes.fetch_add(1, std::memory_order_relaxed);
|
||||
|
||||
// Add extension to new depth
|
||||
@@ -1290,7 +1310,7 @@ moves_loop: // When in check, search starts here
|
||||
}
|
||||
|
||||
// Step 19. Undo move
|
||||
pos.undo_move(move);
|
||||
undo_move(pos, move);
|
||||
|
||||
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
|
||||
|
||||
@@ -1510,7 +1530,6 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
|
||||
|
||||
Move pv[MAX_PLY + 1];
|
||||
StateInfo st;
|
||||
ASSERT_ALIGNED(&st, Eval::NNUE::CacheLineSize);
|
||||
|
||||
Key posKey;
|
||||
Move move, bestMove;
|
||||
@@ -1674,7 +1693,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
|
||||
// Step 7. Make and search the move
|
||||
Piece movedPiece = pos.moved_piece(move);
|
||||
|
||||
pos.do_move(move, st, givesCheck, &tt);
|
||||
do_move(pos, move, st, givesCheck);
|
||||
thisThread->nodes.fetch_add(1, std::memory_order_relaxed);
|
||||
|
||||
// Update the current move
|
||||
@@ -1685,7 +1704,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
|
||||
&thisThread->continuationCorrectionHistory[movedPiece][move.to_sq()];
|
||||
|
||||
value = -qsearch<nodeType>(pos, ss + 1, -beta, -alpha);
|
||||
pos.undo_move(move);
|
||||
undo_move(pos, move);
|
||||
|
||||
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
|
||||
|
||||
@@ -1752,7 +1771,7 @@ TimePoint Search::Worker::elapsed() const {
|
||||
TimePoint Search::Worker::elapsed_time() const { return main_manager()->tm.elapsed_time(); }
|
||||
|
||||
Value Search::Worker::evaluate(const Position& pos) {
|
||||
return Eval::evaluate(networks[numaAccessToken], pos, refreshTable,
|
||||
return Eval::evaluate(networks[numaAccessToken], pos, accumulatorStack, refreshTable,
|
||||
optimism[pos.side_to_move()]);
|
||||
}
|
||||
|
||||
@@ -2178,7 +2197,6 @@ void SearchManager::pv(Search::Worker& worker,
|
||||
bool RootMove::extract_ponder_from_tt(const TranspositionTable& tt, Position& pos) {
|
||||
|
||||
StateInfo st;
|
||||
ASSERT_ALIGNED(&st, Eval::NNUE::CacheLineSize);
|
||||
|
||||
assert(pv.size() == 1);
|
||||
if (pv[0] == Move::none())
|
||||
|
||||
Reference in New Issue
Block a user