mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-06 10:53:50 +08:00
Remove non-functional accumulator reset
Passed Non-regression STC: LLR: 2.93 (-2.94,2.94) <-1.75,0.25> Total: 219360 W: 56600 L: 56583 D: 106177 Ptnml(0-2): 582, 23419, 61620, 23518, 541 https://tests.stockfishchess.org/tests/view/67fad20dcd501869c669780f closes https://github.com/official-stockfish/Stockfish/pull/5986 no functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
f9459e4c8e
commit
f273eea71f
@@ -101,8 +101,6 @@ std::string Eval::trace(Position& pos, const Eval::NNUE::Networks& networks) {
|
||||
Eval::NNUE::AccumulatorStack accumulators;
|
||||
auto caches = std::make_unique<Eval::NNUE::AccumulatorCaches>(networks);
|
||||
|
||||
accumulators.reset(pos, networks, *caches);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::showpoint << std::noshowpos << std::fixed << std::setprecision(2);
|
||||
ss << '\n' << NNUE::trace(pos, networks, *caches) << '\n';
|
||||
|
||||
@@ -19,15 +19,14 @@
|
||||
#include "nnue_accumulator.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include "../bitboard.h"
|
||||
#include "../misc.h"
|
||||
#include "../position.h"
|
||||
#include "../types.h"
|
||||
#include "network.h"
|
||||
#include "nnue_architecture.h"
|
||||
#include "nnue_feature_transformer.h"
|
||||
|
||||
@@ -68,39 +67,24 @@ void AccumulatorState::reset(const DirtyPiece& dp) noexcept {
|
||||
accumulatorSmall.computed.fill(false);
|
||||
}
|
||||
|
||||
const AccumulatorState& AccumulatorStack::latest() const noexcept {
|
||||
return m_accumulators[m_current_idx - 1];
|
||||
}
|
||||
const AccumulatorState& AccumulatorStack::latest() const noexcept { return accumulators[size - 1]; }
|
||||
|
||||
AccumulatorState& AccumulatorStack::mut_latest() noexcept {
|
||||
return m_accumulators[m_current_idx - 1];
|
||||
}
|
||||
AccumulatorState& AccumulatorStack::mut_latest() noexcept { return accumulators[size - 1]; }
|
||||
|
||||
void AccumulatorStack::reset(const Position& rootPos,
|
||||
const Networks& networks,
|
||||
AccumulatorCaches& caches) noexcept {
|
||||
m_current_idx = 1;
|
||||
|
||||
update_accumulator_refresh_cache<WHITE, TransformedFeatureDimensionsBig>(
|
||||
*networks.big.featureTransformer, rootPos, m_accumulators[0], caches.big);
|
||||
update_accumulator_refresh_cache<BLACK, TransformedFeatureDimensionsBig>(
|
||||
*networks.big.featureTransformer, rootPos, m_accumulators[0], caches.big);
|
||||
|
||||
update_accumulator_refresh_cache<WHITE, TransformedFeatureDimensionsSmall>(
|
||||
*networks.small.featureTransformer, rootPos, m_accumulators[0], caches.small);
|
||||
update_accumulator_refresh_cache<BLACK, TransformedFeatureDimensionsSmall>(
|
||||
*networks.small.featureTransformer, rootPos, m_accumulators[0], caches.small);
|
||||
void AccumulatorStack::reset() noexcept {
|
||||
accumulators[0].reset({});
|
||||
size = 1;
|
||||
}
|
||||
|
||||
void AccumulatorStack::push(const DirtyPiece& dirtyPiece) noexcept {
|
||||
assert(m_current_idx + 1 < m_accumulators.size());
|
||||
m_accumulators[m_current_idx].reset(dirtyPiece);
|
||||
m_current_idx++;
|
||||
assert(size + 1 < accumulators.size());
|
||||
accumulators[size].reset(dirtyPiece);
|
||||
size++;
|
||||
}
|
||||
|
||||
void AccumulatorStack::pop() noexcept {
|
||||
assert(m_current_idx > 1);
|
||||
m_current_idx--;
|
||||
assert(size > 1);
|
||||
size--;
|
||||
}
|
||||
|
||||
template<IndexType Dimensions>
|
||||
@@ -119,7 +103,7 @@ void AccumulatorStack::evaluate_side(const Position& pos,
|
||||
|
||||
const auto last_usable_accum = find_last_usable_accumulator<Perspective, Dimensions>();
|
||||
|
||||
if ((m_accumulators[last_usable_accum].template acc<Dimensions>()).computed[Perspective])
|
||||
if ((accumulators[last_usable_accum].template acc<Dimensions>()).computed[Perspective])
|
||||
forward_update_incremental<Perspective>(pos, featureTransformer, last_usable_accum);
|
||||
|
||||
else
|
||||
@@ -134,12 +118,12 @@ void AccumulatorStack::evaluate_side(const Position& pos,
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
std::size_t AccumulatorStack::find_last_usable_accumulator() const noexcept {
|
||||
|
||||
for (std::size_t curr_idx = m_current_idx - 1; curr_idx > 0; curr_idx--)
|
||||
for (std::size_t curr_idx = size - 1; curr_idx > 0; curr_idx--)
|
||||
{
|
||||
if ((m_accumulators[curr_idx].template acc<Dimensions>()).computed[Perspective])
|
||||
if ((accumulators[curr_idx].template acc<Dimensions>()).computed[Perspective])
|
||||
return curr_idx;
|
||||
|
||||
if (FeatureSet::requires_refresh(m_accumulators[curr_idx].dirtyPiece, Perspective))
|
||||
if (FeatureSet::requires_refresh(accumulators[curr_idx].dirtyPiece, Perspective))
|
||||
return curr_idx;
|
||||
}
|
||||
|
||||
@@ -152,14 +136,14 @@ void AccumulatorStack::forward_update_incremental(
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const std::size_t begin) noexcept {
|
||||
|
||||
assert(begin < m_accumulators.size());
|
||||
assert((m_accumulators[begin].acc<Dimensions>()).computed[Perspective]);
|
||||
assert(begin < accumulators.size());
|
||||
assert((accumulators[begin].acc<Dimensions>()).computed[Perspective]);
|
||||
|
||||
const Square ksq = pos.square<KING>(Perspective);
|
||||
|
||||
for (std::size_t next = begin + 1; next < m_current_idx; next++)
|
||||
for (std::size_t next = begin + 1; next < size; next++)
|
||||
update_accumulator_incremental<Perspective, true>(
|
||||
featureTransformer, ksq, m_accumulators[next], m_accumulators[next - 1]);
|
||||
featureTransformer, ksq, accumulators[next], accumulators[next - 1]);
|
||||
|
||||
assert((latest().acc<Dimensions>()).computed[Perspective]);
|
||||
}
|
||||
@@ -170,17 +154,17 @@ void AccumulatorStack::backward_update_incremental(
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const std::size_t end) noexcept {
|
||||
|
||||
assert(end < m_accumulators.size());
|
||||
assert(end < m_current_idx);
|
||||
assert(end < accumulators.size());
|
||||
assert(end < size);
|
||||
assert((latest().acc<Dimensions>()).computed[Perspective]);
|
||||
|
||||
const Square ksq = pos.square<KING>(Perspective);
|
||||
|
||||
for (std::size_t next = m_current_idx - 2; next >= end; next--)
|
||||
for (std::int64_t next = std::int64_t(size) - 2; next >= std::int64_t(end); next--)
|
||||
update_accumulator_incremental<Perspective, false>(
|
||||
featureTransformer, ksq, m_accumulators[next], m_accumulators[next + 1]);
|
||||
featureTransformer, ksq, accumulators[next], accumulators[next + 1]);
|
||||
|
||||
assert((m_accumulators[end].acc<Dimensions>()).computed[Perspective]);
|
||||
assert((accumulators[end].acc<Dimensions>()).computed[Perspective]);
|
||||
}
|
||||
|
||||
// Explicit template instantiations
|
||||
@@ -323,6 +307,7 @@ void update_accumulator_refresh_cache(const FeatureTransformer<Dimensions>& feat
|
||||
const Position& pos,
|
||||
AccumulatorState& accumulatorState,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) {
|
||||
|
||||
using Tiling [[maybe_unused]] = SIMDTiling<Dimensions, Dimensions>;
|
||||
|
||||
const Square ksq = pos.square<KING>(Perspective);
|
||||
|
||||
@@ -41,8 +41,6 @@ using BiasType = std::int16_t;
|
||||
using PSQTWeightType = std::int32_t;
|
||||
using IndexType = std::uint32_t;
|
||||
|
||||
struct Networks;
|
||||
|
||||
template<IndexType Size>
|
||||
struct alignas(CacheLineSize) Accumulator;
|
||||
|
||||
@@ -149,13 +147,12 @@ struct AccumulatorState {
|
||||
class AccumulatorStack {
|
||||
public:
|
||||
AccumulatorStack() :
|
||||
m_accumulators(MAX_PLY + 1),
|
||||
m_current_idx{} {}
|
||||
accumulators(MAX_PLY + 1),
|
||||
size{1} {}
|
||||
|
||||
[[nodiscard]] const AccumulatorState& latest() const noexcept;
|
||||
|
||||
void
|
||||
reset(const Position& rootPos, const Networks& networks, AccumulatorCaches& caches) noexcept;
|
||||
void reset() noexcept;
|
||||
void push(const DirtyPiece& dirtyPiece) noexcept;
|
||||
void pop() noexcept;
|
||||
|
||||
@@ -185,8 +182,8 @@ class AccumulatorStack {
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const std::size_t end) noexcept;
|
||||
|
||||
std::vector<AccumulatorState> m_accumulators;
|
||||
std::size_t m_current_idx;
|
||||
std::vector<AccumulatorState> accumulators;
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
} // namespace Stockfish::Eval::NNUE
|
||||
|
||||
@@ -121,7 +121,6 @@ trace(Position& pos, const Eval::NNUE::Networks& networks, Eval::NNUE::Accumulat
|
||||
};
|
||||
|
||||
AccumulatorStack accumulators;
|
||||
accumulators.reset(pos, networks, caches);
|
||||
|
||||
// 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.
|
||||
@@ -140,7 +139,7 @@ trace(Position& pos, const Eval::NNUE::Networks& networks, Eval::NNUE::Accumulat
|
||||
{
|
||||
pos.remove_piece(sq);
|
||||
|
||||
accumulators.reset(pos, networks, caches);
|
||||
accumulators.reset();
|
||||
std::tie(psqt, positional) = networks.big.evaluate(pos, accumulators, &caches.big);
|
||||
Value eval = psqt + positional;
|
||||
eval = pos.side_to_move() == WHITE ? eval : -eval;
|
||||
@@ -157,7 +156,7 @@ trace(Position& pos, const Eval::NNUE::Networks& networks, Eval::NNUE::Accumulat
|
||||
ss << board[row] << '\n';
|
||||
ss << '\n';
|
||||
|
||||
accumulators.reset(pos, networks, caches);
|
||||
accumulators.reset();
|
||||
auto t = networks.big.trace_evaluate(pos, accumulators, &caches.big);
|
||||
|
||||
ss << " NNUE network contributions "
|
||||
|
||||
@@ -195,7 +195,7 @@ void Search::Worker::ensure_network_replicated() {
|
||||
|
||||
void Search::Worker::start_searching() {
|
||||
|
||||
accumulatorStack.reset(rootPos, networks[numaAccessToken], refreshTable);
|
||||
accumulatorStack.reset();
|
||||
|
||||
// Non-main threads go directly to iterative_deepening()
|
||||
if (!is_mainthread())
|
||||
|
||||
Reference in New Issue
Block a user