Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine remove and add in update_accumulator_refresh_cache(). #5197

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks,
int nnueComplexity;
int v;

Value nnue = smallNet ? networks.small.evaluate(pos, nullptr, true, &nnueComplexity, psqtOnly)
Value nnue = smallNet ? networks.small.evaluate(pos, &caches.small, true, &nnueComplexity, psqtOnly)
: networks.big.evaluate(pos, &caches.big, true, &nnueComplexity, false);

const auto adjustEval = [&](int optDiv, int nnueDiv, int npmDiv, int pawnCountConstant,
Expand Down
4 changes: 2 additions & 2 deletions src/nnue/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ void Network<Arch, Transformer>::verify(std::string evalfilePath) const {
template<typename Arch, typename Transformer>
void Network<Arch, Transformer>::hint_common_access(const Position& pos,
AccumulatorCaches::Cache<FTDimensions>* cache,
bool psqtOnl) const {
featureTransformer->hint_common_access(pos, cache, psqtOnl);
bool psqtOnly) const {
featureTransformer->hint_common_access(pos, cache, psqtOnly);
}

template<typename Arch, typename Transformer>
Expand Down
2 changes: 1 addition & 1 deletion src/nnue/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Network {

void hint_common_access(const Position& pos,
AccumulatorCaches::Cache<FTDimensions>* cache,
bool psqtOnl) const;
bool psqtOnly) const;

void verify(std::string evalfilePath) const;
NnueEvalTrace trace_evaluate(const Position& pos,
Expand Down
6 changes: 4 additions & 2 deletions src/nnue/nnue_accumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ struct AccumulatorCaches {
PSQTWeightType psqtAccumulation[COLOR_NB][PSQTBuckets];
Bitboard byColorBB[COLOR_NB][COLOR_NB];
Bitboard byTypeBB[COLOR_NB][PIECE_TYPE_NB];
bool psqtOnly;

// To initialize a refresh entry, we set all its bitboards empty,
// so we put the biases in the accumulation, without any weights on top
void clear(const BiasType* biases) {

std::memset(byColorBB, 0, sizeof(byColorBB));
std::memset(byTypeBB, 0, sizeof(byTypeBB));
psqtOnly = false;

std::memcpy(accumulation[WHITE], biases, Size * sizeof(BiasType));
std::memcpy(accumulation[BLACK], biases, Size * sizeof(BiasType));
Expand Down Expand Up @@ -92,11 +94,11 @@ struct AccumulatorCaches {
template<typename Networks>
void clear(const Networks& networks) {
big.clear(networks.big);
small.clear(networks.small);
}

// When adding a new cache for a network, i.e. the smallnet
// the appropriate condition must be added to FeatureTransformer::update_accumulator_refresh.
Cache<TransformedFeatureDimensionsBig> big;
Cache<TransformedFeatureDimensionsSmall> small;
};

} // namespace Stockfish::Eval::NNUE
Expand Down
Loading
Loading