Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Andy Duplain
Antoine Champion (antoinechampion)
Aram Tumanian (atumanian)
Arjun Temurnikar
Artem Solopiy (EntityFX)
Auguste Pop
Balint Pfliegel
Ben Koshy (BKSpurgeon)
Expand Down
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ This distribution of Stockfish consists of the following files:
* a file with the .nnue extension, storing the neural network for the NNUE
evaluation. Binary distributions will have this file embedded.

## UCI options
## The UCI protocol and available options

Currently, Stockfish has the following UCI options:
The Universal Chess Interface (UCI) is a standard protocol used to communicate with a chess engine,
and is the recommended way to do so for typical graphical user interfaces (GUI) or chess tools.

Stockfish implements most commands as described in [the UCI protocol](https://www.shredderchess.com/download/div/uci.zip)

For users, the following UCI options, which can typically be set via a GUI, are available in Stockfish:

* #### Threads
The number of CPU threads used for searching a position. For best performance, set
Expand Down Expand Up @@ -136,6 +141,33 @@ Currently, Stockfish has the following UCI options:
* #### Debug Log File
Write all communication to and from the engine into a text file.

For developers the following non-standard commands might be of interest, mainly useful for debugging:

* #### bench ttSize threads limit fenFile limitType evalType
Performs a standard benchmark using various options. The signature or standard node
count is obtained using all defaults. `bench` is currently `bench 16 1 13 default depth mixed`.

* #### compiler
Give information about the compiler and environment used for building a binary.

* #### d
Display the current position, with ascii art and fen.

* #### eval
Return the evaluation of the current position.

* #### export_net [filename]
Exports the currently loaded network to a file.
If the currently loaded network is the embedded network and the filename
is not specified then the network is saved to the file matching the name
of the embedded network, as defined in evaluate.h.
If the currently loaded network is not the embedded network (some net set
through the UCI setoption) then the filename parameter is required and the
network is saved into that file.

* #### flip
Flips the side to move.

### Generating Training Data

To generate training data from the classic eval, use the generate_training_data command with the setting "Use NNUE" set to "false". The given example is generation in its simplest form. There are more commands.
Expand Down
20 changes: 17 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ 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 \
e2k \
armv7 armv7-neon armv8 apple-silicon general-64 general-32))
SUPPORTED_ARCH=true
else
Expand Down Expand Up @@ -301,15 +302,27 @@ ifeq ($(ARCH),ppc-64)
prefetch = yes
endif

ifeq ($(findstring e2k,$(ARCH)),e2k)
arch = e2k
mmx = yes
bits = 64
sse = yes
sse2 = yes
ssse3 = yes
sse41 = yes
popcnt = yes
endif

endif

### ==========================================================================
### Section 3. Low-level Configuration
### ==========================================================================

### 3.1 Selecting compiler (default = gcc)
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++17 -I. $(EXTRACXXFLAGS)
DEPENDFLAGS += -std=c++17
ADDITIONAL_INCLUDE_DIRECTORIES = -I.
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++17 $(ADDITIONAL_INCLUDE_DIRECTORIES) $(EXTRACXXFLAGS)
DEPENDFLAGS += -std=c++17 $(ADDITIONAL_INCLUDE_DIRECTORIES)
LDFLAGS += $(EXTRALDFLAGS)

ifeq ($(COMP),)
Expand Down Expand Up @@ -524,7 +537,6 @@ ifeq ($(popcnt),yes)
endif
endif


ifeq ($(avx2),yes)
CXXFLAGS += -DUSE_AVX2
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
Expand Down Expand Up @@ -692,6 +704,7 @@ help:
@echo "armv7 > ARMv7 32-bit"
@echo "armv7-neon > ARMv7 32-bit with popcnt and neon"
@echo "armv8 > ARMv8 64-bit with popcnt and neon"
@echo "e2k > Elbrus 2000"
@echo "apple-silicon > Apple silicon ARM64"
@echo "general-64 > unspecified 64-bit"
@echo "general-32 > unspecified 32-bit"
Expand Down Expand Up @@ -841,6 +854,7 @@ config-sanity: net
@test "$(SUPPORTED_ARCH)" = "true"
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || \
test "$(arch)" = "e2k" || \
test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64"
@test "$(bits)" = "32" || test "$(bits)" = "64"
@test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
Expand Down
23 changes: 22 additions & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "misc.h"
#include "pawns.h"
#include "thread.h"
#include "timeman.h"
#include "uci.h"
#include "incbin/incbin.h"

