perf: incremental NNUE accumulator in quiescence
Every quiescence node built the network's hidden layer from the whole board: about 30 pieces x 2 perspectives x 128 weights, a third of a middlegame playout. The accumulator (both perspectives) is now built once at the root of the quiescence search and passed down; each child gets a copy updated with the two to four features the move changes (normal move, capture, en passant, promotion, castling). i16 sums wrap the same way in any order, so the values, and the search, are exactly the same as before. Playouts per second at 100k playouts, main -> this (two runs each): startpos 688k -> 705k +2% QGD middlegame 453k -> 495k +9% Kiwipete 128k -> 161k +26% Sicilian middle 385k -> 440k +14% rook endgame 881k -> 905k +3% bench 3.87M -> 4.39M +14% Checked: on 3,240,535 moves from random games (276,756 captures, 3,676 castles, 433 en passant, 30,900 promotions) the updated accumulator is byte for byte equal to a fresh one, and a whole game played on updates alone does not drift. The bench is identical to main. Bench: 546966 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
807ddd90c1
commit
8ceee77166
3 files changed
+106
-16
No files matched your search
+17
-1
@@ -11,11 +11,27 @@ constexpr int SCALE = 400;
|
||||
constexpr int QA = 255;
|
||||
constexpr int QB = 64;
|
||||
|
||||
// The hidden layer before the activation, from white's and from black's point
|
||||
// of view. Kept up to date move by move along the quiescence search.
|
||||
struct Accumulator {
|
||||
alignas(64) i16 values[2][HIDDEN];
|
||||
};
|
||||
|
||||
// Checks and loads the embedded network. Exits with a message if it does not fit.
|
||||
void init();
|
||||
|
||||
// Evaluation in centipawns from the side to move's view, on the network's scale:
|
||||
// Builds the accumulator of `pos` from scratch.
|
||||
void refresh(const Position& pos, Accumulator& acc);
|
||||
|
||||
// The accumulator after `m`, from the one before it; `pos` is the position
|
||||
// before the move. Gives exactly what refresh would give for the new position.
|
||||
void update(const Accumulator& before, const Position& pos, Move m, Accumulator& after);
|
||||
|
||||
// Evaluation in centipawns from the view of `stm`, on the network's scale:
|
||||
// sigmoid(cp / SCALE) is the expected score.
|
||||
int evaluate(const Accumulator& acc, int stm);
|
||||
|
||||
// Same, building the accumulator from scratch.
|
||||
int evaluate(const Position& pos);
|
||||
|
||||
} // namespace rigby::nnue
|
||||
Reference in new issue
Block a user