diff --git a/src/nnue/nnue_accumulator.cpp b/src/nnue/nnue_accumulator.cpp index 37af7a0fa..8b2585b91 100644 --- a/src/nnue/nnue_accumulator.cpp +++ b/src/nnue/nnue_accumulator.cpp @@ -29,7 +29,6 @@ #include "../types.h" #include "network.h" #include "nnue_architecture.h" -#include "nnue_common.h" #include "nnue_feature_transformer.h" namespace Stockfish::Eval::NNUE { @@ -48,9 +47,7 @@ namespace Stockfish::Eval::NNUE { namespace { -template +template void update_accumulator_incremental( const FeatureTransformer& featureTransformer, const Square ksq, @@ -161,8 +158,8 @@ void AccumulatorStack::forward_update_incremental( const Square ksq = pos.square(Perspective); for (std::size_t next = begin + 1; next < m_current_idx; next++) - update_accumulator_incremental(featureTransformer, ksq, m_accumulators[next], - m_accumulators[next - 1]); + update_accumulator_incremental( + featureTransformer, ksq, m_accumulators[next], m_accumulators[next - 1]); assert((latest().acc()).computed[Perspective]); } @@ -180,7 +177,7 @@ void AccumulatorStack::backward_update_incremental( const Square ksq = pos.square(Perspective); for (std::size_t next = m_current_idx - 2; next >= end; next--) - update_accumulator_incremental( + update_accumulator_incremental( featureTransformer, ksq, m_accumulators[next], m_accumulators[next + 1]); assert((m_accumulators[end].acc()).computed[Perspective]); @@ -259,16 +256,12 @@ auto make_accumulator_update_context(const FeatureTransformer& featu accumulatorTo}; } -template +template void update_accumulator_incremental( const FeatureTransformer& featureTransformer, const Square ksq, AccumulatorState& target_state, const AccumulatorState& computed) { - [[maybe_unused]] constexpr bool Forward = Direction == FORWARD; - [[maybe_unused]] constexpr bool Backward = Direction == BACKWARD; - - assert(Forward != Backward); assert((computed.acc()).computed[Perspective]); assert(!(target_state.acc()).computed[Perspective]); @@ -288,11 +281,8 @@ void update_accumulator_incremental( assert(added.size() == 1 || added.size() == 2); assert(removed.size() == 1 || removed.size() == 2); - - if (Forward) - assert(added.size() <= removed.size()); - else - assert(removed.size() <= added.size()); + assert((Forward && added.size() <= removed.size()) + || (!Forward && added.size() >= removed.size())); // Workaround compiler warning for uninitialized variables, replicated on // profile builds on windows with gcc 14.2.0. @@ -303,7 +293,7 @@ void update_accumulator_incremental( auto updateContext = make_accumulator_update_context(featureTransformer, computed, target_state); - if ((Forward && removed.size() == 1) || (Backward && added.size() == 1)) + if ((Forward && removed.size() == 1) || (!Forward && added.size() == 1)) { assert(added.size() == 1 && removed.size() == 1); updateContext.template apply(added[0], removed[0]); @@ -313,7 +303,7 @@ void update_accumulator_incremental( assert(removed.size() == 2); updateContext.template apply(added[0], removed[0], removed[1]); } - else if (Backward && removed.size() == 1) + else if (!Forward && removed.size() == 1) { assert(added.size() == 2); updateContext.template apply(added[0], added[1], removed[0]); @@ -380,7 +370,7 @@ void update_accumulator_refresh_cache(const FeatureTransformer& feat for (IndexType k = 0; k < Tiling::NumRegs; ++k) acc[k] = entryTile[k]; - std::size_t i = 0; + IndexType i = 0; for (; i < std::min(removed.size(), added.size()) - combineLast3; ++i) { IndexType indexR = removed[i]; @@ -460,10 +450,10 @@ void update_accumulator_refresh_cache(const FeatureTransformer& feat auto* entryTilePsqt = reinterpret_cast(&entry.psqtAccumulation[j * Tiling::PsqtTileHeight]); - for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) + for (IndexType k = 0; k < Tiling::NumPsqtRegs; ++k) psqt[k] = entryTilePsqt[k]; - for (std::size_t i = 0; i < removed.size(); ++i) + for (IndexType i = 0; i < removed.size(); ++i) { IndexType index = removed[i]; const IndexType offset = PSQTBuckets * index + j * Tiling::PsqtTileHeight; @@ -473,7 +463,7 @@ void update_accumulator_refresh_cache(const FeatureTransformer& feat for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) psqt[k] = vec_sub_psqt_32(psqt[k], columnPsqt[k]); } - for (std::size_t i = 0; i < added.size(); ++i) + for (IndexType i = 0; i < added.size(); ++i) { IndexType index = added[i]; const IndexType offset = PSQTBuckets * index + j * Tiling::PsqtTileHeight; @@ -484,9 +474,9 @@ void update_accumulator_refresh_cache(const FeatureTransformer& feat psqt[k] = vec_add_psqt_32(psqt[k], columnPsqt[k]); } - for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) + for (IndexType k = 0; k < Tiling::NumPsqtRegs; ++k) vec_store_psqt(&entryTilePsqt[k], psqt[k]); - for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) + for (IndexType k = 0; k < Tiling::NumPsqtRegs; ++k) vec_store_psqt(&accTilePsqt[k], psqt[k]); } diff --git a/src/nnue/nnue_common.h b/src/nnue/nnue_common.h index e6e3017d2..f21a8dec7 100644 --- a/src/nnue/nnue_common.h +++ b/src/nnue/nnue_common.h @@ -279,11 +279,6 @@ inline void write_leb_128(std::ostream& stream, const IntType* values, std::size flush(); } -enum IncUpdateDirection { - FORWARD, - BACKWARD -}; - } // namespace Stockfish::Eval::NNUE #endif // #ifndef NNUE_COMMON_H_INCLUDED