Skip to content
Merged
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
6 changes: 4 additions & 2 deletions .github/workflows/ci-ctests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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($<$<COMPILE_LANGUAGE:CXX>:-flto=auto>
$<$<COMPILE_LANGUAGE:CXX>:-frename-registers>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
Expand Down
5 changes: 5 additions & 0 deletions Chess/Bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sstream>
#include <string>

#include "Nnue/Nnue.h"
#include "PositionFactory.h"
#include "SimpleChessEngine.h"

Expand Down Expand Up @@ -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();
Expand Down
35 changes: 35 additions & 0 deletions Tests/BenchTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <gtest/gtest.h>

#include <cstdlib>
#include <sstream>
#include <string>

#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);
}
}
Loading