From 3c2e5dd69f6224a1b64397ee2557773be960ec4d Mon Sep 17 00:00:00 2001 From: nook0110 Date: Thu, 12 Nov 2026 10:55:26 +0300 Subject: [PATCH] [bench] Require NNUE for bench and report the signature in CI The CI bench check compared against a stale signature from before the Stockfish 19 network. Bench without a loaded network silently fell back to a different evaluation, so it now refuses to run. The signature does not depend on compiler, ISA or TT size (16 to 4096 MiB all give 993713), so CMake rejects TT sizes below 16 MiB and CI builds for x86-64-v3 and prints the expected and actual signature. Bench: 993713 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci-ctests.yml | 6 ++++-- CMakeLists.txt | 7 ++++++- Chess/Bench.cpp | 5 +++++ Tests/BenchTests.cpp | 35 +++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 Tests/BenchTests.cpp diff --git a/.github/workflows/ci-ctests.yml b/.github/workflows/ci-ctests.yml index a254ec8..f10f75a 100644 --- a/.github/workflows/ci-ctests.yml +++ b/.github/workflows/ci-ctests.yml @@ -22,7 +22,7 @@ jobs: apt-get install -y cmake git wget unzip - name: Build run: | - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON -DSCE_WARNINGS_AS_ERRORS=ON + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON -DSCE_WARNINGS_AS_ERRORS=ON -DSCE_TARGET_ARCH=x86-64-v3 -DCMAKE_EXE_LINKER_FLAGS=-flto-partition=one cmake --build build -j2 - name: Download and verify NNUE run: | @@ -47,8 +47,10 @@ jobs: run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" expected=$(git log -1 --format=%B | sed -n 's/^Bench: \([0-9][0-9]*\)$/\1/p') + (cd build && ./SimpleChessEngine bench) | tee build/bench.log + actual=$(sed -n 's/^Nodes searched: \([0-9][0-9]*\)$/\1/p' build/bench.log) + echo "Expected bench signature: $expected; actual: $actual" [[ "$expected" =~ ^[0-9]+$ ]] - actual=$(cd build && ./SimpleChessEngine bench | sed -n 's/^Nodes searched: \([0-9][0-9]*\)$/\1/p') test "$actual" = "$expected" sanitizer: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cc435f..ad80f91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,11 @@ option(SCE_WARNINGS_AS_ERRORS "Treat project warnings as errors" OFF) option(SCE_SANITIZE "Enable AddressSanitizer and UndefinedBehaviorSanitizer" OFF) set(SCE_TT_SIZE_MB 640 CACHE STRING "Shared transposition table size in MiB") set(SCE_EVALFILE "nn-1a298aa575a0.nnue" CACHE STRING "Default NNUE network file") +set(SCE_TARGET_ARCH "native" CACHE STRING "Target architecture for release builds") + +if(NOT SCE_TT_SIZE_MB MATCHES "^[1-9][0-9]*$" OR SCE_TT_SIZE_MB LESS 16) + message(FATAL_ERROR "SCE_TT_SIZE_MB must be a decimal integer of at least 16 MiB for the default bench signature") +endif() set(CMAKE_CXX_STANDARD 26) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -22,7 +27,7 @@ if(SCE_SANITIZE) endif() if(CMAKE_BUILD_TYPE STREQUAL "Release") add_compile_definitions(NDEBUG) - add_compile_options(-Ofast -mtune=native -march=native -fno-stack-protector) + add_compile_options(-Ofast -mtune=native -march=${SCE_TARGET_ARCH} -fno-stack-protector) add_compile_options($<$:-flto=auto> $<$:-frename-registers>) add_compile_options($<$:-fno-exceptions> diff --git a/Chess/Bench.cpp b/Chess/Bench.cpp index 1daca19..1c80e1a 100644 --- a/Chess/Bench.cpp +++ b/Chess/Bench.cpp @@ -6,6 +6,7 @@ #include #include +#include "Nnue/Nnue.h" #include "PositionFactory.h" #include "SimpleChessEngine.h" @@ -56,6 +57,10 @@ constexpr std::array kPositions = { } void RunSearchBench(std::ostream& output, int depth) { + if (!Nnue::IsLoaded()) { + output << "info string Bench requires a loaded NNUE network" << std::endl; + return; + } std::ostringstream search_output; ChessEngine engine(PositionFactory{}(), search_output); engine.NewGame(); diff --git a/Tests/BenchTests.cpp b/Tests/BenchTests.cpp new file mode 100644 index 0000000..b0806b3 --- /dev/null +++ b/Tests/BenchTests.cpp @@ -0,0 +1,35 @@ +#include + +#include +#include +#include + +#include "Bench.h" +#include "Nnue/Nnue.h" + +namespace SimpleChessEngine { +TEST(SearchBench, RequiresLoadedNetwork) { + Nnue::Unload(); + std::ostringstream output; + RunSearchBench(output, 1); + EXPECT_EQ(output.str(), "info string Bench requires a loaded NNUE network\n"); +} + +TEST(SearchBench, RepeatedRunsStartWithFreshSearchState) { + const auto* network = std::getenv("SCE_NNUE"); + if (network == nullptr) GTEST_SKIP() << "SCE_NNUE is not set"; + ASSERT_TRUE(Nnue::Load(network)); + std::ostringstream first; + std::ostringstream second; + RunSearchBench(first, 3); + RunSearchBench(second, 3); + std::istringstream first_lines{first.str()}; + std::istringstream second_lines{second.str()}; + std::string first_signature; + std::string second_signature; + std::getline(first_lines, first_signature); + std::getline(second_lines, second_signature); + EXPECT_TRUE(first_signature.starts_with("Nodes searched: ")); + EXPECT_EQ(first_signature, second_signature); +} +}