This code provides an implementation of a Efficiently Updatable Neural Network (NNUE) for chess, compatible with the original implementation in Stockfish, which was based on contributions from Hisayori Noda aka Nodchip. Now also supporting the SFNNv4 network architecture, via the SFv4 branch.
Copyright 2021-2023 by Jon Dart. All Rights Reserved.
MIT Licensed.
- can read Stockfish network files using insertion operator on the Network class
- templated to support different network sizes, weight types, etc.
- full and incremental update supported
- SIMD support for x86_64 and ARM NEON architectures
- unit test code
- read only, no support for writing network files
- does not validate hash codes from existing network files
Requires C++-17. The Makefile (Gnu Make) builds a test executable. -DSIMD must be specificed to select SIMD optimizations. If SIMD is set then also one or more flags must be set to select the desired instruction set(s).
Add -DNEON to use the ARMv8 NEON instruction set.
For x86_64 processors, the following flags can be set. They can be combined and are utilized in the following order of precedence.
- AVX512_VNNI (in addition to AVX512)
- AVX512
- VNNI (in addition to AVX2)
- AVX2
- SSE41 (in addition to SSSE3)
- SSSE3 (assumes SSE2 also present)
- SSE2
If -DSIMD is enabled, at least one of: AVX2, SSSE3 or SSE2 must also be selected.
The Evaluator class is templated and assumes use of a class or typedef that provides a basic interface to a chess position.
The interface subdirectory contains an implementation named ChessInterface that provides the necessary methods and is used by the test code. Users are likely to want to replace this with a class that wraps whatever native position representation they have.
The nnue_test program in the test subdirectory tests the first layer of the network and the code for the interior linear transformation layers. It should execute and produce "0 errors" on output.
This program can also be used with the -f switch to read an existing network file, although its contents are not validated.