Expand Down Expand Up @@ -126,6 +127,26 @@ namespace Eval {
}
}

void export_net(const std::optional<std::string>& filename) {
std::string actualFilename;
if (filename.has_value()) {
actualFilename = filename.value();
} else {
if (eval_file_loaded != EvalFileDefaultName) {
sync_cout << "Failed to export a net. A non-embedded net can only be saved if the filename is specified." << sync_endl;
return;
}
actualFilename = EvalFileDefaultName;
}

ofstream stream(actualFilename, std::ios_base::binary);
if (save_eval(stream)) {
sync_cout << "Network saved successfully to " << actualFilename << "." << sync_endl;
} else {
sync_cout << "Failed to export a net." << sync_endl;
}
}

/// NNUE::verify() verifies that the last net used was loaded successfully
void verify() {

Expand Down Expand Up @@ -1120,7 +1141,7 @@ Value Eval::evaluate(const Position& pos) {
+ material / 32
- 4 * pos.rule50_count();

Value nnue = NNUE::evaluate(pos) * scale / 1024 + Tempo;
Value nnue = NNUE::evaluate(pos) * scale / 1024 + Time.tempoNNUE;

if (pos.is_chess960())
nnue += fix_FRC(pos);
Expand Down
3 changes: 3 additions & 0 deletions src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define EVALUATE_H_INCLUDED

#include <string>
#include <optional>

#include "types.h"

Expand Down Expand Up @@ -50,7 +51,9 @@ namespace Eval {

Value evaluate(const Position& pos);
bool load_eval(std::string name, std::istream& stream);
bool save_eval(std::ostream& stream);
void init();
void export_net(const std::optional<std::string>& filename);
void verify();
}

Expand Down
14 changes: 13 additions & 1 deletion src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef bool(*fun3_t)(HANDLE, CONST GROUP_AFFINITY*, PGROUP_AFFINITY);
#include <sys/mman.h>
#endif

#if defined(__APPLE__) || defined(__ANDROID__) || defined(__OpenBSD__) || (defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) && !defined(_WIN32))
#if defined(__APPLE__) || defined(__ANDROID__) || defined(__OpenBSD__) || (defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) && !defined(_WIN32)) || defined(__e2k__)
#define POSIXALIGNEDALLOC
#include <stdlib.h>
#endif
Expand Down Expand Up @@ -194,6 +194,18 @@ std::string compiler_info() {
compiler += "(version ";
compiler += stringify(_MSC_FULL_VER) "." stringify(_MSC_BUILD);
compiler += ")";
#elif defined(__e2k__) && defined(__LCC__)
#define dot_ver2(n) \
compiler += (char)'.'; \
compiler += (char)('0' + (n) / 10); \
compiler += (char)('0' + (n) % 10);

compiler += "MCST LCC ";
compiler += "(version ";
compiler += std::to_string(__LCC__ / 100);
dot_ver2(__LCC__ % 100)
dot_ver2(__LCC_MINOR__)
compiler += ")";
#elif __GNUC__
compiler += "g++ (GNUC) ";
compiler += make_version_string(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
Expand Down
43 changes: 43 additions & 0 deletions src/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,49 @@ T* align_ptr_up(T* ptr)
return reinterpret_cast<T*>(reinterpret_cast<char*>((ptrint + (Alignment - 1)) / Alignment * Alignment));
}

template <typename T>
class ValueListInserter {
public:
ValueListInserter(T* v, std::size_t& s) :
values(v),
size(&s)
{
}

void push_back(const T& value) { values[(*size)++] = value; }
private:
T* values;
std::size_t* size;
};

template <typename T, std::size_t MaxSize>
class ValueList {

public:
std::size_t size() const { return size_; }
void resize(std::size_t newSize) { size_ = newSize; }
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_; }
operator ValueListInserter<T>() { return ValueListInserter(values_, size_); }

void swap(ValueList& other) {
const std::size_t maxSize = std::max(size_, other.size_);
for (std::size_t i = 0; i < maxSize; ++i) {
std::swap(values_[i], other.values_[i]);
}
std::swap(size_, other.size_);
}

private:
T values_[MaxSize];
std::size_t size_ = 0;
};

// This logger allows printing many parts in a region atomically
// but doesn't block the threads trying to append to other regions.
// Instead if some region tries to pring while other region holds
Expand Down
Loading