Skip to content

Commit cf9833c

Browse files
gvreulsnoobpwnftw
authored andcommitted
This commit enables a mixed bench, to improve CI and allow for PGO (profile-build) of the NNUE part of the code.
Joint work gvreuls / vondele * Download the default NNUE net in AppVeyor * Download net in travis CI `make net` * Adjust tests to cover more archs, speedup instrumented testing * Introduce 'mixed' bench as default, with further options: classical, NNUE, mixed. mixed (default) and NNUE require the default net to be present, which can be obtained with ``` make net ``` Further examples (first is equivalent to `./stockfish bench`): ``` ./stockfish bench 16 1 13 default depth mixed ./stockfish bench 16 1 13 default depth classical ./stockfish bench 16 1 13 default depth NNUE ``` The net is now downloaded automatically if needed for `profile-build` (usual `build` works fine without net present) PGO gives a nice speedup on fishtest: passed STC: LLR: 2.93 (-2.94,2.94) {-0.50,1.50} Total: 3360 W: 469 L: 343 D: 2548 Ptnml(0-2): 20, 246, 1030, 356, 28 https://tests.stockfishchess.org/tests/view/5f31b5499081672066537569 passed LTC: LLR: 2.97 (-2.94,2.94) {0.25,1.75} Total: 8824 W: 609 L: 502 D: 7713 Ptnml(0-2): 8, 430, 3438, 519, 17 https://tests.stockfishchess.org/tests/view/5f31c87b908167206653757c closes official-stockfish#2931 fixes official-stockfish#2907 requires fishtest updates before commit Bench: 4290577
1 parent d7b1148 commit cf9833c

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

.travis.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ before_script:
4343
- cd src
4444

4545
script:
46+
# Download net
47+
- make net
48+
4649
# Obtain bench reference from git log
4750
- git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9]*\).*/\1/g" > git_sig
4851
- export benchref=$(cat git_sig)
@@ -55,26 +58,38 @@ script:
5558
#
5659
# Verify bench number against various builds
5760
- export CXXFLAGS="-Werror -D_GLIBCXX_DEBUG"
58-
- make clean && make -j2 ARCH=x86-64 optimize=no debug=yes build && ../tests/signature.sh $benchref
61+
- make clean && make -j2 ARCH=x86-64-modern optimize=no debug=yes build && ../tests/signature.sh $benchref
62+
- export CXXFLAGS="-Werror"
63+
- make clean && make -j2 ARCH=x86-64-modern build && ../tests/signature.sh $benchref
64+
- make clean && make -j2 ARCH=x86-64-ssse3 build && ../tests/signature.sh $benchref
65+
- make clean && make -j2 ARCH=x86-64-sse3-popcnt build && ../tests/signature.sh $benchref
66+
- make clean && make -j2 ARCH=x86-64 build && ../tests/signature.sh $benchref
5967
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32 optimize=no debug=yes build && ../tests/signature.sh $benchref; fi
6068
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32 build && ../tests/signature.sh $benchref; fi
69+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32-old build && ../tests/signature.sh $benchref; fi
70+
- if [[ "$TRAVIS_OS_NAME" == "linux" && "$COMP" == "gcc" ]]; then make clean && make -j2 ARCH=x86-64-modern profile-build && ../tests/signature.sh $benchref; fi
71+
72+
# compile only for some more advanced architectures (might not run in travis)
73+
- make clean && make -j2 ARCH=x86-64-avx2 build
74+
- make clean && make -j2 ARCH=x86-64-bmi2 build
75+
# needs gcc 10 to compile
76+
- if [[ "$COMPILER" != "g++-8" ]]; then make clean && make -j2 ARCH=x86-64-avx512 build; fi
6177

6278
#
6379
# Check perft and reproducible search
64-
- export CXXFLAGS="-Werror"
65-
- make clean && make -j2 ARCH=x86-64 build
80+
- make clean && make -j2 ARCH=x86-64-modern build
6681
- ../tests/perft.sh
6782
- ../tests/reprosearch.sh
6883

6984
#
7085
# Valgrind
7186
#
7287
- export CXXFLAGS="-O1 -fno-inline"
73-
- if [ -x "$(command -v valgrind )" ]; then make clean && make -j2 ARCH=x86-64 debug=yes optimize=no build > /dev/null && ../tests/instrumented.sh --valgrind; fi
88+
- if [ -x "$(command -v valgrind )" ]; then make clean && make -j2 ARCH=x86-64-modern debug=yes optimize=no build > /dev/null && ../tests/instrumented.sh --valgrind; fi
7489
- if [ -x "$(command -v valgrind )" ]; then ../tests/instrumented.sh --valgrind-thread; fi
7590

7691
#
7792
# Sanitizer
7893
#
79-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
80-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
94+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-64-modern sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
95+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-64-modern sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi

