mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-06 10:53:50 +08:00
Retire Acc Pointer
Since @xu-shawn's refactor the acc pointer has become a bit unnecessary, we can achieve the same behavior by using the dimension size to get the right accumulator from the `AccumulatorState`. I think the acc pointer has become a bit of a burden required to be passed through multiple different functions together with the necessary templating required. Passed Non-Regression STC: https://tests.stockfishchess.org/tests/view/67ed600f31d7cf8afdc45183 LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 279744 W: 72037 L: 72082 D: 135625 Ptnml(0-2): 673, 29918, 78767, 29809, 705 closes https://github.com/official-stockfish/Stockfish/pull/5942 No functional change
This commit is contained in:
@@ -219,13 +219,13 @@ Network<Arch, Transformer>::evaluate(const Position& pos
|
||||
|
||||
#if defined(ALIGNAS_ON_STACK_VARIABLES_BROKEN)
|
||||
TransformedFeatureType
|
||||
transformedFeaturesUnaligned[FeatureTransformer<FTDimensions, nullptr>::BufferSize
|
||||
transformedFeaturesUnaligned[FeatureTransformer<FTDimensions>::BufferSize
|
||||
+ alignment / sizeof(TransformedFeatureType)];
|
||||
|
||||
auto* transformedFeatures = align_ptr_up<alignment>(&transformedFeaturesUnaligned[0]);
|
||||
#else
|
||||
alignas(alignment) TransformedFeatureType
|
||||
transformedFeatures[FeatureTransformer<FTDimensions, nullptr>::BufferSize];
|
||||
alignas(alignment)
|
||||
TransformedFeatureType transformedFeatures[FeatureTransformer<FTDimensions>::BufferSize];
|
||||
#endif
|
||||
|
||||
ASSERT_ALIGNED(transformedFeatures, alignment);
|
||||
@@ -290,13 +290,13 @@ Network<Arch, Transformer>::trace_evaluate(const Position&
|
||||
|
||||
#if defined(ALIGNAS_ON_STACK_VARIABLES_BROKEN)
|
||||
TransformedFeatureType
|
||||
transformedFeaturesUnaligned[FeatureTransformer<FTDimensions, nullptr>::BufferSize
|
||||
transformedFeaturesUnaligned[FeatureTransformer<FTDimensions>::BufferSize
|
||||
+ alignment / sizeof(TransformedFeatureType)];
|
||||
|
||||
auto* transformedFeatures = align_ptr_up<alignment>(&transformedFeaturesUnaligned[0]);
|
||||
#else
|
||||
alignas(alignment) TransformedFeatureType
|
||||
transformedFeatures[FeatureTransformer<FTDimensions, nullptr>::BufferSize];
|
||||
alignas(alignment)
|
||||
TransformedFeatureType transformedFeatures[FeatureTransformer<FTDimensions>::BufferSize];
|
||||
#endif
|
||||
|
||||
ASSERT_ALIGNED(transformedFeatures, alignment);
|
||||
@@ -452,12 +452,10 @@ bool Network<Arch, Transformer>::write_parameters(std::ostream& stream,
|
||||
|
||||
// Explicit template instantiations
|
||||
|
||||
template class Network<
|
||||
NetworkArchitecture<TransformedFeatureDimensionsBig, L2Big, L3Big>,
|
||||
FeatureTransformer<TransformedFeatureDimensionsBig, &AccumulatorState::accumulatorBig>>;
|
||||
template class Network<NetworkArchitecture<TransformedFeatureDimensionsBig, L2Big, L3Big>,
|
||||
FeatureTransformer<TransformedFeatureDimensionsBig>>;
|
||||
|
||||
template class Network<
|
||||
NetworkArchitecture<TransformedFeatureDimensionsSmall, L2Small, L3Small>,
|
||||
FeatureTransformer<TransformedFeatureDimensionsSmall, &AccumulatorState::accumulatorSmall>>;
|
||||
template class Network<NetworkArchitecture<TransformedFeatureDimensionsSmall, L2Small, L3Small>,
|
||||
FeatureTransformer<TransformedFeatureDimensionsSmall>>;
|
||||
|
||||
} // namespace Stockfish::Eval::NNUE
|
||||
|
||||
@@ -110,13 +110,11 @@ class Network {
|
||||
};
|
||||
|
||||
// Definitions of the network types
|
||||
using SmallFeatureTransformer =
|
||||
FeatureTransformer<TransformedFeatureDimensionsSmall, &AccumulatorState::accumulatorSmall>;
|
||||
using SmallFeatureTransformer = FeatureTransformer<TransformedFeatureDimensionsSmall>;
|
||||
using SmallNetworkArchitecture =
|
||||
NetworkArchitecture<TransformedFeatureDimensionsSmall, L2Small, L3Small>;
|
||||
|
||||
using BigFeatureTransformer =
|
||||
FeatureTransformer<TransformedFeatureDimensionsBig, &AccumulatorState::accumulatorBig>;
|
||||
using BigFeatureTransformer = FeatureTransformer<TransformedFeatureDimensionsBig>;
|
||||
using BigNetworkArchitecture = NetworkArchitecture<TransformedFeatureDimensionsBig, L2Big, L3Big>;
|
||||
|
||||
using NetworkBig = Network<BigNetworkArchitecture, BigFeatureTransformer>;
|
||||
|
||||
@@ -48,22 +48,20 @@ namespace Stockfish::Eval::NNUE {
|
||||
|
||||
namespace {
|
||||
|
||||
template<Color Perspective,
|
||||
IncUpdateDirection Direction = FORWARD,
|
||||
IndexType TransformedFeatureDimensions,
|
||||
Accumulator<TransformedFeatureDimensions> AccumulatorState::*accPtr>
|
||||
template<Color Perspective,
|
||||
IncUpdateDirection Direction = FORWARD,
|
||||
IndexType TransformedFeatureDimensions>
|
||||
void update_accumulator_incremental(
|
||||
const FeatureTransformer<TransformedFeatureDimensions, accPtr>& featureTransformer,
|
||||
const Square ksq,
|
||||
AccumulatorState& target_state,
|
||||
const AccumulatorState& computed);
|
||||
const FeatureTransformer<TransformedFeatureDimensions>& featureTransformer,
|
||||
const Square ksq,
|
||||
AccumulatorState& target_state,
|
||||
const AccumulatorState& computed);
|
||||
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void update_accumulator_refresh_cache(
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
const Position& pos,
|
||||
AccumulatorState& accumulatorState,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache);
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void update_accumulator_refresh_cache(const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const Position& pos,
|
||||
AccumulatorState& accumulatorState,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache);
|
||||
|
||||
}
|
||||
|
||||
@@ -86,18 +84,14 @@ void AccumulatorStack::reset(const Position& rootPos,
|
||||
AccumulatorCaches& caches) noexcept {
|
||||
m_current_idx = 1;
|
||||
|
||||
update_accumulator_refresh_cache<WHITE, TransformedFeatureDimensionsBig,
|
||||
&AccumulatorState::accumulatorBig>(
|
||||
update_accumulator_refresh_cache<WHITE, TransformedFeatureDimensionsBig>(
|
||||
*networks.big.featureTransformer, rootPos, m_accumulators[0], caches.big);
|
||||
update_accumulator_refresh_cache<BLACK, TransformedFeatureDimensionsBig,
|
||||
&AccumulatorState::accumulatorBig>(
|
||||
update_accumulator_refresh_cache<BLACK, TransformedFeatureDimensionsBig>(
|
||||
*networks.big.featureTransformer, rootPos, m_accumulators[0], caches.big);
|
||||
|
||||
update_accumulator_refresh_cache<WHITE, TransformedFeatureDimensionsSmall,
|
||||
&AccumulatorState::accumulatorSmall>(
|
||||
update_accumulator_refresh_cache<WHITE, TransformedFeatureDimensionsSmall>(
|
||||
*networks.small.featureTransformer, rootPos, m_accumulators[0], caches.small);
|
||||
update_accumulator_refresh_cache<BLACK, TransformedFeatureDimensionsSmall,
|
||||
&AccumulatorState::accumulatorSmall>(
|
||||
update_accumulator_refresh_cache<BLACK, TransformedFeatureDimensionsSmall>(
|
||||
*networks.small.featureTransformer, rootPos, m_accumulators[0], caches.small);
|
||||
}
|
||||
|
||||
@@ -112,24 +106,23 @@ void AccumulatorStack::pop() noexcept {
|
||||
m_current_idx--;
|
||||
}
|
||||
|
||||
template<IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void AccumulatorStack::evaluate(const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept {
|
||||
template<IndexType Dimensions>
|
||||
void AccumulatorStack::evaluate(const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept {
|
||||
|
||||
evaluate_side<WHITE>(pos, featureTransformer, cache);
|
||||
evaluate_side<BLACK>(pos, featureTransformer, cache);
|
||||
}
|
||||
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void AccumulatorStack::evaluate_side(
|
||||
const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept {
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void AccumulatorStack::evaluate_side(const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept {
|
||||
|
||||
const auto last_usable_accum = find_last_usable_accumulator<Perspective, Dimensions, accPtr>();
|
||||
const auto last_usable_accum = find_last_usable_accumulator<Perspective, Dimensions>();
|
||||
|
||||
if ((m_accumulators[last_usable_accum].*accPtr).computed[Perspective])
|
||||
if ((m_accumulators[last_usable_accum].template acc<Dimensions>()).computed[Perspective])
|
||||
forward_update_incremental<Perspective>(pos, featureTransformer, last_usable_accum);
|
||||
|
||||
else
|
||||
@@ -141,12 +134,12 @@ void AccumulatorStack::evaluate_side(
|
||||
|
||||
// Find the earliest usable accumulator, this can either be a computed accumulator or the accumulator
|
||||
// state just before a change that requires full refresh.
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
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--)
|
||||
{
|
||||
if ((m_accumulators[curr_idx].*accPtr).computed[Perspective])
|
||||
if ((m_accumulators[curr_idx].template acc<Dimensions>()).computed[Perspective])
|
||||
return curr_idx;
|
||||
|
||||
if (FeatureSet::requires_refresh(m_accumulators[curr_idx].dirtyPiece, Perspective))
|
||||
@@ -156,14 +149,14 @@ std::size_t AccumulatorStack::find_last_usable_accumulator() const noexcept {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void AccumulatorStack::forward_update_incremental(
|
||||
const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
const std::size_t begin) noexcept {
|
||||
const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const std::size_t begin) noexcept {
|
||||
|
||||
assert(begin < m_accumulators.size());
|
||||
assert((m_accumulators[begin].*accPtr).computed[Perspective]);
|
||||
assert((m_accumulators[begin].acc<Dimensions>()).computed[Perspective]);
|
||||
|
||||
const Square ksq = pos.square<KING>(Perspective);
|
||||
|
||||
@@ -171,18 +164,18 @@ void AccumulatorStack::forward_update_incremental(
|
||||
update_accumulator_incremental<Perspective>(featureTransformer, ksq, m_accumulators[next],
|
||||
m_accumulators[next - 1]);
|
||||
|
||||
assert((latest().*accPtr).computed[Perspective]);
|
||||
assert((latest().acc<Dimensions>()).computed[Perspective]);
|
||||
}
|
||||
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void AccumulatorStack::backward_update_incremental(
|
||||
const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
const std::size_t end) noexcept {
|
||||
const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const std::size_t end) noexcept {
|
||||
|
||||
assert(end < m_accumulators.size());
|
||||
assert(end < m_current_idx);
|
||||
assert((latest().*accPtr).computed[Perspective]);
|
||||
assert((latest().acc<Dimensions>()).computed[Perspective]);
|
||||
|
||||
const Square ksq = pos.square<KING>(Perspective);
|
||||
|
||||
@@ -190,21 +183,17 @@ void AccumulatorStack::backward_update_incremental(
|
||||
update_accumulator_incremental<Perspective, BACKWARD>(
|
||||
featureTransformer, ksq, m_accumulators[next], m_accumulators[next + 1]);
|
||||
|
||||
assert((m_accumulators[end].*accPtr).computed[Perspective]);
|
||||
assert((m_accumulators[end].acc<Dimensions>()).computed[Perspective]);
|
||||
}
|
||||
|
||||
// Explicit template instantiations
|
||||
template void
|
||||
AccumulatorStack::evaluate<TransformedFeatureDimensionsBig, &AccumulatorState::accumulatorBig>(
|
||||
const Position& pos,
|
||||
const FeatureTransformer<TransformedFeatureDimensionsBig, &AccumulatorState::accumulatorBig>&
|
||||
featureTransformer,
|
||||
template void AccumulatorStack::evaluate<TransformedFeatureDimensionsBig>(
|
||||
const Position& pos,
|
||||
const FeatureTransformer<TransformedFeatureDimensionsBig>& featureTransformer,
|
||||
AccumulatorCaches::Cache<TransformedFeatureDimensionsBig>& cache) noexcept;
|
||||
template void
|
||||
AccumulatorStack::evaluate<TransformedFeatureDimensionsSmall, &AccumulatorState::accumulatorSmall>(
|
||||
const Position& pos,
|
||||
const FeatureTransformer<TransformedFeatureDimensionsSmall, &AccumulatorState::accumulatorSmall>&
|
||||
featureTransformer,
|
||||
template void AccumulatorStack::evaluate<TransformedFeatureDimensionsSmall>(
|
||||
const Position& pos,
|
||||
const FeatureTransformer<TransformedFeatureDimensionsSmall>& featureTransformer,
|
||||
AccumulatorCaches::Cache<TransformedFeatureDimensionsSmall>& cache) noexcept;
|
||||
|
||||
|
||||
@@ -227,15 +216,15 @@ void fused_row_reduce(const ElementType* in, ElementType* out, const Ts* const..
|
||||
vecIn[i], reinterpret_cast<const typename VectorWrapper::type*>(rows)[i]...);
|
||||
}
|
||||
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
struct AccumulatorUpdateContext {
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer;
|
||||
const AccumulatorState& from;
|
||||
AccumulatorState& to;
|
||||
const FeatureTransformer<Dimensions>& featureTransformer;
|
||||
const AccumulatorState& from;
|
||||
AccumulatorState& to;
|
||||
|
||||
AccumulatorUpdateContext(const FeatureTransformer<Dimensions, accPtr>& ft,
|
||||
const AccumulatorState& accF,
|
||||
AccumulatorState& accT) noexcept :
|
||||
AccumulatorUpdateContext(const FeatureTransformer<Dimensions>& ft,
|
||||
const AccumulatorState& accF,
|
||||
AccumulatorState& accT) noexcept :
|
||||
featureTransformer{ft},
|
||||
from{accF},
|
||||
to{accT} {}
|
||||
@@ -252,41 +241,37 @@ struct AccumulatorUpdateContext {
|
||||
return &featureTransformer.psqtWeights[index * PSQTBuckets];
|
||||
};
|
||||
|
||||
fused_row_reduce<Vec16Wrapper, Dimensions, ops...>((from.*accPtr).accumulation[Perspective],
|
||||
(to.*accPtr).accumulation[Perspective],
|
||||
to_weight_vector(indices)...);
|
||||
fused_row_reduce<Vec16Wrapper, Dimensions, ops...>(
|
||||
(from.acc<Dimensions>()).accumulation[Perspective],
|
||||
(to.acc<Dimensions>()).accumulation[Perspective], to_weight_vector(indices)...);
|
||||
|
||||
fused_row_reduce<Vec32Wrapper, PSQTBuckets, ops...>(
|
||||
(from.*accPtr).psqtAccumulation[Perspective], (to.*accPtr).psqtAccumulation[Perspective],
|
||||
to_psqt_weight_vector(indices)...);
|
||||
(from.acc<Dimensions>()).psqtAccumulation[Perspective],
|
||||
(to.acc<Dimensions>()).psqtAccumulation[Perspective], to_psqt_weight_vector(indices)...);
|
||||
}
|
||||
};
|
||||
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
auto make_accumulator_update_context(
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
const AccumulatorState& accumulatorFrom,
|
||||
AccumulatorState& accumulatorTo) noexcept {
|
||||
return AccumulatorUpdateContext<Perspective, Dimensions, accPtr>{
|
||||
featureTransformer, accumulatorFrom, accumulatorTo};
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
auto make_accumulator_update_context(const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const AccumulatorState& accumulatorFrom,
|
||||
AccumulatorState& accumulatorTo) noexcept {
|
||||
return AccumulatorUpdateContext<Perspective, Dimensions>{featureTransformer, accumulatorFrom,
|
||||
accumulatorTo};
|
||||
}
|
||||
|
||||
template<Color Perspective,
|
||||
IncUpdateDirection Direction,
|
||||
IndexType TransformedFeatureDimensions,
|
||||
Accumulator<TransformedFeatureDimensions> AccumulatorState::*accPtr>
|
||||
template<Color Perspective, IncUpdateDirection Direction, IndexType TransformedFeatureDimensions>
|
||||
void update_accumulator_incremental(
|
||||
const FeatureTransformer<TransformedFeatureDimensions, accPtr>& featureTransformer,
|
||||
const Square ksq,
|
||||
AccumulatorState& target_state,
|
||||
const AccumulatorState& computed) {
|
||||
const FeatureTransformer<TransformedFeatureDimensions>& 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.*accPtr).computed[Perspective]);
|
||||
assert(!(target_state.*accPtr).computed[Perspective]);
|
||||
assert((computed.acc<TransformedFeatureDimensions>()).computed[Perspective]);
|
||||
assert(!(target_state.acc<TransformedFeatureDimensions>()).computed[Perspective]);
|
||||
|
||||
// The size must be enough to contain the largest possible update.
|
||||
// That might depend on the feature set and generally relies on the
|
||||
@@ -340,15 +325,14 @@ void update_accumulator_incremental(
|
||||
removed[1]);
|
||||
}
|
||||
|
||||
(target_state.*accPtr).computed[Perspective] = true;
|
||||
(target_state.acc<TransformedFeatureDimensions>()).computed[Perspective] = true;
|
||||
}
|
||||
|
||||
template<Color Perspective, IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void update_accumulator_refresh_cache(
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
const Position& pos,
|
||||
AccumulatorState& accumulatorState,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) {
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void update_accumulator_refresh_cache(const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const Position& pos,
|
||||
AccumulatorState& accumulatorState,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) {
|
||||
using Tiling [[maybe_unused]] = SIMDTiling<Dimensions, Dimensions>;
|
||||
|
||||
const Square ksq = pos.square<KING>(Perspective);
|
||||
@@ -378,7 +362,7 @@ void update_accumulator_refresh_cache(
|
||||
}
|
||||
}
|
||||
|
||||
auto& accumulator = accumulatorState.*accPtr;
|
||||
auto& accumulator = accumulatorState.acc<Dimensions>();
|
||||
accumulator.computed[Perspective] = true;
|
||||
|
||||
#ifdef VECTOR
|
||||
|
||||
@@ -46,10 +46,7 @@ struct Networks;
|
||||
template<IndexType Size>
|
||||
struct alignas(CacheLineSize) Accumulator;
|
||||
|
||||
struct AccumulatorState;
|
||||
|
||||
template<IndexType TransformedFeatureDimensions,
|
||||
Accumulator<TransformedFeatureDimensions> AccumulatorState::*accPtr>
|
||||
template<IndexType TransformedFeatureDimensions>
|
||||
class FeatureTransformer;
|
||||
|
||||
// Class that holds the result of affine transformation of input features
|
||||
@@ -121,6 +118,30 @@ struct AccumulatorState {
|
||||
Accumulator<TransformedFeatureDimensionsSmall> accumulatorSmall;
|
||||
DirtyPiece dirtyPiece;
|
||||
|
||||
template<IndexType Size>
|
||||
auto& acc() noexcept {
|
||||
static_assert(Size == TransformedFeatureDimensionsBig
|
||||
|| Size == TransformedFeatureDimensionsSmall,
|
||||
"Invalid size for accumulator");
|
||||
|
||||
if constexpr (Size == TransformedFeatureDimensionsBig)
|
||||
return accumulatorBig;
|
||||
else if constexpr (Size == TransformedFeatureDimensionsSmall)
|
||||
return accumulatorSmall;
|
||||
}
|
||||
|
||||
template<IndexType Size>
|
||||
const auto& acc() const noexcept {
|
||||
static_assert(Size == TransformedFeatureDimensionsBig
|
||||
|| Size == TransformedFeatureDimensionsSmall,
|
||||
"Invalid size for accumulator");
|
||||
|
||||
if constexpr (Size == TransformedFeatureDimensionsBig)
|
||||
return accumulatorBig;
|
||||
else if constexpr (Size == TransformedFeatureDimensionsSmall)
|
||||
return accumulatorSmall;
|
||||
}
|
||||
|
||||
void reset(const DirtyPiece& dp) noexcept;
|
||||
};
|
||||
|
||||
@@ -138,41 +159,31 @@ class AccumulatorStack {
|
||||
void push(const DirtyPiece& dirtyPiece) noexcept;
|
||||
void pop() noexcept;
|
||||
|
||||
template<IndexType Dimensions, Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void evaluate(const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept;
|
||||
template<IndexType Dimensions>
|
||||
void evaluate(const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept;
|
||||
|
||||
private:
|
||||
[[nodiscard]] AccumulatorState& mut_latest() noexcept;
|
||||
|
||||
template<Color Perspective,
|
||||
IndexType Dimensions,
|
||||
Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void evaluate_side(const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept;
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void evaluate_side(const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
AccumulatorCaches::Cache<Dimensions>& cache) noexcept;
|
||||
|
||||
template<Color Perspective,
|
||||
IndexType Dimensions,
|
||||
Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
[[nodiscard]] std::size_t find_last_usable_accumulator() const noexcept;
|
||||
|
||||
template<Color Perspective,
|
||||
IndexType Dimensions,
|
||||
Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void
|
||||
forward_update_incremental(const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
const std::size_t begin) noexcept;
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void forward_update_incremental(const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const std::size_t begin) noexcept;
|
||||
|
||||
template<Color Perspective,
|
||||
IndexType Dimensions,
|
||||
Accumulator<Dimensions> AccumulatorState::*accPtr>
|
||||
void
|
||||
backward_update_incremental(const Position& pos,
|
||||
const FeatureTransformer<Dimensions, accPtr>& featureTransformer,
|
||||
const std::size_t end) noexcept;
|
||||
template<Color Perspective, IndexType Dimensions>
|
||||
void backward_update_incremental(const Position& pos,
|
||||
const FeatureTransformer<Dimensions>& featureTransformer,
|
||||
const std::size_t end) noexcept;
|
||||
|
||||
std::vector<AccumulatorState> m_accumulators;
|
||||
std::size_t m_current_idx;
|
||||
|
||||
@@ -294,8 +294,7 @@ class SIMDTiling {
|
||||
|
||||
|
||||
// Input feature converter
|
||||
template<IndexType TransformedFeatureDimensions,
|
||||
Accumulator<TransformedFeatureDimensions> AccumulatorState::*accPtr>
|
||||
template<IndexType TransformedFeatureDimensions>
|
||||
class FeatureTransformer {
|
||||
|
||||
// Number of output dimensions for one side
|
||||
@@ -400,12 +399,12 @@ class FeatureTransformer {
|
||||
const auto& accumulatorState = accumulatorStack.latest();
|
||||
|
||||
const Color perspectives[2] = {pos.side_to_move(), ~pos.side_to_move()};
|
||||
const auto& psqtAccumulation = (accumulatorState.*accPtr).psqtAccumulation;
|
||||
const auto& psqtAccumulation = (accumulatorState.acc<HalfDimensions>()).psqtAccumulation;
|
||||
const auto psqt =
|
||||
(psqtAccumulation[perspectives[0]][bucket] - psqtAccumulation[perspectives[1]][bucket])
|
||||
/ 2;
|
||||
|
||||
const auto& accumulation = (accumulatorState.*accPtr).accumulation;
|
||||
const auto& accumulation = (accumulatorState.acc<HalfDimensions>()).accumulation;
|
||||
|
||||
for (IndexType p = 0; p < 2; ++p)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user