mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 08:37:44 +00:00
Compare commits
95 Commits
nnue-player-wip
...
sf_12
| Author | SHA1 | Date | |
|---|---|---|---|
| c306d83869 | |||
| aa2de71230 | |||
| be87517734 | |||
| a8bbaa1795 | |||
| 61381372ec | |||
| a057f170c6 | |||
| a0afe32d16 | |||
| e0bafa1911 | |||
| 9b5b9ec9a6 | |||
| c02b3a4c7a | |||
| d90d893b5e | |||
| e4ed7d3dd7 | |||
| 406979ea12 | |||
| 242a7d9fea | |||
| 95b8f3f800 | |||
| 9b4967071e | |||
| b0b4ca17db | |||
| 530fccbf27 | |||
| 843a961a8c | |||
| f7b3f0e842 | |||
| 701b2427bd | |||
| e453f09f06 | |||
| d5f86b6359 | |||
| cc9d503dde | |||
| 5f1843c9cb | |||
| 3542033342 | |||
| 34f67c5722 | |||
| cbcb05ca09 | |||
| e64b957274 | |||
| 15abcaedc1 | |||
| 8b45b1c490 | |||
| daac86691d | |||
| a1ad8604a1 | |||
| 2deb08a529 | |||
| 42e8789f0b | |||
| 384d684484 | |||
| fbae5614eb | |||
| 1bcc981a5a | |||
| 581b92e4a7 | |||
| 1c0b7bdf4f | |||
| 65b976439f | |||
| 0e17a89e4d | |||
| 81d716f5cc | |||
| 65572de4a7 | |||
| 72dc7a5c54 | |||
| 8cf43c6317 | |||
| cd0b8b4cf2 | |||
| 6eb186c97e | |||
| e5f450cf0b | |||
| ce009ea1aa | |||
| e8ea215a13 | |||
| 67e48418af | |||
| 69cfe28f31 | |||
| dd63b98fb0 | |||
| 6bc0256292 | |||
| 992f549ae7 | |||
| ee06046412 | |||
| ea6220f381 | |||
| f46c73040c | |||
| 399cddf444 | |||
| 4ab8b0b738 | |||
| a72cec1ff8 | |||
| 220ef1d27d | |||
| 21df37d7fd | |||
| f948cd008d | |||
| cb0504028e | |||
| ad2ad4c657 | |||
| 875183b310 | |||
| a54f9011c3 | |||
| bcdf41dadc | |||
| 651ec3b31e | |||
| 27b593a944 | |||
| a6e89293df | |||
| 2bfde55429 | |||
| cd1bb27dd4 | |||
| 320fa1b2f0 | |||
| d7a26899a9 | |||
| add890a10b | |||
| 1949eb8604 | |||
| 6d6267c378 | |||
| e663bc5330 | |||
| 3368d03285 | |||
| 450b60a303 | |||
| 23ecf3d5c6 | |||
| 910f779eb1 | |||
| f4c27cda1a | |||
| 5ccff25df2 | |||
| dc5af66ead | |||
| 857e045ced | |||
| 615d98da24 | |||
| 7f336dd59b | |||
| af935365e3 | |||
| 8b8412ef87 | |||
| 3dca13a958 | |||
| 84f3e86790 |
+43
-15
@@ -1,5 +1,5 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
dist: xenial
|
dist: bionic
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
@@ -7,7 +7,6 @@ matrix:
|
|||||||
compiler: gcc
|
compiler: gcc
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
|
||||||
packages: ['g++-8', 'g++-8-multilib', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
packages: ['g++-8', 'g++-8-multilib', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||||
env:
|
env:
|
||||||
- COMPILER=g++-8
|
- COMPILER=g++-8
|
||||||
@@ -17,23 +16,23 @@ matrix:
|
|||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-6.0']
|
packages: ['clang-10', 'llvm-10-dev', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
||||||
packages: ['clang-6.0', 'llvm-6.0-dev', 'g++-multilib', 'valgrind', 'expect', 'curl']
|
|
||||||
env:
|
env:
|
||||||
- COMPILER=clang++-6.0
|
- COMPILER=clang++-10
|
||||||
- COMP=clang
|
- COMP=clang
|
||||||
- LDFLAGS=-fuse-ld=lld
|
|
||||||
|
|
||||||
- os: osx
|
- os: osx
|
||||||
|
osx_image: xcode12
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
env:
|
env:
|
||||||
- COMPILER=g++
|
- COMPILER=g++
|
||||||
- COMP=gcc
|
- COMP=gcc
|
||||||
|
|
||||||
- os: osx
|
- os: osx
|
||||||
|
osx_image: xcode12
|
||||||
compiler: clang
|
compiler: clang
|
||||||
env:
|
env:
|
||||||
- COMPILER=clang++ V='Apple LLVM 9.4.1' # Apple LLVM version 9.1.0 (clang-902.0.39.2)
|
- COMPILER=clang++
|
||||||
- COMP=clang
|
- COMP=clang
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
@@ -44,30 +43,59 @@ before_script:
|
|||||||
- cd src
|
- cd src
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
# Download net
|
||||||
|
- make net
|
||||||
|
|
||||||
# Obtain bench reference from git log
|
# Obtain bench reference from git log
|
||||||
- git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9]*\).*/\1/g" > git_sig
|
- git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9]*\).*/\1/g" > git_sig
|
||||||
- export benchref=$(cat git_sig)
|
- export benchref=$(cat git_sig)
|
||||||
- echo "Reference bench:" $benchref
|
- echo "Reference bench:" $benchref
|
||||||
#
|
|
||||||
|
# Compiler version string
|
||||||
|
- $COMPILER -v
|
||||||
|
|
||||||
|
# test help target
|
||||||
|
- make help
|
||||||
|
|
||||||
# Verify bench number against various builds
|
# Verify bench number against various builds
|
||||||
- export CXXFLAGS="-Werror -D_GLIBCXX_DEBUG"
|
- export CXXFLAGS="-Werror -D_GLIBCXX_DEBUG"
|
||||||
- make clean && make -j2 ARCH=x86-64 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
- make clean && make -j2 ARCH=x86-64-modern optimize=no debug=yes build && ../tests/signature.sh $benchref
|
||||||
- make clean && make -j2 ARCH=x86-32 optimize=no debug=yes build && ../tests/signature.sh $benchref
|
- export CXXFLAGS="-Werror"
|
||||||
- make clean && make -j2 ARCH=x86-32 build && ../tests/signature.sh $benchref
|
- make clean && make -j2 ARCH=x86-64-modern build && ../tests/signature.sh $benchref
|
||||||
|
- make clean && make -j2 ARCH=x86-64-ssse3 build && ../tests/signature.sh $benchref
|
||||||
|
- make clean && make -j2 ARCH=x86-64-sse3-popcnt build && ../tests/signature.sh $benchref
|
||||||
|
- make clean && make -j2 ARCH=x86-64 build && ../tests/signature.sh $benchref
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=general-64 build && ../tests/signature.sh $benchref; fi
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32 optimize=no debug=yes build && ../tests/signature.sh $benchref; fi
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32-sse41-popcnt build && ../tests/signature.sh $benchref; fi
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32-sse2 build && ../tests/signature.sh $benchref; fi
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32 build && ../tests/signature.sh $benchref; fi
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=general-32 build && ../tests/signature.sh $benchref; fi
|
||||||
|
# workaround: exclude a custom version of llvm+clang, which doesn't find llvm-profdata on ubuntu
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" != "linux" || "$COMP" == "gcc" ]]; then make clean && make -j2 ARCH=x86-64-modern profile-build && ../tests/signature.sh $benchref; fi
|
||||||
|
|
||||||
|
# compile only for some more advanced architectures (might not run in travis)
|
||||||
|
- make clean && make -j2 ARCH=x86-64-avx2 build
|
||||||
|
- make clean && make -j2 ARCH=x86-64-bmi2 build
|
||||||
|
- make clean && make -j2 ARCH=x86-64-avx512 build
|
||||||
|
- make clean && make -j2 ARCH=x86-64-vnni512 build
|
||||||
|
- make clean && make -j2 ARCH=x86-64-vnni256 build
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check perft and reproducible search
|
# Check perft and reproducible search
|
||||||
|
- make clean && make -j2 ARCH=x86-64-modern build
|
||||||
- ../tests/perft.sh
|
- ../tests/perft.sh
|
||||||
- ../tests/reprosearch.sh
|
- ../tests/reprosearch.sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Valgrind
|
# Valgrind
|
||||||
#
|
#
|
||||||
- export CXXFLAGS="-O1 -fno-inline"
|
- export CXXFLAGS="-O1 -fno-inline"
|
||||||
- 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
|
- 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
|
||||||
- if [ -x "$(command -v valgrind )" ]; then ../tests/instrumented.sh --valgrind-thread; fi
|
- if [ -x "$(command -v valgrind )" ]; then ../tests/instrumented.sh --valgrind-thread; fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Sanitizer
|
# Sanitizer
|
||||||
#
|
#
|
||||||
# Use g++-8 as a proxy for having sanitizers, might need revision as they become available for more recent versions of clang/gcc
|
- 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
|
||||||
- if [[ "$COMPILER" == "g++-8" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-undefined; fi
|
- 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
|
||||||
- if [[ "$COMPILER" == "g++-8" ]]; then make clean && make -j2 ARCH=x86-64 sanitize=thread optimize=no debug=yes build > /dev/null && ../tests/instrumented.sh --sanitizer-thread; fi
|
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
# List of authors for Stockfish, as of March 30, 2020
|
# List of authors for Stockfish, as of August 4, 2020
|
||||||
|
|
||||||
|
# Founders of the Stockfish project and fishtest infrastructure
|
||||||
Tord Romstad (romstad)
|
Tord Romstad (romstad)
|
||||||
Marco Costalba (mcostalba)
|
Marco Costalba (mcostalba)
|
||||||
Joona Kiiski (zamar)
|
Joona Kiiski (zamar)
|
||||||
Gary Linscott (glinscott)
|
Gary Linscott (glinscott)
|
||||||
|
|
||||||
|
# Authors and inventors of NNUE, training, NNUE port
|
||||||
|
Yu Nasu (ynasu87)
|
||||||
|
Motohiro Isozaki (yaneurao)
|
||||||
|
Hisayori Noda (nodchip)
|
||||||
|
|
||||||
|
# all other authors of the code in alphabetical order
|
||||||
Aditya (absimaldata)
|
Aditya (absimaldata)
|
||||||
Adrian Petrescu (apetresc)
|
Adrian Petrescu (apetresc)
|
||||||
Ajith Chandy Jose (ajithcj)
|
Ajith Chandy Jose (ajithcj)
|
||||||
@@ -29,13 +36,15 @@ Bryan Cross (crossbr)
|
|||||||
candirufish
|
candirufish
|
||||||
Chess13234
|
Chess13234
|
||||||
Chris Cain (ceebo)
|
Chris Cain (ceebo)
|
||||||
|
Dale Weiler (graphitemaster)
|
||||||
Dan Schmidt (dfannius)
|
Dan Schmidt (dfannius)
|
||||||
Daniel Axtens (daxtens)
|
Daniel Axtens (daxtens)
|
||||||
Daniel Dugovic (ddugovic)
|
Daniel Dugovic (ddugovic)
|
||||||
Dariusz Orzechowski
|
Dariusz Orzechowski (dorzechowski)
|
||||||
David Zar
|
David Zar
|
||||||
Daylen Yang (daylen)
|
Daylen Yang (daylen)
|
||||||
DiscanX
|
DiscanX
|
||||||
|
Dominik Schlösser (domschl)
|
||||||
double-beep
|
double-beep
|
||||||
Eduardo Cáceres (eduherminio)
|
Eduardo Cáceres (eduherminio)
|
||||||
Eelco de Groot (KingDefender)
|
Eelco de Groot (KingDefender)
|
||||||
@@ -45,11 +54,13 @@ Ernesto Gatti
|
|||||||
Linmiao Xu (linrock)
|
Linmiao Xu (linrock)
|
||||||
Fabian Beuke (madnight)
|
Fabian Beuke (madnight)
|
||||||
Fabian Fichter (ianfab)
|
Fabian Fichter (ianfab)
|
||||||
|
Fanael Linithien (Fanael)
|
||||||
fanon
|
fanon
|
||||||
Fauzi Akram Dabat (FauziAkram)
|
Fauzi Akram Dabat (FauziAkram)
|
||||||
Felix Wittmann
|
Felix Wittmann
|
||||||
gamander
|
gamander
|
||||||
Gary Heckman (gheckman)
|
Gary Heckman (gheckman)
|
||||||
|
George Sobala (gsobala)
|
||||||
gguliash
|
gguliash
|
||||||
Gian-Carlo Pascutto (gcp)
|
Gian-Carlo Pascutto (gcp)
|
||||||
Gontran Lemaire (gonlem)
|
Gontran Lemaire (gonlem)
|
||||||
@@ -71,6 +82,7 @@ Jean Gauthier (OuaisBla)
|
|||||||
Jean-Francois Romang (jromang)
|
Jean-Francois Romang (jromang)
|
||||||
Jekaa
|
Jekaa
|
||||||
Jerry Donald Watson (jerrydonaldwatson)
|
Jerry Donald Watson (jerrydonaldwatson)
|
||||||
|
jjoshua2
|
||||||
Jonathan Calovski (Mysseno)
|
Jonathan Calovski (Mysseno)
|
||||||
Jonathan Dumale (SFisGOD)
|
Jonathan Dumale (SFisGOD)
|
||||||
Joost VandeVondele (vondele)
|
Joost VandeVondele (vondele)
|
||||||
@@ -115,7 +127,9 @@ Nick Pelling (nickpelling)
|
|||||||
Nicklas Persson (NicklasPersson)
|
Nicklas Persson (NicklasPersson)
|
||||||
Niklas Fiekas (niklasf)
|
Niklas Fiekas (niklasf)
|
||||||
Nikolay Kostov (NikolayIT)
|
Nikolay Kostov (NikolayIT)
|
||||||
Nguyen Pham
|
Nguyen Pham (nguyenpham)
|
||||||
|
Norman Schmidt (FireFather)
|
||||||
|
notruck
|
||||||
Ondrej Mosnáček (WOnder93)
|
Ondrej Mosnáček (WOnder93)
|
||||||
Oskar Werkelin Ahlin
|
Oskar Werkelin Ahlin
|
||||||
Pablo Vazquez
|
Pablo Vazquez
|
||||||
@@ -135,14 +149,17 @@ Richard Lloyd
|
|||||||
Rodrigo Exterckötter Tjäder
|
Rodrigo Exterckötter Tjäder
|
||||||
Ron Britvich (Britvich)
|
Ron Britvich (Britvich)
|
||||||
Ronald de Man (syzygy1, syzygy)
|
Ronald de Man (syzygy1, syzygy)
|
||||||
|
rqs
|
||||||
Ryan Schmitt
|
Ryan Schmitt
|
||||||
Ryan Takker
|
Ryan Takker
|
||||||
Sami Kiminki (skiminki)
|
Sami Kiminki (skiminki)
|
||||||
Sebastian Buchwald (UniQP)
|
Sebastian Buchwald (UniQP)
|
||||||
Sergei Antonov (saproj)
|
Sergei Antonov (saproj)
|
||||||
Sergei Ivanov (svivanov72)
|
Sergei Ivanov (svivanov72)
|
||||||
|
Sergio Vieri (sergiovieri)
|
||||||
sf-x
|
sf-x
|
||||||
Shane Booth (shane31)
|
Shane Booth (shane31)
|
||||||
|
Shawn Varghese (xXH4CKST3RXx)
|
||||||
Stefan Geschwentner (locutus2)
|
Stefan Geschwentner (locutus2)
|
||||||
Stefano Cardanobile (Stefano80)
|
Stefano Cardanobile (Stefano80)
|
||||||
Steinar Gunderson (sesse)
|
Steinar Gunderson (sesse)
|
||||||
@@ -155,9 +172,11 @@ Tom Vijlbrief (tomtor)
|
|||||||
Tomasz Sobczyk (Sopel97)
|
Tomasz Sobczyk (Sopel97)
|
||||||
Torsten Franz (torfranz, tfranzer)
|
Torsten Franz (torfranz, tfranzer)
|
||||||
Tracey Emery (basepr1me)
|
Tracey Emery (basepr1me)
|
||||||
|
tttak
|
||||||
Unai Corzo (unaiic)
|
Unai Corzo (unaiic)
|
||||||
Uri Blass (uriblass)
|
Uri Blass (uriblass)
|
||||||
Vince Negri (cuddlestmonkey)
|
Vince Negri (cuddlestmonkey)
|
||||||
|
zz4032
|
||||||
|
|
||||||
|
|
||||||
# Additionally, we acknowledge the authors and maintainers of fishtest,
|
# Additionally, we acknowledge the authors and maintainers of fishtest,
|
||||||
|
|||||||
+101
-47
@@ -4,11 +4,17 @@
|
|||||||
[](https://ci.appveyor.com/project/mcostalba/stockfish/branch/master)
|
[](https://ci.appveyor.com/project/mcostalba/stockfish/branch/master)
|
||||||
|
|
||||||
[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
|
[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
|
||||||
derived from Glaurung 2.1. It is not a complete chess program and requires a
|
derived from Glaurung 2.1. Stockfish is not a complete chess program and requires a
|
||||||
UCI-compatible GUI (e.g. XBoard with PolyGlot, Scid, Cute Chess, eboard, Arena,
|
UCI-compatible graphical user interface (GUI) (e.g. XBoard with PolyGlot, Scid,
|
||||||
Sigma Chess, Shredder, Chess Partner or Fritz) in order to be used comfortably.
|
Cute Chess, eboard, Arena, Sigma Chess, Shredder, Chess Partner or Fritz) in order
|
||||||
Read the documentation for your GUI of choice for information about how to use
|
to be used comfortably. Read the documentation for your GUI of choice for information
|
||||||
Stockfish with it.
|
about how to use Stockfish with it.
|
||||||
|
|
||||||
|
The Stockfish engine features two evaluation functions for chess, the classical
|
||||||
|
evaluation based on handcrafted terms, and the NNUE evaluation based on efficiently
|
||||||
|
updateable neural networks. The classical evaluation runs efficiently on almost all
|
||||||
|
CPU architectures, while the NNUE evaluation benefits from the vector
|
||||||
|
intrinsics available on most CPUs (sse2, avx2, neon, or similar).
|
||||||
|
|
||||||
|
|
||||||
## Files
|
## Files
|
||||||
@@ -22,21 +28,24 @@ This distribution of Stockfish consists of the following files:
|
|||||||
* src, a subdirectory containing the full source code, including a Makefile
|
* src, a subdirectory containing the full source code, including a Makefile
|
||||||
that can be used to compile Stockfish on Unix-like systems.
|
that can be used to compile Stockfish on Unix-like systems.
|
||||||
|
|
||||||
|
* a file with the .nnue extension, storing the neural network for the NNUE
|
||||||
|
evaluation. Binary distributions will have this file embedded.
|
||||||
|
|
||||||
## UCI parameters
|
Note: to use the NNUE evaluation, the additional data file with neural network parameters
|
||||||
|
needs to be available. Normally, this file is already embedded in the binary or it can be downloaded.
|
||||||
|
The filename for the default (recommended) net can be found as the default
|
||||||
|
value of the `EvalFile` UCI option, with the format `nn-[SHA256 first 12 digits].nnue`
|
||||||
|
(for instance, `nn-c157e0a5755b.nnue`). This file can be downloaded from
|
||||||
|
```
|
||||||
|
https://tests.stockfishchess.org/api/nn/[filename]
|
||||||
|
```
|
||||||
|
replacing `[filename]` as needed.
|
||||||
|
|
||||||
|
|
||||||
|
## UCI options
|
||||||
|
|
||||||
Currently, Stockfish has the following UCI options:
|
Currently, Stockfish has the following UCI options:
|
||||||
|
|
||||||
* #### Debug Log File
|
|
||||||
Write all communication to and from the engine into a text file.
|
|
||||||
|
|
||||||
* #### Contempt
|
|
||||||
A positive value for contempt favors middle game positions and avoids draws.
|
|
||||||
|
|
||||||
* #### Analysis Contempt
|
|
||||||
By default, contempt is set to prefer the side to move. Set this option to "White"
|
|
||||||
or "Black" to analyse with contempt for that side, or "Off" to disable contempt.
|
|
||||||
|
|
||||||
* #### Threads
|
* #### Threads
|
||||||
The number of CPU threads used for searching a position. For best performance, set
|
The number of CPU threads used for searching a position. For best performance, set
|
||||||
this equal to the number of CPU cores available.
|
this equal to the number of CPU cores available.
|
||||||
@@ -44,9 +53,6 @@ Currently, Stockfish has the following UCI options:
|
|||||||
* #### Hash
|
* #### Hash
|
||||||
The size of the hash table in MB. It is recommended to set Hash after setting Threads.
|
The size of the hash table in MB. It is recommended to set Hash after setting Threads.
|
||||||
|
|
||||||
* #### Clear Hash
|
|
||||||
Clear the hash table.
|
|
||||||
|
|
||||||
* #### Ponder
|
* #### Ponder
|
||||||
Let Stockfish ponder its next move while the opponent is thinking.
|
Let Stockfish ponder its next move while the opponent is thinking.
|
||||||
|
|
||||||
@@ -54,10 +60,27 @@ Currently, Stockfish has the following UCI options:
|
|||||||
Output the N best lines (principal variations, PVs) when searching.
|
Output the N best lines (principal variations, PVs) when searching.
|
||||||
Leave at 1 for best performance.
|
Leave at 1 for best performance.
|
||||||
|
|
||||||
* #### Skill Level
|
* #### Use NNUE
|
||||||
Lower the Skill Level in order to make Stockfish play weaker (see also UCI_LimitStrength).
|
Toggle between the NNUE and classical evaluation functions. If set to "true",
|
||||||
Internally, MultiPV is enabled, and with a certain probability depending on the Skill Level a
|
the network parameters must be available to load from file (see also EvalFile),
|
||||||
weaker move will be played.
|
if they are not embedded in the binary.
|
||||||
|
|
||||||
|
* #### EvalFile
|
||||||
|
The name of the file of the NNUE evaluation parameters. Depending on the GUI the
|
||||||
|
filename might have to include the full path to the folder/directory that contains the file.
|
||||||
|
Other locations, such as the directory that contains the binary and the working directory,
|
||||||
|
are also searched.
|
||||||
|
|
||||||
|
* #### UCI_AnalyseMode
|
||||||
|
An option handled by your GUI.
|
||||||
|
|
||||||
|
* #### UCI_Chess960
|
||||||
|
An option handled by your GUI. If true, Stockfish will play Chess960.
|
||||||
|
|
||||||
|
* #### UCI_ShowWDL
|
||||||
|
If enabled, show approximate WDL statistics as part of the engine output.
|
||||||
|
These WDL numbers model expected game outcomes for a given evaluation and
|
||||||
|
game ply for engine self-play at fishtest LTC conditions (60+0.6s per game).
|
||||||
|
|
||||||
* #### UCI_LimitStrength
|
* #### UCI_LimitStrength
|
||||||
Enable weaker play aiming for an Elo rating as set by UCI_Elo. This option overrides Skill Level.
|
Enable weaker play aiming for an Elo rating as set by UCI_Elo. This option overrides Skill Level.
|
||||||
@@ -66,28 +89,10 @@ Currently, Stockfish has the following UCI options:
|
|||||||
If enabled by UCI_LimitStrength, aim for an engine strength of the given Elo.
|
If enabled by UCI_LimitStrength, aim for an engine strength of the given Elo.
|
||||||
This Elo rating has been calibrated at a time control of 60s+0.6s and anchored to CCRL 40/4.
|
This Elo rating has been calibrated at a time control of 60s+0.6s and anchored to CCRL 40/4.
|
||||||
|
|
||||||
* #### UCI_ShowWDL
|
* #### Skill Level
|
||||||
If enabled, show approximate WDL statistics as part of the engine output.
|
Lower the Skill Level in order to make Stockfish play weaker (see also UCI_LimitStrength).
|
||||||
These WDL numbers model expected game outcomes for a given evaluation and
|
Internally, MultiPV is enabled, and with a certain probability depending on the Skill Level a
|
||||||
game ply for engine self-play at fishtest LTC conditions (60+0.6s per game).
|
weaker move will be played.
|
||||||
|
|
||||||
* #### Move Overhead
|
|
||||||
Assume a time delay of x ms due to network and GUI overheads. This is useful to
|
|
||||||
avoid losses on time in those cases.
|
|
||||||
|
|
||||||
* #### Slow Mover
|
|
||||||
Lower values will make Stockfish take less time in games, higher values will
|
|
||||||
make it think longer.
|
|
||||||
|
|
||||||
* #### nodestime
|
|
||||||
Tells the engine to use nodes searched instead of wall time to account for
|
|
||||||
elapsed time. Useful for engine testing.
|
|
||||||
|
|
||||||
* #### UCI_Chess960
|
|
||||||
An option handled by your GUI. If true, Stockfish will play Chess960.
|
|
||||||
|
|
||||||
* #### UCI_AnalyseMode
|
|
||||||
An option handled by your GUI.
|
|
||||||
|
|
||||||
* #### SyzygyPath
|
* #### SyzygyPath
|
||||||
Path to the folders/directories storing the Syzygy tablebase files. Multiple
|
Path to the folders/directories storing the Syzygy tablebase files. Multiple
|
||||||
@@ -114,6 +119,55 @@ Currently, Stockfish has the following UCI options:
|
|||||||
Limit Syzygy tablebase probing to positions with at most this many pieces left
|
Limit Syzygy tablebase probing to positions with at most this many pieces left
|
||||||
(including kings and pawns).
|
(including kings and pawns).
|
||||||
|
|
||||||
|
* #### Contempt
|
||||||
|
A positive value for contempt favors middle game positions and avoids draws,
|
||||||
|
effective for the classical evaluation only.
|
||||||
|
|
||||||
|
* #### Analysis Contempt
|
||||||
|
By default, contempt is set to prefer the side to move. Set this option to "White"
|
||||||
|
or "Black" to analyse with contempt for that side, or "Off" to disable contempt.
|
||||||
|
|
||||||
|
* #### Move Overhead
|
||||||
|
Assume a time delay of x ms due to network and GUI overheads. This is useful to
|
||||||
|
avoid losses on time in those cases.
|
||||||
|
|
||||||
|
* #### Slow Mover
|
||||||
|
Lower values will make Stockfish take less time in games, higher values will
|
||||||
|
make it think longer.
|
||||||
|
|
||||||
|
* #### nodestime
|
||||||
|
Tells the engine to use nodes searched instead of wall time to account for
|
||||||
|
elapsed time. Useful for engine testing.
|
||||||
|
|
||||||
|
* #### Clear Hash
|
||||||
|
Clear the hash table.
|
||||||
|
|
||||||
|
* #### Debug Log File
|
||||||
|
Write all communication to and from the engine into a text file.
|
||||||
|
|
||||||
|
## A note on classical and NNUE evaluation
|
||||||
|
|
||||||
|
Both approaches assign a value to a position that is used in alpha-beta (PVS) search
|
||||||
|
to find the best move. The classical evaluation computes this value as a function
|
||||||
|
of various chess concepts, handcrafted by experts, tested and tuned using fishtest.
|
||||||
|
The NNUE evaluation computes this value with a neural network based on basic
|
||||||
|
inputs (e.g. piece positions only). The network is optimized and trained
|
||||||
|
on the evalutions of millions of positions at moderate search depth.
|
||||||
|
|
||||||
|
The NNUE evaluation was first introduced in shogi, and ported to Stockfish afterward.
|
||||||
|
It can be evaluated efficiently on CPUs, and exploits the fact that only parts
|
||||||
|
of the neural network need to be updated after a typical chess move.
|
||||||
|
[The nodchip repository](https://github.com/nodchip/Stockfish) provides additional
|
||||||
|
tools to train and develop the NNUE networks.
|
||||||
|
|
||||||
|
On CPUs supporting modern vector instructions (avx2 and similar), the NNUE evaluation
|
||||||
|
results in stronger playing strength, even if the nodes per second computed by the engine
|
||||||
|
is somewhat lower (roughly 60% of nps is typical).
|
||||||
|
|
||||||
|
Note that the NNUE evaluation depends on the Stockfish binary and the network parameter
|
||||||
|
file (see EvalFile). Not every parameter file is compatible with a given Stockfish binary.
|
||||||
|
The default value of the EvalFile UCI option is the name of a network that is guaranteed
|
||||||
|
to be compatible with that binary.
|
||||||
|
|
||||||
## What to expect from Syzygybases?
|
## What to expect from Syzygybases?
|
||||||
|
|
||||||
@@ -179,6 +233,7 @@ targets with corresponding descriptions.
|
|||||||
cd src
|
cd src
|
||||||
make help
|
make help
|
||||||
make build ARCH=x86-64-modern
|
make build ARCH=x86-64-modern
|
||||||
|
make net
|
||||||
```
|
```
|
||||||
|
|
||||||
When not using the Makefile to compile (for instance with Microsoft MSVC) you
|
When not using the Makefile to compile (for instance with Microsoft MSVC) you
|
||||||
@@ -190,8 +245,7 @@ compiler you used to create your executable. These informations can
|
|||||||
be found by typing the following commands in a console:
|
be found by typing the following commands in a console:
|
||||||
|
|
||||||
```
|
```
|
||||||
./stockfish
|
./stockfish compiler
|
||||||
compiler
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Understanding the code base and participating in the project
|
## Understanding the code base and participating in the project
|
||||||
+169
-150
@@ -1,154 +1,173 @@
|
|||||||
Contributors with >10,000 CPU hours as of January 7, 2020
|
Contributors with >10,000 CPU hours as of Sept 2, 2020
|
||||||
Thank you!
|
Thank you!
|
||||||
|
|
||||||
Username CPU Hours Games played
|
Username CPU Hours Games played
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
noobpwnftw 9305707 695548021
|
noobpwnftw 19352969 1231459677
|
||||||
mlang 780050 61648867
|
mlang 957168 61657446
|
||||||
dew 621626 43921547
|
dew 949885 56893432
|
||||||
mibere 524702 42238645
|
mibere 703817 46865007
|
||||||
crunchy 354587 27344275
|
crunchy 427035 27344275
|
||||||
cw 354495 27274181
|
cw 416006 27521077
|
||||||
fastgm 332801 22804359
|
JojoM 415904 24479564
|
||||||
JojoM 295750 20437451
|
fastgm 404873 23953472
|
||||||
CSU_Dynasty 262015 21828122
|
CSU_Dynasty 335774 22850550
|
||||||
Fisherman 232181 18939229
|
tvijlbrief 335199 21871270
|
||||||
ctoks 218866 17622052
|
Fisherman 325053 21786603
|
||||||
glinscott 201989 13780820
|
gvreuls 311480 20751516
|
||||||
tvijlbrief 201204 15337115
|
ctoks 275877 18710423
|
||||||
velislav 188630 14348485
|
velislav 241267 15596372
|
||||||
gvreuls 187164 15149976
|
glinscott 217799 13780820
|
||||||
bking_US 180289 11876016
|
nordlandia 211692 13484886
|
||||||
nordlandia 172076 13467830
|
bcross 206213 14934233
|
||||||
leszek 157152 11443978
|
bking_US 198894 11876016
|
||||||
Thanar 148021 12365359
|
leszek 189170 11446821
|
||||||
spams 141975 10319326
|
mgrabiak 183896 11778092
|
||||||
drabel 138073 11121749
|
drabel 181408 12489478
|
||||||
vdv 137850 9394330
|
TueRens 181349 12192000
|
||||||
mgrabiak 133578 10454324
|
Thanar 179852 12365359
|
||||||
TueRens 132485 10878471
|
vdv 175171 9881246
|
||||||
bcross 129683 11557084
|
robal 166948 10702862
|
||||||
marrco 126078 9356740
|
spams 157128 10319326
|
||||||
sqrt2 125830 9724586
|
marrco 149947 9376421
|
||||||
robal 122873 9593418
|
sqrt2 147963 9724586
|
||||||
vdbergh 120766 8926915
|
vdbergh 137041 8926915
|
||||||
malala 115926 8002293
|
CoffeeOne 136294 5004100
|
||||||
CoffeeOne 114241 5004100
|
malala 136182 8002293
|
||||||
dsmith 113189 7570238
|
mhoram 128934 8177193
|
||||||
BrunoBanani 104644 7436849
|
davar 122092 7960001
|
||||||
Data 92328 8220352
|
dsmith 122059 7570238
|
||||||
mhoram 89333 6695109
|
xoto 119696 8222144
|
||||||
davar 87924 7009424
|
grandphish2 116481 7582197
|
||||||
xoto 81094 6869316
|
Data 113305 8220352
|
||||||
ElbertoOne 80899 7023771
|
BrunoBanani 112960 7436849
|
||||||
grandphish2 78067 6160199
|
ElbertoOne 99028 7023771
|
||||||
brabos 77212 6186135
|
MaZePallas 98571 6362619
|
||||||
psk 75733 5984901
|
brabos 92118 6186135
|
||||||
BRAVONE 73875 5054681
|
psk 89957 5984901
|
||||||
sunu 70771 5597972
|
sunu 88463 6007033
|
||||||
sterni1971 70605 5590573
|
sterni1971 86948 5613788
|
||||||
MaZePallas 66886 5188978
|
Vizvezdenec 83752 5343724
|
||||||
Vizvezdenec 63708 4967313
|
BRAVONE 81239 5054681
|
||||||
nssy 63462 5259388
|
nssy 76497 5259388
|
||||||
jromang 61634 4940891
|
teddybaer 75125 5407666
|
||||||
teddybaer 61231 5407666
|
Pking_cda 73776 5293873
|
||||||
Pking_cda 60099 5293873
|
jromang 70695 4940891
|
||||||
solarlight 57469 5028306
|
solarlight 70517 5028306
|
||||||
dv8silencer 56913 3883992
|
dv8silencer 70287 3883992
|
||||||
tinker 54936 4086118
|
Bobo1239 68515 4652287
|
||||||
renouve 49732 3501516
|
racerschmacer 67468 4935996
|
||||||
Freja 49543 3733019
|
manap 66273 4121774
|
||||||
robnjr 46972 4053117
|
tinker 63458 4213726
|
||||||
rap 46563 3219146
|
linrock 59082 4516053
|
||||||
Bobo1239 46036 3817196
|
robnjr 57262 4053117
|
||||||
ttruscott 45304 3649765
|
Freja 56938 3733019
|
||||||
racerschmacer 44881 3975413
|
ttruscott 56005 3679485
|
||||||
finfish 44764 3370515
|
renouve 53811 3501516
|
||||||
eva42 41783 3599691
|
cuistot 52532 3014920
|
||||||
biffhero 40263 3111352
|
finfish 51360 3370515
|
||||||
bigpen0r 39817 3291647
|
eva42 51272 3599691
|
||||||
mhunt 38871 2691355
|
rkl 50759 3840947
|
||||||
ronaldjerum 38820 3240695
|
rap 49985 3219146
|
||||||
Antihistamine 38785 2761312
|
pb00067 49727 3298270
|
||||||
pb00067 38038 3086320
|
ronaldjerum 47654 3240695
|
||||||
speedycpu 37591 3003273
|
bigpen0r 47278 3291647
|
||||||
rkl 37207 3289580
|
biffhero 46564 3111352
|
||||||
VoyagerOne 37050 3441673
|
VoyagerOne 45386 3445881
|
||||||
jbwiebe 35320 2805433
|
speedycpu 43842 3003273
|
||||||
cuistot 34191 2146279
|
jbwiebe 43305 2805433
|
||||||
homyur 33927 2850481
|
Antihistamine 41788 2761312
|
||||||
manap 32873 2327384
|
mhunt 41735 2691355
|
||||||
gri 32538 2515779
|
eastorwest 40387 2812173
|
||||||
oryx 31267 2899051
|
homyur 39893 2850481
|
||||||
EthanOConnor 30959 2090311
|
gri 39871 2515779
|
||||||
SC 30832 2730764
|
oryx 38228 2941656
|
||||||
csnodgrass 29505 2688994
|
0x3C33 37773 2529097
|
||||||
jmdana 29458 2205261
|
SC 37290 2731014
|
||||||
strelock 28219 2067805
|
csnodgrass 36207 2688994
|
||||||
jkiiski 27832 1904470
|
jmdana 36108 2205261
|
||||||
Pyafue 27533 1902349
|
strelock 34716 2074055
|
||||||
Garf 27515 2747562
|
Garf 33800 2747562
|
||||||
eastorwest 27421 2317535
|
EthanOConnor 33370 2090311
|
||||||
slakovv 26903 2021889
|
slakovv 32915 2021889
|
||||||
Prcuvu 24835 2170122
|
Spprtr 32591 2139601
|
||||||
anst 24714 2190091
|
Prcuvu 30377 2170122
|
||||||
hyperbolic.tom 24319 2017394
|
anst 30301 2190091
|
||||||
Patrick_G 23687 1801617
|
jkiiski 30136 1904470
|
||||||
Sharaf_DG 22896 1786697
|
hyperbolic.tom 29840 2017394
|
||||||
nabildanial 22195 1519409
|
Pyafue 29650 1902349
|
||||||
chriswk 21931 1868317
|
OuaisBla 27629 1578000
|
||||||
achambord 21665 1767323
|
chriswk 26902 1868317
|
||||||
Zirie 20887 1472937
|
achambord 26582 1767323
|
||||||
team-oh 20217 1636708
|
Patrick_G 26276 1801617
|
||||||
Isidor 20096 1680691
|
yorkman 26193 1992080
|
||||||
ncfish1 19931 1520927
|
SFTUser 25182 1675689
|
||||||
nesoneg 19875 1463031
|
nabildanial 24942 1519409
|
||||||
Spprtr 19853 1548165
|
Sharaf_DG 24765 1786697
|
||||||
JanErik 19849 1703875
|
ncfish1 24411 1520927
|
||||||
agg177 19478 1395014
|
agg177 23890 1395014
|
||||||
SFTUser 19231 1567999
|
JanErik 23408 1703875
|
||||||
xor12 19017 1680165
|
Isidor 23388 1680691
|
||||||
sg4032 18431 1641865
|
Norabor 22976 1587862
|
||||||
rstoesser 18118 1293588
|
cisco2015 22880 1759669
|
||||||
MazeOfGalious 17917 1629593
|
Zirie 22542 1472937
|
||||||
j3corre 17743 941444
|
team-oh 22272 1636708
|
||||||
cisco2015 17725 1690126
|
MazeOfGalious 21978 1629593
|
||||||
ianh2105 17706 1632562
|
sg4032 21945 1643065
|
||||||
dex 17678 1467203
|
ianh2105 21725 1632562
|
||||||
jundery 17194 1115855
|
xor12 21628 1680365
|
||||||
iisiraider 17019 1101015
|
dex 21612 1467203
|
||||||
horst.prack 17012 1465656
|
nesoneg 21494 1463031
|
||||||
Adrian.Schmidt123 16563 1281436
|
horst.prack 20878 1465656
|
||||||
purplefishies 16342 1092533
|
0xB00B1ES 20590 1208666
|
||||||
wei 16274 1745989
|
j3corre 20405 941444
|
||||||
ville 16144 1384026
|
Adrian.Schmidt123 20316 1281436
|
||||||
eudhan 15712 1283717
|
wei 19973 1745989
|
||||||
OuaisBla 15581 972000
|
rstoesser 19569 1293588
|
||||||
DragonLord 15559 1162790
|
eudhan 19274 1283717
|
||||||
dju 14716 875569
|
Ente 19070 1373058
|
||||||
chris 14479 1487385
|
jundery 18445 1115855
|
||||||
0xB00B1ES 14079 1001120
|
iisiraider 18247 1101015
|
||||||
OssumOpossum 13776 1007129
|
ville 17883 1384026
|
||||||
enedene 13460 905279
|
chris 17698 1487385
|
||||||
bpfliegel 13346 884523
|
purplefishies 17595 1092533
|
||||||
Ente 13198 1156722
|
DragonLord 17014 1162790
|
||||||
IgorLeMasson 13087 1147232
|
dju 16515 929427
|
||||||
jpulman 13000 870599
|
IgorLeMasson 16064 1147232
|
||||||
ako027ako 12775 1173203
|
ako027ako 15671 1173203
|
||||||
Nikolay.IT 12352 1068349
|
Nikolay.IT 15154 1068349
|
||||||
Andrew Grant 12327 895539
|
Andrew Grant 15114 895539
|
||||||
joster 12008 950160
|
yurikvelo 15027 1165616
|
||||||
AdrianSA 11996 804972
|
OssumOpossum 14857 1007129
|
||||||
Nesa92 11455 1111993
|
enedene 14476 905279
|
||||||
fatmurphy 11345 853210
|
bpfliegel 14298 884523
|
||||||
Dark_wizzie 11108 1007152
|
jpulman 13982 870599
|
||||||
modolief 10869 896470
|
joster 13794 950160
|
||||||
mschmidt 10757 803401
|
Nesa92 13786 1114691
|
||||||
infinity 10594 727027
|
Dark_wizzie 13422 1007152
|
||||||
mabichito 10524 749391
|
Hjax 13350 900887
|
||||||
Thomas A. Anderson 10474 732094
|
Fifis 13313 965473
|
||||||
thijsk 10431 719357
|
mabichito 12903 749391
|
||||||
Flopzee 10339 894821
|
thijsk 12886 722107
|
||||||
crocogoat 10104 1013854
|
crocogoat 12876 1048802
|
||||||
SapphireBrand 10104 969604
|
AdrianSA 12860 804972
|
||||||
stocky 10017 699440
|
Flopzee 12698 894821
|
||||||
|
fatmurphy 12547 853210
|
||||||
|
SapphireBrand 12416 969604
|
||||||
|
modolief 12386 896470
|
||||||
|
scuzzi 12362 833465
|
||||||
|
pgontarz 12151 848794
|
||||||
|
stocky 11954 699440
|
||||||
|
mschmidt 11941 803401
|
||||||
|
infinity 11470 727027
|
||||||
|
torbjo 11387 728873
|
||||||
|
Thomas A. Anderson 11372 732094
|
||||||
|
snicolet 11106 869170
|
||||||
|
amicic 10779 733593
|
||||||
|
rpngn 10712 688203
|
||||||
|
d64 10680 771144
|
||||||
|
basepi 10637 744851
|
||||||
|
jjoshua2 10559 670905
|
||||||
|
dzjp 10343 732529
|
||||||
|
ols 10259 570669
|
||||||
|
lbraesch 10252 647825
|
||||||
|
|||||||
+24
-7
@@ -4,10 +4,9 @@ clone_depth: 50
|
|||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- appveyor
|
|
||||||
|
|
||||||
# Operating system (build VM template)
|
# Operating system (build VM template)
|
||||||
os: Visual Studio 2017
|
os: Visual Studio 2019
|
||||||
|
|
||||||
# Build platform, i.e. x86, x64, AnyCPU. This setting is optional.
|
# Build platform, i.e. x86, x64, AnyCPU. This setting is optional.
|
||||||
platform:
|
platform:
|
||||||
@@ -36,8 +35,11 @@ before_build:
|
|||||||
$src = $src.Replace("\", "/")
|
$src = $src.Replace("\", "/")
|
||||||
|
|
||||||
# Build CMakeLists.txt
|
# Build CMakeLists.txt
|
||||||
$t = 'cmake_minimum_required(VERSION 3.8)',
|
$t = 'cmake_minimum_required(VERSION 3.17)',
|
||||||
'project(Stockfish)',
|
'project(Stockfish)',
|
||||||
|
'set(CMAKE_CXX_STANDARD 17)',
|
||||||
|
'set(CMAKE_CXX_STANDARD_REQUIRED ON)',
|
||||||
|
'set (CMAKE_CXX_EXTENSIONS OFF)',
|
||||||
'set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/src)',
|
'set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/src)',
|
||||||
'set(source_files', $src, ')',
|
'set(source_files', $src, ')',
|
||||||
'add_executable(stockfish ${source_files})'
|
'add_executable(stockfish ${source_files})'
|
||||||
@@ -51,13 +53,28 @@ before_build:
|
|||||||
$b = git log HEAD | sls "\b[Bb]ench[ :]+[0-9]{7}" | select -first 1
|
$b = git log HEAD | sls "\b[Bb]ench[ :]+[0-9]{7}" | select -first 1
|
||||||
$bench = $b -match '\D+(\d+)' | % { $matches[1] }
|
$bench = $b -match '\D+(\d+)' | % { $matches[1] }
|
||||||
Write-Host "Reference bench:" $bench
|
Write-Host "Reference bench:" $bench
|
||||||
$g = "Visual Studio 15 2017"
|
$g = "Visual Studio 16 2019"
|
||||||
If (${env:PLATFORM} -eq 'x64') { $g = $g + ' Win64' }
|
If (${env:PLATFORM} -eq 'x64') { $a = "x64" }
|
||||||
cmake -G "${g}" .
|
If (${env:PLATFORM} -eq 'x86') { $a = "Win32" }
|
||||||
Write-Host "Generated files for: " $g
|
cmake -G "${g}" -A ${a} .
|
||||||
|
Write-Host "Generated files for: " $g $a
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- cmake --build . --config %CONFIGURATION% -- /verbosity:minimal
|
- cmake --build . --config %CONFIGURATION% -- /verbosity:minimal
|
||||||
|
- ps: |
|
||||||
|
# Download default NNUE net from fishtest
|
||||||
|
$nnuenet = Get-Content -Path src\evaluate.h | Select-String -CaseSensitive -Pattern "EvalFileDefaultName" | Select-String -CaseSensitive -Pattern "nn-[a-z0-9]{12}.nnue"
|
||||||
|
$dummy = $nnuenet -match "(?<nnuenet>nn-[a-z0-9]{12}.nnue)"
|
||||||
|
$nnuenet = $Matches.nnuenet
|
||||||
|
Write-Host "Default net:" $nnuenet
|
||||||
|
$nnuedownloadurl = "https://tests.stockfishchess.org/api/nn/$nnuenet"
|
||||||
|
$nnuefilepath = "src\${env:CONFIGURATION}\$nnuenet"
|
||||||
|
if (Test-Path -Path $nnuefilepath) {
|
||||||
|
Write-Host "Already available."
|
||||||
|
} else {
|
||||||
|
Write-Host "Downloading $nnuedownloadurl to $nnuefilepath"
|
||||||
|
Invoke-WebRequest -Uri $nnuedownloadurl -OutFile $nnuefilepath
|
||||||
|
}
|
||||||
|
|
||||||
before_test:
|
before_test:
|
||||||
- cd src/%CONFIGURATION%
|
- cd src/%CONFIGURATION%
|
||||||
|
|||||||
+418
-80
@@ -38,11 +38,12 @@ PGOBENCH = ./$(EXE) bench
|
|||||||
### Source and object files
|
### Source and object files
|
||||||
SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp \
|
SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp \
|
||||||
material.cpp misc.cpp movegen.cpp movepick.cpp pawns.cpp position.cpp psqt.cpp \
|
material.cpp misc.cpp movegen.cpp movepick.cpp pawns.cpp position.cpp psqt.cpp \
|
||||||
search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp
|
search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp \
|
||||||
|
nnue/evaluate_nnue.cpp nnue/features/half_kp.cpp
|
||||||
|
|
||||||
OBJS = $(notdir $(SRCS:.cpp=.o))
|
OBJS = $(notdir $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
VPATH = syzygy
|
VPATH = syzygy:nnue:nnue/features
|
||||||
|
|
||||||
### Establish the operating system name
|
### Establish the operating system name
|
||||||
KERNEL = $(shell uname -s)
|
KERNEL = $(shell uname -s)
|
||||||
@@ -66,76 +67,215 @@ endif
|
|||||||
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
||||||
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
|
# prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
|
||||||
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
|
# popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
|
||||||
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
|
||||||
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
# pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
|
||||||
|
# sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
|
||||||
|
# mmx = yes/no --- -mmmx --- Use Intel MMX instructions
|
||||||
|
# sse2 = yes/no --- -msse2 --- Use Intel Streaming SIMD Extensions 2
|
||||||
|
# ssse3 = yes/no --- -mssse3 --- Use Intel Supplemental Streaming SIMD Extensions 3
|
||||||
|
# sse41 = yes/no --- -msse4.1 --- Use Intel Streaming SIMD Extensions 4.1
|
||||||
|
# avx2 = yes/no --- -mavx2 --- Use Intel Advanced Vector Extensions 2
|
||||||
|
# avx512 = yes/no --- -mavx512bw --- Use Intel Advanced Vector Extensions 512
|
||||||
|
# vnni256 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 256
|
||||||
|
# vnni512 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 512
|
||||||
|
# neon = yes/no --- -DUSE_NEON --- Use ARM SIMD architecture
|
||||||
#
|
#
|
||||||
# Note that Makefile is space sensitive, so when adding new architectures
|
# Note that Makefile is space sensitive, so when adding new architectures
|
||||||
# or modifying existing flags, you have to make sure there are no extra spaces
|
# or modifying existing flags, you have to make sure there are no extra spaces
|
||||||
# at the end of the line for flag values.
|
# at the end of the line for flag values.
|
||||||
|
|
||||||
### 2.1. General and architecture defaults
|
### 2.1. General and architecture defaults
|
||||||
|
|
||||||
|
ifeq ($(ARCH),)
|
||||||
|
ARCH = x86-64-modern
|
||||||
|
help_skip_sanity = yes
|
||||||
|
endif
|
||||||
|
# explicitly check for the list of supported architectures (as listed with make help),
|
||||||
|
# the user can override with `make ARCH=x86-32-vnni256 SUPPORTED_ARCH=true`
|
||||||
|
ifeq ($(ARCH), $(filter $(ARCH), \
|
||||||
|
x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-bmi2 x86-64-avx2 \
|
||||||
|
x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
|
||||||
|
x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 \
|
||||||
|
armv7 armv7-neon armv8 apple-silicon general-64 general-32))
|
||||||
|
SUPPORTED_ARCH=true
|
||||||
|
else
|
||||||
|
SUPPORTED_ARCH=false
|
||||||
|
endif
|
||||||
|
|
||||||
optimize = yes
|
optimize = yes
|
||||||
debug = no
|
debug = no
|
||||||
sanitize = no
|
sanitize = no
|
||||||
bits = 64
|
bits = 64
|
||||||
prefetch = no
|
prefetch = no
|
||||||
popcnt = no
|
popcnt = no
|
||||||
sse = no
|
|
||||||
pext = no
|
pext = no
|
||||||
|
sse = no
|
||||||
|
mmx = no
|
||||||
|
sse2 = no
|
||||||
|
ssse3 = no
|
||||||
|
sse41 = no
|
||||||
|
avx2 = no
|
||||||
|
avx512 = no
|
||||||
|
vnni256 = no
|
||||||
|
vnni512 = no
|
||||||
|
neon = no
|
||||||
|
STRIP = strip
|
||||||
|
|
||||||
### 2.2 Architecture specific
|
### 2.2 Architecture specific
|
||||||
|
|
||||||
|
ifeq ($(findstring x86,$(ARCH)),x86)
|
||||||
|
|
||||||
|
# x86-32/64
|
||||||
|
|
||||||
|
ifeq ($(findstring x86-32,$(ARCH)),x86-32)
|
||||||
|
arch = i386
|
||||||
|
bits = 32
|
||||||
|
sse = yes
|
||||||
|
mmx = yes
|
||||||
|
else
|
||||||
|
arch = x86_64
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -sse,$(ARCH)),-sse)
|
||||||
|
sse = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -popcnt,$(ARCH)),-popcnt)
|
||||||
|
popcnt = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -mmx,$(ARCH)),-mmx)
|
||||||
|
mmx = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -sse2,$(ARCH)),-sse2)
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -ssse3,$(ARCH)),-ssse3)
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -sse41,$(ARCH)),-sse41)
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
sse41 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -modern,$(ARCH)),-modern)
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
sse41 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -avx2,$(ARCH)),-avx2)
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
sse41 = yes
|
||||||
|
avx2 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -bmi2,$(ARCH)),-bmi2)
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
sse41 = yes
|
||||||
|
avx2 = yes
|
||||||
|
pext = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -avx512,$(ARCH)),-avx512)
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
sse41 = yes
|
||||||
|
avx2 = yes
|
||||||
|
pext = yes
|
||||||
|
avx512 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -vnni256,$(ARCH)),-vnni256)
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
sse41 = yes
|
||||||
|
avx2 = yes
|
||||||
|
pext = yes
|
||||||
|
vnni256 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring -vnni512,$(ARCH)),-vnni512)
|
||||||
|
popcnt = yes
|
||||||
|
sse = yes
|
||||||
|
sse2 = yes
|
||||||
|
ssse3 = yes
|
||||||
|
sse41 = yes
|
||||||
|
avx2 = yes
|
||||||
|
pext = yes
|
||||||
|
avx512 = yes
|
||||||
|
vnni512 = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(sse),yes)
|
||||||
|
prefetch = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
# 64-bit pext is not available on x86-32
|
||||||
|
ifeq ($(bits),32)
|
||||||
|
pext = no
|
||||||
|
endif
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
# all other architectures
|
||||||
|
|
||||||
ifeq ($(ARCH),general-32)
|
ifeq ($(ARCH),general-32)
|
||||||
arch = any
|
arch = any
|
||||||
bits = 32
|
bits = 32
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-32-old)
|
|
||||||
arch = i386
|
|
||||||
bits = 32
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-32)
|
|
||||||
arch = i386
|
|
||||||
bits = 32
|
|
||||||
prefetch = yes
|
|
||||||
sse = yes
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),general-64)
|
ifeq ($(ARCH),general-64)
|
||||||
arch = any
|
arch = any
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-64)
|
|
||||||
arch = x86_64
|
|
||||||
prefetch = yes
|
|
||||||
sse = yes
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-64-modern)
|
|
||||||
arch = x86_64
|
|
||||||
prefetch = yes
|
|
||||||
popcnt = yes
|
|
||||||
sse = yes
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),x86-64-bmi2)
|
|
||||||
arch = x86_64
|
|
||||||
prefetch = yes
|
|
||||||
popcnt = yes
|
|
||||||
sse = yes
|
|
||||||
pext = yes
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),armv7)
|
ifeq ($(ARCH),armv7)
|
||||||
arch = armv7
|
arch = armv7
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
bits = 32
|
bits = 32
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),armv8)
|
ifeq ($(ARCH),armv7-neon)
|
||||||
arch = armv8-a
|
arch = armv7
|
||||||
prefetch = yes
|
prefetch = yes
|
||||||
popcnt = yes
|
popcnt = yes
|
||||||
|
neon = yes
|
||||||
|
bits = 32
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),armv8)
|
||||||
|
arch = armv8
|
||||||
|
prefetch = yes
|
||||||
|
popcnt = yes
|
||||||
|
neon = yes
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ARCH),apple-silicon)
|
||||||
|
arch = arm64
|
||||||
|
prefetch = yes
|
||||||
|
popcnt = yes
|
||||||
|
neon = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),ppc-32)
|
ifeq ($(ARCH),ppc-32)
|
||||||
@@ -149,13 +289,15 @@ ifeq ($(ARCH),ppc-64)
|
|||||||
prefetch = yes
|
prefetch = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 3. Low-level Configuration
|
### Section 3. Low-level Configuration
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
### 3.1 Selecting compiler (default = gcc)
|
### 3.1 Selecting compiler (default = gcc)
|
||||||
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
|
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
|
||||||
DEPENDFLAGS += -std=c++11
|
DEPENDFLAGS += -std=c++17
|
||||||
LDFLAGS += $(EXTRALDFLAGS)
|
LDFLAGS += $(EXTRALDFLAGS)
|
||||||
|
|
||||||
ifeq ($(COMP),)
|
ifeq ($(COMP),)
|
||||||
@@ -167,7 +309,7 @@ ifeq ($(COMP),gcc)
|
|||||||
CXX=g++
|
CXX=g++
|
||||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||||
|
|
||||||
ifeq ($(ARCH),$(filter $(ARCH),armv7 armv8))
|
ifeq ($(arch),$(filter $(arch),armv7 armv8))
|
||||||
ifeq ($(OS),Android)
|
ifeq ($(OS),Android)
|
||||||
CXXFLAGS += -m$(bits)
|
CXXFLAGS += -m$(bits)
|
||||||
LDFLAGS += -m$(bits)
|
LDFLAGS += -m$(bits)
|
||||||
@@ -177,6 +319,10 @@ ifeq ($(COMP),gcc)
|
|||||||
LDFLAGS += -m$(bits)
|
LDFLAGS += -m$(bits)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(arch),$(filter $(arch),armv7))
|
||||||
|
LDFLAGS += -latomic
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq ($(KERNEL),Darwin)
|
ifneq ($(KERNEL),Darwin)
|
||||||
LDFLAGS += -Wl,--no-as-needed
|
LDFLAGS += -Wl,--no-as-needed
|
||||||
endif
|
endif
|
||||||
@@ -224,7 +370,7 @@ ifeq ($(COMP),clang)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ARCH),$(filter $(ARCH),armv7 armv8))
|
ifeq ($(arch),$(filter $(arch),armv7 armv8))
|
||||||
ifeq ($(OS),Android)
|
ifeq ($(OS),Android)
|
||||||
CXXFLAGS += -m$(bits)
|
CXXFLAGS += -m$(bits)
|
||||||
LDFLAGS += -m$(bits)
|
LDFLAGS += -m$(bits)
|
||||||
@@ -249,8 +395,28 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(KERNEL),Darwin)
|
||||||
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.14
|
||||||
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
|
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.14
|
||||||
|
XCRUN = xcrun
|
||||||
|
endif
|
||||||
|
|
||||||
|
# To cross-compile for Android, NDK version r21 or later is recommended.
|
||||||
|
# In earlier NDK versions, you'll need to pass -fno-addrsig if using GNU binutils.
|
||||||
|
# Currently we don't know how to make PGO builds with the NDK yet.
|
||||||
|
ifeq ($(COMP),ndk)
|
||||||
|
CXXFLAGS += -stdlib=libc++ -fPIE
|
||||||
|
ifeq ($(arch),armv7)
|
||||||
|
comp=armv7a-linux-androideabi16-clang
|
||||||
|
CXX=armv7a-linux-androideabi16-clang++
|
||||||
|
CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
|
||||||
|
STRIP=arm-linux-androideabi-strip
|
||||||
|
endif
|
||||||
|
ifeq ($(arch),armv8)
|
||||||
|
comp=aarch64-linux-android21-clang
|
||||||
|
CXX=aarch64-linux-android21-clang++
|
||||||
|
STRIP=aarch64-linux-android-strip
|
||||||
|
endif
|
||||||
|
LDFLAGS += -static-libstdc++ -pie -lm -latomic
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### Travis CI script uses COMPILER to overwrite CXX
|
### Travis CI script uses COMPILER to overwrite CXX
|
||||||
@@ -263,13 +429,26 @@ ifdef COMPCXX
|
|||||||
CXX=$(COMPCXX)
|
CXX=$(COMPCXX)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
### Sometimes gcc is really clang
|
||||||
|
ifeq ($(COMP),gcc)
|
||||||
|
gccversion = $(shell $(CXX) --version)
|
||||||
|
gccisclang = $(findstring clang,$(gccversion))
|
||||||
|
ifneq ($(gccisclang),)
|
||||||
|
profile_make = clang-profile-make
|
||||||
|
profile_use = clang-profile-use
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
### On mingw use Windows threads, otherwise POSIX
|
### On mingw use Windows threads, otherwise POSIX
|
||||||
ifneq ($(comp),mingw)
|
ifneq ($(comp),mingw)
|
||||||
|
CXXFLAGS += -DUSE_PTHREADS
|
||||||
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
# On Android Bionic's C library comes with its own pthread implementation bundled in
|
||||||
ifneq ($(OS),Android)
|
ifneq ($(OS),Android)
|
||||||
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
# Haiku has pthreads in its libroot, so only link it in on other platforms
|
||||||
ifneq ($(KERNEL),Haiku)
|
ifneq ($(KERNEL),Haiku)
|
||||||
LDFLAGS += -lpthread
|
ifneq ($(COMP),ndk)
|
||||||
|
LDFLAGS += -lpthread
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -283,8 +462,8 @@ endif
|
|||||||
|
|
||||||
### 3.2.2 Debugging with undefined behavior sanitizers
|
### 3.2.2 Debugging with undefined behavior sanitizers
|
||||||
ifneq ($(sanitize),no)
|
ifneq ($(sanitize),no)
|
||||||
CXXFLAGS += -g3 -fsanitize=$(sanitize) -fuse-ld=gold
|
CXXFLAGS += -g3 -fsanitize=$(sanitize)
|
||||||
LDFLAGS += -fsanitize=$(sanitize) -fuse-ld=gold
|
LDFLAGS += -fsanitize=$(sanitize)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.3 Optimization
|
### 3.3 Optimization
|
||||||
@@ -314,7 +493,6 @@ endif
|
|||||||
ifeq ($(prefetch),yes)
|
ifeq ($(prefetch),yes)
|
||||||
ifeq ($(sse),yes)
|
ifeq ($(sse),yes)
|
||||||
CXXFLAGS += -msse
|
CXXFLAGS += -msse
|
||||||
DEPENDFLAGS += -msse
|
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
CXXFLAGS += -DNO_PREFETCH
|
CXXFLAGS += -DNO_PREFETCH
|
||||||
@@ -322,7 +500,7 @@ endif
|
|||||||
|
|
||||||
### 3.6 popcnt
|
### 3.6 popcnt
|
||||||
ifeq ($(popcnt),yes)
|
ifeq ($(popcnt),yes)
|
||||||
ifeq ($(arch),$(filter $(arch),ppc64 armv8-a))
|
ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
|
||||||
CXXFLAGS += -DUSE_POPCNT
|
CXXFLAGS += -DUSE_POPCNT
|
||||||
else ifeq ($(comp),icc)
|
else ifeq ($(comp),icc)
|
||||||
CXXFLAGS += -msse3 -DUSE_POPCNT
|
CXXFLAGS += -msse3 -DUSE_POPCNT
|
||||||
@@ -331,11 +509,79 @@ ifeq ($(popcnt),yes)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
ifeq ($(avx2),yes)
|
||||||
|
CXXFLAGS += -DUSE_AVX2
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -mavx2
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(avx512),yes)
|
||||||
|
CXXFLAGS += -DUSE_AVX512
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -mavx512f -mavx512bw
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(vnni256),yes)
|
||||||
|
CXXFLAGS += -DUSE_VNNI
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=256
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(vnni512),yes)
|
||||||
|
CXXFLAGS += -DUSE_VNNI
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -mavx512vnni -mavx512dq -mavx512vl
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(sse41),yes)
|
||||||
|
CXXFLAGS += -DUSE_SSE41
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -msse4.1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ssse3),yes)
|
||||||
|
CXXFLAGS += -DUSE_SSSE3
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -mssse3
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(sse2),yes)
|
||||||
|
CXXFLAGS += -DUSE_SSE2
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -msse2
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(mmx),yes)
|
||||||
|
CXXFLAGS += -DUSE_MMX
|
||||||
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
|
CXXFLAGS += -mmmx
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(neon),yes)
|
||||||
|
CXXFLAGS += -DUSE_NEON
|
||||||
|
ifeq ($(KERNEL),Linux)
|
||||||
|
ifneq ($(COMP),ndk)
|
||||||
|
ifneq ($(arch),armv8)
|
||||||
|
CXXFLAGS += -mfpu=neon
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
### 3.7 pext
|
### 3.7 pext
|
||||||
ifeq ($(pext),yes)
|
ifeq ($(pext),yes)
|
||||||
CXXFLAGS += -DUSE_PEXT
|
CXXFLAGS += -DUSE_PEXT
|
||||||
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||||
CXXFLAGS += -msse4 -mbmi2
|
CXXFLAGS += -mbmi2
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -344,18 +590,43 @@ endif
|
|||||||
### needs access to the optimization flags.
|
### needs access to the optimization flags.
|
||||||
ifeq ($(optimize),yes)
|
ifeq ($(optimize),yes)
|
||||||
ifeq ($(debug), no)
|
ifeq ($(debug), no)
|
||||||
ifeq ($(comp),$(filter $(comp),gcc clang))
|
ifeq ($(COMP),ndk)
|
||||||
|
CXXFLAGS += -flto=thin
|
||||||
|
LDFLAGS += $(CXXFLAGS)
|
||||||
|
else ifeq ($(comp),clang)
|
||||||
|
CXXFLAGS += -flto=thin
|
||||||
|
ifneq ($(findstring MINGW,$(KERNEL)),)
|
||||||
|
CXXFLAGS += -fuse-ld=lld
|
||||||
|
else ifneq ($(findstring MSYS,$(KERNEL)),)
|
||||||
|
CXXFLAGS += -fuse-ld=lld
|
||||||
|
endif
|
||||||
|
LDFLAGS += $(CXXFLAGS)
|
||||||
|
|
||||||
|
# GCC and CLANG use different methods for parallelizing LTO and CLANG pretends to be
|
||||||
|
# GCC on some systems.
|
||||||
|
else ifeq ($(comp),gcc)
|
||||||
|
ifeq ($(gccisclang),)
|
||||||
CXXFLAGS += -flto
|
CXXFLAGS += -flto
|
||||||
|
LDFLAGS += $(CXXFLAGS) -flto=jobserver
|
||||||
|
ifneq ($(findstring MINGW,$(KERNEL)),)
|
||||||
|
LDFLAGS += -save-temps
|
||||||
|
else ifneq ($(findstring MSYS,$(KERNEL)),)
|
||||||
|
LDFLAGS += -save-temps
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
CXXFLAGS += -flto=thin
|
||||||
LDFLAGS += $(CXXFLAGS)
|
LDFLAGS += $(CXXFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# To use LTO and static linking on windows, the tool chain requires a recent gcc:
|
# To use LTO and static linking on windows, the tool chain requires a recent gcc:
|
||||||
# gcc version 10.1 in msys2 or TDM-GCC version 9.2 are know to work, older might not.
|
# gcc version 10.1 in msys2 or TDM-GCC version 9.2 are known to work, older might not.
|
||||||
# So, only enable it for a cross from Linux by default.
|
# So, only enable it for a cross from Linux by default.
|
||||||
ifeq ($(comp),mingw)
|
else ifeq ($(comp),mingw)
|
||||||
ifeq ($(KERNEL),Linux)
|
ifeq ($(KERNEL),Linux)
|
||||||
|
ifneq ($(arch),i386)
|
||||||
CXXFLAGS += -flto
|
CXXFLAGS += -flto
|
||||||
LDFLAGS += $(CXXFLAGS)
|
LDFLAGS += $(CXXFLAGS) -flto=jobserver
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -372,6 +643,7 @@ endif
|
|||||||
### Section 4. Public Targets
|
### Section 4. Public Targets
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
|
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "To compile stockfish, type: "
|
@echo "To compile stockfish, type: "
|
||||||
@@ -380,23 +652,35 @@ help:
|
|||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported targets:"
|
@echo "Supported targets:"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@echo "help > Display architecture details"
|
||||||
@echo "build > Standard build"
|
@echo "build > Standard build"
|
||||||
@echo "profile-build > PGO build"
|
@echo "net > Download the default nnue net"
|
||||||
|
@echo "profile-build > Faster build (with profile-guided optimization)"
|
||||||
@echo "strip > Strip executable"
|
@echo "strip > Strip executable"
|
||||||
@echo "install > Install executable"
|
@echo "install > Install executable"
|
||||||
@echo "clean > Clean up"
|
@echo "clean > Clean up"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Supported archs:"
|
@echo "Supported archs:"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "x86-64-bmi2 > x86 64-bit with pext support (also enables SSE4)"
|
@echo "x86-64-vnni512 > x86 64-bit with vnni support 512bit wide"
|
||||||
@echo "x86-64-modern > x86 64-bit with popcnt support (also enables SSE3)"
|
@echo "x86-64-vnni256 > x86 64-bit with vnni support 256bit wide"
|
||||||
@echo "x86-64 > x86 64-bit generic"
|
@echo "x86-64-avx512 > x86 64-bit with avx512 support"
|
||||||
@echo "x86-32 > x86 32-bit (also enables SSE)"
|
@echo "x86-64-bmi2 > x86 64-bit with bmi2 support"
|
||||||
@echo "x86-32-old > x86 32-bit fall back for old hardware"
|
@echo "x86-64-avx2 > x86 64-bit with avx2 support"
|
||||||
|
@echo "x86-64-sse41-popcnt > x86 64-bit with sse41 and popcnt support"
|
||||||
|
@echo "x86-64-modern > common modern CPU, currently x86-64-sse41-popcnt"
|
||||||
|
@echo "x86-64-ssse3 > x86 64-bit with ssse3 support"
|
||||||
|
@echo "x86-64-sse3-popcnt > x86 64-bit with sse3 and popcnt support"
|
||||||
|
@echo "x86-64 > x86 64-bit generic (with sse2 support)"
|
||||||
|
@echo "x86-32-sse41-popcnt > x86 32-bit with sse41 and popcnt support"
|
||||||
|
@echo "x86-32-sse2 > x86 32-bit with sse2 support"
|
||||||
|
@echo "x86-32 > x86 32-bit generic (with mmx and sse support)"
|
||||||
@echo "ppc-64 > PPC 64-bit"
|
@echo "ppc-64 > PPC 64-bit"
|
||||||
@echo "ppc-32 > PPC 32-bit"
|
@echo "ppc-32 > PPC 32-bit"
|
||||||
@echo "armv7 > ARMv7 32-bit"
|
@echo "armv7 > ARMv7 32-bit"
|
||||||
@echo "armv8 > ARMv8 64-bit"
|
@echo "armv7-neon > ARMv7 32-bit with popcnt and neon"
|
||||||
|
@echo "armv8 > ARMv8 64-bit with popcnt and neon"
|
||||||
|
@echo "apple-silicon > Apple silicon ARM64"
|
||||||
@echo "general-64 > unspecified 64-bit"
|
@echo "general-64 > unspecified 64-bit"
|
||||||
@echo "general-32 > unspecified 32-bit"
|
@echo "general-32 > unspecified 32-bit"
|
||||||
@echo ""
|
@echo ""
|
||||||
@@ -406,27 +690,37 @@ help:
|
|||||||
@echo "mingw > Gnu compiler with MinGW under Windows"
|
@echo "mingw > Gnu compiler with MinGW under Windows"
|
||||||
@echo "clang > LLVM Clang compiler"
|
@echo "clang > LLVM Clang compiler"
|
||||||
@echo "icc > Intel compiler"
|
@echo "icc > Intel compiler"
|
||||||
|
@echo "ndk > Google NDK to cross-compile for Android"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Simple examples. If you don't know what to do, you likely want to run: "
|
@echo "Simple examples. If you don't know what to do, you likely want to run: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make build ARCH=x86-64 (This is for 64-bit systems)"
|
@echo "make -j build ARCH=x86-64 (A portable, slow compile for 64-bit systems)"
|
||||||
@echo "make build ARCH=x86-32 (This is for 32-bit systems)"
|
@echo "make -j build ARCH=x86-32 (A portable, slow compile for 32-bit systems)"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Advanced examples, for experienced users: "
|
@echo "Advanced examples, for experienced users looking for performance: "
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "make build ARCH=x86-64 COMP=clang"
|
@echo "make help ARCH=x86-64-bmi2"
|
||||||
@echo "make profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-4.8"
|
@echo "make -j profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-9.0"
|
||||||
|
@echo "make -j build ARCH=x86-64-ssse3 COMP=clang"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@echo "-------------------------------"
|
||||||
|
ifeq ($(SUPPORTED_ARCH)$(help_skip_sanity), true)
|
||||||
|
@echo "The selected architecture $(ARCH) will enable the following configuration: "
|
||||||
|
@$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
|
||||||
|
else
|
||||||
|
@echo "Specify a supported architecture with the ARCH option for more details"
|
||||||
|
@echo ""
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
.PHONY: help build profile-build strip install clean objclean profileclean \
|
.PHONY: help build profile-build strip install clean net objclean profileclean \
|
||||||
config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
|
config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
|
||||||
clang-profile-use clang-profile-make
|
clang-profile-use clang-profile-make
|
||||||
|
|
||||||
build: config-sanity
|
build: config-sanity net
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
||||||
|
|
||||||
profile-build: config-sanity objclean profileclean
|
profile-build: net config-sanity objclean profileclean
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 1/4. Building instrumented executable ..."
|
@echo "Step 1/4. Building instrumented executable ..."
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
||||||
@@ -442,25 +736,49 @@ profile-build: config-sanity objclean profileclean
|
|||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
|
||||||
|
|
||||||
strip:
|
strip:
|
||||||
strip $(EXE)
|
$(STRIP) $(EXE)
|
||||||
|
|
||||||
install:
|
install:
|
||||||
-mkdir -p -m 755 $(BINDIR)
|
-mkdir -p -m 755 $(BINDIR)
|
||||||
-cp $(EXE) $(BINDIR)
|
-cp $(EXE) $(BINDIR)
|
||||||
-strip $(BINDIR)/$(EXE)
|
-strip $(BINDIR)/$(EXE)
|
||||||
|
|
||||||
#clean all
|
# clean all
|
||||||
clean: objclean profileclean
|
clean: objclean profileclean
|
||||||
@rm -f .depend *~ core
|
@rm -f .depend *~ core
|
||||||
|
|
||||||
|
# evaluation network (nnue)
|
||||||
|
net:
|
||||||
|
$(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
|
||||||
|
@echo "Default net: $(nnuenet)"
|
||||||
|
$(eval nnuedownloadurl := https://tests.stockfishchess.org/api/nn/$(nnuenet))
|
||||||
|
$(eval curl_or_wget := $(shell if hash curl 2>/dev/null; then echo "curl -skL"; elif hash wget 2>/dev/null; then echo "wget -qO-"; fi))
|
||||||
|
@if test -f "$(nnuenet)"; then \
|
||||||
|
echo "Already available."; \
|
||||||
|
else \
|
||||||
|
if [ "x$(curl_or_wget)" = "x" ]; then \
|
||||||
|
echo "Automatic download failed: neither curl nor wget is installed. Install one of these tools or download the net manually"; exit 1; \
|
||||||
|
else \
|
||||||
|
echo "Downloading $(nnuedownloadurl)"; $(curl_or_wget) $(nnuedownloadurl) > $(nnuenet);\
|
||||||
|
fi; \
|
||||||
|
fi;
|
||||||
|
$(eval shasum_command := $(shell if hash shasum 2>/dev/null; then echo "shasum -a 256 "; elif hash sha256sum 2>/dev/null; then echo "sha256sum "; fi))
|
||||||
|
@if [ "x$(shasum_command)" != "x" ]; then \
|
||||||
|
if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
|
||||||
|
echo "Failed download or $(nnuenet) corrupted, please delete!"; exit 1; \
|
||||||
|
fi \
|
||||||
|
else \
|
||||||
|
echo "shasum / sha256sum not found, skipping net validation"; \
|
||||||
|
fi
|
||||||
|
|
||||||
# clean binaries and objects
|
# clean binaries and objects
|
||||||
objclean:
|
objclean:
|
||||||
@rm -f $(EXE) *.o ./syzygy/*.o
|
@rm -f $(EXE) *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
|
||||||
|
|
||||||
# clean auxiliary profiling files
|
# clean auxiliary profiling files
|
||||||
profileclean:
|
profileclean:
|
||||||
@rm -rf profdir
|
@rm -rf profdir
|
||||||
@rm -f bench.txt *.gcda *.gcno
|
@rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda *.s
|
||||||
@rm -f stockfish.profdata *.profraw
|
@rm -f stockfish.profdata *.profraw
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -484,8 +802,17 @@ config-sanity:
|
|||||||
@echo "os: '$(OS)'"
|
@echo "os: '$(OS)'"
|
||||||
@echo "prefetch: '$(prefetch)'"
|
@echo "prefetch: '$(prefetch)'"
|
||||||
@echo "popcnt: '$(popcnt)'"
|
@echo "popcnt: '$(popcnt)'"
|
||||||
@echo "sse: '$(sse)'"
|
|
||||||
@echo "pext: '$(pext)'"
|
@echo "pext: '$(pext)'"
|
||||||
|
@echo "sse: '$(sse)'"
|
||||||
|
@echo "mmx: '$(mmx)'"
|
||||||
|
@echo "sse2: '$(sse2)'"
|
||||||
|
@echo "ssse3: '$(ssse3)'"
|
||||||
|
@echo "sse41: '$(sse41)'"
|
||||||
|
@echo "avx2: '$(avx2)'"
|
||||||
|
@echo "avx512: '$(avx512)'"
|
||||||
|
@echo "vnni256: '$(vnni256)'"
|
||||||
|
@echo "vnni512: '$(vnni512)'"
|
||||||
|
@echo "neon: '$(neon)'"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Flags:"
|
@echo "Flags:"
|
||||||
@echo "CXX: $(CXX)"
|
@echo "CXX: $(CXX)"
|
||||||
@@ -497,18 +824,29 @@ config-sanity:
|
|||||||
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
||||||
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "address" || test "$(sanitize)" = "no"
|
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "address" || test "$(sanitize)" = "no"
|
||||||
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||||
|
@test "$(SUPPORTED_ARCH)" = "true"
|
||||||
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||||
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || \
|
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || \
|
||||||
test "$(arch)" = "armv7" || test "$(arch)" = "armv8-a"
|
test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64"
|
||||||
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
@test "$(bits)" = "32" || test "$(bits)" = "64"
|
||||||
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
|
||||||
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
@test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
|
||||||
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
|
||||||
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
@test "$(pext)" = "yes" || test "$(pext)" = "no"
|
||||||
@test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
|
@test "$(sse)" = "yes" || test "$(sse)" = "no"
|
||||||
|
@test "$(mmx)" = "yes" || test "$(mmx)" = "no"
|
||||||
|
@test "$(sse2)" = "yes" || test "$(sse2)" = "no"
|
||||||
|
@test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
|
||||||
|
@test "$(sse41)" = "yes" || test "$(sse41)" = "no"
|
||||||
|
@test "$(avx2)" = "yes" || test "$(avx2)" = "no"
|
||||||
|
@test "$(avx512)" = "yes" || test "$(avx512)" = "no"
|
||||||
|
@test "$(vnni256)" = "yes" || test "$(vnni256)" = "no"
|
||||||
|
@test "$(vnni512)" = "yes" || test "$(vnni512)" = "no"
|
||||||
|
@test "$(neon)" = "yes" || test "$(neon)" = "no"
|
||||||
|
@test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
|
||||||
|
|| test "$(comp)" = "armv7a-linux-androideabi16-clang" || test "$(comp)" = "aarch64-linux-android21-clang"
|
||||||
|
|
||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
+$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
clang-profile-make:
|
clang-profile-make:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
@@ -517,7 +855,7 @@ clang-profile-make:
|
|||||||
all
|
all
|
||||||
|
|
||||||
clang-profile-use:
|
clang-profile-use:
|
||||||
llvm-profdata merge -output=stockfish.profdata *.profraw
|
$(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
|
EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
|
||||||
EXTRALDFLAGS='-fprofile-use ' \
|
EXTRALDFLAGS='-fprofile-use ' \
|
||||||
|
|||||||
+12
-5
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -97,8 +95,9 @@ const vector<string> Defaults = {
|
|||||||
/// setup_bench() builds a list of UCI commands to be run by bench. There
|
/// setup_bench() builds a list of UCI commands to be run by bench. There
|
||||||
/// are five parameters: TT size in MB, number of search threads that
|
/// are five parameters: TT size in MB, number of search threads that
|
||||||
/// should be used, the limit value spent for each position, a file name
|
/// should be used, the limit value spent for each position, a file name
|
||||||
/// where to look for positions in FEN format and the type of the limit:
|
/// where to look for positions in FEN format, the type of the limit:
|
||||||
/// depth, perft, nodes and movetime (in millisecs).
|
/// depth, perft, nodes and movetime (in millisecs), and evaluation type
|
||||||
|
/// mixed (default), classical, NNUE.
|
||||||
///
|
///
|
||||||
/// bench -> search default positions up to depth 13
|
/// bench -> search default positions up to depth 13
|
||||||
/// bench 64 1 15 -> search default positions up to depth 15 (TT = 64MB)
|
/// bench 64 1 15 -> search default positions up to depth 15 (TT = 64MB)
|
||||||
@@ -117,6 +116,7 @@ vector<string> setup_bench(const Position& current, istream& is) {
|
|||||||
string limit = (is >> token) ? token : "13";
|
string limit = (is >> token) ? token : "13";
|
||||||
string fenFile = (is >> token) ? token : "default";
|
string fenFile = (is >> token) ? token : "default";
|
||||||
string limitType = (is >> token) ? token : "depth";
|
string limitType = (is >> token) ? token : "depth";
|
||||||
|
string evalType = (is >> token) ? token : "mixed";
|
||||||
|
|
||||||
go = limitType == "eval" ? "eval" : "go " + limitType + " " + limit;
|
go = limitType == "eval" ? "eval" : "go " + limitType + " " + limit;
|
||||||
|
|
||||||
@@ -148,13 +148,20 @@ vector<string> setup_bench(const Position& current, istream& is) {
|
|||||||
list.emplace_back("setoption name Hash value " + ttSize);
|
list.emplace_back("setoption name Hash value " + ttSize);
|
||||||
list.emplace_back("ucinewgame");
|
list.emplace_back("ucinewgame");
|
||||||
|
|
||||||
|
size_t posCounter = 0;
|
||||||
|
|
||||||
for (const string& fen : fens)
|
for (const string& fen : fens)
|
||||||
if (fen.find("setoption") != string::npos)
|
if (fen.find("setoption") != string::npos)
|
||||||
list.emplace_back(fen);
|
list.emplace_back(fen);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (evalType == "classical" || (evalType == "mixed" && posCounter % 2 == 0))
|
||||||
|
list.emplace_back("setoption name Use NNUE value false");
|
||||||
|
else if (evalType == "NNUE" || (evalType == "mixed" && posCounter % 2 != 0))
|
||||||
|
list.emplace_back("setoption name Use NNUE value true");
|
||||||
list.emplace_back("position fen " + fen);
|
list.emplace_back("position fen " + fen);
|
||||||
list.emplace_back(go);
|
list.emplace_back(go);
|
||||||
|
++posCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+12
-4
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -41,6 +39,16 @@ namespace {
|
|||||||
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
Bitboard BishopTable[0x1480]; // To store bishop attacks
|
||||||
|
|
||||||
void init_magics(PieceType pt, Bitboard table[], Magic magics[]);
|
void init_magics(PieceType pt, Bitboard table[], Magic magics[]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// safe_destination() returns the bitboard of target square for the given step
|
||||||
|
/// from the given square. If the step is off the board, returns empty bitboard.
|
||||||
|
|
||||||
|
inline Bitboard safe_destination(Square s, int step) {
|
||||||
|
Square to = Square(s + step);
|
||||||
|
return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +120,7 @@ namespace {
|
|||||||
Direction RookDirections[4] = {NORTH, SOUTH, EAST, WEST};
|
Direction RookDirections[4] = {NORTH, SOUTH, EAST, WEST};
|
||||||
Direction BishopDirections[4] = {NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST};
|
Direction BishopDirections[4] = {NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST};
|
||||||
|
|
||||||
for(Direction d : (pt == ROOK ? RookDirections : BishopDirections))
|
for (Direction d : (pt == ROOK ? RookDirections : BishopDirections))
|
||||||
{
|
{
|
||||||
Square s = sq;
|
Square s = sq;
|
||||||
while(safe_destination(s, d) && !(occupied & s))
|
while(safe_destination(s, d) && !(occupied & s))
|
||||||
|
|||||||
+1
-13
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -281,16 +279,6 @@ inline int edge_distance(File f) { return std::min(f, File(FILE_H - f)); }
|
|||||||
inline int edge_distance(Rank r) { return std::min(r, Rank(RANK_8 - r)); }
|
inline int edge_distance(Rank r) { return std::min(r, Rank(RANK_8 - r)); }
|
||||||
|
|
||||||
|
|
||||||
/// safe_destination() returns the bitboard of target square for the given step
|
|
||||||
/// from the given square. If the step is off the board, returns empty bitboard.
|
|
||||||
|
|
||||||
inline Bitboard safe_destination(Square s, int step)
|
|
||||||
{
|
|
||||||
Square to = Square(s + step);
|
|
||||||
return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// attacks_bb(Square) returns the pseudo attacks of the give piece type
|
/// attacks_bb(Square) returns the pseudo attacks of the give piece type
|
||||||
/// assuming an empty board.
|
/// assuming an empty board.
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+171
-33
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,15 +18,130 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstdlib>
|
||||||
#include <cstring> // For std::memset
|
#include <cstring> // For std::memset
|
||||||
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <streambuf>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "evaluate.h"
|
#include "evaluate.h"
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
#include "misc.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#include "uci.h"
|
||||||
|
#include "incbin/incbin.h"
|
||||||
|
|
||||||
|
|
||||||
|
// Macro to embed the default NNUE file data in the engine binary (using incbin.h, by Dale Weiler).
|
||||||
|
// This macro invocation will declare the following three variables
|
||||||
|
// const unsigned char gEmbeddedNNUEData[]; // a pointer to the embedded data
|
||||||
|
// const unsigned char *const gEmbeddedNNUEEnd; // a marker to the end
|
||||||
|
// const unsigned int gEmbeddedNNUESize; // the size of the embedded file
|
||||||
|
// Note that this does not work in Microsof Visual Studio.
|
||||||
|
#if !defined(_MSC_VER) && !defined(NNUE_EMBEDDING_OFF)
|
||||||
|
INCBIN(EmbeddedNNUE, EvalFileDefaultName);
|
||||||
|
#else
|
||||||
|
const unsigned char gEmbeddedNNUEData[1] = {0x0};
|
||||||
|
const unsigned char *const gEmbeddedNNUEEnd = &gEmbeddedNNUEData[1];
|
||||||
|
const unsigned int gEmbeddedNNUESize = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Eval::NNUE;
|
||||||
|
|
||||||
|
namespace Eval {
|
||||||
|
|
||||||
|
bool useNNUE;
|
||||||
|
string eval_file_loaded = "None";
|
||||||
|
|
||||||
|
/// init_NNUE() tries to load a nnue network at startup time, or when the engine
|
||||||
|
/// receives a UCI command "setoption name EvalFile value nn-[a-z0-9]{12}.nnue"
|
||||||
|
/// The name of the nnue network is always retrieved from the EvalFile option.
|
||||||
|
/// We search the given network in three locations: internally (the default
|
||||||
|
/// network may be embedded in the binary), in the active working directory and
|
||||||
|
/// in the engine directory. Distro packagers may define the DEFAULT_NNUE_DIRECTORY
|
||||||
|
/// variable to have the engine search in a special directory in their distro.
|
||||||
|
|
||||||
|
void init_NNUE() {
|
||||||
|
|
||||||
|
useNNUE = Options["Use NNUE"];
|
||||||
|
if (!useNNUE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string eval_file = string(Options["EvalFile"]);
|
||||||
|
|
||||||
|
#if defined(DEFAULT_NNUE_DIRECTORY)
|
||||||
|
#define stringify2(x) #x
|
||||||
|
#define stringify(x) stringify2(x)
|
||||||
|
vector<string> dirs = { "<internal>" , "" , CommandLine::binaryDirectory , stringify(DEFAULT_NNUE_DIRECTORY) };
|
||||||
|
#else
|
||||||
|
vector<string> dirs = { "<internal>" , "" , CommandLine::binaryDirectory };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (string directory : dirs)
|
||||||
|
if (eval_file_loaded != eval_file)
|
||||||
|
{
|
||||||
|
if (directory != "<internal>")
|
||||||
|
{
|
||||||
|
ifstream stream(directory + eval_file, ios::binary);
|
||||||
|
if (load_eval(eval_file, stream))
|
||||||
|
eval_file_loaded = eval_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (directory == "<internal>" && eval_file == EvalFileDefaultName)
|
||||||
|
{
|
||||||
|
// C++ way to prepare a buffer for a memory stream
|
||||||
|
class MemoryBuffer : public basic_streambuf<char> {
|
||||||
|
public: MemoryBuffer(char* p, size_t n) { setg(p, p, p + n); setp(p, p + n); }
|
||||||
|
};
|
||||||
|
|
||||||
|
MemoryBuffer buffer(const_cast<char*>(reinterpret_cast<const char*>(gEmbeddedNNUEData)),
|
||||||
|
size_t(gEmbeddedNNUESize));
|
||||||
|
|
||||||
|
istream stream(&buffer);
|
||||||
|
if (load_eval(eval_file, stream))
|
||||||
|
eval_file_loaded = eval_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// verify_NNUE() verifies that the last net used was loaded successfully
|
||||||
|
void verify_NNUE() {
|
||||||
|
|
||||||
|
string eval_file = string(Options["EvalFile"]);
|
||||||
|
|
||||||
|
if (useNNUE && eval_file_loaded != eval_file)
|
||||||
|
{
|
||||||
|
UCI::OptionsMap defaults;
|
||||||
|
UCI::init(defaults);
|
||||||
|
|
||||||
|
string msg1 = "If the UCI option \"Use NNUE\" is set to true, network evaluation parameters compatible with the engine must be available.";
|
||||||
|
string msg2 = "The option is set to true, but the network file " + eval_file + " was not loaded successfully.";
|
||||||
|
string msg3 = "The UCI option EvalFile might need to specify the full path, including the directory name, to the network file.";
|
||||||
|
string msg4 = "The default net can be downloaded from: https://tests.stockfishchess.org/api/nn/" + string(defaults["EvalFile"]);
|
||||||
|
string msg5 = "The engine will be terminated now.";
|
||||||
|
|
||||||
|
sync_cout << "info string ERROR: " << msg1 << sync_endl;
|
||||||
|
sync_cout << "info string ERROR: " << msg2 << sync_endl;
|
||||||
|
sync_cout << "info string ERROR: " << msg3 << sync_endl;
|
||||||
|
sync_cout << "info string ERROR: " << msg4 << sync_endl;
|
||||||
|
sync_cout << "info string ERROR: " << msg5 << sync_endl;
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useNNUE)
|
||||||
|
sync_cout << "info string NNUE evaluation using " << eval_file << " enabled" << sync_endl;
|
||||||
|
else
|
||||||
|
sync_cout << "info string classical evaluation enabled" << sync_endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace Trace {
|
namespace Trace {
|
||||||
|
|
||||||
@@ -74,9 +187,11 @@ using namespace Trace;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Threshold for lazy and space evaluation
|
// Threshold for lazy and space evaluation
|
||||||
constexpr Value LazyThreshold1 = Value(1400);
|
constexpr Value LazyThreshold1 = Value(1400);
|
||||||
constexpr Value LazyThreshold2 = Value(1300);
|
constexpr Value LazyThreshold2 = Value(1300);
|
||||||
constexpr Value SpaceThreshold = Value(12222);
|
constexpr Value SpaceThreshold = Value(12222);
|
||||||
|
constexpr Value NNUEThreshold1 = Value(550);
|
||||||
|
constexpr Value NNUEThreshold2 = Value(150);
|
||||||
|
|
||||||
// KingAttackWeights[PieceType] contains king attack weights by piece type
|
// KingAttackWeights[PieceType] contains king attack weights by piece type
|
||||||
constexpr int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 81, 52, 44, 10 };
|
constexpr int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 81, 52, 44, 10 };
|
||||||
@@ -112,26 +227,26 @@ namespace {
|
|||||||
|
|
||||||
// Outpost[knight/bishop] contains bonuses for each knight or bishop occupying a
|
// Outpost[knight/bishop] contains bonuses for each knight or bishop occupying a
|
||||||
// pawn protected square on rank 4 to 6 which is also safe from a pawn attack.
|
// pawn protected square on rank 4 to 6 which is also safe from a pawn attack.
|
||||||
constexpr Score Outpost[] = { S(56, 36), S(30, 23) };
|
constexpr Score Outpost[] = { S(56, 34), S(31, 23) };
|
||||||
|
|
||||||
// PassedRank[Rank] contains a bonus according to the rank of a passed pawn
|
// PassedRank[Rank] contains a bonus according to the rank of a passed pawn
|
||||||
constexpr Score PassedRank[RANK_NB] = {
|
constexpr Score PassedRank[RANK_NB] = {
|
||||||
S(0, 0), S(10, 28), S(17, 33), S(15, 41), S(62, 72), S(168, 177), S(276, 260)
|
S(0, 0), S(9, 28), S(15, 31), S(17, 39), S(64, 70), S(171, 177), S(277, 260)
|
||||||
};
|
};
|
||||||
|
|
||||||
// RookOnFile[semiopen/open] contains bonuses for each rook when there is
|
// RookOnFile[semiopen/open] contains bonuses for each rook when there is
|
||||||
// no (friendly) pawn on the rook file.
|
// no (friendly) pawn on the rook file.
|
||||||
constexpr Score RookOnFile[] = { S(19, 7), S(48, 29) };
|
constexpr Score RookOnFile[] = { S(19, 7), S(48, 27) };
|
||||||
|
|
||||||
// ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
|
// ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
|
||||||
// which piece type attacks which one. Attacks on lesser pieces which are
|
// which piece type attacks which one. Attacks on lesser pieces which are
|
||||||
// pawn-defended are not considered.
|
// pawn-defended are not considered.
|
||||||
constexpr Score ThreatByMinor[PIECE_TYPE_NB] = {
|
constexpr Score ThreatByMinor[PIECE_TYPE_NB] = {
|
||||||
S(0, 0), S(5, 32), S(57, 41), S(77, 56), S(88, 119), S(79, 161)
|
S(0, 0), S(5, 32), S(55, 41), S(77, 56), S(89, 119), S(79, 162)
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Score ThreatByRook[PIECE_TYPE_NB] = {
|
constexpr Score ThreatByRook[PIECE_TYPE_NB] = {
|
||||||
S(0, 0), S(3, 46), S(37, 68), S(42, 60), S(0, 38), S(58, 41)
|
S(0, 0), S(3, 44), S(37, 68), S(42, 60), S(0, 39), S(58, 43)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Assorted bonuses and penalties
|
// Assorted bonuses and penalties
|
||||||
@@ -147,7 +262,6 @@ namespace {
|
|||||||
constexpr Score MinorBehindPawn = S( 18, 3);
|
constexpr Score MinorBehindPawn = S( 18, 3);
|
||||||
constexpr Score PassedFile = S( 11, 8);
|
constexpr Score PassedFile = S( 11, 8);
|
||||||
constexpr Score PawnlessFlank = S( 17, 95);
|
constexpr Score PawnlessFlank = S( 17, 95);
|
||||||
constexpr Score QueenInfiltration = S( -2, 14);
|
|
||||||
constexpr Score ReachableOutpost = S( 31, 22);
|
constexpr Score ReachableOutpost = S( 31, 22);
|
||||||
constexpr Score RestrictedPiece = S( 7, 7);
|
constexpr Score RestrictedPiece = S( 7, 7);
|
||||||
constexpr Score RookOnKingRing = S( 16, 0);
|
constexpr Score RookOnKingRing = S( 16, 0);
|
||||||
@@ -249,8 +363,8 @@ namespace {
|
|||||||
attackedBy2[Us] = dblAttackByPawn | (attackedBy[Us][KING] & attackedBy[Us][PAWN]);
|
attackedBy2[Us] = dblAttackByPawn | (attackedBy[Us][KING] & attackedBy[Us][PAWN]);
|
||||||
|
|
||||||
// Init our king safety tables
|
// Init our king safety tables
|
||||||
Square s = make_square(Utility::clamp(file_of(ksq), FILE_B, FILE_G),
|
Square s = make_square(std::clamp(file_of(ksq), FILE_B, FILE_G),
|
||||||
Utility::clamp(rank_of(ksq), RANK_2, RANK_7));
|
std::clamp(rank_of(ksq), RANK_2, RANK_7));
|
||||||
kingRing[Us] = attacks_bb<KING>(s) | s;
|
kingRing[Us] = attacks_bb<KING>(s) | s;
|
||||||
|
|
||||||
kingAttackersCount[Them] = popcount(kingRing[Us] & pe->pawn_attacks(Them));
|
kingAttackersCount[Them] = popcount(kingRing[Us] & pe->pawn_attacks(Them));
|
||||||
@@ -312,7 +426,8 @@ namespace {
|
|||||||
{
|
{
|
||||||
// Bonus if the piece is on an outpost square or can reach one
|
// Bonus if the piece is on an outpost square or can reach one
|
||||||
// Reduced bonus for knights (BadOutpost) if few relevant targets
|
// Reduced bonus for knights (BadOutpost) if few relevant targets
|
||||||
bb = OutpostRanks & attackedBy[Us][PAWN] & ~pe->pawn_attacks_span(Them);
|
bb = OutpostRanks & (attackedBy[Us][PAWN] | shift<Down>(pos.pieces(PAWN)))
|
||||||
|
& ~pe->pawn_attacks_span(Them);
|
||||||
Bitboard targets = pos.pieces(Them) & ~pos.pieces(PAWN);
|
Bitboard targets = pos.pieces(Them) & ~pos.pieces(PAWN);
|
||||||
|
|
||||||
if ( Pt == KNIGHT
|
if ( Pt == KNIGHT
|
||||||
@@ -389,10 +504,6 @@ namespace {
|
|||||||
Bitboard queenPinners;
|
Bitboard queenPinners;
|
||||||
if (pos.slider_blockers(pos.pieces(Them, ROOK, BISHOP), s, queenPinners))
|
if (pos.slider_blockers(pos.pieces(Them, ROOK, BISHOP), s, queenPinners))
|
||||||
score -= WeakQueen;
|
score -= WeakQueen;
|
||||||
|
|
||||||
// Bonus for queen on weak square in enemy camp
|
|
||||||
if (relative_rank(Us, s) > RANK_4 && (~pe->pawn_attacks_span(Them) & s))
|
|
||||||
score += QueenInfiltration;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (T)
|
if (T)
|
||||||
@@ -650,8 +761,8 @@ namespace {
|
|||||||
Square blockSq = s + Up;
|
Square blockSq = s + Up;
|
||||||
|
|
||||||
// Adjust bonus based on the king's proximity
|
// Adjust bonus based on the king's proximity
|
||||||
bonus += make_score(0, ( (king_proximity(Them, blockSq) * 19) / 4
|
bonus += make_score(0, ( king_proximity(Them, blockSq) * 19 / 4
|
||||||
- king_proximity(Us, blockSq) * 2) * w);
|
- king_proximity(Us, blockSq) * 2) * w);
|
||||||
|
|
||||||
// If blockSq is not the queening square then consider also a second push
|
// If blockSq is not the queening square then consider also a second push
|
||||||
if (r != RANK_7)
|
if (r != RANK_7)
|
||||||
@@ -695,7 +806,7 @@ namespace {
|
|||||||
|
|
||||||
|
|
||||||
// Evaluation::space() computes a space evaluation for a given side, aiming to improve game
|
// Evaluation::space() computes a space evaluation for a given side, aiming to improve game
|
||||||
// play in the opening. It is based on the number of safe squares on the 4 central files
|
// play in the opening. It is based on the number of safe squares on the four central files
|
||||||
// on ranks 2 to 4. Completely safe squares behind a friendly pawn are counted twice.
|
// on ranks 2 to 4. Completely safe squares behind a friendly pawn are counted twice.
|
||||||
// Finally, the space bonus is multiplied by a weight which decreases according to occupancy.
|
// Finally, the space bonus is multiplied by a weight which decreases according to occupancy.
|
||||||
|
|
||||||
@@ -768,7 +879,7 @@ namespace {
|
|||||||
// Now apply the bonus: note that we find the attacking side by extracting the
|
// Now apply the bonus: note that we find the attacking side by extracting the
|
||||||
// sign of the midgame or endgame values, and that we carefully cap the bonus
|
// sign of the midgame or endgame values, and that we carefully cap the bonus
|
||||||
// so that the midgame and endgame scores do not change sign after the bonus.
|
// so that the midgame and endgame scores do not change sign after the bonus.
|
||||||
int u = ((mg > 0) - (mg < 0)) * Utility::clamp(complexity + 50, -abs(mg), 0);
|
int u = ((mg > 0) - (mg < 0)) * std::clamp(complexity + 50, -abs(mg), 0);
|
||||||
int v = ((eg > 0) - (eg < 0)) * std::max(complexity, -abs(eg));
|
int v = ((eg > 0) - (eg < 0)) * std::max(complexity, -abs(eg));
|
||||||
|
|
||||||
mg += u;
|
mg += u;
|
||||||
@@ -893,9 +1004,6 @@ make_v:
|
|||||||
// Side to move point of view
|
// Side to move point of view
|
||||||
v = (pos.side_to_move() == WHITE ? v : -v) + Tempo;
|
v = (pos.side_to_move() == WHITE ? v : -v) + Tempo;
|
||||||
|
|
||||||
// Damp down the evaluation linearly when shuffling
|
|
||||||
v = v * (100 - pos.rule50_count()) / 100;
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,28 +1014,45 @@ make_v:
|
|||||||
/// evaluation of the position from the point of view of the side to move.
|
/// evaluation of the position from the point of view of the side to move.
|
||||||
|
|
||||||
Value Eval::evaluate(const Position& pos) {
|
Value Eval::evaluate(const Position& pos) {
|
||||||
return Evaluation<NO_TRACE>(pos).value();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
bool classical = !Eval::useNNUE
|
||||||
|
|| abs(eg_value(pos.psq_score())) * 16 > NNUEThreshold1 * (16 + pos.rule50_count());
|
||||||
|
Value v = classical ? Evaluation<NO_TRACE>(pos).value()
|
||||||
|
: NNUE::evaluate(pos) * 5 / 4 + Tempo;
|
||||||
|
|
||||||
|
if (classical && Eval::useNNUE && abs(v) * 16 < NNUEThreshold2 * (16 + pos.rule50_count()))
|
||||||
|
v = NNUE::evaluate(pos) * 5 / 4 + Tempo;
|
||||||
|
|
||||||
|
// Damp down the evaluation linearly when shuffling
|
||||||
|
v = v * (100 - pos.rule50_count()) / 100;
|
||||||
|
|
||||||
|
// Guarantee evaluation does not hit the tablebase range
|
||||||
|
v = std::clamp(v, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
/// trace() is like evaluate(), but instead of returning a value, it returns
|
/// trace() is like evaluate(), but instead of returning a value, it returns
|
||||||
/// a string (suitable for outputting to stdout) that contains the detailed
|
/// a string (suitable for outputting to stdout) that contains the detailed
|
||||||
/// descriptions and values of each evaluation term. Useful for debugging.
|
/// descriptions and values of each evaluation term. Useful for debugging.
|
||||||
|
/// Trace scores are from white's point of view
|
||||||
|
|
||||||
std::string Eval::trace(const Position& pos) {
|
std::string Eval::trace(const Position& pos) {
|
||||||
|
|
||||||
if (pos.checkers())
|
if (pos.checkers())
|
||||||
return "Total evaluation: none (in check)";
|
return "Final evaluation: none (in check)";
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::showpoint << std::noshowpos << std::fixed << std::setprecision(2);
|
||||||
|
|
||||||
|
Value v;
|
||||||
|
|
||||||
std::memset(scores, 0, sizeof(scores));
|
std::memset(scores, 0, sizeof(scores));
|
||||||
|
|
||||||
pos.this_thread()->contempt = SCORE_ZERO; // Reset any dynamic contempt
|
pos.this_thread()->contempt = SCORE_ZERO; // Reset any dynamic contempt
|
||||||
|
|
||||||
Value v = Evaluation<TRACE>(pos).value();
|
v = Evaluation<TRACE>(pos).value();
|
||||||
|
|
||||||
v = pos.side_to_move() == WHITE ? v : -v; // Trace scores are from white's point of view
|
|
||||||
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << std::showpoint << std::noshowpos << std::fixed << std::setprecision(2)
|
ss << std::showpoint << std::noshowpos << std::fixed << std::setprecision(2)
|
||||||
<< " Term | White | Black | Total \n"
|
<< " Term | White | Black | Total \n"
|
||||||
<< " | MG EG | MG EG | MG EG \n"
|
<< " | MG EG | MG EG | MG EG \n"
|
||||||
@@ -948,7 +1073,20 @@ std::string Eval::trace(const Position& pos) {
|
|||||||
<< " ------------+-------------+-------------+------------\n"
|
<< " ------------+-------------+-------------+------------\n"
|
||||||
<< " Total | " << Term(TOTAL);
|
<< " Total | " << Term(TOTAL);
|
||||||
|
|
||||||
ss << "\nFinal evaluation: " << to_cp(v) << " (white side)\n";
|
v = pos.side_to_move() == WHITE ? v : -v;
|
||||||
|
|
||||||
|
ss << "\nClassical evaluation: " << to_cp(v) << " (white side)\n";
|
||||||
|
|
||||||
|
if (Eval::useNNUE)
|
||||||
|
{
|
||||||
|
v = NNUE::evaluate(pos);
|
||||||
|
v = pos.side_to_move() == WHITE ? v : -v;
|
||||||
|
ss << "\nNNUE evaluation: " << to_cp(v) << " (white side)\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
v = evaluate(pos);
|
||||||
|
v = pos.side_to_move() == WHITE ? v : -v;
|
||||||
|
ss << "\nFinal evaluation: " << to_cp(v) << " (white side)\n";
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-6
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,9 +27,28 @@ class Position;
|
|||||||
|
|
||||||
namespace Eval {
|
namespace Eval {
|
||||||
|
|
||||||
std::string trace(const Position& pos);
|
std::string trace(const Position& pos);
|
||||||
|
Value evaluate(const Position& pos);
|
||||||
|
|
||||||
Value evaluate(const Position& pos);
|
extern bool useNNUE;
|
||||||
}
|
extern std::string eval_file_loaded;
|
||||||
|
void init_NNUE();
|
||||||
|
void verify_NNUE();
|
||||||
|
|
||||||
|
// The default net name MUST follow the format nn-[SHA256 first 12 digits].nnue
|
||||||
|
// for the build process (profile-build and fishtest) to work. Do not change the
|
||||||
|
// name of the macro, as it is used in the Makefile.
|
||||||
|
#define EvalFileDefaultName "nn-82215d0fd0df.nnue"
|
||||||
|
|
||||||
|
namespace NNUE {
|
||||||
|
|
||||||
|
Value evaluate(const Position& pos);
|
||||||
|
Value compute_eval(const Position& pos);
|
||||||
|
void update_eval(const Position& pos);
|
||||||
|
bool load_eval(std::string streamName, std::istream& stream);
|
||||||
|
|
||||||
|
} // namespace NNUE
|
||||||
|
|
||||||
|
} // namespace Eval
|
||||||
|
|
||||||
#endif // #ifndef EVALUATE_H_INCLUDED
|
#endif // #ifndef EVALUATE_H_INCLUDED
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
The file "incbin.h" is free and unencumbered software released into
|
||||||
|
the public domain by Dale Weiler, see:
|
||||||
|
<https://github.com/graphitemaster/incbin>
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org/>
|
||||||
Executable
+368
@@ -0,0 +1,368 @@
|
|||||||
|
/**
|
||||||
|
* @file incbin.h
|
||||||
|
* @author Dale Weiler
|
||||||
|
* @brief Utility for including binary files
|
||||||
|
*
|
||||||
|
* Facilities for including binary files into the current translation unit and
|
||||||
|
* making use from them externally in other translation units.
|
||||||
|
*/
|
||||||
|
#ifndef INCBIN_HDR
|
||||||
|
#define INCBIN_HDR
|
||||||
|
#include <limits.h>
|
||||||
|
#if defined(__AVX512BW__) || \
|
||||||
|
defined(__AVX512CD__) || \
|
||||||
|
defined(__AVX512DQ__) || \
|
||||||
|
defined(__AVX512ER__) || \
|
||||||
|
defined(__AVX512PF__) || \
|
||||||
|
defined(__AVX512VL__) || \
|
||||||
|
defined(__AVX512F__)
|
||||||
|
# define INCBIN_ALIGNMENT_INDEX 6
|
||||||
|
#elif defined(__AVX__) || \
|
||||||
|
defined(__AVX2__)
|
||||||
|
# define INCBIN_ALIGNMENT_INDEX 5
|
||||||
|
#elif defined(__SSE__) || \
|
||||||
|
defined(__SSE2__) || \
|
||||||
|
defined(__SSE3__) || \
|
||||||
|
defined(__SSSE3__) || \
|
||||||
|
defined(__SSE4_1__) || \
|
||||||
|
defined(__SSE4_2__) || \
|
||||||
|
defined(__neon__)
|
||||||
|
# define INCBIN_ALIGNMENT_INDEX 4
|
||||||
|
#elif ULONG_MAX != 0xffffffffu
|
||||||
|
# define INCBIN_ALIGNMENT_INDEX 3
|
||||||
|
# else
|
||||||
|
# define INCBIN_ALIGNMENT_INDEX 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Lookup table of (1 << n) where `n' is `INCBIN_ALIGNMENT_INDEX' */
|
||||||
|
#define INCBIN_ALIGN_SHIFT_0 1
|
||||||
|
#define INCBIN_ALIGN_SHIFT_1 2
|
||||||
|
#define INCBIN_ALIGN_SHIFT_2 4
|
||||||
|
#define INCBIN_ALIGN_SHIFT_3 8
|
||||||
|
#define INCBIN_ALIGN_SHIFT_4 16
|
||||||
|
#define INCBIN_ALIGN_SHIFT_5 32
|
||||||
|
#define INCBIN_ALIGN_SHIFT_6 64
|
||||||
|
|
||||||
|
/* Actual alignment value */
|
||||||
|
#define INCBIN_ALIGNMENT \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
INCBIN_CONCATENATE(INCBIN_ALIGN_SHIFT, _), \
|
||||||
|
INCBIN_ALIGNMENT_INDEX)
|
||||||
|
|
||||||
|
/* Stringize */
|
||||||
|
#define INCBIN_STR(X) \
|
||||||
|
#X
|
||||||
|
#define INCBIN_STRINGIZE(X) \
|
||||||
|
INCBIN_STR(X)
|
||||||
|
/* Concatenate */
|
||||||
|
#define INCBIN_CAT(X, Y) \
|
||||||
|
X ## Y
|
||||||
|
#define INCBIN_CONCATENATE(X, Y) \
|
||||||
|
INCBIN_CAT(X, Y)
|
||||||
|
/* Deferred macro expansion */
|
||||||
|
#define INCBIN_EVAL(X) \
|
||||||
|
X
|
||||||
|
#define INCBIN_INVOKE(N, ...) \
|
||||||
|
INCBIN_EVAL(N(__VA_ARGS__))
|
||||||
|
|
||||||
|
/* Green Hills uses a different directive for including binary data */
|
||||||
|
#if defined(__ghs__)
|
||||||
|
# if (__ghs_asm == 2)
|
||||||
|
# define INCBIN_MACRO ".file"
|
||||||
|
/* Or consider the ".myrawdata" entry in the ld file */
|
||||||
|
# else
|
||||||
|
# define INCBIN_MACRO "\tINCBIN"
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define INCBIN_MACRO ".incbin"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
# define INCBIN_ALIGN \
|
||||||
|
__attribute__((aligned(INCBIN_ALIGNMENT)))
|
||||||
|
#else
|
||||||
|
# define INCBIN_ALIGN __declspec(align(INCBIN_ALIGNMENT))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__arm__) || /* GNU C and RealView */ \
|
||||||
|
defined(__arm) || /* Diab */ \
|
||||||
|
defined(_ARM) /* ImageCraft */
|
||||||
|
# define INCBIN_ARM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
/* Utilize .balign where supported */
|
||||||
|
# define INCBIN_ALIGN_HOST ".balign " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
|
||||||
|
# define INCBIN_ALIGN_BYTE ".balign 1\n"
|
||||||
|
#elif defined(INCBIN_ARM)
|
||||||
|
/*
|
||||||
|
* On arm assemblers, the alignment value is calculated as (1 << n) where `n' is
|
||||||
|
* the shift count. This is the value passed to `.align'
|
||||||
|
*/
|
||||||
|
# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT_INDEX) "\n"
|
||||||
|
# define INCBIN_ALIGN_BYTE ".align 0\n"
|
||||||
|
#else
|
||||||
|
/* We assume other inline assembler's treat `.align' as `.balign' */
|
||||||
|
# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
|
||||||
|
# define INCBIN_ALIGN_BYTE ".align 1\n"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* INCBIN_CONST is used by incbin.c generated files */
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
# define INCBIN_EXTERNAL extern "C"
|
||||||
|
# define INCBIN_CONST extern const
|
||||||
|
#else
|
||||||
|
# define INCBIN_EXTERNAL extern
|
||||||
|
# define INCBIN_CONST const
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Optionally override the linker section into which data is emitted.
|
||||||
|
*
|
||||||
|
* @warning If you use this facility, you'll have to deal with platform-specific linker output
|
||||||
|
* section naming on your own
|
||||||
|
*
|
||||||
|
* Overriding the default linker output section, e.g for esp8266/Arduino:
|
||||||
|
* @code
|
||||||
|
* #define INCBIN_OUTPUT_SECTION ".irom.text"
|
||||||
|
* #include "incbin.h"
|
||||||
|
* INCBIN(Foo, "foo.txt");
|
||||||
|
* // Data is emitted into program memory that never gets copied to RAM
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
#if !defined(INCBIN_OUTPUT_SECTION)
|
||||||
|
# if defined(__APPLE__)
|
||||||
|
# define INCBIN_OUTPUT_SECTION ".const_data"
|
||||||
|
# else
|
||||||
|
# define INCBIN_OUTPUT_SECTION ".rodata"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
/* The directives are different for Apple branded compilers */
|
||||||
|
# define INCBIN_SECTION INCBIN_OUTPUT_SECTION "\n"
|
||||||
|
# define INCBIN_GLOBAL(NAME) ".globl " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
|
||||||
|
# define INCBIN_INT ".long "
|
||||||
|
# define INCBIN_MANGLE "_"
|
||||||
|
# define INCBIN_BYTE ".byte "
|
||||||
|
# define INCBIN_TYPE(...)
|
||||||
|
#else
|
||||||
|
# define INCBIN_SECTION ".section " INCBIN_OUTPUT_SECTION "\n"
|
||||||
|
# define INCBIN_GLOBAL(NAME) ".global " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
|
||||||
|
# if defined(__ghs__)
|
||||||
|
# define INCBIN_INT ".word "
|
||||||
|
# else
|
||||||
|
# define INCBIN_INT ".int "
|
||||||
|
# endif
|
||||||
|
# if defined(__USER_LABEL_PREFIX__)
|
||||||
|
# define INCBIN_MANGLE INCBIN_STRINGIZE(__USER_LABEL_PREFIX__)
|
||||||
|
# else
|
||||||
|
# define INCBIN_MANGLE ""
|
||||||
|
# endif
|
||||||
|
# if defined(INCBIN_ARM)
|
||||||
|
/* On arm assemblers, `@' is used as a line comment token */
|
||||||
|
# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", %object\n"
|
||||||
|
# elif defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
|
/* Mingw doesn't support this directive either */
|
||||||
|
# define INCBIN_TYPE(NAME)
|
||||||
|
# else
|
||||||
|
/* It's safe to use `@' on other architectures */
|
||||||
|
# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", @object\n"
|
||||||
|
# endif
|
||||||
|
# define INCBIN_BYTE ".byte "
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* List of style types used for symbol names */
|
||||||
|
#define INCBIN_STYLE_CAMEL 0
|
||||||
|
#define INCBIN_STYLE_SNAKE 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Specify the prefix to use for symbol names.
|
||||||
|
*
|
||||||
|
* By default this is `g', producing symbols of the form:
|
||||||
|
* @code
|
||||||
|
* #include "incbin.h"
|
||||||
|
* INCBIN(Foo, "foo.txt");
|
||||||
|
*
|
||||||
|
* // Now you have the following symbols:
|
||||||
|
* // const unsigned char gFooData[];
|
||||||
|
* // const unsigned char *const gFooEnd;
|
||||||
|
* // const unsigned int gFooSize;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* If however you specify a prefix before including: e.g:
|
||||||
|
* @code
|
||||||
|
* #define INCBIN_PREFIX incbin
|
||||||
|
* #include "incbin.h"
|
||||||
|
* INCBIN(Foo, "foo.txt");
|
||||||
|
*
|
||||||
|
* // Now you have the following symbols instead:
|
||||||
|
* // const unsigned char incbinFooData[];
|
||||||
|
* // const unsigned char *const incbinFooEnd;
|
||||||
|
* // const unsigned int incbinFooSize;
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
#if !defined(INCBIN_PREFIX)
|
||||||
|
# define INCBIN_PREFIX g
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Specify the style used for symbol names.
|
||||||
|
*
|
||||||
|
* Possible options are
|
||||||
|
* - INCBIN_STYLE_CAMEL "CamelCase"
|
||||||
|
* - INCBIN_STYLE_SNAKE "snake_case"
|
||||||
|
*
|
||||||
|
* Default option is *INCBIN_STYLE_CAMEL* producing symbols of the form:
|
||||||
|
* @code
|
||||||
|
* #include "incbin.h"
|
||||||
|
* INCBIN(Foo, "foo.txt");
|
||||||
|
*
|
||||||
|
* // Now you have the following symbols:
|
||||||
|
* // const unsigned char <prefix>FooData[];
|
||||||
|
* // const unsigned char *const <prefix>FooEnd;
|
||||||
|
* // const unsigned int <prefix>FooSize;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* If however you specify a style before including: e.g:
|
||||||
|
* @code
|
||||||
|
* #define INCBIN_STYLE INCBIN_STYLE_SNAKE
|
||||||
|
* #include "incbin.h"
|
||||||
|
* INCBIN(foo, "foo.txt");
|
||||||
|
*
|
||||||
|
* // Now you have the following symbols:
|
||||||
|
* // const unsigned char <prefix>foo_data[];
|
||||||
|
* // const unsigned char *const <prefix>foo_end;
|
||||||
|
* // const unsigned int <prefix>foo_size;
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
#if !defined(INCBIN_STYLE)
|
||||||
|
# define INCBIN_STYLE INCBIN_STYLE_CAMEL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Style lookup tables */
|
||||||
|
#define INCBIN_STYLE_0_DATA Data
|
||||||
|
#define INCBIN_STYLE_0_END End
|
||||||
|
#define INCBIN_STYLE_0_SIZE Size
|
||||||
|
#define INCBIN_STYLE_1_DATA _data
|
||||||
|
#define INCBIN_STYLE_1_END _end
|
||||||
|
#define INCBIN_STYLE_1_SIZE _size
|
||||||
|
|
||||||
|
/* Style lookup: returning identifier */
|
||||||
|
#define INCBIN_STYLE_IDENT(TYPE) \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
INCBIN_STYLE_, \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
INCBIN_EVAL(INCBIN_STYLE), \
|
||||||
|
INCBIN_CONCATENATE(_, TYPE)))
|
||||||
|
|
||||||
|
/* Style lookup: returning string literal */
|
||||||
|
#define INCBIN_STYLE_STRING(TYPE) \
|
||||||
|
INCBIN_STRINGIZE( \
|
||||||
|
INCBIN_STYLE_IDENT(TYPE)) \
|
||||||
|
|
||||||
|
/* Generate the global labels by indirectly invoking the macro with our style
|
||||||
|
* type and concatenating the name against them. */
|
||||||
|
#define INCBIN_GLOBAL_LABELS(NAME, TYPE) \
|
||||||
|
INCBIN_INVOKE( \
|
||||||
|
INCBIN_GLOBAL, \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
NAME, \
|
||||||
|
INCBIN_INVOKE( \
|
||||||
|
INCBIN_STYLE_IDENT, \
|
||||||
|
TYPE))) \
|
||||||
|
INCBIN_INVOKE( \
|
||||||
|
INCBIN_TYPE, \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
NAME, \
|
||||||
|
INCBIN_INVOKE( \
|
||||||
|
INCBIN_STYLE_IDENT, \
|
||||||
|
TYPE)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Externally reference binary data included in another translation unit.
|
||||||
|
*
|
||||||
|
* Produces three external symbols that reference the binary data included in
|
||||||
|
* another translation unit.
|
||||||
|
*
|
||||||
|
* The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with
|
||||||
|
* "Data", as well as "End" and "Size" after. An example is provided below.
|
||||||
|
*
|
||||||
|
* @param NAME The name given for the binary data
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* INCBIN_EXTERN(Foo);
|
||||||
|
*
|
||||||
|
* // Now you have the following symbols:
|
||||||
|
* // extern const unsigned char <prefix>FooData[];
|
||||||
|
* // extern const unsigned char *const <prefix>FooEnd;
|
||||||
|
* // extern const unsigned int <prefix>FooSize;
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
#define INCBIN_EXTERN(NAME) \
|
||||||
|
INCBIN_EXTERNAL const INCBIN_ALIGN unsigned char \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||||
|
INCBIN_STYLE_IDENT(DATA))[]; \
|
||||||
|
INCBIN_EXTERNAL const INCBIN_ALIGN unsigned char *const \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||||
|
INCBIN_STYLE_IDENT(END)); \
|
||||||
|
INCBIN_EXTERNAL const unsigned int \
|
||||||
|
INCBIN_CONCATENATE( \
|
||||||
|
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||||
|
INCBIN_STYLE_IDENT(SIZE))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Include a binary file into the current translation unit.
|
||||||
|
*
|
||||||
|
* Includes a binary file into the current translation unit, producing three symbols
|
||||||
|
* for objects that encode the data and size respectively.
|
||||||
|
*
|
||||||
|
* The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with
|
||||||
|
* "Data", as well as "End" and "Size" after. An example is provided below.
|
||||||
|
*
|
||||||
|
* @param NAME The name to associate with this binary data (as an identifier.)
|
||||||
|
* @param FILENAME The file to include (as a string literal.)
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* INCBIN(Icon, "icon.png");
|
||||||
|
*
|
||||||
|
* // Now you have the following symbols:
|
||||||
|
* // const unsigned char <prefix>IconData[];
|
||||||
|
* // const unsigned char *const <prefix>IconEnd;
|
||||||
|
* // const unsigned int <prefix>IconSize;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @warning This must be used in global scope
|
||||||
|
* @warning The identifiers may be different if INCBIN_STYLE is not default
|
||||||
|
*
|
||||||
|
* To externally reference the data included by this in another translation unit
|
||||||
|
* please @see INCBIN_EXTERN.
|
||||||
|
*/
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define INCBIN(NAME, FILENAME) \
|
||||||
|
INCBIN_EXTERN(NAME)
|
||||||
|
#else
|
||||||
|
#define INCBIN(NAME, FILENAME) \
|
||||||
|
__asm__(INCBIN_SECTION \
|
||||||
|
INCBIN_GLOBAL_LABELS(NAME, DATA) \
|
||||||
|
INCBIN_ALIGN_HOST \
|
||||||
|
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) ":\n" \
|
||||||
|
INCBIN_MACRO " \"" FILENAME "\"\n" \
|
||||||
|
INCBIN_GLOBAL_LABELS(NAME, END) \
|
||||||
|
INCBIN_ALIGN_BYTE \
|
||||||
|
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) ":\n" \
|
||||||
|
INCBIN_BYTE "1\n" \
|
||||||
|
INCBIN_GLOBAL_LABELS(NAME, SIZE) \
|
||||||
|
INCBIN_ALIGN_HOST \
|
||||||
|
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(SIZE) ":\n" \
|
||||||
|
INCBIN_INT INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) " - " \
|
||||||
|
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) "\n" \
|
||||||
|
INCBIN_ALIGN_HOST \
|
||||||
|
".text\n" \
|
||||||
|
); \
|
||||||
|
INCBIN_EXTERN(NAME)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
+3
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -37,6 +35,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
std::cout << engine_info() << std::endl;
|
std::cout << engine_info() << std::endl;
|
||||||
|
|
||||||
|
CommandLine::init(argc, argv);
|
||||||
UCI::init(Options);
|
UCI::init(Options);
|
||||||
Tune::init();
|
Tune::init();
|
||||||
PSQT::init();
|
PSQT::init();
|
||||||
@@ -46,6 +45,7 @@ int main(int argc, char* argv[]) {
|
|||||||
Endgames::init();
|
Endgames::init();
|
||||||
Threads.set(size_t(Options["Threads"]));
|
Threads.set(size_t(Options["Threads"]));
|
||||||
Search::clear(); // After threads are up
|
Search::clear(); // After threads are up
|
||||||
|
Eval::init_NNUE();
|
||||||
|
|
||||||
UCI::loop(argc, argv);
|
UCI::loop(argc, argv);
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -132,7 +130,7 @@ Entry* probe(const Position& pos) {
|
|||||||
|
|
||||||
Value npm_w = pos.non_pawn_material(WHITE);
|
Value npm_w = pos.non_pawn_material(WHITE);
|
||||||
Value npm_b = pos.non_pawn_material(BLACK);
|
Value npm_b = pos.non_pawn_material(BLACK);
|
||||||
Value npm = Utility::clamp(npm_w + npm_b, EndgameLimit, MidgameLimit);
|
Value npm = std::clamp(npm_w + npm_b, EndgameLimit, MidgameLimit);
|
||||||
|
|
||||||
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
|
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
|
||||||
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
|
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+133
-10
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -46,12 +44,18 @@ typedef bool(*fun3_t)(HANDLE, CONST GROUP_AFFINITY*, PGROUP_AFFINITY);
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#if defined(__linux__) && !defined(__ANDROID__)
|
#if defined(__linux__) && !defined(__ANDROID__)
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__) || defined(__ANDROID__) || defined(__OpenBSD__) || (defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) && !defined(_WIN32))
|
||||||
|
#define POSIXALIGNEDALLOC
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
@@ -61,7 +65,7 @@ namespace {
|
|||||||
|
|
||||||
/// Version number. If Version is left empty, then compile date in the format
|
/// Version number. If Version is left empty, then compile date in the format
|
||||||
/// DD-MM-YY and show in engine_info.
|
/// DD-MM-YY and show in engine_info.
|
||||||
const string Version = "";
|
const string Version = "12";
|
||||||
|
|
||||||
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
|
||||||
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
|
||||||
@@ -128,6 +132,7 @@ public:
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
/// engine_info() returns the full name of the current Stockfish version. This
|
/// engine_info() returns the full name of the current Stockfish version. This
|
||||||
/// will be either "Stockfish <Tag> DD-MM-YY" (where DD-MM-YY is the date when
|
/// will be either "Stockfish <Tag> DD-MM-YY" (where DD-MM-YY is the date when
|
||||||
/// the program was compiled) or "Stockfish <Version>", depending on whether
|
/// the program was compiled) or "Stockfish <Version>", depending on whether
|
||||||
@@ -147,10 +152,8 @@ const string engine_info(bool to_uci) {
|
|||||||
ss << setw(2) << day << setw(2) << (1 + months.find(month) / 4) << year.substr(2);
|
ss << setw(2) << day << setw(2) << (1 + months.find(month) / 4) << year.substr(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
ss << (Is64Bit ? " 64" : "")
|
ss << (to_uci ? "\nid author ": " by ")
|
||||||
<< (HasPext ? " BMI2" : (HasPopCnt ? " POPCNT" : ""))
|
<< "the Stockfish developers (see AUTHORS file)";
|
||||||
<< (to_uci ? "\nid author ": " by ")
|
|
||||||
<< "T. Romstad, M. Costalba, J. Kiiski, G. Linscott";
|
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
@@ -215,7 +218,40 @@ const std::string compiler_info() {
|
|||||||
compiler += " on unknown system";
|
compiler += " on unknown system";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
compiler += "\n __VERSION__ macro expands to: ";
|
compiler += "\nCompilation settings include: ";
|
||||||
|
compiler += (Is64Bit ? " 64bit" : " 32bit");
|
||||||
|
#if defined(USE_VNNI)
|
||||||
|
compiler += " VNNI";
|
||||||
|
#endif
|
||||||
|
#if defined(USE_AVX512)
|
||||||
|
compiler += " AVX512";
|
||||||
|
#endif
|
||||||
|
compiler += (HasPext ? " BMI2" : "");
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
compiler += " AVX2";
|
||||||
|
#endif
|
||||||
|
#if defined(USE_SSE41)
|
||||||
|
compiler += " SSE41";
|
||||||
|
#endif
|
||||||
|
#if defined(USE_SSSE3)
|
||||||
|
compiler += " SSSE3";
|
||||||
|
#endif
|
||||||
|
#if defined(USE_SSE2)
|
||||||
|
compiler += " SSE2";
|
||||||
|
#endif
|
||||||
|
compiler += (HasPopCnt ? " POPCNT" : "");
|
||||||
|
#if defined(USE_MMX)
|
||||||
|
compiler += " MMX";
|
||||||
|
#endif
|
||||||
|
#if defined(USE_NEON)
|
||||||
|
compiler += " NEON";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
compiler += " DEBUG";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
compiler += "\n__VERSION__ macro expands to: ";
|
||||||
#ifdef __VERSION__
|
#ifdef __VERSION__
|
||||||
compiler += __VERSION__;
|
compiler += __VERSION__;
|
||||||
#else
|
#else
|
||||||
@@ -294,7 +330,34 @@ void prefetch(void* addr) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// aligned_ttmem_alloc() will return suitably aligned memory, and if possible use large pages.
|
/// std_aligned_alloc() is our wrapper for systems where the c++17 implementation
|
||||||
|
/// does not guarantee the availability of aligned_alloc(). Memory allocated with
|
||||||
|
/// std_aligned_alloc() must be freed with std_aligned_free().
|
||||||
|
|
||||||
|
void* std_aligned_alloc(size_t alignment, size_t size) {
|
||||||
|
|
||||||
|
#if defined(POSIXALIGNEDALLOC)
|
||||||
|
void *mem;
|
||||||
|
return posix_memalign(&mem, alignment, size) ? nullptr : mem;
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
return _mm_malloc(size, alignment);
|
||||||
|
#else
|
||||||
|
return std::aligned_alloc(alignment, size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void std_aligned_free(void* ptr) {
|
||||||
|
|
||||||
|
#if defined(POSIXALIGNEDALLOC)
|
||||||
|
free(ptr);
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
_mm_free(ptr);
|
||||||
|
#else
|
||||||
|
free(ptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// aligned_ttmem_alloc() will return suitably aligned memory, if possible using large pages.
|
||||||
/// The returned pointer is the aligned one, while the mem argument is the one that needs
|
/// The returned pointer is the aligned one, while the mem argument is the one that needs
|
||||||
/// to be passed to free. With c++17 some of this functionality could be simplified.
|
/// to be passed to free. With c++17 some of this functionality could be simplified.
|
||||||
|
|
||||||
@@ -306,7 +369,9 @@ void* aligned_ttmem_alloc(size_t allocSize, void*& mem) {
|
|||||||
size_t size = ((allocSize + alignment - 1) / alignment) * alignment; // multiple of alignment
|
size_t size = ((allocSize + alignment - 1) / alignment) * alignment; // multiple of alignment
|
||||||
if (posix_memalign(&mem, alignment, size))
|
if (posix_memalign(&mem, alignment, size))
|
||||||
mem = nullptr;
|
mem = nullptr;
|
||||||
|
#if defined(MADV_HUGEPAGE)
|
||||||
madvise(mem, allocSize, MADV_HUGEPAGE);
|
madvise(mem, allocSize, MADV_HUGEPAGE);
|
||||||
|
#endif
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,3 +590,61 @@ void bindThisThread(size_t idx) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace WinProcGroup
|
} // namespace WinProcGroup
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <direct.h>
|
||||||
|
#define GETCWD _getcwd
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#define GETCWD getcwd
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace CommandLine {
|
||||||
|
|
||||||
|
string argv0; // path+name of the executable binary, as given by argv[0]
|
||||||
|
string binaryDirectory; // path of the executable directory
|
||||||
|
string workingDirectory; // path of the working directory
|
||||||
|
string pathSeparator; // Separator for our current OS
|
||||||
|
|
||||||
|
void init(int argc, char* argv[]) {
|
||||||
|
(void)argc;
|
||||||
|
string separator;
|
||||||
|
|
||||||
|
// extract the path+name of the executable binary
|
||||||
|
argv0 = argv[0];
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
pathSeparator = "\\";
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
// Under windows argv[0] may not have the extension. Also _get_pgmptr() had
|
||||||
|
// issues in some windows 10 versions, so check returned values carefully.
|
||||||
|
char* pgmptr = nullptr;
|
||||||
|
if (!_get_pgmptr(&pgmptr) && pgmptr != nullptr && *pgmptr)
|
||||||
|
argv0 = pgmptr;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
pathSeparator = "/";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// extract the working directory
|
||||||
|
workingDirectory = "";
|
||||||
|
char buff[40000];
|
||||||
|
char* cwd = GETCWD(buff, 40000);
|
||||||
|
if (cwd)
|
||||||
|
workingDirectory = cwd;
|
||||||
|
|
||||||
|
// extract the binary directory path from argv0
|
||||||
|
binaryDirectory = argv0;
|
||||||
|
size_t pos = binaryDirectory.find_last_of("\\/");
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
binaryDirectory = "." + pathSeparator;
|
||||||
|
else
|
||||||
|
binaryDirectory.resize(pos + 1);
|
||||||
|
|
||||||
|
// pattern replacement: "./" at the start of path is replaced by the working directory
|
||||||
|
if (binaryDirectory.find("." + pathSeparator) == 0)
|
||||||
|
binaryDirectory.replace(0, 1, workingDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace CommandLine
|
||||||
|
|||||||
+10
-13
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,6 +31,8 @@ const std::string engine_info(bool to_uci = false);
|
|||||||
const std::string compiler_info();
|
const std::string compiler_info();
|
||||||
void prefetch(void* addr);
|
void prefetch(void* addr);
|
||||||
void start_logger(const std::string& fname);
|
void start_logger(const std::string& fname);
|
||||||
|
void* std_aligned_alloc(size_t alignment, size_t size);
|
||||||
|
void std_aligned_free(void* ptr);
|
||||||
void* aligned_ttmem_alloc(size_t size, void*& mem);
|
void* aligned_ttmem_alloc(size_t size, void*& mem);
|
||||||
void aligned_ttmem_free(void* mem); // nop if mem == nullptr
|
void aligned_ttmem_free(void* mem); // nop if mem == nullptr
|
||||||
|
|
||||||
@@ -42,9 +42,7 @@ void dbg_mean_of(int v);
|
|||||||
void dbg_print();
|
void dbg_print();
|
||||||
|
|
||||||
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
||||||
|
|
||||||
static_assert(sizeof(TimePoint) == sizeof(int64_t), "TimePoint should be 64 bits");
|
static_assert(sizeof(TimePoint) == sizeof(int64_t), "TimePoint should be 64 bits");
|
||||||
|
|
||||||
inline TimePoint now() {
|
inline TimePoint now() {
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>
|
return std::chrono::duration_cast<std::chrono::milliseconds>
|
||||||
(std::chrono::steady_clock::now().time_since_epoch()).count();
|
(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||||
@@ -65,14 +63,6 @@ std::ostream& operator<<(std::ostream&, SyncCout);
|
|||||||
#define sync_cout std::cout << IO_LOCK
|
#define sync_cout std::cout << IO_LOCK
|
||||||
#define sync_endl std::endl << IO_UNLOCK
|
#define sync_endl std::endl << IO_UNLOCK
|
||||||
|
|
||||||
namespace Utility {
|
|
||||||
|
|
||||||
/// Clamp a value between lo and hi. Available in c++17.
|
|
||||||
template<class T> constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
|
|
||||||
return v < lo ? lo : v > hi ? hi : v;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// xorshift64star Pseudo-Random Number Generator
|
/// xorshift64star Pseudo-Random Number Generator
|
||||||
/// This class is based on original code written and dedicated
|
/// This class is based on original code written and dedicated
|
||||||
@@ -134,4 +124,11 @@ namespace WinProcGroup {
|
|||||||
void bindThisThread(size_t idx);
|
void bindThisThread(size_t idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace CommandLine {
|
||||||
|
void init(int argc, char* argv[]);
|
||||||
|
|
||||||
|
extern std::string binaryDirectory; // path of the executable directory
|
||||||
|
extern std::string workingDirectory; // path of the working directory
|
||||||
|
}
|
||||||
|
|
||||||
#endif // #ifndef MISC_H_INCLUDED
|
#endif // #ifndef MISC_H_INCLUDED
|
||||||
|
|||||||
+2
-4
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -250,7 +248,7 @@ namespace {
|
|||||||
*moveList++ = make_move(ksq, pop_lsb(&b));
|
*moveList++ = make_move(ksq, pop_lsb(&b));
|
||||||
|
|
||||||
if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING))
|
if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING))
|
||||||
for(CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
|
for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
|
||||||
if (!pos.castling_impeded(cr) && pos.can_castle(cr))
|
if (!pos.castling_impeded(cr) && pos.can_castle(cr))
|
||||||
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(cr));
|
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(cr));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+8
-10
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -184,7 +182,7 @@ top:
|
|||||||
--endMoves;
|
--endMoves;
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
[[fallthrough]];
|
||||||
|
|
||||||
case REFUTATION:
|
case REFUTATION:
|
||||||
if (select<Next>([&](){ return *cur != MOVE_NONE
|
if (select<Next>([&](){ return *cur != MOVE_NONE
|
||||||
@@ -192,7 +190,7 @@ top:
|
|||||||
&& pos.pseudo_legal(*cur); }))
|
&& pos.pseudo_legal(*cur); }))
|
||||||
return *(cur - 1);
|
return *(cur - 1);
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
[[fallthrough]];
|
||||||
|
|
||||||
case QUIET_INIT:
|
case QUIET_INIT:
|
||||||
if (!skipQuiets)
|
if (!skipQuiets)
|
||||||
@@ -205,7 +203,7 @@ top:
|
|||||||
}
|
}
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
[[fallthrough]];
|
||||||
|
|
||||||
case QUIET:
|
case QUIET:
|
||||||
if ( !skipQuiets
|
if ( !skipQuiets
|
||||||
@@ -219,7 +217,7 @@ top:
|
|||||||
endMoves = endBadCaptures;
|
endMoves = endBadCaptures;
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
[[fallthrough]];
|
||||||
|
|
||||||
case BAD_CAPTURE:
|
case BAD_CAPTURE:
|
||||||
return select<Next>([](){ return true; });
|
return select<Next>([](){ return true; });
|
||||||
@@ -230,7 +228,7 @@ top:
|
|||||||
|
|
||||||
score<EVASIONS>();
|
score<EVASIONS>();
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
[[fallthrough]];
|
||||||
|
|
||||||
case EVASION:
|
case EVASION:
|
||||||
return select<Best>([](){ return true; });
|
return select<Best>([](){ return true; });
|
||||||
@@ -248,14 +246,14 @@ top:
|
|||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
[[fallthrough]];
|
||||||
|
|
||||||
case QCHECK_INIT:
|
case QCHECK_INIT:
|
||||||
cur = moves;
|
cur = moves;
|
||||||
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
||||||
|
|
||||||
++stage;
|
++stage;
|
||||||
/* fallthrough */
|
[[fallthrough]];
|
||||||
|
|
||||||
case QCHECK:
|
case QCHECK:
|
||||||
return select<Next>([](){ return true; });
|
return select<Next>([](){ return true; });
|
||||||
|
|||||||
+4
-6
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -88,9 +86,9 @@ enum StatsType { NoCaptures, Captures };
|
|||||||
/// the move's from and to squares, see www.chessprogramming.org/Butterfly_Boards
|
/// the move's from and to squares, see www.chessprogramming.org/Butterfly_Boards
|
||||||
typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyHistory;
|
typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyHistory;
|
||||||
|
|
||||||
/// At higher depths LowPlyHistory records successful quiet moves near the root and quiet
|
/// At higher depths LowPlyHistory records successful quiet moves near the root
|
||||||
/// moves which are/were in the PV (ttPv)
|
/// and quiet moves which are/were in the PV (ttPv). It is cleared with each new
|
||||||
/// It is cleared with each new search and filled during iterative deepening
|
/// search and filled during iterative deepening.
|
||||||
constexpr int MAX_LPH = 4;
|
constexpr int MAX_LPH = 4;
|
||||||
typedef Stats<int16_t, 10692, MAX_LPH, int(SQUARE_NB) * int(SQUARE_NB)> LowPlyHistory;
|
typedef Stats<int16_t, 10692, MAX_LPH, int(SQUARE_NB) * int(SQUARE_NB)> LowPlyHistory;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Definition of input features and network structure used in NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_HALFKP_256X2_32_32_H_INCLUDED
|
||||||
|
#define NNUE_HALFKP_256X2_32_32_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../features/feature_set.h"
|
||||||
|
#include "../features/half_kp.h"
|
||||||
|
|
||||||
|
#include "../layers/input_slice.h"
|
||||||
|
#include "../layers/affine_transform.h"
|
||||||
|
#include "../layers/clipped_relu.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE {
|
||||||
|
|
||||||
|
// Input features used in evaluation function
|
||||||
|
using RawFeatures = Features::FeatureSet<
|
||||||
|
Features::HalfKP<Features::Side::kFriend>>;
|
||||||
|
|
||||||
|
// Number of input feature dimensions after conversion
|
||||||
|
constexpr IndexType kTransformedFeatureDimensions = 256;
|
||||||
|
|
||||||
|
namespace Layers {
|
||||||
|
|
||||||
|
// Define network structure
|
||||||
|
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
|
||||||
|
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 32>>;
|
||||||
|
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
|
||||||
|
using OutputLayer = AffineTransform<HiddenLayer2, 1>;
|
||||||
|
|
||||||
|
} // namespace Layers
|
||||||
|
|
||||||
|
using Network = Layers::OutputLayer;
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_HALFKP_256X2_32_32_H_INCLUDED
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Code for calculating NNUE evaluation function
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#include "../evaluate.h"
|
||||||
|
#include "../position.h"
|
||||||
|
#include "../misc.h"
|
||||||
|
#include "../uci.h"
|
||||||
|
|
||||||
|
#include "evaluate_nnue.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE {
|
||||||
|
|
||||||
|
uint32_t kpp_board_index[PIECE_NB][COLOR_NB] = {
|
||||||
|
// convention: W - us, B - them
|
||||||
|
// viewed from other side, W and B are reversed
|
||||||
|
{ PS_NONE, PS_NONE },
|
||||||
|
{ PS_W_PAWN, PS_B_PAWN },
|
||||||
|
{ PS_W_KNIGHT, PS_B_KNIGHT },
|
||||||
|
{ PS_W_BISHOP, PS_B_BISHOP },
|
||||||
|
{ PS_W_ROOK, PS_B_ROOK },
|
||||||
|
{ PS_W_QUEEN, PS_B_QUEEN },
|
||||||
|
{ PS_W_KING, PS_B_KING },
|
||||||
|
{ PS_NONE, PS_NONE },
|
||||||
|
{ PS_NONE, PS_NONE },
|
||||||
|
{ PS_B_PAWN, PS_W_PAWN },
|
||||||
|
{ PS_B_KNIGHT, PS_W_KNIGHT },
|
||||||
|
{ PS_B_BISHOP, PS_W_BISHOP },
|
||||||
|
{ PS_B_ROOK, PS_W_ROOK },
|
||||||
|
{ PS_B_QUEEN, PS_W_QUEEN },
|
||||||
|
{ PS_B_KING, PS_W_KING },
|
||||||
|
{ PS_NONE, PS_NONE }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Input feature converter
|
||||||
|
AlignedPtr<FeatureTransformer> feature_transformer;
|
||||||
|
|
||||||
|
// Evaluation function
|
||||||
|
AlignedPtr<Network> network;
|
||||||
|
|
||||||
|
// Evaluation function file name
|
||||||
|
std::string fileName;
|
||||||
|
|
||||||
|
namespace Detail {
|
||||||
|
|
||||||
|
// Initialize the evaluation function parameters
|
||||||
|
template <typename T>
|
||||||
|
void Initialize(AlignedPtr<T>& pointer) {
|
||||||
|
|
||||||
|
pointer.reset(reinterpret_cast<T*>(std_aligned_alloc(alignof(T), sizeof(T))));
|
||||||
|
std::memset(pointer.get(), 0, sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read evaluation function parameters
|
||||||
|
template <typename T>
|
||||||
|
bool ReadParameters(std::istream& stream, const AlignedPtr<T>& pointer) {
|
||||||
|
|
||||||
|
std::uint32_t header;
|
||||||
|
header = read_little_endian<std::uint32_t>(stream);
|
||||||
|
if (!stream || header != T::GetHashValue()) return false;
|
||||||
|
return pointer->ReadParameters(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Detail
|
||||||
|
|
||||||
|
// Initialize the evaluation function parameters
|
||||||
|
void Initialize() {
|
||||||
|
|
||||||
|
Detail::Initialize(feature_transformer);
|
||||||
|
Detail::Initialize(network);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read network header
|
||||||
|
bool ReadHeader(std::istream& stream, std::uint32_t* hash_value, std::string* architecture)
|
||||||
|
{
|
||||||
|
std::uint32_t version, size;
|
||||||
|
|
||||||
|
version = read_little_endian<std::uint32_t>(stream);
|
||||||
|
*hash_value = read_little_endian<std::uint32_t>(stream);
|
||||||
|
size = read_little_endian<std::uint32_t>(stream);
|
||||||
|
if (!stream || version != kVersion) return false;
|
||||||
|
architecture->resize(size);
|
||||||
|
stream.read(&(*architecture)[0], size);
|
||||||
|
return !stream.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read network parameters
|
||||||
|
bool ReadParameters(std::istream& stream) {
|
||||||
|
|
||||||
|
std::uint32_t hash_value;
|
||||||
|
std::string architecture;
|
||||||
|
if (!ReadHeader(stream, &hash_value, &architecture)) return false;
|
||||||
|
if (hash_value != kHashValue) return false;
|
||||||
|
if (!Detail::ReadParameters(stream, feature_transformer)) return false;
|
||||||
|
if (!Detail::ReadParameters(stream, network)) return false;
|
||||||
|
return stream && stream.peek() == std::ios::traits_type::eof();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Proceed with the difference calculation if possible
|
||||||
|
static void UpdateAccumulatorIfPossible(const Position& pos) {
|
||||||
|
|
||||||
|
feature_transformer->UpdateAccumulatorIfPossible(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the evaluation value
|
||||||
|
static Value ComputeScore(const Position& pos, bool refresh) {
|
||||||
|
|
||||||
|
auto& accumulator = pos.state()->accumulator;
|
||||||
|
if (!refresh && accumulator.computed_score) {
|
||||||
|
return accumulator.score;
|
||||||
|
}
|
||||||
|
|
||||||
|
alignas(kCacheLineSize) TransformedFeatureType
|
||||||
|
transformed_features[FeatureTransformer::kBufferSize];
|
||||||
|
feature_transformer->Transform(pos, transformed_features, refresh);
|
||||||
|
alignas(kCacheLineSize) char buffer[Network::kBufferSize];
|
||||||
|
const auto output = network->Propagate(transformed_features, buffer);
|
||||||
|
|
||||||
|
auto score = static_cast<Value>(output[0] / FV_SCALE);
|
||||||
|
|
||||||
|
accumulator.score = score;
|
||||||
|
accumulator.computed_score = true;
|
||||||
|
return accumulator.score;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load eval, from a file stream or a memory stream
|
||||||
|
bool load_eval(std::string streamName, std::istream& stream) {
|
||||||
|
|
||||||
|
Initialize();
|
||||||
|
fileName = streamName;
|
||||||
|
return ReadParameters(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Evaluation function. Perform differential calculation.
|
||||||
|
Value evaluate(const Position& pos) {
|
||||||
|
return ComputeScore(pos, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Evaluation function. Perform full calculation.
|
||||||
|
Value compute_eval(const Position& pos) {
|
||||||
|
return ComputeScore(pos, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Proceed with the difference calculation if possible
|
||||||
|
void update_eval(const Position& pos) {
|
||||||
|
UpdateAccumulatorIfPossible(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// header used in NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_EVALUATE_NNUE_H_INCLUDED
|
||||||
|
#define NNUE_EVALUATE_NNUE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "nnue_feature_transformer.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Eval::NNUE {
|
||||||
|
|
||||||
|
// Hash value of evaluation function structure
|
||||||
|
constexpr std::uint32_t kHashValue =
|
||||||
|
FeatureTransformer::GetHashValue() ^ Network::GetHashValue();
|
||||||
|
|
||||||
|
// Deleter for automating release of memory area
|
||||||
|
template <typename T>
|
||||||
|
struct AlignedDeleter {
|
||||||
|
void operator()(T* ptr) const {
|
||||||
|
ptr->~T();
|
||||||
|
std_aligned_free(ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using AlignedPtr = std::unique_ptr<T, AlignedDeleter<T>>;
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_EVALUATE_NNUE_H_INCLUDED
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// A class template that represents the input feature set of the NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_FEATURE_SET_H_INCLUDED
|
||||||
|
#define NNUE_FEATURE_SET_H_INCLUDED
|
||||||
|
|
||||||
|
#include "features_common.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Features {
|
||||||
|
|
||||||
|
// Class template that represents a list of values
|
||||||
|
template <typename T, T... Values>
|
||||||
|
struct CompileTimeList;
|
||||||
|
|
||||||
|
template <typename T, T First, T... Remaining>
|
||||||
|
struct CompileTimeList<T, First, Remaining...> {
|
||||||
|
static constexpr bool Contains(T value) {
|
||||||
|
return value == First || CompileTimeList<T, Remaining...>::Contains(value);
|
||||||
|
}
|
||||||
|
static constexpr std::array<T, sizeof...(Remaining) + 1>
|
||||||
|
kValues = {{First, Remaining...}};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Base class of feature set
|
||||||
|
template <typename Derived>
|
||||||
|
class FeatureSetBase {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Get a list of indices for active features
|
||||||
|
template <typename IndexListType>
|
||||||
|
static void AppendActiveIndices(
|
||||||
|
const Position& pos, TriggerEvent trigger, IndexListType active[2]) {
|
||||||
|
|
||||||
|
for (Color perspective : { WHITE, BLACK }) {
|
||||||
|
Derived::CollectActiveIndices(
|
||||||
|
pos, trigger, perspective, &active[perspective]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a list of indices for recently changed features
|
||||||
|
template <typename PositionType, typename IndexListType>
|
||||||
|
static void AppendChangedIndices(
|
||||||
|
const PositionType& pos, TriggerEvent trigger,
|
||||||
|
IndexListType removed[2], IndexListType added[2], bool reset[2]) {
|
||||||
|
|
||||||
|
const auto& dp = pos.state()->dirtyPiece;
|
||||||
|
if (dp.dirty_num == 0) return;
|
||||||
|
|
||||||
|
for (Color perspective : { WHITE, BLACK }) {
|
||||||
|
reset[perspective] = false;
|
||||||
|
switch (trigger) {
|
||||||
|
case TriggerEvent::kFriendKingMoved:
|
||||||
|
reset[perspective] = dp.piece[0] == make_piece(perspective, KING);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (reset[perspective]) {
|
||||||
|
Derived::CollectActiveIndices(
|
||||||
|
pos, trigger, perspective, &added[perspective]);
|
||||||
|
} else {
|
||||||
|
Derived::CollectChangedIndices(
|
||||||
|
pos, trigger, perspective,
|
||||||
|
&removed[perspective], &added[perspective]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Class template that represents the feature set
|
||||||
|
template <typename FeatureType>
|
||||||
|
class FeatureSet<FeatureType> : public FeatureSetBase<FeatureSet<FeatureType>> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Hash value embedded in the evaluation file
|
||||||
|
static constexpr std::uint32_t kHashValue = FeatureType::kHashValue;
|
||||||
|
// Number of feature dimensions
|
||||||
|
static constexpr IndexType kDimensions = FeatureType::kDimensions;
|
||||||
|
// Maximum number of simultaneously active features
|
||||||
|
static constexpr IndexType kMaxActiveDimensions =
|
||||||
|
FeatureType::kMaxActiveDimensions;
|
||||||
|
// Trigger for full calculation instead of difference calculation
|
||||||
|
using SortedTriggerSet =
|
||||||
|
CompileTimeList<TriggerEvent, FeatureType::kRefreshTrigger>;
|
||||||
|
static constexpr auto kRefreshTriggers = SortedTriggerSet::kValues;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Get a list of indices for active features
|
||||||
|
static void CollectActiveIndices(
|
||||||
|
const Position& pos, const TriggerEvent trigger, const Color perspective,
|
||||||
|
IndexList* const active) {
|
||||||
|
if (FeatureType::kRefreshTrigger == trigger) {
|
||||||
|
FeatureType::AppendActiveIndices(pos, perspective, active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a list of indices for recently changed features
|
||||||
|
static void CollectChangedIndices(
|
||||||
|
const Position& pos, const TriggerEvent trigger, const Color perspective,
|
||||||
|
IndexList* const removed, IndexList* const added) {
|
||||||
|
|
||||||
|
if (FeatureType::kRefreshTrigger == trigger) {
|
||||||
|
FeatureType::AppendChangedIndices(pos, perspective, removed, added);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the base class and the class template that recursively uses itself a friend
|
||||||
|
friend class FeatureSetBase<FeatureSet>;
|
||||||
|
template <typename... FeatureTypes>
|
||||||
|
friend class FeatureSet;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE::Features
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_FEATURE_SET_H_INCLUDED
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Common header of input features of NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_FEATURES_COMMON_H_INCLUDED
|
||||||
|
#define NNUE_FEATURES_COMMON_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../../evaluate.h"
|
||||||
|
#include "../nnue_common.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Features {
|
||||||
|
|
||||||
|
class IndexList;
|
||||||
|
|
||||||
|
template <typename... FeatureTypes>
|
||||||
|
class FeatureSet;
|
||||||
|
|
||||||
|
// Trigger to perform full calculations instead of difference only
|
||||||
|
enum class TriggerEvent {
|
||||||
|
kFriendKingMoved // calculate full evaluation when own king moves
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Side {
|
||||||
|
kFriend // side to move
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE::Features
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_FEATURES_COMMON_H_INCLUDED
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Definition of input features HalfKP of NNUE evaluation function
|
||||||
|
|
||||||
|
#include "half_kp.h"
|
||||||
|
#include "index_list.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Features {
|
||||||
|
|
||||||
|
// Orient a square according to perspective (rotates by 180 for black)
|
||||||
|
inline Square orient(Color perspective, Square s) {
|
||||||
|
return Square(int(s) ^ (bool(perspective) * 63));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the index of the feature quantity from the king position and PieceSquare
|
||||||
|
template <Side AssociatedKing>
|
||||||
|
inline IndexType HalfKP<AssociatedKing>::MakeIndex(
|
||||||
|
Color perspective, Square s, Piece pc, Square ksq) {
|
||||||
|
|
||||||
|
return IndexType(orient(perspective, s) + kpp_board_index[pc][perspective] + PS_END * ksq);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a list of indices for active features
|
||||||
|
template <Side AssociatedKing>
|
||||||
|
void HalfKP<AssociatedKing>::AppendActiveIndices(
|
||||||
|
const Position& pos, Color perspective, IndexList* active) {
|
||||||
|
|
||||||
|
Square ksq = orient(perspective, pos.square<KING>(perspective));
|
||||||
|
Bitboard bb = pos.pieces() & ~pos.pieces(KING);
|
||||||
|
while (bb) {
|
||||||
|
Square s = pop_lsb(&bb);
|
||||||
|
active->push_back(MakeIndex(perspective, s, pos.piece_on(s), ksq));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a list of indices for recently changed features
|
||||||
|
template <Side AssociatedKing>
|
||||||
|
void HalfKP<AssociatedKing>::AppendChangedIndices(
|
||||||
|
const Position& pos, Color perspective,
|
||||||
|
IndexList* removed, IndexList* added) {
|
||||||
|
|
||||||
|
Square ksq = orient(perspective, pos.square<KING>(perspective));
|
||||||
|
const auto& dp = pos.state()->dirtyPiece;
|
||||||
|
for (int i = 0; i < dp.dirty_num; ++i) {
|
||||||
|
Piece pc = dp.piece[i];
|
||||||
|
if (type_of(pc) == KING) continue;
|
||||||
|
if (dp.from[i] != SQ_NONE)
|
||||||
|
removed->push_back(MakeIndex(perspective, dp.from[i], pc, ksq));
|
||||||
|
if (dp.to[i] != SQ_NONE)
|
||||||
|
added->push_back(MakeIndex(perspective, dp.to[i], pc, ksq));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template class HalfKP<Side::kFriend>;
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE::Features
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Definition of input features HalfKP of NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_FEATURES_HALF_KP_H_INCLUDED
|
||||||
|
#define NNUE_FEATURES_HALF_KP_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../../evaluate.h"
|
||||||
|
#include "features_common.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Features {
|
||||||
|
|
||||||
|
// Feature HalfKP: Combination of the position of own king
|
||||||
|
// and the position of pieces other than kings
|
||||||
|
template <Side AssociatedKing>
|
||||||
|
class HalfKP {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Feature name
|
||||||
|
static constexpr const char* kName = "HalfKP(Friend)";
|
||||||
|
// Hash value embedded in the evaluation file
|
||||||
|
static constexpr std::uint32_t kHashValue =
|
||||||
|
0x5D69D5B9u ^ (AssociatedKing == Side::kFriend);
|
||||||
|
// Number of feature dimensions
|
||||||
|
static constexpr IndexType kDimensions =
|
||||||
|
static_cast<IndexType>(SQUARE_NB) * static_cast<IndexType>(PS_END);
|
||||||
|
// Maximum number of simultaneously active features
|
||||||
|
static constexpr IndexType kMaxActiveDimensions = 30; // Kings don't count
|
||||||
|
// Trigger for full calculation instead of difference calculation
|
||||||
|
static constexpr TriggerEvent kRefreshTrigger = TriggerEvent::kFriendKingMoved;
|
||||||
|
|
||||||
|
// Get a list of indices for active features
|
||||||
|
static void AppendActiveIndices(const Position& pos, Color perspective,
|
||||||
|
IndexList* active);
|
||||||
|
|
||||||
|
// Get a list of indices for recently changed features
|
||||||
|
static void AppendChangedIndices(const Position& pos, Color perspective,
|
||||||
|
IndexList* removed, IndexList* added);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Index of a feature for a given king position and another piece on some square
|
||||||
|
static IndexType MakeIndex(Color perspective, Square s, Piece pc, Square sq_k);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE::Features
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_FEATURES_HALF_KP_H_INCLUDED
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Definition of index list of input features
|
||||||
|
|
||||||
|
#ifndef NNUE_FEATURES_INDEX_LIST_H_INCLUDED
|
||||||
|
#define NNUE_FEATURES_INDEX_LIST_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../../position.h"
|
||||||
|
#include "../nnue_architecture.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Features {
|
||||||
|
|
||||||
|
// Class template used for feature index list
|
||||||
|
template <typename T, std::size_t MaxSize>
|
||||||
|
class ValueList {
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::size_t size() const { return size_; }
|
||||||
|
void resize(std::size_t size) { size_ = size; }
|
||||||
|
void push_back(const T& value) { values_[size_++] = value; }
|
||||||
|
T& operator[](std::size_t index) { return values_[index]; }
|
||||||
|
T* begin() { return values_; }
|
||||||
|
T* end() { return values_ + size_; }
|
||||||
|
const T& operator[](std::size_t index) const { return values_[index]; }
|
||||||
|
const T* begin() const { return values_; }
|
||||||
|
const T* end() const { return values_ + size_; }
|
||||||
|
|
||||||
|
void swap(ValueList& other) {
|
||||||
|
const std::size_t max_size = std::max(size_, other.size_);
|
||||||
|
for (std::size_t i = 0; i < max_size; ++i) {
|
||||||
|
std::swap(values_[i], other.values_[i]);
|
||||||
|
}
|
||||||
|
std::swap(size_, other.size_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
T values_[MaxSize];
|
||||||
|
std::size_t size_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
//Type of feature index list
|
||||||
|
class IndexList
|
||||||
|
: public ValueList<IndexType, RawFeatures::kMaxActiveDimensions> {
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE::Features
|
||||||
|
|
||||||
|
#endif // NNUE_FEATURES_INDEX_LIST_H_INCLUDED
|
||||||
@@ -0,0 +1,266 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Definition of layer AffineTransform of NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_LAYERS_AFFINE_TRANSFORM_H_INCLUDED
|
||||||
|
#define NNUE_LAYERS_AFFINE_TRANSFORM_H_INCLUDED
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "../nnue_common.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Layers {
|
||||||
|
|
||||||
|
// Affine transformation layer
|
||||||
|
template <typename PreviousLayer, IndexType OutputDimensions>
|
||||||
|
class AffineTransform {
|
||||||
|
public:
|
||||||
|
// Input/output type
|
||||||
|
using InputType = typename PreviousLayer::OutputType;
|
||||||
|
using OutputType = std::int32_t;
|
||||||
|
static_assert(std::is_same<InputType, std::uint8_t>::value, "");
|
||||||
|
|
||||||
|
// Number of input/output dimensions
|
||||||
|
static constexpr IndexType kInputDimensions =
|
||||||
|
PreviousLayer::kOutputDimensions;
|
||||||
|
static constexpr IndexType kOutputDimensions = OutputDimensions;
|
||||||
|
static constexpr IndexType kPaddedInputDimensions =
|
||||||
|
CeilToMultiple<IndexType>(kInputDimensions, kMaxSimdWidth);
|
||||||
|
|
||||||
|
// Size of forward propagation buffer used in this layer
|
||||||
|
static constexpr std::size_t kSelfBufferSize =
|
||||||
|
CeilToMultiple(kOutputDimensions * sizeof(OutputType), kCacheLineSize);
|
||||||
|
|
||||||
|
// Size of the forward propagation buffer used from the input layer to this layer
|
||||||
|
static constexpr std::size_t kBufferSize =
|
||||||
|
PreviousLayer::kBufferSize + kSelfBufferSize;
|
||||||
|
|
||||||
|
// Hash value embedded in the evaluation file
|
||||||
|
static constexpr std::uint32_t GetHashValue() {
|
||||||
|
std::uint32_t hash_value = 0xCC03DAE4u;
|
||||||
|
hash_value += kOutputDimensions;
|
||||||
|
hash_value ^= PreviousLayer::GetHashValue() >> 1;
|
||||||
|
hash_value ^= PreviousLayer::GetHashValue() << 31;
|
||||||
|
return hash_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read network parameters
|
||||||
|
bool ReadParameters(std::istream& stream) {
|
||||||
|
if (!previous_layer_.ReadParameters(stream)) return false;
|
||||||
|
for (std::size_t i = 0; i < kOutputDimensions; ++i)
|
||||||
|
biases_[i] = read_little_endian<BiasType>(stream);
|
||||||
|
for (std::size_t i = 0; i < kOutputDimensions * kPaddedInputDimensions; ++i)
|
||||||
|
weights_[i] = read_little_endian<WeightType>(stream);
|
||||||
|
return !stream.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward propagation
|
||||||
|
const OutputType* Propagate(
|
||||||
|
const TransformedFeatureType* transformed_features, char* buffer) const {
|
||||||
|
const auto input = previous_layer_.Propagate(
|
||||||
|
transformed_features, buffer + kSelfBufferSize);
|
||||||
|
const auto output = reinterpret_cast<OutputType*>(buffer);
|
||||||
|
|
||||||
|
#if defined(USE_AVX512)
|
||||||
|
constexpr IndexType kNumChunks = kPaddedInputDimensions / (kSimdWidth * 2);
|
||||||
|
const auto input_vector = reinterpret_cast<const __m512i*>(input);
|
||||||
|
#if !defined(USE_VNNI)
|
||||||
|
const __m512i kOnes = _mm512_set1_epi16(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(USE_AVX2)
|
||||||
|
constexpr IndexType kNumChunks = kPaddedInputDimensions / kSimdWidth;
|
||||||
|
const auto input_vector = reinterpret_cast<const __m256i*>(input);
|
||||||
|
#if !defined(USE_VNNI)
|
||||||
|
const __m256i kOnes = _mm256_set1_epi16(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
constexpr IndexType kNumChunks = kPaddedInputDimensions / kSimdWidth;
|
||||||
|
#ifndef USE_SSSE3
|
||||||
|
const __m128i kZeros = _mm_setzero_si128();
|
||||||
|
#else
|
||||||
|
const __m128i kOnes = _mm_set1_epi16(1);
|
||||||
|
#endif
|
||||||
|
const auto input_vector = reinterpret_cast<const __m128i*>(input);
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
constexpr IndexType kNumChunks = kPaddedInputDimensions / kSimdWidth;
|
||||||
|
const __m64 kZeros = _mm_setzero_si64();
|
||||||
|
const auto input_vector = reinterpret_cast<const __m64*>(input);
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
constexpr IndexType kNumChunks = kPaddedInputDimensions / kSimdWidth;
|
||||||
|
const auto input_vector = reinterpret_cast<const int8x8_t*>(input);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (IndexType i = 0; i < kOutputDimensions; ++i) {
|
||||||
|
const IndexType offset = i * kPaddedInputDimensions;
|
||||||
|
|
||||||
|
#if defined(USE_AVX512)
|
||||||
|
__m512i sum = _mm512_setzero_si512();
|
||||||
|
const auto row = reinterpret_cast<const __m512i*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
#if defined(USE_VNNI)
|
||||||
|
sum = _mm512_dpbusd_epi32(sum, _mm512_loadA_si512(&input_vector[j]), _mm512_load_si512(&row[j]));
|
||||||
|
#else
|
||||||
|
__m512i product = _mm512_maddubs_epi16(_mm512_loadA_si512(&input_vector[j]), _mm512_load_si512(&row[j]));
|
||||||
|
product = _mm512_madd_epi16(product, kOnes);
|
||||||
|
sum = _mm512_add_epi32(sum, product);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: Changing kMaxSimdWidth from 32 to 64 breaks loading existing networks.
|
||||||
|
// As a result kPaddedInputDimensions may not be an even multiple of 64(512bit)
|
||||||
|
// and we have to do one more 256bit chunk.
|
||||||
|
if (kPaddedInputDimensions != kNumChunks * kSimdWidth * 2)
|
||||||
|
{
|
||||||
|
const auto iv256 = reinterpret_cast<const __m256i*>(&input_vector[kNumChunks]);
|
||||||
|
const auto row256 = reinterpret_cast<const __m256i*>(&row[kNumChunks]);
|
||||||
|
#if defined(USE_VNNI)
|
||||||
|
__m256i product256 = _mm256_dpbusd_epi32(
|
||||||
|
_mm512_castsi512_si256(sum), _mm256_loadA_si256(&iv256[0]), _mm256_load_si256(&row256[0]));
|
||||||
|
sum = _mm512_inserti32x8(sum, product256, 0);
|
||||||
|
#else
|
||||||
|
__m256i product256 = _mm256_maddubs_epi16(_mm256_loadA_si256(&iv256[0]), _mm256_load_si256(&row256[0]));
|
||||||
|
sum = _mm512_add_epi32(sum, _mm512_cvtepi16_epi32(product256));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
output[i] = _mm512_reduce_add_epi32(sum) + biases_[i];
|
||||||
|
|
||||||
|
#elif defined(USE_AVX2)
|
||||||
|
__m256i sum = _mm256_setzero_si256();
|
||||||
|
const auto row = reinterpret_cast<const __m256i*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
#if defined(USE_VNNI)
|
||||||
|
sum = _mm256_dpbusd_epi32(sum, _mm256_loadA_si256(&input_vector[j]), _mm256_load_si256(&row[j]));
|
||||||
|
#else
|
||||||
|
__m256i product = _mm256_maddubs_epi16(_mm256_loadA_si256(&input_vector[j]), _mm256_load_si256(&row[j]));
|
||||||
|
product = _mm256_madd_epi16(product, kOnes);
|
||||||
|
sum = _mm256_add_epi32(sum, product);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
__m128i sum128 = _mm_add_epi32(_mm256_castsi256_si128(sum), _mm256_extracti128_si256(sum, 1));
|
||||||
|
sum128 = _mm_add_epi32(sum128, _mm_shuffle_epi32(sum128, _MM_PERM_BADC));
|
||||||
|
sum128 = _mm_add_epi32(sum128, _mm_shuffle_epi32(sum128, _MM_PERM_CDAB));
|
||||||
|
output[i] = _mm_cvtsi128_si32(sum128) + biases_[i];
|
||||||
|
|
||||||
|
#elif defined(USE_SSSE3)
|
||||||
|
__m128i sum = _mm_setzero_si128();
|
||||||
|
const auto row = reinterpret_cast<const __m128i*>(&weights_[offset]);
|
||||||
|
for (int j = 0; j < (int)kNumChunks - 1; j += 2) {
|
||||||
|
__m128i product0 = _mm_maddubs_epi16(_mm_load_si128(&input_vector[j]), _mm_load_si128(&row[j]));
|
||||||
|
product0 = _mm_madd_epi16(product0, kOnes);
|
||||||
|
sum = _mm_add_epi32(sum, product0);
|
||||||
|
__m128i product1 = _mm_maddubs_epi16(_mm_load_si128(&input_vector[j+1]), _mm_load_si128(&row[j+1]));
|
||||||
|
product1 = _mm_madd_epi16(product1, kOnes);
|
||||||
|
sum = _mm_add_epi32(sum, product1);
|
||||||
|
}
|
||||||
|
if (kNumChunks & 0x1) {
|
||||||
|
__m128i product = _mm_maddubs_epi16(_mm_load_si128(&input_vector[kNumChunks-1]), _mm_load_si128(&row[kNumChunks-1]));
|
||||||
|
product = _mm_madd_epi16(product, kOnes);
|
||||||
|
sum = _mm_add_epi32(sum, product);
|
||||||
|
}
|
||||||
|
sum = _mm_add_epi32(sum, _mm_shuffle_epi32(sum, 0x4E)); //_MM_PERM_BADC
|
||||||
|
sum = _mm_add_epi32(sum, _mm_shuffle_epi32(sum, 0xB1)); //_MM_PERM_CDAB
|
||||||
|
output[i] = _mm_cvtsi128_si32(sum) + biases_[i];
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
__m128i sum_lo = _mm_cvtsi32_si128(biases_[i]);
|
||||||
|
__m128i sum_hi = kZeros;
|
||||||
|
const auto row = reinterpret_cast<const __m128i*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
__m128i row_j = _mm_load_si128(&row[j]);
|
||||||
|
__m128i input_j = _mm_load_si128(&input_vector[j]);
|
||||||
|
__m128i row_signs = _mm_cmpgt_epi8(kZeros, row_j);
|
||||||
|
__m128i extended_row_lo = _mm_unpacklo_epi8(row_j, row_signs);
|
||||||
|
__m128i extended_row_hi = _mm_unpackhi_epi8(row_j, row_signs);
|
||||||
|
__m128i extended_input_lo = _mm_unpacklo_epi8(input_j, kZeros);
|
||||||
|
__m128i extended_input_hi = _mm_unpackhi_epi8(input_j, kZeros);
|
||||||
|
__m128i product_lo = _mm_madd_epi16(extended_row_lo, extended_input_lo);
|
||||||
|
__m128i product_hi = _mm_madd_epi16(extended_row_hi, extended_input_hi);
|
||||||
|
sum_lo = _mm_add_epi32(sum_lo, product_lo);
|
||||||
|
sum_hi = _mm_add_epi32(sum_hi, product_hi);
|
||||||
|
}
|
||||||
|
__m128i sum = _mm_add_epi32(sum_lo, sum_hi);
|
||||||
|
__m128i sum_high_64 = _mm_shuffle_epi32(sum, _MM_SHUFFLE(1, 0, 3, 2));
|
||||||
|
sum = _mm_add_epi32(sum, sum_high_64);
|
||||||
|
__m128i sum_second_32 = _mm_shufflelo_epi16(sum, _MM_SHUFFLE(1, 0, 3, 2));
|
||||||
|
sum = _mm_add_epi32(sum, sum_second_32);
|
||||||
|
output[i] = _mm_cvtsi128_si32(sum);
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
__m64 sum_lo = _mm_cvtsi32_si64(biases_[i]);
|
||||||
|
__m64 sum_hi = kZeros;
|
||||||
|
const auto row = reinterpret_cast<const __m64*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
__m64 row_j = row[j];
|
||||||
|
__m64 input_j = input_vector[j];
|
||||||
|
__m64 row_signs = _mm_cmpgt_pi8(kZeros, row_j);
|
||||||
|
__m64 extended_row_lo = _mm_unpacklo_pi8(row_j, row_signs);
|
||||||
|
__m64 extended_row_hi = _mm_unpackhi_pi8(row_j, row_signs);
|
||||||
|
__m64 extended_input_lo = _mm_unpacklo_pi8(input_j, kZeros);
|
||||||
|
__m64 extended_input_hi = _mm_unpackhi_pi8(input_j, kZeros);
|
||||||
|
__m64 product_lo = _mm_madd_pi16(extended_row_lo, extended_input_lo);
|
||||||
|
__m64 product_hi = _mm_madd_pi16(extended_row_hi, extended_input_hi);
|
||||||
|
sum_lo = _mm_add_pi32(sum_lo, product_lo);
|
||||||
|
sum_hi = _mm_add_pi32(sum_hi, product_hi);
|
||||||
|
}
|
||||||
|
__m64 sum = _mm_add_pi32(sum_lo, sum_hi);
|
||||||
|
sum = _mm_add_pi32(sum, _mm_unpackhi_pi32(sum, sum));
|
||||||
|
output[i] = _mm_cvtsi64_si32(sum);
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
int32x4_t sum = {biases_[i]};
|
||||||
|
const auto row = reinterpret_cast<const int8x8_t*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
int16x8_t product = vmull_s8(input_vector[j * 2], row[j * 2]);
|
||||||
|
product = vmlal_s8(product, input_vector[j * 2 + 1], row[j * 2 + 1]);
|
||||||
|
sum = vpadalq_s16(sum, product);
|
||||||
|
}
|
||||||
|
output[i] = sum[0] + sum[1] + sum[2] + sum[3];
|
||||||
|
|
||||||
|
#else
|
||||||
|
OutputType sum = biases_[i];
|
||||||
|
for (IndexType j = 0; j < kInputDimensions; ++j) {
|
||||||
|
sum += weights_[offset + j] * input[j];
|
||||||
|
}
|
||||||
|
output[i] = sum;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
#if defined(USE_MMX)
|
||||||
|
_mm_empty();
|
||||||
|
#endif
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
using BiasType = OutputType;
|
||||||
|
using WeightType = std::int8_t;
|
||||||
|
|
||||||
|
PreviousLayer previous_layer_;
|
||||||
|
|
||||||
|
alignas(kCacheLineSize) BiasType biases_[kOutputDimensions];
|
||||||
|
alignas(kCacheLineSize)
|
||||||
|
WeightType weights_[kOutputDimensions * kPaddedInputDimensions];
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE::Layers
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_LAYERS_AFFINE_TRANSFORM_H_INCLUDED
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Definition of layer ClippedReLU of NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_LAYERS_CLIPPED_RELU_H_INCLUDED
|
||||||
|
#define NNUE_LAYERS_CLIPPED_RELU_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../nnue_common.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Layers {
|
||||||
|
|
||||||
|
// Clipped ReLU
|
||||||
|
template <typename PreviousLayer>
|
||||||
|
class ClippedReLU {
|
||||||
|
public:
|
||||||
|
// Input/output type
|
||||||
|
using InputType = typename PreviousLayer::OutputType;
|
||||||
|
using OutputType = std::uint8_t;
|
||||||
|
static_assert(std::is_same<InputType, std::int32_t>::value, "");
|
||||||
|
|
||||||
|
// Number of input/output dimensions
|
||||||
|
static constexpr IndexType kInputDimensions =
|
||||||
|
PreviousLayer::kOutputDimensions;
|
||||||
|
static constexpr IndexType kOutputDimensions = kInputDimensions;
|
||||||
|
|
||||||
|
// Size of forward propagation buffer used in this layer
|
||||||
|
static constexpr std::size_t kSelfBufferSize =
|
||||||
|
CeilToMultiple(kOutputDimensions * sizeof(OutputType), kCacheLineSize);
|
||||||
|
|
||||||
|
// Size of the forward propagation buffer used from the input layer to this layer
|
||||||
|
static constexpr std::size_t kBufferSize =
|
||||||
|
PreviousLayer::kBufferSize + kSelfBufferSize;
|
||||||
|
|
||||||
|
// Hash value embedded in the evaluation file
|
||||||
|
static constexpr std::uint32_t GetHashValue() {
|
||||||
|
std::uint32_t hash_value = 0x538D24C7u;
|
||||||
|
hash_value += PreviousLayer::GetHashValue();
|
||||||
|
return hash_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read network parameters
|
||||||
|
bool ReadParameters(std::istream& stream) {
|
||||||
|
return previous_layer_.ReadParameters(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward propagation
|
||||||
|
const OutputType* Propagate(
|
||||||
|
const TransformedFeatureType* transformed_features, char* buffer) const {
|
||||||
|
const auto input = previous_layer_.Propagate(
|
||||||
|
transformed_features, buffer + kSelfBufferSize);
|
||||||
|
const auto output = reinterpret_cast<OutputType*>(buffer);
|
||||||
|
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
constexpr IndexType kNumChunks = kInputDimensions / kSimdWidth;
|
||||||
|
const __m256i kZero = _mm256_setzero_si256();
|
||||||
|
const __m256i kOffsets = _mm256_set_epi32(7, 3, 6, 2, 5, 1, 4, 0);
|
||||||
|
const auto in = reinterpret_cast<const __m256i*>(input);
|
||||||
|
const auto out = reinterpret_cast<__m256i*>(output);
|
||||||
|
for (IndexType i = 0; i < kNumChunks; ++i) {
|
||||||
|
const __m256i words0 = _mm256_srai_epi16(_mm256_packs_epi32(
|
||||||
|
_mm256_loadA_si256(&in[i * 4 + 0]),
|
||||||
|
_mm256_loadA_si256(&in[i * 4 + 1])), kWeightScaleBits);
|
||||||
|
const __m256i words1 = _mm256_srai_epi16(_mm256_packs_epi32(
|
||||||
|
_mm256_loadA_si256(&in[i * 4 + 2]),
|
||||||
|
_mm256_loadA_si256(&in[i * 4 + 3])), kWeightScaleBits);
|
||||||
|
_mm256_storeA_si256(&out[i], _mm256_permutevar8x32_epi32(_mm256_max_epi8(
|
||||||
|
_mm256_packs_epi16(words0, words1), kZero), kOffsets));
|
||||||
|
}
|
||||||
|
constexpr IndexType kStart = kNumChunks * kSimdWidth;
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
constexpr IndexType kNumChunks = kInputDimensions / kSimdWidth;
|
||||||
|
|
||||||
|
#ifdef USE_SSE41
|
||||||
|
const __m128i kZero = _mm_setzero_si128();
|
||||||
|
#else
|
||||||
|
const __m128i k0x80s = _mm_set1_epi8(-128);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const auto in = reinterpret_cast<const __m128i*>(input);
|
||||||
|
const auto out = reinterpret_cast<__m128i*>(output);
|
||||||
|
for (IndexType i = 0; i < kNumChunks; ++i) {
|
||||||
|
const __m128i words0 = _mm_srai_epi16(_mm_packs_epi32(
|
||||||
|
_mm_load_si128(&in[i * 4 + 0]),
|
||||||
|
_mm_load_si128(&in[i * 4 + 1])), kWeightScaleBits);
|
||||||
|
const __m128i words1 = _mm_srai_epi16(_mm_packs_epi32(
|
||||||
|
_mm_load_si128(&in[i * 4 + 2]),
|
||||||
|
_mm_load_si128(&in[i * 4 + 3])), kWeightScaleBits);
|
||||||
|
const __m128i packedbytes = _mm_packs_epi16(words0, words1);
|
||||||
|
_mm_store_si128(&out[i],
|
||||||
|
|
||||||
|
#ifdef USE_SSE41
|
||||||
|
_mm_max_epi8(packedbytes, kZero)
|
||||||
|
#else
|
||||||
|
_mm_subs_epi8(_mm_adds_epi8(packedbytes, k0x80s), k0x80s)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
constexpr IndexType kStart = kNumChunks * kSimdWidth;
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
constexpr IndexType kNumChunks = kInputDimensions / kSimdWidth;
|
||||||
|
const __m64 k0x80s = _mm_set1_pi8(-128);
|
||||||
|
const auto in = reinterpret_cast<const __m64*>(input);
|
||||||
|
const auto out = reinterpret_cast<__m64*>(output);
|
||||||
|
for (IndexType i = 0; i < kNumChunks; ++i) {
|
||||||
|
const __m64 words0 = _mm_srai_pi16(
|
||||||
|
_mm_packs_pi32(in[i * 4 + 0], in[i * 4 + 1]),
|
||||||
|
kWeightScaleBits);
|
||||||
|
const __m64 words1 = _mm_srai_pi16(
|
||||||
|
_mm_packs_pi32(in[i * 4 + 2], in[i * 4 + 3]),
|
||||||
|
kWeightScaleBits);
|
||||||
|
const __m64 packedbytes = _mm_packs_pi16(words0, words1);
|
||||||
|
out[i] = _mm_subs_pi8(_mm_adds_pi8(packedbytes, k0x80s), k0x80s);
|
||||||
|
}
|
||||||
|
_mm_empty();
|
||||||
|
constexpr IndexType kStart = kNumChunks * kSimdWidth;
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
constexpr IndexType kNumChunks = kInputDimensions / (kSimdWidth / 2);
|
||||||
|
const int8x8_t kZero = {0};
|
||||||
|
const auto in = reinterpret_cast<const int32x4_t*>(input);
|
||||||
|
const auto out = reinterpret_cast<int8x8_t*>(output);
|
||||||
|
for (IndexType i = 0; i < kNumChunks; ++i) {
|
||||||
|
int16x8_t shifted;
|
||||||
|
const auto pack = reinterpret_cast<int16x4_t*>(&shifted);
|
||||||
|
pack[0] = vqshrn_n_s32(in[i * 2 + 0], kWeightScaleBits);
|
||||||
|
pack[1] = vqshrn_n_s32(in[i * 2 + 1], kWeightScaleBits);
|
||||||
|
out[i] = vmax_s8(vqmovn_s16(shifted), kZero);
|
||||||
|
}
|
||||||
|
constexpr IndexType kStart = kNumChunks * (kSimdWidth / 2);
|
||||||
|
#else
|
||||||
|
constexpr IndexType kStart = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (IndexType i = kStart; i < kInputDimensions; ++i) {
|
||||||
|
output[i] = static_cast<OutputType>(
|
||||||
|
std::max(0, std::min(127, input[i] >> kWeightScaleBits)));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PreviousLayer previous_layer_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE::Layers
|
||||||
|
|
||||||
|
#endif // NNUE_LAYERS_CLIPPED_RELU_H_INCLUDED
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// NNUE evaluation function layer InputSlice definition
|
||||||
|
|
||||||
|
#ifndef NNUE_LAYERS_INPUT_SLICE_H_INCLUDED
|
||||||
|
#define NNUE_LAYERS_INPUT_SLICE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../nnue_common.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE::Layers {
|
||||||
|
|
||||||
|
// Input layer
|
||||||
|
template <IndexType OutputDimensions, IndexType Offset = 0>
|
||||||
|
class InputSlice {
|
||||||
|
public:
|
||||||
|
// Need to maintain alignment
|
||||||
|
static_assert(Offset % kMaxSimdWidth == 0, "");
|
||||||
|
|
||||||
|
// Output type
|
||||||
|
using OutputType = TransformedFeatureType;
|
||||||
|
|
||||||
|
// Output dimensionality
|
||||||
|
static constexpr IndexType kOutputDimensions = OutputDimensions;
|
||||||
|
|
||||||
|
// Size of forward propagation buffer used from the input layer to this layer
|
||||||
|
static constexpr std::size_t kBufferSize = 0;
|
||||||
|
|
||||||
|
// Hash value embedded in the evaluation file
|
||||||
|
static constexpr std::uint32_t GetHashValue() {
|
||||||
|
std::uint32_t hash_value = 0xEC42E90Du;
|
||||||
|
hash_value ^= kOutputDimensions ^ (Offset << 10);
|
||||||
|
return hash_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read network parameters
|
||||||
|
bool ReadParameters(std::istream& /*stream*/) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward propagation
|
||||||
|
const OutputType* Propagate(
|
||||||
|
const TransformedFeatureType* transformed_features,
|
||||||
|
char* /*buffer*/) const {
|
||||||
|
return transformed_features + Offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Layers
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_LAYERS_INPUT_SLICE_H_INCLUDED
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Class for difference calculation of NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_ACCUMULATOR_H_INCLUDED
|
||||||
|
#define NNUE_ACCUMULATOR_H_INCLUDED
|
||||||
|
|
||||||
|
#include "nnue_architecture.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE {
|
||||||
|
|
||||||
|
// Class that holds the result of affine transformation of input features
|
||||||
|
struct alignas(kCacheLineSize) Accumulator {
|
||||||
|
std::int16_t
|
||||||
|
accumulation[2][kRefreshTriggers.size()][kTransformedFeatureDimensions];
|
||||||
|
Value score;
|
||||||
|
bool computed_accumulation;
|
||||||
|
bool computed_score;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE
|
||||||
|
|
||||||
|
#endif // NNUE_ACCUMULATOR_H_INCLUDED
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Input features and network structure used in NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_ARCHITECTURE_H_INCLUDED
|
||||||
|
#define NNUE_ARCHITECTURE_H_INCLUDED
|
||||||
|
|
||||||
|
// Defines the network structure
|
||||||
|
#include "architectures/halfkp_256x2-32-32.h"
|
||||||
|
|
||||||
|
namespace Eval::NNUE {
|
||||||
|
|
||||||
|
static_assert(kTransformedFeatureDimensions % kMaxSimdWidth == 0, "");
|
||||||
|
static_assert(Network::kOutputDimensions == 1, "");
|
||||||
|
static_assert(std::is_same<Network::OutputType, std::int32_t>::value, "");
|
||||||
|
|
||||||
|
// Trigger for full calculation instead of difference calculation
|
||||||
|
constexpr auto kRefreshTriggers = RawFeatures::kRefreshTriggers;
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_ARCHITECTURE_H_INCLUDED
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Constants used in NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_COMMON_H_INCLUDED
|
||||||
|
#define NNUE_COMMON_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
#include <immintrin.h>
|
||||||
|
|
||||||
|
#elif defined(USE_SSE41)
|
||||||
|
#include <smmintrin.h>
|
||||||
|
|
||||||
|
#elif defined(USE_SSSE3)
|
||||||
|
#include <tmmintrin.h>
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
#include <emmintrin.h>
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
#include <mmintrin.h>
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
#include <arm_neon.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// HACK: Use _mm256_loadu_si256() instead of _mm256_load_si256. Otherwise a binary
|
||||||
|
// compiled with older g++ crashes because the output memory is not aligned
|
||||||
|
// even though alignas is specified.
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
#if defined(__GNUC__ ) && (__GNUC__ < 9) && defined(_WIN32) && !defined(__clang__)
|
||||||
|
#define _mm256_loadA_si256 _mm256_loadu_si256
|
||||||
|
#define _mm256_storeA_si256 _mm256_storeu_si256
|
||||||
|
#else
|
||||||
|
#define _mm256_loadA_si256 _mm256_load_si256
|
||||||
|
#define _mm256_storeA_si256 _mm256_store_si256
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USE_AVX512)
|
||||||
|
#if defined(__GNUC__ ) && (__GNUC__ < 9) && defined(_WIN32) && !defined(__clang__)
|
||||||
|
#define _mm512_loadA_si512 _mm512_loadu_si512
|
||||||
|
#define _mm512_storeA_si512 _mm512_storeu_si512
|
||||||
|
#else
|
||||||
|
#define _mm512_loadA_si512 _mm512_load_si512
|
||||||
|
#define _mm512_storeA_si512 _mm512_store_si512
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Eval::NNUE {
|
||||||
|
|
||||||
|
// Version of the evaluation file
|
||||||
|
constexpr std::uint32_t kVersion = 0x7AF32F16u;
|
||||||
|
|
||||||
|
// Constant used in evaluation value calculation
|
||||||
|
constexpr int FV_SCALE = 16;
|
||||||
|
constexpr int kWeightScaleBits = 6;
|
||||||
|
|
||||||
|
// Size of cache line (in bytes)
|
||||||
|
constexpr std::size_t kCacheLineSize = 64;
|
||||||
|
|
||||||
|
// SIMD width (in bytes)
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
constexpr std::size_t kSimdWidth = 32;
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
constexpr std::size_t kSimdWidth = 16;
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
constexpr std::size_t kSimdWidth = 8;
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
constexpr std::size_t kSimdWidth = 16;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
constexpr std::size_t kMaxSimdWidth = 32;
|
||||||
|
|
||||||
|
// unique number for each piece type on each square
|
||||||
|
enum {
|
||||||
|
PS_NONE = 0,
|
||||||
|
PS_W_PAWN = 1,
|
||||||
|
PS_B_PAWN = 1 * SQUARE_NB + 1,
|
||||||
|
PS_W_KNIGHT = 2 * SQUARE_NB + 1,
|
||||||
|
PS_B_KNIGHT = 3 * SQUARE_NB + 1,
|
||||||
|
PS_W_BISHOP = 4 * SQUARE_NB + 1,
|
||||||
|
PS_B_BISHOP = 5 * SQUARE_NB + 1,
|
||||||
|
PS_W_ROOK = 6 * SQUARE_NB + 1,
|
||||||
|
PS_B_ROOK = 7 * SQUARE_NB + 1,
|
||||||
|
PS_W_QUEEN = 8 * SQUARE_NB + 1,
|
||||||
|
PS_B_QUEEN = 9 * SQUARE_NB + 1,
|
||||||
|
PS_W_KING = 10 * SQUARE_NB + 1,
|
||||||
|
PS_END = PS_W_KING, // pieces without kings (pawns included)
|
||||||
|
PS_B_KING = 11 * SQUARE_NB + 1,
|
||||||
|
PS_END2 = 12 * SQUARE_NB + 1
|
||||||
|
};
|
||||||
|
|
||||||
|
extern uint32_t kpp_board_index[PIECE_NB][COLOR_NB];
|
||||||
|
|
||||||
|
// Type of input feature after conversion
|
||||||
|
using TransformedFeatureType = std::uint8_t;
|
||||||
|
using IndexType = std::uint32_t;
|
||||||
|
|
||||||
|
// Round n up to be a multiple of base
|
||||||
|
template <typename IntType>
|
||||||
|
constexpr IntType CeilToMultiple(IntType n, IntType base) {
|
||||||
|
return (n + base - 1) / base * base;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read_little_endian() is our utility to read an integer (signed or unsigned, any size)
|
||||||
|
// from a stream in little-endian order. We swap the byte order after the read if
|
||||||
|
// necessary to return a result with the byte ordering of the compiling machine.
|
||||||
|
template <typename IntType>
|
||||||
|
inline IntType read_little_endian(std::istream& stream) {
|
||||||
|
|
||||||
|
IntType result;
|
||||||
|
std::uint8_t u[sizeof(IntType)];
|
||||||
|
typename std::make_unsigned<IntType>::type v = 0;
|
||||||
|
|
||||||
|
stream.read(reinterpret_cast<char*>(u), sizeof(IntType));
|
||||||
|
for (std::size_t i = 0; i < sizeof(IntType); ++i)
|
||||||
|
v = (v << 8) | u[sizeof(IntType) - i - 1];
|
||||||
|
|
||||||
|
std::memcpy(&result, &v, sizeof(IntType));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_COMMON_H_INCLUDED
|
||||||
@@ -0,0 +1,378 @@
|
|||||||
|
/*
|
||||||
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
|
|
||||||
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Stockfish is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// A class that converts the input features of the NNUE evaluation function
|
||||||
|
|
||||||
|
#ifndef NNUE_FEATURE_TRANSFORMER_H_INCLUDED
|
||||||
|
#define NNUE_FEATURE_TRANSFORMER_H_INCLUDED
|
||||||
|
|
||||||
|
#include "nnue_common.h"
|
||||||
|
#include "nnue_architecture.h"
|
||||||
|
#include "features/index_list.h"
|
||||||
|
|
||||||
|
#include <cstring> // std::memset()
|
||||||
|
|
||||||
|
namespace Eval::NNUE {
|
||||||
|
|
||||||
|
// Input feature converter
|
||||||
|
class FeatureTransformer {
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Number of output dimensions for one side
|
||||||
|
static constexpr IndexType kHalfDimensions = kTransformedFeatureDimensions;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Output type
|
||||||
|
using OutputType = TransformedFeatureType;
|
||||||
|
|
||||||
|
// Number of input/output dimensions
|
||||||
|
static constexpr IndexType kInputDimensions = RawFeatures::kDimensions;
|
||||||
|
static constexpr IndexType kOutputDimensions = kHalfDimensions * 2;
|
||||||
|
|
||||||
|
// Size of forward propagation buffer
|
||||||
|
static constexpr std::size_t kBufferSize =
|
||||||
|
kOutputDimensions * sizeof(OutputType);
|
||||||
|
|
||||||
|
// Hash value embedded in the evaluation file
|
||||||
|
static constexpr std::uint32_t GetHashValue() {
|
||||||
|
return RawFeatures::kHashValue ^ kOutputDimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read network parameters
|
||||||
|
bool ReadParameters(std::istream& stream) {
|
||||||
|
for (std::size_t i = 0; i < kHalfDimensions; ++i)
|
||||||
|
biases_[i] = read_little_endian<BiasType>(stream);
|
||||||
|
for (std::size_t i = 0; i < kHalfDimensions * kInputDimensions; ++i)
|
||||||
|
weights_[i] = read_little_endian<WeightType>(stream);
|
||||||
|
return !stream.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Proceed with the difference calculation if possible
|
||||||
|
bool UpdateAccumulatorIfPossible(const Position& pos) const {
|
||||||
|
const auto now = pos.state();
|
||||||
|
if (now->accumulator.computed_accumulation) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const auto prev = now->previous;
|
||||||
|
if (prev && prev->accumulator.computed_accumulation) {
|
||||||
|
UpdateAccumulator(pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert input features
|
||||||
|
void Transform(const Position& pos, OutputType* output, bool refresh) const {
|
||||||
|
if (refresh || !UpdateAccumulatorIfPossible(pos)) {
|
||||||
|
RefreshAccumulator(pos);
|
||||||
|
}
|
||||||
|
const auto& accumulation = pos.state()->accumulator.accumulation;
|
||||||
|
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / kSimdWidth;
|
||||||
|
constexpr int kControl = 0b11011000;
|
||||||
|
const __m256i kZero = _mm256_setzero_si256();
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / kSimdWidth;
|
||||||
|
|
||||||
|
#ifdef USE_SSE41
|
||||||
|
const __m128i kZero = _mm_setzero_si128();
|
||||||
|
#else
|
||||||
|
const __m128i k0x80s = _mm_set1_epi8(-128);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / kSimdWidth;
|
||||||
|
const __m64 k0x80s = _mm_set1_pi8(-128);
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
const int8x8_t kZero = {0};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const Color perspectives[2] = {pos.side_to_move(), ~pos.side_to_move()};
|
||||||
|
for (IndexType p = 0; p < 2; ++p) {
|
||||||
|
const IndexType offset = kHalfDimensions * p;
|
||||||
|
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
auto out = reinterpret_cast<__m256i*>(&output[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
__m256i sum0 = _mm256_loadA_si256(
|
||||||
|
&reinterpret_cast<const __m256i*>(accumulation[perspectives[p]][0])[j * 2 + 0]);
|
||||||
|
__m256i sum1 = _mm256_loadA_si256(
|
||||||
|
&reinterpret_cast<const __m256i*>(accumulation[perspectives[p]][0])[j * 2 + 1]);
|
||||||
|
_mm256_storeA_si256(&out[j], _mm256_permute4x64_epi64(_mm256_max_epi8(
|
||||||
|
_mm256_packs_epi16(sum0, sum1), kZero), kControl));
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
auto out = reinterpret_cast<__m128i*>(&output[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
__m128i sum0 = _mm_load_si128(&reinterpret_cast<const __m128i*>(
|
||||||
|
accumulation[perspectives[p]][0])[j * 2 + 0]);
|
||||||
|
__m128i sum1 = _mm_load_si128(&reinterpret_cast<const __m128i*>(
|
||||||
|
accumulation[perspectives[p]][0])[j * 2 + 1]);
|
||||||
|
const __m128i packedbytes = _mm_packs_epi16(sum0, sum1);
|
||||||
|
|
||||||
|
_mm_store_si128(&out[j],
|
||||||
|
|
||||||
|
#ifdef USE_SSE41
|
||||||
|
_mm_max_epi8(packedbytes, kZero)
|
||||||
|
#else
|
||||||
|
_mm_subs_epi8(_mm_adds_epi8(packedbytes, k0x80s), k0x80s)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
auto out = reinterpret_cast<__m64*>(&output[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
__m64 sum0 = *(&reinterpret_cast<const __m64*>(
|
||||||
|
accumulation[perspectives[p]][0])[j * 2 + 0]);
|
||||||
|
__m64 sum1 = *(&reinterpret_cast<const __m64*>(
|
||||||
|
accumulation[perspectives[p]][0])[j * 2 + 1]);
|
||||||
|
const __m64 packedbytes = _mm_packs_pi16(sum0, sum1);
|
||||||
|
out[j] = _mm_subs_pi8(_mm_adds_pi8(packedbytes, k0x80s), k0x80s);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
const auto out = reinterpret_cast<int8x8_t*>(&output[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
int16x8_t sum = reinterpret_cast<const int16x8_t*>(
|
||||||
|
accumulation[perspectives[p]][0])[j];
|
||||||
|
out[j] = vmax_s8(vqmovn_s16(sum), kZero);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
for (IndexType j = 0; j < kHalfDimensions; ++j) {
|
||||||
|
BiasType sum = accumulation[static_cast<int>(perspectives[p])][0][j];
|
||||||
|
output[offset + j] = static_cast<OutputType>(
|
||||||
|
std::max<int>(0, std::min<int>(127, sum)));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
#if defined(USE_MMX)
|
||||||
|
_mm_empty();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Calculate cumulative value without using difference calculation
|
||||||
|
void RefreshAccumulator(const Position& pos) const {
|
||||||
|
auto& accumulator = pos.state()->accumulator;
|
||||||
|
IndexType i = 0;
|
||||||
|
Features::IndexList active_indices[2];
|
||||||
|
RawFeatures::AppendActiveIndices(pos, kRefreshTriggers[i],
|
||||||
|
active_indices);
|
||||||
|
for (Color perspective : { WHITE, BLACK }) {
|
||||||
|
std::memcpy(accumulator.accumulation[perspective][i], biases_,
|
||||||
|
kHalfDimensions * sizeof(BiasType));
|
||||||
|
for (const auto index : active_indices[perspective]) {
|
||||||
|
const IndexType offset = kHalfDimensions * index;
|
||||||
|
#if defined(USE_AVX512)
|
||||||
|
auto accumulation = reinterpret_cast<__m512i*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
auto column = reinterpret_cast<const __m512i*>(&weights_[offset]);
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / kSimdWidth;
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j)
|
||||||
|
_mm512_storeA_si512(&accumulation[j], _mm512_add_epi16(_mm512_loadA_si512(&accumulation[j]), column[j]));
|
||||||
|
|
||||||
|
#elif defined(USE_AVX2)
|
||||||
|
auto accumulation = reinterpret_cast<__m256i*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
auto column = reinterpret_cast<const __m256i*>(&weights_[offset]);
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j)
|
||||||
|
_mm256_storeA_si256(&accumulation[j], _mm256_add_epi16(_mm256_loadA_si256(&accumulation[j]), column[j]));
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
auto accumulation = reinterpret_cast<__m128i*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
auto column = reinterpret_cast<const __m128i*>(&weights_[offset]);
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j)
|
||||||
|
accumulation[j] = _mm_add_epi16(accumulation[j], column[j]);
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
auto accumulation = reinterpret_cast<__m64*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
auto column = reinterpret_cast<const __m64*>(&weights_[offset]);
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = _mm_add_pi16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
auto accumulation = reinterpret_cast<int16x8_t*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
auto column = reinterpret_cast<const int16x8_t*>(&weights_[offset]);
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j)
|
||||||
|
accumulation[j] = vaddq_s16(accumulation[j], column[j]);
|
||||||
|
|
||||||
|
#else
|
||||||
|
for (IndexType j = 0; j < kHalfDimensions; ++j)
|
||||||
|
accumulator.accumulation[perspective][i][j] += weights_[offset + j];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if defined(USE_MMX)
|
||||||
|
_mm_empty();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
accumulator.computed_accumulation = true;
|
||||||
|
accumulator.computed_score = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate cumulative value using difference calculation
|
||||||
|
void UpdateAccumulator(const Position& pos) const {
|
||||||
|
const auto prev_accumulator = pos.state()->previous->accumulator;
|
||||||
|
auto& accumulator = pos.state()->accumulator;
|
||||||
|
IndexType i = 0;
|
||||||
|
Features::IndexList removed_indices[2], added_indices[2];
|
||||||
|
bool reset[2];
|
||||||
|
RawFeatures::AppendChangedIndices(pos, kRefreshTriggers[i],
|
||||||
|
removed_indices, added_indices, reset);
|
||||||
|
for (Color perspective : { WHITE, BLACK }) {
|
||||||
|
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
auto accumulation = reinterpret_cast<__m256i*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
auto accumulation = reinterpret_cast<__m128i*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
auto accumulation = reinterpret_cast<__m64*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||||
|
auto accumulation = reinterpret_cast<int16x8_t*>(
|
||||||
|
&accumulator.accumulation[perspective][i][0]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (reset[perspective]) {
|
||||||
|
std::memcpy(accumulator.accumulation[perspective][i], biases_,
|
||||||
|
kHalfDimensions * sizeof(BiasType));
|
||||||
|
} else {
|
||||||
|
std::memcpy(accumulator.accumulation[perspective][i],
|
||||||
|
prev_accumulator.accumulation[perspective][i],
|
||||||
|
kHalfDimensions * sizeof(BiasType));
|
||||||
|
// Difference calculation for the deactivated features
|
||||||
|
for (const auto index : removed_indices[perspective]) {
|
||||||
|
const IndexType offset = kHalfDimensions * index;
|
||||||
|
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
auto column = reinterpret_cast<const __m256i*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = _mm256_sub_epi16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
auto column = reinterpret_cast<const __m128i*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = _mm_sub_epi16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
auto column = reinterpret_cast<const __m64*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = _mm_sub_pi16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
auto column = reinterpret_cast<const int16x8_t*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = vsubq_s16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
for (IndexType j = 0; j < kHalfDimensions; ++j) {
|
||||||
|
accumulator.accumulation[perspective][i][j] -=
|
||||||
|
weights_[offset + j];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ // Difference calculation for the activated features
|
||||||
|
for (const auto index : added_indices[perspective]) {
|
||||||
|
const IndexType offset = kHalfDimensions * index;
|
||||||
|
|
||||||
|
#if defined(USE_AVX2)
|
||||||
|
auto column = reinterpret_cast<const __m256i*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = _mm256_add_epi16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_SSE2)
|
||||||
|
auto column = reinterpret_cast<const __m128i*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = _mm_add_epi16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_MMX)
|
||||||
|
auto column = reinterpret_cast<const __m64*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = _mm_add_pi16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_NEON)
|
||||||
|
auto column = reinterpret_cast<const int16x8_t*>(&weights_[offset]);
|
||||||
|
for (IndexType j = 0; j < kNumChunks; ++j) {
|
||||||
|
accumulation[j] = vaddq_s16(accumulation[j], column[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
for (IndexType j = 0; j < kHalfDimensions; ++j) {
|
||||||
|
accumulator.accumulation[perspective][i][j] +=
|
||||||
|
weights_[offset + j];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if defined(USE_MMX)
|
||||||
|
_mm_empty();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
accumulator.computed_accumulation = true;
|
||||||
|
accumulator.computed_score = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
using BiasType = std::int16_t;
|
||||||
|
using WeightType = std::int16_t;
|
||||||
|
|
||||||
|
alignas(kCacheLineSize) BiasType biases_[kHalfDimensions];
|
||||||
|
alignas(kCacheLineSize)
|
||||||
|
WeightType weights_[kHalfDimensions * kInputDimensions];
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Eval::NNUE
|
||||||
|
|
||||||
|
#endif // #ifndef NNUE_FEATURE_TRANSFORMER_H_INCLUDED
|
||||||
+9
-11
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -32,21 +30,21 @@ namespace {
|
|||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// Pawn penalties
|
// Pawn penalties
|
||||||
constexpr Score Backward = S( 9, 24);
|
constexpr Score Backward = S( 8, 27);
|
||||||
constexpr Score Doubled = S(11, 56);
|
constexpr Score Doubled = S(11, 55);
|
||||||
constexpr Score Isolated = S( 5, 15);
|
constexpr Score Isolated = S( 5, 17);
|
||||||
constexpr Score WeakLever = S( 0, 56);
|
constexpr Score WeakLever = S( 2, 54);
|
||||||
constexpr Score WeakUnopposed = S(13, 27);
|
constexpr Score WeakUnopposed = S(15, 25);
|
||||||
|
|
||||||
// Bonus for blocked pawns at 5th or 6th rank
|
// Bonus for blocked pawns at 5th or 6th rank
|
||||||
constexpr Score BlockedPawn[2] = { S(-11, -4), S(-3, 4) };
|
constexpr Score BlockedPawn[2] = { S(-13, -4), S(-4, 3) };
|
||||||
|
|
||||||
constexpr Score BlockedStorm[RANK_NB] = {
|
constexpr Score BlockedStorm[RANK_NB] = {
|
||||||
S(0, 0), S(0, 0), S(76, 78), S(-10, 15), S(-7, 10), S(-4, 6), S(-1, 2)
|
S(0, 0), S(0, 0), S(76, 78), S(-10, 15), S(-7, 10), S(-4, 6), S(-1, 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connected pawn bonus
|
// Connected pawn bonus
|
||||||
constexpr int Connected[RANK_NB] = { 0, 7, 8, 12, 29, 48, 86 };
|
constexpr int Connected[RANK_NB] = { 0, 7, 8, 11, 24, 45, 85 };
|
||||||
|
|
||||||
// Strength of pawn shelter for our king by [distance from edge][rank].
|
// Strength of pawn shelter for our king by [distance from edge][rank].
|
||||||
// RANK_1 = 0 is used for files where we have no pawn, or pawn is behind our king.
|
// RANK_1 = 0 is used for files where we have no pawn, or pawn is behind our king.
|
||||||
@@ -221,7 +219,7 @@ Score Entry::evaluate_shelter(const Position& pos, Square ksq) const {
|
|||||||
|
|
||||||
Score bonus = make_score(5, 5);
|
Score bonus = make_score(5, 5);
|
||||||
|
|
||||||
File center = Utility::clamp(file_of(ksq), FILE_B, FILE_G);
|
File center = std::clamp(file_of(ksq), FILE_B, FILE_G);
|
||||||
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
||||||
{
|
{
|
||||||
b = ourPawns & file_bb(f);
|
b = ourPawns & file_bb(f);
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+57
-8
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -211,8 +209,7 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
|
|||||||
else if (token == '/')
|
else if (token == '/')
|
||||||
sq += 2 * SOUTH;
|
sq += 2 * SOUTH;
|
||||||
|
|
||||||
else if ((idx = PieceToChar.find(token)) != string::npos)
|
else if ((idx = PieceToChar.find(token)) != string::npos) {
|
||||||
{
|
|
||||||
put_piece(Piece(idx), sq);
|
put_piece(Piece(idx), sq);
|
||||||
++sq;
|
++sq;
|
||||||
}
|
}
|
||||||
@@ -705,6 +702,12 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
++st->rule50;
|
++st->rule50;
|
||||||
++st->pliesFromNull;
|
++st->pliesFromNull;
|
||||||
|
|
||||||
|
// Used by NNUE
|
||||||
|
st->accumulator.computed_accumulation = false;
|
||||||
|
st->accumulator.computed_score = false;
|
||||||
|
auto& dp = st->dirtyPiece;
|
||||||
|
dp.dirty_num = 1;
|
||||||
|
|
||||||
Color us = sideToMove;
|
Color us = sideToMove;
|
||||||
Color them = ~us;
|
Color them = ~us;
|
||||||
Square from = from_sq(m);
|
Square from = from_sq(m);
|
||||||
@@ -752,6 +755,14 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
else
|
else
|
||||||
st->nonPawnMaterial[them] -= PieceValue[MG][captured];
|
st->nonPawnMaterial[them] -= PieceValue[MG][captured];
|
||||||
|
|
||||||
|
if (Eval::useNNUE)
|
||||||
|
{
|
||||||
|
dp.dirty_num = 2; // 1 piece moved, 1 piece captured
|
||||||
|
dp.piece[1] = captured;
|
||||||
|
dp.from[1] = capsq;
|
||||||
|
dp.to[1] = SQ_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
// Update board and piece lists
|
// Update board and piece lists
|
||||||
remove_piece(capsq);
|
remove_piece(capsq);
|
||||||
|
|
||||||
@@ -787,7 +798,16 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
|
|
||||||
// Move the piece. The tricky Chess960 castling is handled earlier
|
// Move the piece. The tricky Chess960 castling is handled earlier
|
||||||
if (type_of(m) != CASTLING)
|
if (type_of(m) != CASTLING)
|
||||||
|
{
|
||||||
|
if (Eval::useNNUE)
|
||||||
|
{
|
||||||
|
dp.piece[0] = pc;
|
||||||
|
dp.from[0] = from;
|
||||||
|
dp.to[0] = to;
|
||||||
|
}
|
||||||
|
|
||||||
move_piece(from, to);
|
move_piece(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
// If the moving piece is a pawn do some special extra work
|
// If the moving piece is a pawn do some special extra work
|
||||||
if (type_of(pc) == PAWN)
|
if (type_of(pc) == PAWN)
|
||||||
@@ -810,6 +830,16 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|
|||||||
remove_piece(to);
|
remove_piece(to);
|
||||||
put_piece(promotion, to);
|
put_piece(promotion, to);
|
||||||
|
|
||||||
|
if (Eval::useNNUE)
|
||||||
|
{
|
||||||
|
// Promoting pawn to SQ_NONE, promoted piece from SQ_NONE
|
||||||
|
dp.to[0] = SQ_NONE;
|
||||||
|
dp.piece[dp.dirty_num] = promotion;
|
||||||
|
dp.from[dp.dirty_num] = SQ_NONE;
|
||||||
|
dp.to[dp.dirty_num] = to;
|
||||||
|
dp.dirty_num++;
|
||||||
|
}
|
||||||
|
|
||||||
// Update hash keys
|
// Update hash keys
|
||||||
k ^= Zobrist::psq[pc][to] ^ Zobrist::psq[promotion][to];
|
k ^= Zobrist::psq[pc][to] ^ Zobrist::psq[promotion][to];
|
||||||
st->pawnKey ^= Zobrist::psq[pc][to];
|
st->pawnKey ^= Zobrist::psq[pc][to];
|
||||||
@@ -938,6 +968,18 @@ void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Squ
|
|||||||
rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1);
|
rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1);
|
||||||
to = relative_square(us, kingSide ? SQ_G1 : SQ_C1);
|
to = relative_square(us, kingSide ? SQ_G1 : SQ_C1);
|
||||||
|
|
||||||
|
if (Do && Eval::useNNUE)
|
||||||
|
{
|
||||||
|
auto& dp = st->dirtyPiece;
|
||||||
|
dp.piece[0] = make_piece(us, KING);
|
||||||
|
dp.from[0] = from;
|
||||||
|
dp.to[0] = to;
|
||||||
|
dp.piece[1] = make_piece(us, ROOK);
|
||||||
|
dp.from[1] = rfrom;
|
||||||
|
dp.to[1] = rto;
|
||||||
|
dp.dirty_num = 2;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove both pieces first since squares could overlap in Chess960
|
// Remove both pieces first since squares could overlap in Chess960
|
||||||
remove_piece(Do ? from : to);
|
remove_piece(Do ? from : to);
|
||||||
remove_piece(Do ? rfrom : rto);
|
remove_piece(Do ? rfrom : rto);
|
||||||
@@ -955,7 +997,14 @@ void Position::do_null_move(StateInfo& newSt) {
|
|||||||
assert(!checkers());
|
assert(!checkers());
|
||||||
assert(&newSt != st);
|
assert(&newSt != st);
|
||||||
|
|
||||||
std::memcpy(&newSt, st, sizeof(StateInfo));
|
if (Eval::useNNUE)
|
||||||
|
{
|
||||||
|
std::memcpy(&newSt, st, sizeof(StateInfo));
|
||||||
|
st->accumulator.computed_score = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::memcpy(&newSt, st, offsetof(StateInfo, accumulator));
|
||||||
|
|
||||||
newSt.previous = st;
|
newSt.previous = st;
|
||||||
st = &newSt;
|
st = &newSt;
|
||||||
|
|
||||||
@@ -1047,8 +1096,8 @@ bool Position::see_ge(Move m, Value threshold) const {
|
|||||||
|
|
||||||
// Don't allow pinned pieces to attack (except the king) as long as
|
// Don't allow pinned pieces to attack (except the king) as long as
|
||||||
// there are pinners on their original square.
|
// there are pinners on their original square.
|
||||||
if (st->pinners[~stm] & occupied)
|
if (pinners(~stm) & occupied)
|
||||||
stmAttackers &= ~st->blockersForKing[stm];
|
stmAttackers &= ~blockers_for_king(stm);
|
||||||
|
|
||||||
if (!stmAttackers)
|
if (!stmAttackers)
|
||||||
break;
|
break;
|
||||||
|
|||||||
+21
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,8 +25,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
|
#include "evaluate.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
#include "nnue/nnue_accumulator.h"
|
||||||
|
|
||||||
|
|
||||||
/// StateInfo struct stores information needed to restore a Position object to
|
/// StateInfo struct stores information needed to restore a Position object to
|
||||||
/// its previous state when we retract a move. Whenever a move is made on the
|
/// its previous state when we retract a move. Whenever a move is made on the
|
||||||
@@ -54,6 +55,10 @@ struct StateInfo {
|
|||||||
Bitboard pinners[COLOR_NB];
|
Bitboard pinners[COLOR_NB];
|
||||||
Bitboard checkSquares[PIECE_TYPE_NB];
|
Bitboard checkSquares[PIECE_TYPE_NB];
|
||||||
int repetition;
|
int repetition;
|
||||||
|
|
||||||
|
// Used by NNUE
|
||||||
|
Eval::NNUE::Accumulator accumulator;
|
||||||
|
DirtyPiece dirtyPiece;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -108,6 +113,7 @@ public:
|
|||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
Bitboard blockers_for_king(Color c) const;
|
Bitboard blockers_for_king(Color c) const;
|
||||||
Bitboard check_squares(PieceType pt) const;
|
Bitboard check_squares(PieceType pt) const;
|
||||||
|
Bitboard pinners(Color c) const;
|
||||||
bool is_discovery_check_on_king(Color c, Move m) const;
|
bool is_discovery_check_on_king(Color c, Move m) const;
|
||||||
|
|
||||||
// Attacks to/from a given square
|
// Attacks to/from a given square
|
||||||
@@ -163,6 +169,9 @@ public:
|
|||||||
bool pos_is_ok() const;
|
bool pos_is_ok() const;
|
||||||
void flip();
|
void flip();
|
||||||
|
|
||||||
|
// Used by NNUE
|
||||||
|
StateInfo* state() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Initialization helpers (used while setting up a position)
|
// Initialization helpers (used while setting up a position)
|
||||||
void set_castling_right(Color c, Square rfrom);
|
void set_castling_right(Color c, Square rfrom);
|
||||||
@@ -294,6 +303,10 @@ inline Bitboard Position::blockers_for_king(Color c) const {
|
|||||||
return st->blockersForKing[c];
|
return st->blockersForKing[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Bitboard Position::pinners(Color c) const {
|
||||||
|
return st->pinners[c];
|
||||||
|
}
|
||||||
|
|
||||||
inline Bitboard Position::check_squares(PieceType pt) const {
|
inline Bitboard Position::check_squares(PieceType pt) const {
|
||||||
return st->checkSquares[pt];
|
return st->checkSquares[pt];
|
||||||
}
|
}
|
||||||
@@ -426,4 +439,9 @@ inline void Position::do_move(Move m, StateInfo& newSt) {
|
|||||||
do_move(m, newSt, gives_check(m));
|
do_move(m, newSt, gives_check(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline StateInfo* Position::state() const {
|
||||||
|
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // #ifndef POSITION_H_INCLUDED
|
#endif // #ifndef POSITION_H_INCLUDED
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+119
-96
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -65,9 +63,9 @@ namespace {
|
|||||||
constexpr uint64_t TtHitAverageResolution = 1024;
|
constexpr uint64_t TtHitAverageResolution = 1024;
|
||||||
|
|
||||||
// Razor and futility margins
|
// Razor and futility margins
|
||||||
constexpr int RazorMargin = 527;
|
constexpr int RazorMargin = 510;
|
||||||
Value futility_margin(Depth d, bool improving) {
|
Value futility_margin(Depth d, bool improving) {
|
||||||
return Value(227 * (d - improving));
|
return Value(223 * (d - improving));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reductions lookup table, initialized at startup
|
// Reductions lookup table, initialized at startup
|
||||||
@@ -75,7 +73,7 @@ namespace {
|
|||||||
|
|
||||||
Depth reduction(bool i, Depth d, int mn) {
|
Depth reduction(bool i, Depth d, int mn) {
|
||||||
int r = Reductions[d] * Reductions[mn];
|
int r = Reductions[d] * Reductions[mn];
|
||||||
return (r + 570) / 1024 + (!i && r > 1018);
|
return (r + 509) / 1024 + (!i && r > 894);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int futility_move_count(bool improving, Depth depth) {
|
constexpr int futility_move_count(bool improving, Depth depth) {
|
||||||
@@ -84,7 +82,7 @@ namespace {
|
|||||||
|
|
||||||
// History and stats update bonus, based on depth
|
// History and stats update bonus, based on depth
|
||||||
int stat_bonus(Depth d) {
|
int stat_bonus(Depth d) {
|
||||||
return d > 15 ? 27 : 17 * d * d + 133 * d - 134;
|
return d > 13 ? 29 : 17 * d * d + 134 * d - 134;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a small random component to draw evaluations to avoid 3fold-blindness
|
// Add a small random component to draw evaluations to avoid 3fold-blindness
|
||||||
@@ -194,7 +192,7 @@ namespace {
|
|||||||
void Search::init() {
|
void Search::init() {
|
||||||
|
|
||||||
for (int i = 1; i < MAX_MOVES; ++i)
|
for (int i = 1; i < MAX_MOVES; ++i)
|
||||||
Reductions[i] = int((24.8 + std::log(Threads.size())) * std::log(i));
|
Reductions[i] = int((22.0 + std::log(Threads.size())) * std::log(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -227,6 +225,8 @@ void MainThread::search() {
|
|||||||
Time.init(Limits, us, rootPos.game_ply());
|
Time.init(Limits, us, rootPos.game_ply());
|
||||||
TT.new_search();
|
TT.new_search();
|
||||||
|
|
||||||
|
Eval::verify_NNUE();
|
||||||
|
|
||||||
if (rootMoves.empty())
|
if (rootMoves.empty())
|
||||||
{
|
{
|
||||||
rootMoves.emplace_back(MOVE_NONE);
|
rootMoves.emplace_back(MOVE_NONE);
|
||||||
@@ -335,7 +335,7 @@ void Thread::search() {
|
|||||||
// for match (TC 60+0.6) results spanning a wide range of k values.
|
// for match (TC 60+0.6) results spanning a wide range of k values.
|
||||||
PRNG rng(now());
|
PRNG rng(now());
|
||||||
double floatLevel = Options["UCI_LimitStrength"] ?
|
double floatLevel = Options["UCI_LimitStrength"] ?
|
||||||
Utility::clamp(std::pow((Options["UCI_Elo"] - 1346.6) / 143.4, 1 / 0.806), 0.0, 20.0) :
|
std::clamp(std::pow((Options["UCI_Elo"] - 1346.6) / 143.4, 1 / 0.806), 0.0, 20.0) :
|
||||||
double(Options["Skill Level"]);
|
double(Options["Skill Level"]);
|
||||||
int intLevel = int(floatLevel) +
|
int intLevel = int(floatLevel) +
|
||||||
((floatLevel - int(floatLevel)) * 1024 > rng.rand<unsigned>() % 1024 ? 1 : 0);
|
((floatLevel - int(floatLevel)) * 1024 > rng.rand<unsigned>() % 1024 ? 1 : 0);
|
||||||
@@ -403,12 +403,12 @@ void Thread::search() {
|
|||||||
if (rootDepth >= 4)
|
if (rootDepth >= 4)
|
||||||
{
|
{
|
||||||
Value prev = rootMoves[pvIdx].previousScore;
|
Value prev = rootMoves[pvIdx].previousScore;
|
||||||
delta = Value(19);
|
delta = Value(17);
|
||||||
alpha = std::max(prev - delta,-VALUE_INFINITE);
|
alpha = std::max(prev - delta,-VALUE_INFINITE);
|
||||||
beta = std::min(prev + delta, VALUE_INFINITE);
|
beta = std::min(prev + delta, VALUE_INFINITE);
|
||||||
|
|
||||||
// Adjust contempt based on root move's previousScore (dynamic contempt)
|
// Adjust contempt based on root move's previousScore (dynamic contempt)
|
||||||
int dct = ct + (110 - ct / 2) * prev / (abs(prev) + 140);
|
int dct = ct + (105 - ct / 2) * prev / (abs(prev) + 149);
|
||||||
|
|
||||||
contempt = (us == WHITE ? make_score(dct, dct / 2)
|
contempt = (us == WHITE ? make_score(dct, dct / 2)
|
||||||
: -make_score(dct, dct / 2));
|
: -make_score(dct, dct / 2));
|
||||||
@@ -506,13 +506,13 @@ void Thread::search() {
|
|||||||
&& !Threads.stop
|
&& !Threads.stop
|
||||||
&& !mainThread->stopOnPonderhit)
|
&& !mainThread->stopOnPonderhit)
|
||||||
{
|
{
|
||||||
double fallingEval = (296 + 6 * (mainThread->bestPreviousScore - bestValue)
|
double fallingEval = (318 + 6 * (mainThread->bestPreviousScore - bestValue)
|
||||||
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 725.0;
|
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 825.0;
|
||||||
fallingEval = Utility::clamp(fallingEval, 0.5, 1.5);
|
fallingEval = std::clamp(fallingEval, 0.5, 1.5);
|
||||||
|
|
||||||
// If the bestMove is stable over several iterations, reduce time accordingly
|
// If the bestMove is stable over several iterations, reduce time accordingly
|
||||||
timeReduction = lastBestMoveDepth + 10 < completedDepth ? 1.92 : 0.95;
|
timeReduction = lastBestMoveDepth + 9 < completedDepth ? 1.92 : 0.95;
|
||||||
double reduction = (1.47 + mainThread->previousTimeReduction) / (2.22 * timeReduction);
|
double reduction = (1.47 + mainThread->previousTimeReduction) / (2.32 * timeReduction);
|
||||||
|
|
||||||
// Use part of the gained time from a previous stable move for the current move
|
// Use part of the gained time from a previous stable move for the current move
|
||||||
for (Thread* th : Threads)
|
for (Thread* th : Threads)
|
||||||
@@ -537,7 +537,7 @@ void Thread::search() {
|
|||||||
}
|
}
|
||||||
else if ( Threads.increaseDepth
|
else if ( Threads.increaseDepth
|
||||||
&& !mainThread->ponder
|
&& !mainThread->ponder
|
||||||
&& Time.elapsed() > totalTime * 0.56)
|
&& Time.elapsed() > totalTime * 0.58)
|
||||||
Threads.increaseDepth = false;
|
Threads.increaseDepth = false;
|
||||||
else
|
else
|
||||||
Threads.increaseDepth = true;
|
Threads.increaseDepth = true;
|
||||||
@@ -596,8 +596,8 @@ namespace {
|
|||||||
Key posKey;
|
Key posKey;
|
||||||
Move ttMove, move, excludedMove, bestMove;
|
Move ttMove, move, excludedMove, bestMove;
|
||||||
Depth extension, newDepth;
|
Depth extension, newDepth;
|
||||||
Value bestValue, value, ttValue, eval, maxValue, probcutBeta;
|
Value bestValue, value, ttValue, eval, maxValue, probCutBeta;
|
||||||
bool ttHit, ttPv, formerPv, givesCheck, improving, didLMR, priorCapture;
|
bool ttHit, formerPv, givesCheck, improving, didLMR, priorCapture;
|
||||||
bool captureOrPromotion, doFullDepthSearch, moveCountPruning,
|
bool captureOrPromotion, doFullDepthSearch, moveCountPruning,
|
||||||
ttCapture, singularQuietLMR;
|
ttCapture, singularQuietLMR;
|
||||||
Piece movedPiece;
|
Piece movedPiece;
|
||||||
@@ -644,6 +644,7 @@ namespace {
|
|||||||
assert(0 <= ss->ply && ss->ply < MAX_PLY);
|
assert(0 <= ss->ply && ss->ply < MAX_PLY);
|
||||||
|
|
||||||
(ss+1)->ply = ss->ply + 1;
|
(ss+1)->ply = ss->ply + 1;
|
||||||
|
(ss+1)->ttPv = false;
|
||||||
(ss+1)->excludedMove = bestMove = MOVE_NONE;
|
(ss+1)->excludedMove = bestMove = MOVE_NONE;
|
||||||
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
|
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
|
||||||
Square prevSq = to_sq((ss-1)->currentMove);
|
Square prevSq = to_sq((ss-1)->currentMove);
|
||||||
@@ -667,10 +668,11 @@ namespace {
|
|||||||
ttValue = ttHit ? value_from_tt(tte->value(), ss->ply, pos.rule50_count()) : VALUE_NONE;
|
ttValue = ttHit ? value_from_tt(tte->value(), ss->ply, pos.rule50_count()) : VALUE_NONE;
|
||||||
ttMove = rootNode ? thisThread->rootMoves[thisThread->pvIdx].pv[0]
|
ttMove = rootNode ? thisThread->rootMoves[thisThread->pvIdx].pv[0]
|
||||||
: ttHit ? tte->move() : MOVE_NONE;
|
: ttHit ? tte->move() : MOVE_NONE;
|
||||||
ttPv = PvNode || (ttHit && tte->is_pv());
|
if (!excludedMove)
|
||||||
formerPv = ttPv && !PvNode;
|
ss->ttPv = PvNode || (ttHit && tte->is_pv());
|
||||||
|
formerPv = ss->ttPv && !PvNode;
|
||||||
|
|
||||||
if ( ttPv
|
if ( ss->ttPv
|
||||||
&& depth > 12
|
&& depth > 12
|
||||||
&& ss->ply - 1 < MAX_LPH
|
&& ss->ply - 1 < MAX_LPH
|
||||||
&& !priorCapture
|
&& !priorCapture
|
||||||
@@ -748,7 +750,7 @@ namespace {
|
|||||||
if ( b == BOUND_EXACT
|
if ( b == BOUND_EXACT
|
||||||
|| (b == BOUND_LOWER ? value >= beta : value <= alpha))
|
|| (b == BOUND_LOWER ? value >= beta : value <= alpha))
|
||||||
{
|
{
|
||||||
tte->save(posKey, value_to_tt(value, ss->ply), ttPv, b,
|
tte->save(posKey, value_to_tt(value, ss->ply), ss->ttPv, b,
|
||||||
std::min(MAX_PLY - 1, depth + 6),
|
std::min(MAX_PLY - 1, depth + 6),
|
||||||
MOVE_NONE, VALUE_NONE);
|
MOVE_NONE, VALUE_NONE);
|
||||||
|
|
||||||
@@ -794,15 +796,11 @@ namespace {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((ss-1)->currentMove != MOVE_NULL)
|
if ((ss-1)->currentMove != MOVE_NULL)
|
||||||
{
|
ss->staticEval = eval = evaluate(pos);
|
||||||
int bonus = -(ss-1)->statScore / 512;
|
|
||||||
|
|
||||||
ss->staticEval = eval = evaluate(pos) + bonus;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
ss->staticEval = eval = -(ss-1)->staticEval + 2 * Tempo;
|
ss->staticEval = eval = -(ss-1)->staticEval + 2 * Tempo;
|
||||||
|
|
||||||
tte->save(posKey, VALUE_NONE, ttPv, BOUND_NONE, DEPTH_NONE, MOVE_NONE, eval);
|
tte->save(posKey, VALUE_NONE, ss->ttPv, BOUND_NONE, DEPTH_NONE, MOVE_NONE, eval);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 7. Razoring (~1 Elo)
|
// Step 7. Razoring (~1 Elo)
|
||||||
@@ -811,12 +809,13 @@ namespace {
|
|||||||
&& eval <= alpha - RazorMargin)
|
&& eval <= alpha - RazorMargin)
|
||||||
return qsearch<NT>(pos, ss, alpha, beta);
|
return qsearch<NT>(pos, ss, alpha, beta);
|
||||||
|
|
||||||
improving = (ss-2)->staticEval == VALUE_NONE ? (ss->staticEval > (ss-4)->staticEval
|
improving = (ss-2)->staticEval == VALUE_NONE
|
||||||
|| (ss-4)->staticEval == VALUE_NONE) : ss->staticEval > (ss-2)->staticEval;
|
? ss->staticEval > (ss-4)->staticEval || (ss-4)->staticEval == VALUE_NONE
|
||||||
|
: ss->staticEval > (ss-2)->staticEval;
|
||||||
|
|
||||||
// Step 8. Futility pruning: child node (~50 Elo)
|
// Step 8. Futility pruning: child node (~50 Elo)
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& depth < 6
|
&& depth < 8
|
||||||
&& eval - futility_margin(depth, improving) >= beta
|
&& eval - futility_margin(depth, improving) >= beta
|
||||||
&& eval < VALUE_KNOWN_WIN) // Do not return unproven wins
|
&& eval < VALUE_KNOWN_WIN) // Do not return unproven wins
|
||||||
return eval;
|
return eval;
|
||||||
@@ -824,10 +823,10 @@ namespace {
|
|||||||
// Step 9. Null move search with verification search (~40 Elo)
|
// Step 9. Null move search with verification search (~40 Elo)
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& (ss-1)->currentMove != MOVE_NULL
|
&& (ss-1)->currentMove != MOVE_NULL
|
||||||
&& (ss-1)->statScore < 23824
|
&& (ss-1)->statScore < 22977
|
||||||
&& eval >= beta
|
&& eval >= beta
|
||||||
&& eval >= ss->staticEval
|
&& eval >= ss->staticEval
|
||||||
&& ss->staticEval >= beta - 33 * depth - 33 * improving + 112 * ttPv + 311
|
&& ss->staticEval >= beta - 30 * depth - 28 * improving + 84 * ss->ttPv + 182
|
||||||
&& !excludedMove
|
&& !excludedMove
|
||||||
&& pos.non_pawn_material(us)
|
&& pos.non_pawn_material(us)
|
||||||
&& (ss->ply >= thisThread->nmpMinPly || us != thisThread->nmpColor))
|
&& (ss->ply >= thisThread->nmpMinPly || us != thisThread->nmpColor))
|
||||||
@@ -835,7 +834,7 @@ namespace {
|
|||||||
assert(eval - beta >= 0);
|
assert(eval - beta >= 0);
|
||||||
|
|
||||||
// Null move dynamic reduction based on depth and value
|
// Null move dynamic reduction based on depth and value
|
||||||
Depth R = (737 + 77 * depth) / 246 + std::min(int(eval - beta) / 192, 3);
|
Depth R = (817 + 71 * depth) / 213 + std::min(int(eval - beta) / 192, 3);
|
||||||
|
|
||||||
ss->currentMove = MOVE_NULL;
|
ss->currentMove = MOVE_NULL;
|
||||||
ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0];
|
ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0];
|
||||||
@@ -871,7 +870,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
probcutBeta = beta + 176 - 49 * improving;
|
probCutBeta = beta + 176 - 49 * improving;
|
||||||
|
|
||||||
// Step 10. ProbCut (~10 Elo)
|
// Step 10. ProbCut (~10 Elo)
|
||||||
// If we have a good enough capture and a reduced search returns a value
|
// If we have a good enough capture and a reduced search returns a value
|
||||||
@@ -879,22 +878,30 @@ namespace {
|
|||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& depth > 4
|
&& depth > 4
|
||||||
&& abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
|
&& abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
|
||||||
|
// if value from transposition table is lower than probCutBeta, don't attempt probCut
|
||||||
|
// there and in further interactions with transposition table cutoff depth is set to depth - 3
|
||||||
|
// because probCut search has depth set to depth - 4 but we also do a move before it
|
||||||
|
// so effective depth is equal to depth - 3
|
||||||
&& !( ttHit
|
&& !( ttHit
|
||||||
&& tte->depth() >= depth - 3
|
&& tte->depth() >= depth - 3
|
||||||
&& ttValue != VALUE_NONE
|
&& ttValue != VALUE_NONE
|
||||||
&& ttValue < probcutBeta))
|
&& ttValue < probCutBeta))
|
||||||
{
|
{
|
||||||
|
// if ttMove is a capture and value from transposition table is good enough produce probCut
|
||||||
|
// cutoff without digging into actual probCut search
|
||||||
if ( ttHit
|
if ( ttHit
|
||||||
&& tte->depth() >= depth - 3
|
&& tte->depth() >= depth - 3
|
||||||
&& ttValue != VALUE_NONE
|
&& ttValue != VALUE_NONE
|
||||||
&& ttValue >= probcutBeta
|
&& ttValue >= probCutBeta
|
||||||
&& ttMove
|
&& ttMove
|
||||||
&& pos.capture_or_promotion(ttMove))
|
&& pos.capture_or_promotion(ttMove))
|
||||||
return probcutBeta;
|
return probCutBeta;
|
||||||
|
|
||||||
assert(probcutBeta < VALUE_INFINITE);
|
assert(probCutBeta < VALUE_INFINITE);
|
||||||
MovePicker mp(pos, ttMove, probcutBeta - ss->staticEval, &captureHistory);
|
MovePicker mp(pos, ttMove, probCutBeta - ss->staticEval, &captureHistory);
|
||||||
int probCutCount = 0;
|
int probCutCount = 0;
|
||||||
|
bool ttPv = ss->ttPv;
|
||||||
|
ss->ttPv = false;
|
||||||
|
|
||||||
while ( (move = mp.next_move()) != MOVE_NONE
|
while ( (move = mp.next_move()) != MOVE_NONE
|
||||||
&& probCutCount < 2 + 2 * cutNode)
|
&& probCutCount < 2 + 2 * cutNode)
|
||||||
@@ -915,16 +922,17 @@ namespace {
|
|||||||
pos.do_move(move, st);
|
pos.do_move(move, st);
|
||||||
|
|
||||||
// Perform a preliminary qsearch to verify that the move holds
|
// Perform a preliminary qsearch to verify that the move holds
|
||||||
value = -qsearch<NonPV>(pos, ss+1, -probcutBeta, -probcutBeta+1);
|
value = -qsearch<NonPV>(pos, ss+1, -probCutBeta, -probCutBeta+1);
|
||||||
|
|
||||||
// If the qsearch held, perform the regular search
|
// If the qsearch held, perform the regular search
|
||||||
if (value >= probcutBeta)
|
if (value >= probCutBeta)
|
||||||
value = -search<NonPV>(pos, ss+1, -probcutBeta, -probcutBeta+1, depth - 4, !cutNode);
|
value = -search<NonPV>(pos, ss+1, -probCutBeta, -probCutBeta+1, depth - 4, !cutNode);
|
||||||
|
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
|
|
||||||
if (value >= probcutBeta)
|
if (value >= probCutBeta)
|
||||||
{
|
{
|
||||||
|
// if transposition table doesn't have equal or more deep info write probCut data into it
|
||||||
if ( !(ttHit
|
if ( !(ttHit
|
||||||
&& tte->depth() >= depth - 3
|
&& tte->depth() >= depth - 3
|
||||||
&& ttValue != VALUE_NONE))
|
&& ttValue != VALUE_NONE))
|
||||||
@@ -934,17 +942,14 @@ namespace {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ss->ttPv = ttPv;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 11. Internal iterative deepening (~1 Elo)
|
// Step 11. If the position is not in TT, decrease depth by 2
|
||||||
if (depth >= 7 && !ttMove)
|
if ( PvNode
|
||||||
{
|
&& depth >= 6
|
||||||
search<NT>(pos, ss, alpha, beta, depth - 7, cutNode);
|
&& !ttMove)
|
||||||
|
depth -= 2;
|
||||||
tte = TT.probe(posKey, ttHit);
|
|
||||||
ttValue = ttHit ? value_from_tt(tte->value(), ss->ply, pos.rule50_count()) : VALUE_NONE;
|
|
||||||
ttMove = ttHit ? tte->move() : MOVE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
moves_loop: // When in check, search starts from here
|
moves_loop: // When in check, search starts from here
|
||||||
|
|
||||||
@@ -986,6 +991,10 @@ moves_loop: // When in check, search starts from here
|
|||||||
thisThread->rootMoves.begin() + thisThread->pvLast, move))
|
thisThread->rootMoves.begin() + thisThread->pvLast, move))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Check for legality
|
||||||
|
if (!rootNode && !pos.legal(move))
|
||||||
|
continue;
|
||||||
|
|
||||||
ss->moveCount = ++moveCount;
|
ss->moveCount = ++moveCount;
|
||||||
|
|
||||||
if (rootNode && thisThread == Threads.main() && Time.elapsed() > 3000)
|
if (rootNode && thisThread == Threads.main() && Time.elapsed() > 3000)
|
||||||
@@ -1024,17 +1033,17 @@ moves_loop: // When in check, search starts from here
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Futility pruning: parent node (~5 Elo)
|
// Futility pruning: parent node (~5 Elo)
|
||||||
if ( lmrDepth < 6
|
if ( lmrDepth < 7
|
||||||
&& !ss->inCheck
|
&& !ss->inCheck
|
||||||
&& ss->staticEval + 284 + 188 * lmrDepth <= alpha
|
&& ss->staticEval + 283 + 170 * lmrDepth <= alpha
|
||||||
&& (*contHist[0])[movedPiece][to_sq(move)]
|
&& (*contHist[0])[movedPiece][to_sq(move)]
|
||||||
+ (*contHist[1])[movedPiece][to_sq(move)]
|
+ (*contHist[1])[movedPiece][to_sq(move)]
|
||||||
+ (*contHist[3])[movedPiece][to_sq(move)]
|
+ (*contHist[3])[movedPiece][to_sq(move)]
|
||||||
+ (*contHist[5])[movedPiece][to_sq(move)] / 2 < 28388)
|
+ (*contHist[5])[movedPiece][to_sq(move)] / 2 < 27376)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Prune moves with negative SEE (~20 Elo)
|
// Prune moves with negative SEE (~20 Elo)
|
||||||
if (!pos.see_ge(move, Value(-(29 - std::min(lmrDepth, 17)) * lmrDepth * lmrDepth)))
|
if (!pos.see_ge(move, Value(-(29 - std::min(lmrDepth, 18)) * lmrDepth * lmrDepth)))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1051,12 +1060,12 @@ moves_loop: // When in check, search starts from here
|
|||||||
&& !(PvNode && abs(bestValue) < 2)
|
&& !(PvNode && abs(bestValue) < 2)
|
||||||
&& PieceValue[MG][type_of(movedPiece)] >= PieceValue[MG][type_of(pos.piece_on(to_sq(move)))]
|
&& PieceValue[MG][type_of(movedPiece)] >= PieceValue[MG][type_of(pos.piece_on(to_sq(move)))]
|
||||||
&& !ss->inCheck
|
&& !ss->inCheck
|
||||||
&& ss->staticEval + 267 + 391 * lmrDepth
|
&& ss->staticEval + 169 + 244 * lmrDepth
|
||||||
+ PieceValue[MG][type_of(pos.piece_on(to_sq(move)))] <= alpha)
|
+ PieceValue[MG][type_of(pos.piece_on(to_sq(move)))] <= alpha)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// See based pruning
|
// See based pruning
|
||||||
if (!pos.see_ge(move, Value(-202) * depth)) // (~25 Elo)
|
if (!pos.see_ge(move, Value(-221) * depth)) // (~25 Elo)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1068,15 +1077,14 @@ moves_loop: // When in check, search starts from here
|
|||||||
// then that move is singular and should be extended. To verify this we do
|
// then that move is singular and should be extended. To verify this we do
|
||||||
// a reduced search on all the other moves but the ttMove and if the
|
// a reduced search on all the other moves but the ttMove and if the
|
||||||
// result is lower than ttValue minus a margin, then we will extend the ttMove.
|
// result is lower than ttValue minus a margin, then we will extend the ttMove.
|
||||||
if ( depth >= 6
|
if ( depth >= 7
|
||||||
&& move == ttMove
|
&& move == ttMove
|
||||||
&& !rootNode
|
&& !rootNode
|
||||||
&& !excludedMove // Avoid recursive singular search
|
&& !excludedMove // Avoid recursive singular search
|
||||||
/* && ttValue != VALUE_NONE Already implicit in the next condition */
|
/* && ttValue != VALUE_NONE Already implicit in the next condition */
|
||||||
&& abs(ttValue) < VALUE_KNOWN_WIN
|
&& abs(ttValue) < VALUE_KNOWN_WIN
|
||||||
&& (tte->bound() & BOUND_LOWER)
|
&& (tte->bound() & BOUND_LOWER)
|
||||||
&& tte->depth() >= depth - 3
|
&& tte->depth() >= depth - 3)
|
||||||
&& pos.legal(move))
|
|
||||||
{
|
{
|
||||||
Value singularBeta = ttValue - ((formerPv + 4) * depth) / 2;
|
Value singularBeta = ttValue - ((formerPv + 4) * depth) / 2;
|
||||||
Depth singularDepth = (depth - 1 + 3 * formerPv) / 2;
|
Depth singularDepth = (depth - 1 + 3 * formerPv) / 2;
|
||||||
@@ -1116,34 +1124,28 @@ moves_loop: // When in check, search starts from here
|
|||||||
&& (pos.is_discovery_check_on_king(~us, move) || pos.see_ge(move)))
|
&& (pos.is_discovery_check_on_king(~us, move) || pos.see_ge(move)))
|
||||||
extension = 1;
|
extension = 1;
|
||||||
|
|
||||||
// Passed pawn extension
|
|
||||||
else if ( move == ss->killers[0]
|
|
||||||
&& pos.advanced_pawn_push(move)
|
|
||||||
&& pos.pawn_passed(us, to_sq(move)))
|
|
||||||
extension = 1;
|
|
||||||
|
|
||||||
// Last captures extension
|
// Last captures extension
|
||||||
else if ( PieceValue[EG][pos.captured_piece()] > PawnValueEg
|
else if ( PieceValue[EG][pos.captured_piece()] > PawnValueEg
|
||||||
&& pos.non_pawn_material() <= 2 * RookValueMg)
|
&& pos.non_pawn_material() <= 2 * RookValueMg)
|
||||||
extension = 1;
|
extension = 1;
|
||||||
|
|
||||||
// Castling extension
|
// Castling extension
|
||||||
if (type_of(move) == CASTLING)
|
if ( type_of(move) == CASTLING
|
||||||
|
&& popcount(pos.pieces(us) & ~pos.pieces(PAWN) & (to_sq(move) & KingSide ? KingSide : QueenSide)) <= 2)
|
||||||
extension = 1;
|
extension = 1;
|
||||||
|
|
||||||
|
// Late irreversible move extension
|
||||||
|
if ( move == ttMove
|
||||||
|
&& pos.rule50_count() > 80
|
||||||
|
&& (captureOrPromotion || type_of(movedPiece) == PAWN))
|
||||||
|
extension = 2;
|
||||||
|
|
||||||
// Add extension to new depth
|
// Add extension to new depth
|
||||||
newDepth += extension;
|
newDepth += extension;
|
||||||
|
|
||||||
// Speculative prefetch as early as possible
|
// Speculative prefetch as early as possible
|
||||||
prefetch(TT.first_entry(pos.key_after(move)));
|
prefetch(TT.first_entry(pos.key_after(move)));
|
||||||
|
|
||||||
// Check for legality just before making the move
|
|
||||||
if (!rootNode && !pos.legal(move))
|
|
||||||
{
|
|
||||||
ss->moveCount = --moveCount;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the current move (this must be done after singular extension search)
|
// Update the current move (this must be done after singular extension search)
|
||||||
ss->currentMove = move;
|
ss->currentMove = move;
|
||||||
ss->continuationHistory = &thisThread->continuationHistory[ss->inCheck]
|
ss->continuationHistory = &thisThread->continuationHistory[ss->inCheck]
|
||||||
@@ -1157,13 +1159,12 @@ moves_loop: // When in check, search starts from here
|
|||||||
// Step 16. Reduced depth search (LMR, ~200 Elo). If the move fails high it will be
|
// Step 16. Reduced depth search (LMR, ~200 Elo). If the move fails high it will be
|
||||||
// re-searched at full depth.
|
// re-searched at full depth.
|
||||||
if ( depth >= 3
|
if ( depth >= 3
|
||||||
&& moveCount > 1 + 2 * rootNode
|
&& moveCount > 1 + 2 * rootNode + 2 * (PvNode && abs(bestValue) < 2)
|
||||||
&& (!rootNode || thisThread->best_move_count(move) == 0)
|
|
||||||
&& ( !captureOrPromotion
|
&& ( !captureOrPromotion
|
||||||
|| moveCountPruning
|
|| moveCountPruning
|
||||||
|| ss->staticEval + PieceValue[EG][pos.captured_piece()] <= alpha
|
|| ss->staticEval + PieceValue[EG][pos.captured_piece()] <= alpha
|
||||||
|| cutNode
|
|| cutNode
|
||||||
|| thisThread->ttHitAverage < 415 * TtHitAverageResolution * TtHitAverageWindow / 1024))
|
|| thisThread->ttHitAverage < 427 * TtHitAverageResolution * TtHitAverageWindow / 1024))
|
||||||
{
|
{
|
||||||
Depth r = reduction(improving, depth, moveCount);
|
Depth r = reduction(improving, depth, moveCount);
|
||||||
|
|
||||||
@@ -1175,7 +1176,7 @@ moves_loop: // When in check, search starts from here
|
|||||||
r--;
|
r--;
|
||||||
|
|
||||||
// Decrease reduction if the ttHit running average is large
|
// Decrease reduction if the ttHit running average is large
|
||||||
if (thisThread->ttHitAverage > 473 * TtHitAverageResolution * TtHitAverageWindow / 1024)
|
if (thisThread->ttHitAverage > 509 * TtHitAverageResolution * TtHitAverageWindow / 1024)
|
||||||
r--;
|
r--;
|
||||||
|
|
||||||
// Reduction if other threads are searching this position
|
// Reduction if other threads are searching this position
|
||||||
@@ -1183,7 +1184,7 @@ moves_loop: // When in check, search starts from here
|
|||||||
r++;
|
r++;
|
||||||
|
|
||||||
// Decrease reduction if position is or has been on the PV (~10 Elo)
|
// Decrease reduction if position is or has been on the PV (~10 Elo)
|
||||||
if (ttPv)
|
if (ss->ttPv)
|
||||||
r -= 2;
|
r -= 2;
|
||||||
|
|
||||||
if (moveCountPruning && !formerPv)
|
if (moveCountPruning && !formerPv)
|
||||||
@@ -1212,23 +1213,23 @@ moves_loop: // When in check, search starts from here
|
|||||||
// hence break make_move(). (~2 Elo)
|
// hence break make_move(). (~2 Elo)
|
||||||
else if ( type_of(move) == NORMAL
|
else if ( type_of(move) == NORMAL
|
||||||
&& !pos.see_ge(reverse_move(move)))
|
&& !pos.see_ge(reverse_move(move)))
|
||||||
r -= 2 + ttPv - (type_of(movedPiece) == PAWN);
|
r -= 2 + ss->ttPv - (type_of(movedPiece) == PAWN);
|
||||||
|
|
||||||
ss->statScore = thisThread->mainHistory[us][from_to(move)]
|
ss->statScore = thisThread->mainHistory[us][from_to(move)]
|
||||||
+ (*contHist[0])[movedPiece][to_sq(move)]
|
+ (*contHist[0])[movedPiece][to_sq(move)]
|
||||||
+ (*contHist[1])[movedPiece][to_sq(move)]
|
+ (*contHist[1])[movedPiece][to_sq(move)]
|
||||||
+ (*contHist[3])[movedPiece][to_sq(move)]
|
+ (*contHist[3])[movedPiece][to_sq(move)]
|
||||||
- 4826;
|
- 5287;
|
||||||
|
|
||||||
// Decrease/increase reduction by comparing opponent's stat score (~10 Elo)
|
// Decrease/increase reduction by comparing opponent's stat score (~10 Elo)
|
||||||
if (ss->statScore >= -100 && (ss-1)->statScore < -112)
|
if (ss->statScore >= -106 && (ss-1)->statScore < -104)
|
||||||
r--;
|
r--;
|
||||||
|
|
||||||
else if ((ss-1)->statScore >= -125 && ss->statScore < -138)
|
else if ((ss-1)->statScore >= -119 && ss->statScore < -140)
|
||||||
r++;
|
r++;
|
||||||
|
|
||||||
// Decrease/increase reduction for moves with a good/bad history (~30 Elo)
|
// Decrease/increase reduction for moves with a good/bad history (~30 Elo)
|
||||||
r -= ss->statScore / 14615;
|
r -= ss->statScore / 14884;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1238,11 +1239,11 @@ moves_loop: // When in check, search starts from here
|
|||||||
|
|
||||||
// Unless giving check, this capture is likely bad
|
// Unless giving check, this capture is likely bad
|
||||||
if ( !givesCheck
|
if ( !givesCheck
|
||||||
&& ss->staticEval + PieceValue[EG][pos.captured_piece()] + 211 * depth <= alpha)
|
&& ss->staticEval + PieceValue[EG][pos.captured_piece()] + 213 * depth <= alpha)
|
||||||
r++;
|
r++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Depth d = Utility::clamp(newDepth - r, 1, newDepth);
|
Depth d = std::clamp(newDepth - r, 1, newDepth);
|
||||||
|
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
||||||
|
|
||||||
@@ -1390,8 +1391,17 @@ moves_loop: // When in check, search starts from here
|
|||||||
if (PvNode)
|
if (PvNode)
|
||||||
bestValue = std::min(bestValue, maxValue);
|
bestValue = std::min(bestValue, maxValue);
|
||||||
|
|
||||||
|
// If no good move is found and the previous position was ttPv, then the previous
|
||||||
|
// opponent move is probably good and the new position is added to the search tree.
|
||||||
|
if (bestValue <= alpha)
|
||||||
|
ss->ttPv = ss->ttPv || ((ss-1)->ttPv && depth > 3);
|
||||||
|
// Otherwise, a counter move has been found and if the position is the last leaf
|
||||||
|
// in the search tree, remove the position from the search tree.
|
||||||
|
else if (depth > 3)
|
||||||
|
ss->ttPv = ss->ttPv && (ss+1)->ttPv;
|
||||||
|
|
||||||
if (!excludedMove && !(rootNode && thisThread->pvIdx))
|
if (!excludedMove && !(rootNode && thisThread->pvIdx))
|
||||||
tte->save(posKey, value_to_tt(bestValue, ss->ply), ttPv,
|
tte->save(posKey, value_to_tt(bestValue, ss->ply), ss->ttPv,
|
||||||
bestValue >= beta ? BOUND_LOWER :
|
bestValue >= beta ? BOUND_LOWER :
|
||||||
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
|
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
|
||||||
depth, bestMove, ss->staticEval);
|
depth, bestMove, ss->staticEval);
|
||||||
@@ -1500,7 +1510,7 @@ moves_loop: // When in check, search starts from here
|
|||||||
if (PvNode && bestValue > alpha)
|
if (PvNode && bestValue > alpha)
|
||||||
alpha = bestValue;
|
alpha = bestValue;
|
||||||
|
|
||||||
futilityBase = bestValue + 141;
|
futilityBase = bestValue + 145;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory,
|
const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory,
|
||||||
@@ -1534,6 +1544,10 @@ moves_loop: // When in check, search starts from here
|
|||||||
{
|
{
|
||||||
assert(type_of(move) != ENPASSANT); // Due to !pos.advanced_pawn_push
|
assert(type_of(move) != ENPASSANT); // Due to !pos.advanced_pawn_push
|
||||||
|
|
||||||
|
// moveCount pruning
|
||||||
|
if (moveCount > 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
futilityValue = futilityBase + PieceValue[EG][pos.piece_on(to_sq(move))];
|
futilityValue = futilityBase + PieceValue[EG][pos.piece_on(to_sq(move))];
|
||||||
|
|
||||||
if (futilityValue <= alpha)
|
if (futilityValue <= alpha)
|
||||||
@@ -1550,7 +1564,7 @@ moves_loop: // When in check, search starts from here
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do not search moves with negative SEE values
|
// Do not search moves with negative SEE values
|
||||||
if ( !ss->inCheck && !pos.see_ge(move))
|
if (!ss->inCheck && !pos.see_ge(move))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Speculative prefetch as early as possible
|
// Speculative prefetch as early as possible
|
||||||
@@ -1569,6 +1583,12 @@ moves_loop: // When in check, search starts from here
|
|||||||
[pos.moved_piece(move)]
|
[pos.moved_piece(move)]
|
||||||
[to_sq(move)];
|
[to_sq(move)];
|
||||||
|
|
||||||
|
if ( !captureOrPromotion
|
||||||
|
&& moveCount
|
||||||
|
&& (*contHist[0])[pos.moved_piece(move)][to_sq(move)] < CounterMovePruneThreshold
|
||||||
|
&& (*contHist[1])[pos.moved_piece(move)][to_sq(move)] < CounterMovePruneThreshold)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Make and search the move
|
// Make and search the move
|
||||||
pos.do_move(move, st, givesCheck);
|
pos.do_move(move, st, givesCheck);
|
||||||
value = -qsearch<NT>(pos, ss+1, -beta, -alpha, depth - 1);
|
value = -qsearch<NT>(pos, ss+1, -beta, -alpha, depth - 1);
|
||||||
@@ -1751,7 +1771,7 @@ moves_loop: // When in check, search starts from here
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (depth > 11 && ss->ply < MAX_LPH)
|
if (depth > 11 && ss->ply < MAX_LPH)
|
||||||
thisThread->lowPlyHistory[ss->ply][from_to(move)] << stat_bonus(depth - 6);
|
thisThread->lowPlyHistory[ss->ply][from_to(move)] << stat_bonus(depth - 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When playing with strength handicap, choose best move among a set of RootMoves
|
// When playing with strength handicap, choose best move among a set of RootMoves
|
||||||
@@ -1840,12 +1860,15 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
|
|||||||
{
|
{
|
||||||
bool updated = rootMoves[i].score != -VALUE_INFINITE;
|
bool updated = rootMoves[i].score != -VALUE_INFINITE;
|
||||||
|
|
||||||
if (depth == 1 && !updated)
|
if (depth == 1 && !updated && i > 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Depth d = updated ? depth : depth - 1;
|
Depth d = updated ? depth : std::max(1, depth - 1);
|
||||||
Value v = updated ? rootMoves[i].score : rootMoves[i].previousScore;
|
Value v = updated ? rootMoves[i].score : rootMoves[i].previousScore;
|
||||||
|
|
||||||
|
if (v == -VALUE_INFINITE)
|
||||||
|
v = VALUE_ZERO;
|
||||||
|
|
||||||
bool tb = TB::RootInTB && abs(v) < VALUE_MATE_IN_MAX_PLY;
|
bool tb = TB::RootInTB && abs(v) < VALUE_MATE_IN_MAX_PLY;
|
||||||
v = tb ? rootMoves[i].tbScore : v;
|
v = tb ? rootMoves[i].tbScore : v;
|
||||||
|
|
||||||
@@ -1943,7 +1966,7 @@ void Tablebases::rank_root_moves(Position& pos, Search::RootMoves& rootMoves) {
|
|||||||
if (RootInTB)
|
if (RootInTB)
|
||||||
{
|
{
|
||||||
// Sort moves according to TB rank
|
// Sort moves according to TB rank
|
||||||
std::sort(rootMoves.begin(), rootMoves.end(),
|
std::stable_sort(rootMoves.begin(), rootMoves.end(),
|
||||||
[](const RootMove &a, const RootMove &b) { return a.tbRank > b.tbRank; } );
|
[](const RootMove &a, const RootMove &b) { return a.tbRank > b.tbRank; } );
|
||||||
|
|
||||||
// Probe during search only if DTZ is not available and we are winning
|
// Probe during search only if DTZ is not available and we are winning
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -50,6 +48,7 @@ struct Stack {
|
|||||||
int statScore;
|
int statScore;
|
||||||
int moveCount;
|
int moveCount;
|
||||||
bool inCheck;
|
bool inCheck;
|
||||||
|
bool ttPv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (c) 2013 Ronald de Man
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2016-2020 Marco Costalba, Lucas Braesch
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -224,7 +223,9 @@ public:
|
|||||||
|
|
||||||
*mapping = statbuf.st_size;
|
*mapping = statbuf.st_size;
|
||||||
*baseAddress = mmap(nullptr, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
*baseAddress = mmap(nullptr, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||||
|
#if defined(MADV_RANDOM)
|
||||||
madvise(*baseAddress, statbuf.st_size, MADV_RANDOM);
|
madvise(*baseAddress, statbuf.st_size, MADV_RANDOM);
|
||||||
|
#endif
|
||||||
::close(fd);
|
::close(fd);
|
||||||
|
|
||||||
if (*baseAddress == MAP_FAILED)
|
if (*baseAddress == MAP_FAILED)
|
||||||
@@ -759,7 +760,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
|
|||||||
if (entry->hasPawns) {
|
if (entry->hasPawns) {
|
||||||
idx = LeadPawnIdx[leadPawnsCnt][squares[0]];
|
idx = LeadPawnIdx[leadPawnsCnt][squares[0]];
|
||||||
|
|
||||||
std::sort(squares + 1, squares + leadPawnsCnt, pawns_comp);
|
std::stable_sort(squares + 1, squares + leadPawnsCnt, pawns_comp);
|
||||||
|
|
||||||
for (int i = 1; i < leadPawnsCnt; ++i)
|
for (int i = 1; i < leadPawnsCnt; ++i)
|
||||||
idx += Binomial[i][MapPawns[squares[i]]];
|
idx += Binomial[i][MapPawns[squares[i]]];
|
||||||
@@ -860,7 +861,7 @@ encode_remaining:
|
|||||||
|
|
||||||
while (d->groupLen[++next])
|
while (d->groupLen[++next])
|
||||||
{
|
{
|
||||||
std::sort(groupSq, groupSq + d->groupLen[next]);
|
std::stable_sort(groupSq, groupSq + d->groupLen[next]);
|
||||||
uint64_t n = 0;
|
uint64_t n = 0;
|
||||||
|
|
||||||
// Map down a square if "comes later" than a square in the previous
|
// Map down a square if "comes later" than a square in the previous
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (c) 2013 Ronald de Man
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2016-2020 Marco Costalba, Lucas Braesch
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+6
-22
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -53,17 +51,6 @@ Thread::~Thread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread::bestMoveCount(Move move) return best move counter for the given root move
|
|
||||||
|
|
||||||
int Thread::best_move_count(Move move) const {
|
|
||||||
|
|
||||||
auto rm = std::find(rootMoves.begin() + pvIdx,
|
|
||||||
rootMoves.begin() + pvLast, move);
|
|
||||||
|
|
||||||
return rm != rootMoves.begin() + pvLast ? rm->bestMoveCount : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Thread::clear() reset histories, usually before a new game
|
/// Thread::clear() reset histories, usually before a new game
|
||||||
|
|
||||||
void Thread::clear() {
|
void Thread::clear() {
|
||||||
@@ -206,21 +193,18 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
|||||||
|
|
||||||
// We use Position::set() to set root position across threads. But there are
|
// We use Position::set() to set root position across threads. But there are
|
||||||
// some StateInfo fields (previous, pliesFromNull, capturedPiece) that cannot
|
// some StateInfo fields (previous, pliesFromNull, capturedPiece) that cannot
|
||||||
// be deduced from a fen string, so set() clears them and to not lose the info
|
// be deduced from a fen string, so set() clears them and they are set from
|
||||||
// we need to backup and later restore setupStates->back(). Note that setupStates
|
// setupStates->back() later. The rootState is per thread, earlier states are shared
|
||||||
// is shared by threads but is accessed in read-only mode.
|
// since they are read-only.
|
||||||
StateInfo tmp = setupStates->back();
|
|
||||||
|
|
||||||
for (Thread* th : *this)
|
for (Thread* th : *this)
|
||||||
{
|
{
|
||||||
th->nodes = th->tbHits = th->nmpMinPly = th->bestMoveChanges = 0;
|
th->nodes = th->tbHits = th->nmpMinPly = th->bestMoveChanges = 0;
|
||||||
th->rootDepth = th->completedDepth = 0;
|
th->rootDepth = th->completedDepth = 0;
|
||||||
th->rootMoves = rootMoves;
|
th->rootMoves = rootMoves;
|
||||||
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
th->rootPos.set(pos.fen(), pos.is_chess960(), &th->rootState, th);
|
||||||
|
th->rootState = setupStates->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
setupStates->back() = tmp;
|
|
||||||
|
|
||||||
main()->start_searching();
|
main()->start_searching();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -56,7 +54,6 @@ public:
|
|||||||
void idle_loop();
|
void idle_loop();
|
||||||
void start_searching();
|
void start_searching();
|
||||||
void wait_for_search_finished();
|
void wait_for_search_finished();
|
||||||
int best_move_count(Move move) const;
|
|
||||||
|
|
||||||
Pawns::Table pawnsTable;
|
Pawns::Table pawnsTable;
|
||||||
Material::Table materialTable;
|
Material::Table materialTable;
|
||||||
@@ -67,6 +64,7 @@ public:
|
|||||||
std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;
|
std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;
|
||||||
|
|
||||||
Position rootPos;
|
Position rootPos;
|
||||||
|
StateInfo rootState;
|
||||||
Search::RootMoves rootMoves;
|
Search::RootMoves rootMoves;
|
||||||
Depth rootDepth, completedDepth;
|
Depth rootDepth, completedDepth;
|
||||||
CounterMoveHistory counterMoves;
|
CounterMoveHistory counterMoves;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,7 +27,7 @@
|
|||||||
/// The implementation calls pthread_create() with the stack size parameter
|
/// The implementation calls pthread_create() with the stack size parameter
|
||||||
/// equal to the linux 8MB default, on platforms that support it.
|
/// equal to the linux 8MB default, on platforms that support it.
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
|
#if defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(USE_PTHREADS)
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|||||||
+10
-12
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -40,9 +38,9 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
|||||||
TimePoint slowMover = TimePoint(Options["Slow Mover"]);
|
TimePoint slowMover = TimePoint(Options["Slow Mover"]);
|
||||||
TimePoint npmsec = TimePoint(Options["nodestime"]);
|
TimePoint npmsec = TimePoint(Options["nodestime"]);
|
||||||
|
|
||||||
// opt_scale is a percentage of available time to use for the current move.
|
// optScale is a percentage of available time to use for the current move.
|
||||||
// max_scale is a multiplier applied to optimumTime.
|
// maxScale is a multiplier applied to optimumTime.
|
||||||
double opt_scale, max_scale;
|
double optScale, maxScale;
|
||||||
|
|
||||||
// If we have to play in 'nodes as time' mode, then convert from time
|
// If we have to play in 'nodes as time' mode, then convert from time
|
||||||
// to nodes, and use resulting values in time management formulas.
|
// to nodes, and use resulting values in time management formulas.
|
||||||
@@ -77,22 +75,22 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
|||||||
// game time for the current move, so also cap to 20% of available game time.
|
// game time for the current move, so also cap to 20% of available game time.
|
||||||
if (limits.movestogo == 0)
|
if (limits.movestogo == 0)
|
||||||
{
|
{
|
||||||
opt_scale = std::min(0.008 + std::pow(ply + 3.0, 0.5) / 250.0,
|
optScale = std::min(0.008 + std::pow(ply + 3.0, 0.5) / 250.0,
|
||||||
0.2 * limits.time[us] / double(timeLeft));
|
0.2 * limits.time[us] / double(timeLeft));
|
||||||
max_scale = std::min(7.0, 4.0 + ply / 12.0);
|
maxScale = std::min(7.0, 4.0 + ply / 12.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// x moves in y seconds (+ z increment)
|
// x moves in y seconds (+ z increment)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
opt_scale = std::min((0.8 + ply / 128.0) / mtg,
|
optScale = std::min((0.8 + ply / 128.0) / mtg,
|
||||||
0.8 * limits.time[us] / double(timeLeft));
|
0.8 * limits.time[us] / double(timeLeft));
|
||||||
max_scale = std::min(6.3, 1.5 + 0.11 * mtg);
|
maxScale = std::min(6.3, 1.5 + 0.11 * mtg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never use more than 80% of the available time for this move
|
// Never use more than 80% of the available time for this move
|
||||||
optimumTime = TimePoint(opt_scale * timeLeft);
|
optimumTime = TimePoint(optScale * timeLeft);
|
||||||
maximumTime = TimePoint(std::min(0.8 * limits.time[us] - moveOverhead, max_scale * optimumTime));
|
maximumTime = TimePoint(std::min(0.8 * limits.time[us] - moveOverhead, maxScale * optimumTime));
|
||||||
|
|
||||||
if (Options["Ponder"])
|
if (Options["Ponder"])
|
||||||
optimumTime += optimumTime / 4;
|
optimumTime += optimumTime / 4;
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+12
-13
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -39,18 +37,19 @@ void TTEntry::save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev)
|
|||||||
if (m || (uint16_t)k != key16)
|
if (m || (uint16_t)k != key16)
|
||||||
move16 = (uint16_t)m;
|
move16 = (uint16_t)m;
|
||||||
|
|
||||||
// Overwrite less valuable entries
|
// Overwrite less valuable entries (cheapest checks first)
|
||||||
if ((uint16_t)k != key16
|
if (b == BOUND_EXACT
|
||||||
|| d - DEPTH_OFFSET > depth8 - 4
|
|| (uint16_t)k != key16
|
||||||
|| b == BOUND_EXACT)
|
|| d - DEPTH_OFFSET > depth8 - 4)
|
||||||
{
|
{
|
||||||
assert(d >= DEPTH_OFFSET);
|
assert(d > DEPTH_OFFSET);
|
||||||
|
assert(d < 256 + DEPTH_OFFSET);
|
||||||
|
|
||||||
key16 = (uint16_t)k;
|
key16 = (uint16_t)k;
|
||||||
|
depth8 = (uint8_t)(d - DEPTH_OFFSET);
|
||||||
|
genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
|
||||||
value16 = (int16_t)v;
|
value16 = (int16_t)v;
|
||||||
eval16 = (int16_t)ev;
|
eval16 = (int16_t)ev;
|
||||||
genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
|
|
||||||
depth8 = (uint8_t)(d - DEPTH_OFFSET);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,11 +120,11 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
|||||||
const uint16_t key16 = (uint16_t)key; // Use the low 16 bits as key inside the cluster
|
const uint16_t key16 = (uint16_t)key; // Use the low 16 bits as key inside the cluster
|
||||||
|
|
||||||
for (int i = 0; i < ClusterSize; ++i)
|
for (int i = 0; i < ClusterSize; ++i)
|
||||||
if (!tte[i].key16 || tte[i].key16 == key16)
|
if (tte[i].key16 == key16 || !tte[i].depth8)
|
||||||
{
|
{
|
||||||
tte[i].genBound8 = uint8_t(generation8 | (tte[i].genBound8 & 0x7)); // Refresh
|
tte[i].genBound8 = uint8_t(generation8 | (tte[i].genBound8 & 0x7)); // Refresh
|
||||||
|
|
||||||
return found = (bool)tte[i].key16, &tte[i];
|
return found = (bool)tte[i].depth8, &tte[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find an entry to be replaced according to the replacement strategy
|
// Find an entry to be replaced according to the replacement strategy
|
||||||
@@ -151,7 +150,7 @@ int TranspositionTable::hashfull() const {
|
|||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (int i = 0; i < 1000; ++i)
|
for (int i = 0; i < 1000; ++i)
|
||||||
for (int j = 0; j < ClusterSize; ++j)
|
for (int j = 0; j < ClusterSize; ++j)
|
||||||
cnt += (table[i].entry[j].genBound8 & 0xF8) == generation8;
|
cnt += table[i].entry[j].depth8 && (table[i].entry[j].genBound8 & 0xF8) == generation8;
|
||||||
|
|
||||||
return cnt / ClusterSize;
|
return cnt / ClusterSize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,13 +25,13 @@
|
|||||||
/// TTEntry struct is the 10 bytes transposition table entry, defined as below:
|
/// TTEntry struct is the 10 bytes transposition table entry, defined as below:
|
||||||
///
|
///
|
||||||
/// key 16 bit
|
/// key 16 bit
|
||||||
/// move 16 bit
|
/// depth 8 bit
|
||||||
/// value 16 bit
|
|
||||||
/// eval value 16 bit
|
|
||||||
/// generation 5 bit
|
/// generation 5 bit
|
||||||
/// pv node 1 bit
|
/// pv node 1 bit
|
||||||
/// bound type 2 bit
|
/// bound type 2 bit
|
||||||
/// depth 8 bit
|
/// move 16 bit
|
||||||
|
/// value 16 bit
|
||||||
|
/// eval value 16 bit
|
||||||
|
|
||||||
struct TTEntry {
|
struct TTEntry {
|
||||||
|
|
||||||
@@ -49,11 +47,11 @@ private:
|
|||||||
friend class TranspositionTable;
|
friend class TranspositionTable;
|
||||||
|
|
||||||
uint16_t key16;
|
uint16_t key16;
|
||||||
|
uint8_t depth8;
|
||||||
|
uint8_t genBound8;
|
||||||
uint16_t move16;
|
uint16_t move16;
|
||||||
int16_t value16;
|
int16_t value16;
|
||||||
int16_t eval16;
|
int16_t eval16;
|
||||||
uint8_t genBound8;
|
|
||||||
uint8_t depth8;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2017 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+25
-9
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -180,7 +178,7 @@ enum Value : int {
|
|||||||
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - MAX_PLY,
|
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - MAX_PLY,
|
||||||
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE_IN_MAX_PLY,
|
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE_IN_MAX_PLY,
|
||||||
|
|
||||||
PawnValueMg = 124, PawnValueEg = 206,
|
PawnValueMg = 126, PawnValueEg = 208,
|
||||||
KnightValueMg = 781, KnightValueEg = 854,
|
KnightValueMg = 781, KnightValueEg = 854,
|
||||||
BishopValueMg = 825, BishopValueEg = 915,
|
BishopValueMg = 825, BishopValueEg = 915,
|
||||||
RookValueMg = 1276, RookValueEg = 1380,
|
RookValueMg = 1276, RookValueEg = 1380,
|
||||||
@@ -218,7 +216,8 @@ enum : int {
|
|||||||
DEPTH_QS_RECAPTURES = -5,
|
DEPTH_QS_RECAPTURES = -5,
|
||||||
|
|
||||||
DEPTH_NONE = -6,
|
DEPTH_NONE = -6,
|
||||||
DEPTH_OFFSET = DEPTH_NONE
|
|
||||||
|
DEPTH_OFFSET = -7 // value used only for TT entry occupancy check
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Square : int {
|
enum Square : int {
|
||||||
@@ -232,7 +231,8 @@ enum Square : int {
|
|||||||
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
|
||||||
SQ_NONE,
|
SQ_NONE,
|
||||||
|
|
||||||
SQUARE_NB = 64
|
SQUARE_ZERO = 0,
|
||||||
|
SQUARE_NB = 64
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Direction : int {
|
enum Direction : int {
|
||||||
@@ -255,6 +255,21 @@ enum Rank : int {
|
|||||||
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Keep track of what a move changes on the board (used by NNUE)
|
||||||
|
struct DirtyPiece {
|
||||||
|
|
||||||
|
// Number of changed pieces
|
||||||
|
int dirty_num;
|
||||||
|
|
||||||
|
// Max 3 pieces can change in one move. A promotion with capture moves
|
||||||
|
// both the pawn and the captured piece to SQ_NONE and the piece promoted
|
||||||
|
// to from SQ_NONE to the capture square.
|
||||||
|
Piece piece[3];
|
||||||
|
|
||||||
|
// From and to squares, which may be SQ_NONE
|
||||||
|
Square from[3];
|
||||||
|
Square to[3];
|
||||||
|
};
|
||||||
|
|
||||||
/// Score enum stores a middlegame and an endgame value in a single integer (enum).
|
/// Score enum stores a middlegame and an endgame value in a single integer (enum).
|
||||||
/// The least significant 16 bits are used to store the middlegame value and the
|
/// The least significant 16 bits are used to store the middlegame value and the
|
||||||
@@ -280,10 +295,10 @@ inline Value mg_value(Score s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ENABLE_BASE_OPERATORS_ON(T) \
|
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
constexpr T operator+(T d1, int d2) { return T(int(d1) + d2); } \
|
constexpr T operator+(T d1, int d2) { return T(int(d1) + d2); } \
|
||||||
constexpr T operator-(T d1, int d2) { return T(int(d1) - d2); } \
|
constexpr T operator-(T d1, int d2) { return T(int(d1) - d2); } \
|
||||||
constexpr T operator-(T d) { return T(-int(d)); } \
|
constexpr T operator-(T d) { return T(-int(d)); } \
|
||||||
inline T& operator+=(T& d1, int d2) { return d1 = d1 + d2; } \
|
inline T& operator+=(T& d1, int d2) { return d1 = d1 + d2; } \
|
||||||
inline T& operator-=(T& d1, int d2) { return d1 = d1 - d2; }
|
inline T& operator-=(T& d1, int d2) { return d1 = d1 - d2; }
|
||||||
|
|
||||||
#define ENABLE_INCR_OPERATORS_ON(T) \
|
#define ENABLE_INCR_OPERATORS_ON(T) \
|
||||||
@@ -302,6 +317,7 @@ inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
|||||||
ENABLE_FULL_OPERATORS_ON(Value)
|
ENABLE_FULL_OPERATORS_ON(Value)
|
||||||
ENABLE_FULL_OPERATORS_ON(Direction)
|
ENABLE_FULL_OPERATORS_ON(Direction)
|
||||||
|
|
||||||
|
ENABLE_INCR_OPERATORS_ON(Piece)
|
||||||
ENABLE_INCR_OPERATORS_ON(PieceType)
|
ENABLE_INCR_OPERATORS_ON(PieceType)
|
||||||
ENABLE_INCR_OPERATORS_ON(Square)
|
ENABLE_INCR_OPERATORS_ON(Square)
|
||||||
ENABLE_INCR_OPERATORS_ON(File)
|
ENABLE_INCR_OPERATORS_ON(File)
|
||||||
|
|||||||
+18
-6
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -78,6 +76,20 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trace_eval() prints the evaluation for the current position, consistent with the UCI
|
||||||
|
// options set so far.
|
||||||
|
|
||||||
|
void trace_eval(Position& pos) {
|
||||||
|
|
||||||
|
StateListPtr states(new std::deque<StateInfo>(1));
|
||||||
|
Position p;
|
||||||
|
p.set(pos.fen(), Options["UCI_Chess960"], &states->back(), Threads.main());
|
||||||
|
|
||||||
|
Eval::verify_NNUE();
|
||||||
|
|
||||||
|
sync_cout << "\n" << Eval::trace(p) << sync_endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// setoption() is called when engine receives the "setoption" UCI command. The
|
// setoption() is called when engine receives the "setoption" UCI command. The
|
||||||
// function updates the UCI option ("name") to the given value ("value").
|
// function updates the UCI option ("name") to the given value ("value").
|
||||||
@@ -166,7 +178,7 @@ namespace {
|
|||||||
nodes += Threads.nodes_searched();
|
nodes += Threads.nodes_searched();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sync_cout << "\n" << Eval::trace(pos) << sync_endl;
|
trace_eval(pos);
|
||||||
}
|
}
|
||||||
else if (token == "setoption") setoption(is);
|
else if (token == "setoption") setoption(is);
|
||||||
else if (token == "position") position(pos, is, states);
|
else if (token == "position") position(pos, is, states);
|
||||||
@@ -199,7 +211,7 @@ namespace {
|
|||||||
double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3];
|
double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3];
|
||||||
|
|
||||||
// Transform eval to centipawns with limited range
|
// Transform eval to centipawns with limited range
|
||||||
double x = Utility::clamp(double(100 * v) / PawnValueEg, -1000.0, 1000.0);
|
double x = std::clamp(double(100 * v) / PawnValueEg, -1000.0, 1000.0);
|
||||||
|
|
||||||
// Return win rate in per mille (rounded to nearest)
|
// Return win rate in per mille (rounded to nearest)
|
||||||
return int(0.5 + 1000 / (1 + std::exp((a - x) / b)));
|
return int(0.5 + 1000 / (1 + std::exp((a - x) / b)));
|
||||||
@@ -261,7 +273,7 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
else if (token == "flip") pos.flip();
|
else if (token == "flip") pos.flip();
|
||||||
else if (token == "bench") bench(pos, is, states);
|
else if (token == "bench") bench(pos, is, states);
|
||||||
else if (token == "d") sync_cout << pos << sync_endl;
|
else if (token == "d") sync_cout << pos << sync_endl;
|
||||||
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
else if (token == "eval") trace_eval(pos);
|
||||||
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
||||||
else
|
else
|
||||||
sync_cout << "Unknown command: " << cmd << sync_endl;
|
sync_cout << "Unknown command: " << cmd << sync_endl;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+6
-4
@@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
Stockfish is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,6 +21,7 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "evaluate.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
@@ -42,7 +41,8 @@ void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
|
|||||||
void on_logger(const Option& o) { start_logger(o); }
|
void on_logger(const Option& o) { start_logger(o); }
|
||||||
void on_threads(const Option& o) { Threads.set(size_t(o)); }
|
void on_threads(const Option& o) { Threads.set(size_t(o)); }
|
||||||
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||||
|
void on_use_NNUE(const Option& ) { Eval::init_NNUE(); }
|
||||||
|
void on_eval_file(const Option& ) { Eval::init_NNUE(); }
|
||||||
|
|
||||||
/// Our case insensitive less() function as required by UCI protocol
|
/// Our case insensitive less() function as required by UCI protocol
|
||||||
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
||||||
@@ -79,6 +79,8 @@ void init(OptionsMap& o) {
|
|||||||
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
||||||
o["Syzygy50MoveRule"] << Option(true);
|
o["Syzygy50MoveRule"] << Option(true);
|
||||||
o["SyzygyProbeLimit"] << Option(7, 0, 7);
|
o["SyzygyProbeLimit"] << Option(7, 0, 7);
|
||||||
|
o["Use NNUE"] << Option(true, on_use_NNUE);
|
||||||
|
o["EvalFile"] << Option(EvalFileDefaultName, on_eval_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ for args in "eval" \
|
|||||||
"go depth 10" \
|
"go depth 10" \
|
||||||
"go movetime 1000" \
|
"go movetime 1000" \
|
||||||
"go wtime 8000 btime 8000 winc 500 binc 500" \
|
"go wtime 8000 btime 8000 winc 500 binc 500" \
|
||||||
"bench 128 $threads 10 default depth"
|
"bench 128 $threads 8 default depth"
|
||||||
do
|
do
|
||||||
|
|
||||||
echo "$prefix $exeprefix ./stockfish $args $postfix"
|
echo "$prefix $exeprefix ./stockfish $args $postfix"
|
||||||
@@ -80,7 +80,7 @@ done
|
|||||||
|
|
||||||
# more general testing, following an uci protocol exchange
|
# more general testing, following an uci protocol exchange
|
||||||
cat << EOF > game.exp
|
cat << EOF > game.exp
|
||||||
set timeout 10
|
set timeout 240
|
||||||
spawn $exeprefix ./stockfish
|
spawn $exeprefix ./stockfish
|
||||||
|
|
||||||
send "uci\n"
|
send "uci\n"
|
||||||
@@ -98,7 +98,7 @@ cat << EOF > game.exp
|
|||||||
expect "bestmove"
|
expect "bestmove"
|
||||||
|
|
||||||
send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
|
send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
|
||||||
send "go depth 30\n"
|
send "go depth 20\n"
|
||||||
expect "bestmove"
|
expect "bestmove"
|
||||||
|
|
||||||
send "quit\n"
|
send "quit\n"
|
||||||
@@ -121,7 +121,7 @@ cat << EOF > syzygy.exp
|
|||||||
send "uci\n"
|
send "uci\n"
|
||||||
send "setoption name SyzygyPath value ../tests/syzygy/\n"
|
send "setoption name SyzygyPath value ../tests/syzygy/\n"
|
||||||
expect "info string Found 35 tablebases" {} timeout {exit 1}
|
expect "info string Found 35 tablebases" {} timeout {exit 1}
|
||||||
send "bench 128 1 10 default depth\n"
|
send "bench 128 1 8 default depth\n"
|
||||||
send "quit\n"
|
send "quit\n"
|
||||||
expect eof
|
expect eof
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user