appveyor.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ before_build:
6161
6262
build_script:
6363
- cmake --build . --config %CONFIGURATION% -- /verbosity:minimal
64+
- ps: |
65+
# Download default NNUE net from fishtest
66+
$nnuenet = Get-Content -Path src\ucioption.cpp | Select-String -CaseSensitive -Pattern "Option" | Select-String -CaseSensitive -Pattern "nn-[a-z0-9]{12}.nnue"
67+
$dummy = $nnuenet -match "(?<nnuenet>nn-[a-z0-9]{12}.nnue)"
68+
$nnuenet = $Matches.nnuenet
69+
Write-Host "Default net:" $nnuenet
70+
$nnuedownloadurl = "https://tests.stockfishchess.org/api/nn/$nnuenet"
71+
$nnuefilepath = "src\${env:CONFIGURATION}\$nnuenet"
72+
if (Test-Path -Path $nnuefilepath) {
73+
Write-Host "Already available."
74+
} else {
75+
Write-Host "Downloading $nnuedownloadurl to $nnuefilepath"
76+
Invoke-WebRequest -Uri $nnuedownloadurl -OutFile $nnuefilepath
77+
}
6478
6579
before_test:
6680
- cd src/%CONFIGURATION%

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ help:
569569
build: config-sanity
570570
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
571571

572-
profile-build: config-sanity objclean profileclean
572+
profile-build: config-sanity objclean profileclean net
573573
@echo ""
574574
@echo "Step 1/4. Building instrumented executable ..."
575575
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)

src/benchmark.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ const vector<string> Defaults = {
9595
/// setup_bench() builds a list of UCI commands to be run by bench. There
9696
/// are five parameters: TT size in MB, number of search threads that
9797
/// should be used, the limit value spent for each position, a file name
98-
/// where to look for positions in FEN format and the type of the limit:
99-
/// depth, perft, nodes and movetime (in millisecs).
98+
/// where to look for positions in FEN format, the type of the limit:
99+
/// depth, perft, nodes and movetime (in millisecs), and evaluation type
100+
/// mixed (default), classical, NNUE.
100101
///
101102
/// bench -> search default positions up to depth 13
102103
/// bench 64 1 15 -> search default positions up to depth 15 (TT = 64MB)
@@ -115,6 +116,7 @@ vector<string> setup_bench(const Position& current, istream& is) {
115116
string limit = (is >> token) ? token : "13";
116117
string fenFile = (is >> token) ? token : "default";
117118
string limitType = (is >> token) ? token : "depth";
119+
string evalType = (is >> token) ? token : "mixed";
118120

119121
go = limitType == "eval" ? "eval" : "go " + limitType + " " + limit;
120122

@@ -146,13 +148,20 @@ vector<string> setup_bench(const Position& current, istream& is) {
146148
list.emplace_back("setoption name Hash value " + ttSize);
147149
list.emplace_back("ucinewgame");
148150

151+
size_t posCounter = 0;
152+
149153
for (const string& fen : fens)
150154
if (fen.find("setoption") != string::npos)
151155
list.emplace_back(fen);
152156
else
153157
{
158+
if (evalType == "classical" || (evalType == "mixed" && posCounter % 2 == 0))
159+
list.emplace_back("setoption name Use NNUE value false");
160+
else if (evalType == "NNUE" || (evalType == "mixed" && posCounter % 2 != 0))
161+
list.emplace_back("setoption name Use NNUE value true");
154162
list.emplace_back("position fen " + fen);
155163
list.emplace_back(go);
164+
++posCounter;
156165
}
157166

158167
return list;

tests/instrumented.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ for args in "eval" \
7070
"go depth 10" \
7171
"go movetime 1000" \
7272
"go wtime 8000 btime 8000 winc 500 binc 500" \
73-
"bench 128 $threads 10 default depth"
73+
"bench 128 $threads 8 default depth"
7474
do
7575

7676
echo "$prefix $exeprefix ./stockfish $args $postfix"
@@ -80,7 +80,7 @@ done
8080

8181
# more general testing, following an uci protocol exchange
8282
cat << EOF > game.exp
83-
set timeout 10
83+
set timeout 240
8484
spawn $exeprefix ./stockfish
8585
8686
send "uci\n"
@@ -98,7 +98,7 @@ cat << EOF > game.exp
9898
expect "bestmove"
9999
100100
send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
101-
send "go depth 30\n"
101+
send "go depth 20\n"
102102
expect "bestmove"
103103
104104
send "quit\n"
@@ -121,7 +121,7 @@ cat << EOF > syzygy.exp
121121
send "uci\n"
122122
send "setoption name SyzygyPath value ../tests/syzygy/\n"
123123
expect "info string Found 35 tablebases" {} timeout {exit 1}
124-
send "bench 128 1 10 default depth\n"
124+
send "bench 128 1 8 default depth\n"
125125
send "quit\n"
126126
expect eof
127127

0 commit comments

Comments
 (0)