Skip to content

Commit f9b002c

Browse files
anematodeDisservin
authored andcommitted
Share continuation history between threads
Passed 8th 5+0.05 https://tests.stockfishchess.org/tests/view/6a0bfdb46524d21ee79b879b LLR: 2.94 (-2.94,2.94) <0.00,2.00> Total: 23472 W: 6103 L: 5823 D: 11546 Ptnml(0-2): 26, 2501, 6403, 2779, 27 Passed 8th 20+0.2 https://tests.stockfishchess.org/tests/view/6a0c87196524d21ee79b885c LLR: 2.95 (-2.94,2.94) <0.50,2.50> Total: 44692 W: 11640 L: 11319 D: 21733 Ptnml(0-2): 12, 4418, 13169, 4731, 16 Passed 16th 5+0.05 https://tests.stockfishchess.org/tests/view/6a20533f818cacc1db0ad32b LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 14720 W: 3910 L: 3642 D: 7168 Ptnml(0-2): 6, 1434, 4223, 1680, 17 Passed 64th 10+0.1 https://tests.stockfishchess.org/tests/view/6a20ae8e818cacc1db0ad369 LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 34096 W: 8889 L: 8607 D: 16600 Ptnml(0-2): 4, 2974, 10808, 3260, 2 Continuation history is fixed size so there's a much more false sharing and a larger speed loss here at high thread counts, unfortunately. vondele's machine, 4x70 ``` ==== master ==== Average (over 3): 294528128 ==== shared-conthist ==== Average (over 3): 282364217 (~4% slowdown) ``` my machine, 8x32 ``` Nodes/second : 243157385 Nodes/second : 228374554 (~6% slowdown) ``` Evidently it still gains at 64th, but a few followup ideas to try get the speed back: - Add padding in `PieceToHistory` stats so there's less false sharing. - Subdivide continuation history more finely than shared correction history. - Scramble the `PieceToHistory` indexing so there's less false sharing closes official-stockfish#6905 No functional change
1 parent f9beec5 commit f9b002c

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/history.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ using LowPlyHistory = Stats<i16, 7183, LOW_PLY_HISTORY_SIZE, UINT_16_HISTORY_SIZ
132132
using CapturePieceToHistory = Stats<i16, 10692, PIECE_NB, SQUARE_NB, PIECE_TYPE_NB>;
133133

134134
// PieceToHistory is like ButterflyHistory but is addressed by a move's [piece][to]
135-
using PieceToHistory = Stats<i16, 30000, PIECE_NB, SQUARE_NB>;
135+
using PieceToHistory = AtomicStats<i16, 30000, PIECE_NB, SQUARE_NB>;
136136

137137
// ContinuationHistory is the combined history of a given pair of moves, usually
138138
// the current one given a previous one. The nested history table is based on
@@ -238,6 +238,7 @@ struct SharedHistories {
238238
}
239239

240240
UnifiedCorrectionHistory correctionHistory;
241+
ContinuationHistory continuationHistory[2][2];
241242
PawnHistory pawnHistory;
242243

243244

src/search.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Search::Worker::Worker(SharedState& sharedState,
165165
NumaReplicatedAccessToken token) :
166166
// Unpack the SharedState struct into member variables
167167
sharedHistory(sharedState.sharedHistories.at(token.get_numa_index())),
168+
continuationHistory(sharedHistory.continuationHistory),
168169
threadIdx(threadId),
169170
numaThreadIdx(numaThreadId),
170171
numaTotal(numaTotalThreads),

src/search.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ class Worker {
336336
LowPlyHistory lowPlyHistory;
337337

338338
CapturePieceToHistory captureHistory;
339-
ContinuationHistory continuationHistory[2][2];
340339
CorrectionHistory<Continuation> continuationCorrectionHistory;
341340

342341
TTMoveHistory ttMoveHistory;
343342
SharedHistories& sharedHistory;
343+
ContinuationHistory (&continuationHistory)[2][2];
344344

345345
private:
346346
bool iterative_deepening();

0 commit comments

Comments
 (0)