Stack allocate NNUE buffer

Passed simp STC

LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 29632 W: 7772 L: 7552 D: 14308
Ptnml(0-2): 76, 3155, 8147, 3349,

Id expect there to be a small speedup (bc the compiler can skip some
stores) but i haven’t tried to measure it

closes https://github.com/official-stockfish/Stockfish/pull/6688

No functional change
This commit is contained in:
anematode
2026-04-02 20:30:44 +02:00
committed by Disservin
parent 7926f16ea7
commit 347fcaa392
3 changed files with 7 additions and 16 deletions
+2 -2
View File
@@ -48,8 +48,8 @@ namespace Stockfish {
namespace NN = Eval::NNUE; namespace NN = Eval::NNUE;
constexpr int MaxHashMB = Is64Bit ? 33554432 : 2048; constexpr int MaxHashMB = Is64Bit ? 33554432 : 2048;
int MaxThreads = std::max(1024, 4 * int(get_hardware_concurrency())); int MaxThreads = std::max(1024, 4 * int(get_hardware_concurrency()));
// The default configuration will attempt to group L3 domains up to 32 threads. // The default configuration will attempt to group L3 domains up to 32 threads.
// This size was found to be a good balance between the Elo gain of increased // This size was found to be a good balance between the Elo gain of increased
+2 -9
View File
@@ -109,17 +109,10 @@ struct NetworkArchitecture {
alignas(CacheLineSize) typename decltype(ac_1)::OutputBuffer ac_1_out; alignas(CacheLineSize) typename decltype(ac_1)::OutputBuffer ac_1_out;
alignas(CacheLineSize) typename decltype(fc_2)::OutputBuffer fc_2_out; alignas(CacheLineSize) typename decltype(fc_2)::OutputBuffer fc_2_out;
Buffer() { std::memset(this, 0, sizeof(*this)); } Buffer() { std::memset(ac_sqr_0_out, 0, sizeof(ac_sqr_0_out)); }
}; };
#if defined(__clang__) && (__APPLE__) Buffer buffer;
// workaround for a bug reported with xcode 12
static thread_local auto tlsBuffer = std::make_unique<Buffer>();
// Access TLS only once, cache result.
Buffer& buffer = *tlsBuffer;
#else
alignas(CacheLineSize) static thread_local Buffer buffer;
#endif
fc_0.propagate(transformedFeatures, buffer.fc_0_out); fc_0.propagate(transformedFeatures, buffer.fc_0_out);
ac_sqr_0.propagate(buffer.fc_0_out, buffer.ac_sqr_0_out); ac_sqr_0.propagate(buffer.fc_0_out, buffer.ac_sqr_0_out);
+3 -5
View File
@@ -2035,9 +2035,8 @@ void syzygy_extend_pv(const OptionsMap& options,
for (const auto& m : MoveList<LEGAL>(pos)) for (const auto& m : MoveList<LEGAL>(pos))
legalMoves.emplace_back(m); legalMoves.emplace_back(m);
TB::Config config = TB::Config config = TB::rank_root_moves(options, pos, legalMoves, false, time_abort);
TB::rank_root_moves(options, pos, legalMoves, false, time_abort); RootMove& rm = *std::find(legalMoves.begin(), legalMoves.end(), pvMove);
RootMove& rm = *std::find(legalMoves.begin(), legalMoves.end(), pvMove);
if (legalMoves[0].tbRank != rm.tbRank) if (legalMoves[0].tbRank != rm.tbRank)
break; break;
@@ -2096,8 +2095,7 @@ void syzygy_extend_pv(const OptionsMap& options,
[](const Search::RootMove& a, const Search::RootMove& b) { return a.tbRank > b.tbRank; }); [](const Search::RootMove& a, const Search::RootMove& b) { return a.tbRank > b.tbRank; });
// The winning side tries to minimize DTZ, the losing side maximizes it // The winning side tries to minimize DTZ, the losing side maximizes it
TB::Config config = TB::Config config = TB::rank_root_moves(options, pos, legalMoves, true, time_abort);
TB::rank_root_moves(options, pos, legalMoves, true, time_abort);
// If DTZ is not available we might not find a mate, so we bail out // If DTZ is not available we might not find a mate, so we bail out
if (!config.rootInTB || config.cardinality > 0) if (!config.rootInTB || config.cardinality > 0)