27 | {% trans %}Please activate JavaScript to enable the search
28 | functionality.{% endtrans %}
29 |
30 |
31 |
32 | {% trans %}From here you can search these documents. Enter your search
33 | words into the box below and click "search". Note that the search
34 | function will automatically search for all of the words. Pages
35 | containing fewer words won't appear in the result list.{% endtrans %}
36 |
4 | Integral is a top chess engine developed in C++. It is a personal project developed with the goal of meshing my admiration for chess with programming.
5 |
6 |
7 | Play against Integral on Lichess
8 |
9 |
10 |
11 | ## Search
12 | Integral implements the widely adopted negamax search approach with alpha-beta pruning, and alongside it the various search heuristics that it enables. It utilizes the Lazy SMP approach for multi-threaded search, and has been proven to scale very well at higher thread counts compared to other alpha-beta chess engines.
13 |
14 | ## Evaluation
15 | Integral utilizes an efficiently updatable neural network (NNUE) for its evaluation function.
16 |
17 | ### Architecture
18 | Integral's neural network is a horizontally mirrored perspective network, containing 12 factorized king input buckets, an L1 of 1536 neurons, an L2 of 16 neurons, an L3 of 32 neurons, and 8 output buckets.
19 | `(768x12 (Factorized) -> 1536)x2 -> (16 -> 32 -> 1)1x8`
20 |
21 | ### Data Generation Process
22 | This neural network is trained on tens of millions of self-play games. Each self-play game starts with 3-4 randomly selected moves off a randomly selected opening from the **UHO_Lichess_4852_v1** book. Additionally, 5-man Syzygy endgame tablebases are used to guide the data generation search.
23 |
24 | ### Training Process
25 | The first iteration of Integral's neural network was trained on data from version 4, which had a powerful hand-crafted evaluation (HCE). Each iteration of Integral's neural network since then has been trained on a fresh dataset using the prior network.
26 | All networks are trained using the Bullet trainer, which has made my life way easier.
27 |
28 | ## Compiling Integral
29 | > [!NOTE]
30 | > Integral should be compiled with GCC >= v13 or Clang >= v10
31 |
32 | Integral provides a Makefile for compilation, but you can use CMake as well.\
33 | To compile Integral, enter the following commands in a terminal:
34 | ```
35 | git clone https://github.com/aronpetko/integral
36 | cd integral
37 | make [native | vnni512 | avx512 | avx2_bmi2 | avx2 | sse41_popcnt]
38 | ```
--------------------------------------------------------------------------------
/third-party/fmt/test/gtest-extra.cc:
--------------------------------------------------------------------------------
1 | // Formatting library for C++ - custom Google Test assertions
2 | //
3 | // Copyright (c) 2012 - present, Victor Zverovich
4 | // All rights reserved.
5 | //
6 | // For the license information refer to format.h.
7 |
8 | #include "gtest-extra.h"
9 |
10 | #if FMT_USE_FCNTL
11 |
12 | using fmt::file;
13 |
14 | output_redirect::output_redirect(FILE* f, bool flush) : file_(f) {
15 | if (flush) this->flush();
16 | int fd = FMT_POSIX(fileno(f));
17 | // Create a file object referring to the original file.
18 | original_ = file::dup(fd);
19 | // Create a pipe.
20 | file write_end;
21 | file::pipe(read_end_, write_end);
22 | // Connect the passed FILE object to the write end of the pipe.
23 | write_end.dup2(fd);
24 | }
25 |
26 | output_redirect::~output_redirect() noexcept {
27 | try {
28 | restore();
29 | } catch (const std::exception& e) {
30 | std::fputs(e.what(), stderr);
31 | }
32 | }
33 |
34 | void output_redirect::flush() {
35 | int result = 0;
36 | do {
37 | result = fflush(file_);
38 | } while (result == EOF && errno == EINTR);
39 | if (result != 0) throw fmt::system_error(errno, "cannot flush stream");
40 | }
41 |
42 | void output_redirect::restore() {
43 | if (original_.descriptor() == -1) return; // Already restored.
44 | flush();
45 | // Restore the original file.
46 | original_.dup2(FMT_POSIX(fileno(file_)));
47 | original_.close();
48 | }
49 |
50 | std::string output_redirect::restore_and_read() {
51 | // Restore output.
52 | restore();
53 |
54 | // Read everything from the pipe.
55 | std::string content;
56 | if (read_end_.descriptor() == -1) return content; // Already read.
57 | enum { BUFFER_SIZE = 4096 };
58 | char buffer[BUFFER_SIZE];
59 | size_t count = 0;
60 | do {
61 | count = read_end_.read(buffer, BUFFER_SIZE);
62 | content.append(buffer, count);
63 | } while (count != 0);
64 | read_end_.close();
65 | return content;
66 | }
67 |
68 | std::string read(file& f, size_t count) {
69 | std::string buffer(count, '\0');
70 | size_t n = 0, offset = 0;
71 | do {
72 | n = f.read(&buffer[offset], count - offset);
73 | // We can't read more than size_t bytes since count has type size_t.
74 | offset += n;
75 | } while (offset < count && n != 0);
76 | buffer.resize(offset);
77 | return buffer;
78 | }
79 |
80 | #endif // FMT_USE_FCNTL
81 |
--------------------------------------------------------------------------------
/third-party/fmt/doc/bootstrap/pagination.less:
--------------------------------------------------------------------------------
1 | //
2 | // Pagination (multiple pages)
3 | // --------------------------------------------------
4 | .pagination {
5 | display: inline-block;
6 | padding-left: 0;
7 | margin: @line-height-computed 0;
8 | border-radius: @border-radius-base;
9 |
10 | > li {
11 | display: inline; // Remove list-style and block-level defaults
12 | > a,
13 | > span {
14 | position: relative;
15 | float: left; // Collapse white-space
16 | padding: @padding-base-vertical @padding-base-horizontal;
17 | line-height: @line-height-base;
18 | text-decoration: none;
19 | color: @pagination-color;
20 | background-color: @pagination-bg;
21 | border: 1px solid @pagination-border;
22 | margin-left: -1px;
23 | }
24 | &:first-child {
25 | > a,
26 | > span {
27 | margin-left: 0;
28 | .border-left-radius(@border-radius-base);
29 | }
30 | }
31 | &:last-child {
32 | > a,
33 | > span {
34 | .border-right-radius(@border-radius-base);
35 | }
36 | }
37 | }
38 |
39 | > li > a,
40 | > li > span {
41 | &:hover,
42 | &:focus {
43 | color: @pagination-hover-color;
44 | background-color: @pagination-hover-bg;
45 | border-color: @pagination-hover-border;
46 | }
47 | }
48 |
49 | > .active > a,
50 | > .active > span {
51 | &,
52 | &:hover,
53 | &:focus {
54 | z-index: 2;
55 | color: @pagination-active-color;
56 | background-color: @pagination-active-bg;
57 | border-color: @pagination-active-border;
58 | cursor: default;
59 | }
60 | }
61 |
62 | > .disabled {
63 | > span,
64 | > span:hover,
65 | > span:focus,
66 | > a,
67 | > a:hover,
68 | > a:focus {
69 | color: @pagination-disabled-color;
70 | background-color: @pagination-disabled-bg;
71 | border-color: @pagination-disabled-border;
72 | cursor: @cursor-disabled;
73 | }
74 | }
75 | }
76 |
77 | // Sizing
78 | // --------------------------------------------------
79 |
80 | // Large
81 | .pagination-lg {
82 | .pagination-size(@padding-large-vertical; @padding-large-horizontal; @font-size-large; @border-radius-large);
83 | }
84 |
85 | // Small
86 | .pagination-sm {
87 | .pagination-size(@padding-small-vertical; @padding-small-horizontal; @font-size-small; @border-radius-small);
88 | }
89 |
--------------------------------------------------------------------------------
/third-party/fmt/test/util.h:
--------------------------------------------------------------------------------
1 | // Formatting library for C++ - test utilities
2 | //
3 | // Copyright (c) 2012 - present, Victor Zverovich
4 | // All rights reserved.
5 | //
6 | // For the license information refer to format.h.
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include "fmt/os.h"
14 |
15 | #ifdef _MSC_VER
16 | # define FMT_VSNPRINTF vsprintf_s
17 | #else
18 | # define FMT_VSNPRINTF vsnprintf
19 | #endif
20 |
21 | template
22 | void safe_sprintf(char (&buffer)[SIZE], const char* format, ...) {
23 | std::va_list args;
24 | va_start(args, format);
25 | FMT_VSNPRINTF(buffer, SIZE, format, args);
26 | va_end(args);
27 | }
28 |
29 | extern const char* const file_content;
30 |
31 | // Opens a buffered file for reading.
32 | auto open_buffered_file(FILE** fp = nullptr) -> fmt::buffered_file;
33 |
34 | inline auto safe_fopen(const char* filename, const char* mode) -> FILE* {
35 | #if defined(_WIN32) && !defined(__MINGW32__)
36 | // Fix MSVC warning about "unsafe" fopen.
37 | FILE* f = nullptr;
38 | errno = fopen_s(&f, filename, mode);
39 | return f;
40 | #else
41 | return std::fopen(filename, mode);
42 | #endif
43 | }
44 |
45 | template class basic_test_string {
46 | private:
47 | std::basic_string value_;
48 |
49 | static const Char empty[];
50 |
51 | public:
52 | explicit basic_test_string(const Char* value = empty) : value_(value) {}
53 |
54 | auto value() const -> const std::basic_string& { return value_; }
55 | };
56 |
57 | template const Char basic_test_string::empty[] = {0};
58 |
59 | using test_string = basic_test_string;
60 | using test_wstring = basic_test_string;
61 |
62 | template
63 | auto operator<<(std::basic_ostream& os, const basic_test_string& s)
64 | -> std::basic_ostream& {
65 | os << s.value();
66 | return os;
67 | }
68 |
69 | class date {
70 | int year_, month_, day_;
71 |
72 | public:
73 | date(int year, int month, int day) : year_(year), month_(month), day_(day) {}
74 |
75 | auto year() const -> int { return year_; }
76 | auto month() const -> int { return month_; }
77 | auto day() const -> int { return day_; }
78 | };
79 |
80 | // Returns a locale with the given name if available or classic locale
81 | // otherwise.
82 | auto get_locale(const char* name, const char* alt_name = nullptr)
83 | -> std::locale;
84 |
--------------------------------------------------------------------------------
/third-party/fmt/test/fuzzing/one-arg.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019, Paul Dreik
2 | // For the license information refer to format.h.
3 |
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | #include "fuzzer-common.h"
10 |
11 | template const T* from_repr(const Repr& r) {
12 | return &r;
13 | }
14 |
15 | template <> const std::tm* from_repr(const std::time_t& t) {
16 | return std::localtime(&t);
17 | }
18 |
19 | template
20 | void invoke_fmt(const uint8_t* data, size_t size) {
21 | static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22 | if (size <= fixed_size) return;
23 | auto repr = assign_from_buf(data);
24 | const T* value = from_repr(repr);
25 | if (!value) return;
26 | data += fixed_size;
27 | size -= fixed_size;
28 | data_to_string format_str(data, size);
29 | try {
30 | #if FMT_FUZZ_FORMAT_TO_STRING
31 | std::string message = fmt::format(format_str.get(), *value);
32 | #else
33 | auto buf = fmt::memory_buffer();
34 | fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35 | #endif
36 | } catch (std::exception&) {
37 | }
38 | }
39 |
40 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
41 | if (size <= 3) return 0;
42 |
43 | const auto first = data[0];
44 | data++;
45 | size--;
46 |
47 | switch (first) {
48 | case 0:
49 | invoke_fmt(data, size);
50 | break;
51 | case 1:
52 | invoke_fmt(data, size);
53 | break;
54 | case 2:
55 | invoke_fmt(data, size);
56 | break;
57 | case 3:
58 | invoke_fmt(data, size);
59 | break;
60 | case 4:
61 | invoke_fmt(data, size);
62 | break;
63 | case 5:
64 | invoke_fmt(data, size);
65 | break;
66 | case 6:
67 | invoke_fmt(data, size);
68 | break;
69 | case 7:
70 | invoke_fmt(data, size);
71 | break;
72 | case 8:
73 | invoke_fmt(data, size);
74 | break;
75 | case 9:
76 | invoke_fmt(data, size);
77 | break;
78 | case 10:
79 | invoke_fmt(data, size);
80 | break;
81 | case 11:
82 | invoke_fmt(data, size);
83 | break;
84 | case 12:
85 | invoke_fmt(data, size);
86 | break;
87 | case 13:
88 | invoke_fmt(data, size);
89 | break;
90 | }
91 | return 0;
92 | }
93 |
--------------------------------------------------------------------------------
/shared/nnue/definitions.h:
--------------------------------------------------------------------------------
1 | #ifndef INTEGRAL_ARCH_H
2 | #define INTEGRAL_ARCH_H
3 |
4 | #include
5 |
6 | #include "../multi_array.h"
7 | #include "../simd.h"
8 |
9 | namespace nnue {
10 |
11 | namespace arch {
12 |
13 | constexpr std::size_t kL1Size = 1536;
14 | constexpr std::size_t kL2Size = 16;
15 | constexpr std::size_t kL3Size = 32;
16 | constexpr std::size_t kInputBucketCount = 12;
17 | constexpr std::size_t kOutputBucketCount = 8;
18 |
19 | constexpr std::int32_t kFtQuantization = 255;
20 | constexpr std::int32_t kL1Quantization = 128;
21 |
22 | constexpr std::int32_t kEvalScale = 200;
23 |
24 | } // namespace arch
25 |
26 | // clang-format off
27 | struct RawNetwork {
28 | MultiArray feature_weights;
29 | MultiArray feature_biases;
30 | MultiArray l1_weights;
31 | MultiArray l1_biases;
32 | MultiArray l2_weights;
33 | MultiArray l2_biases;
34 | MultiArray l3_weights;
35 | MultiArray l3_biases;
36 | };
37 |
38 | struct alignas(simd::kAlignment) Network {
39 | alignas(simd::kAlignment) MultiArray feature_weights;
40 | alignas(simd::kAlignment) MultiArray feature_biases;
41 | union {
42 | alignas(simd::kAlignment) MultiArray l1_weights;
43 | alignas(simd::kAlignment) MultiArray l1_weights_alt;
44 | };
45 | alignas(simd::kAlignment) MultiArray l1_biases;
46 | alignas(simd::kAlignment) MultiArray l2_weights;
47 | alignas(simd::kAlignment) MultiArray l2_biases;
48 | alignas(simd::kAlignment) MultiArray l3_weights;
49 | alignas(simd::kAlignment) MultiArray l3_biases;
50 | };
51 | // clang-format on
52 |
53 | }; // namespace nnue
54 |
55 | #endif // INTEGRAL_ARCH_H
--------------------------------------------------------------------------------
/preprocess/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.16)
2 | set(CMAKE_CXX_STANDARD 20)
3 |
4 | # Build options for different architectures
5 | option(BUILD_NATIVE "Build with native optimizations" ${PREPROCESS_BUILD_NATIVE})
6 | option(BUILD_VNNI512 "Build with AVX512 VNNI support" ${PREPROCESS_BUILD_VNNI512})
7 | option(BUILD_AVX512 "Build with AVX512 optimizations" ${PREPROCESS_BUILD_AVX512})
8 | option(BUILD_AVX2_BMI2 "Build with AVX2 + BMI2 optimizations" ${PREPROCESS_BUILD_AVX2_BMI2})
9 | option(BUILD_AVX2 "Build with AVX2 optimizations" ${PREPROCESS_BUILD_AVX2})
10 | option(BUILD_SSE41_POPCNT "Build with SSE4.1 + POPCNT optimizations" ${PREPROCESS_BUILD_SSE41_POPCNT})
11 | option(BUILD_DEBUG "Build with debug information" ${PREPROCESS_BUILD_DEBUG})
12 | option(SPARSE_PERMUTE "Use sparse permute network format" ${PREPROCESS_SPARSE_PERMUTE})
13 |
14 | # Architecture-specific flags
15 | set(CXXFLAGS_NATIVE "-march=native")
16 | set(CXXFLAGS_VNNI512 "-march=znver4 -mtune=znver4 -DBUILD_VNNI512 -DBUILD_FAST_PEXT")
17 | set(CXXFLAGS_AVX512 "-march=x86-64-v4 -mtune=skylake-avx512 -DBUILD_AVX512 -DBUILD_FAST_PEXT")
18 | set(CXXFLAGS_AVX2_BMI2 "-march=haswell -mtune=haswell -mavx2 -mbmi2 -DBUILD_AVX2_BMI2 -DBUILD_FAST_PEXT")
19 | set(CXXFLAGS_AVX2 "-march=bdver4 -mno-tbm -mno-sse4a -mno-bmi2 -mtune=znver2 -DBUILD_AVX2")
20 | set(CXXFLAGS_SSE41_POPCNT "-march=nehalem -mtune=sandybridge -DBUILD_SSE41_POPCNT")
21 |
22 | # Apply the correct flags based on the build type
23 | if (BUILD_DEBUG)
24 | set(CMAKE_BUILD_TYPE Debug)
25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
26 | elseif (BUILD_VNNI512)
27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_VNNI512} -DBUILD_VNNI512")
28 | elseif (BUILD_AVX512)
29 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_AVX512} -DBUILD_AVX512")
30 | elseif (BUILD_AVX2_BMI2)
31 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_AVX2_BMI2} -DBUILD_AVX2_BMI2")
32 | elseif (BUILD_AVX2)
33 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_AVX2} -DBUILD_AVX2")
34 | elseif (BUILD_SSE41_POPCNT)
35 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_SSE41_POPCNT} -DBUILD_SSE41_POPCNT")
36 | elseif (BUILD_NATIVE)
37 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_NATIVE} -DBUILD_NATIVE")
38 | endif ()
39 |
40 | # Include third-party directories
41 | include_directories(../third-party/fathom)
42 | include_directories(../third-party/fmt/include)
43 | add_definitions(-DFMT_HEADER_ONLY)
44 |
45 | add_executable(preprocess net_processing.cc)
--------------------------------------------------------------------------------
/third-party/fmt/test/fuzzing/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Creates fuzzer builds of various kinds
4 | # - oss-fuzz emulated mode (makes sure a simulated invocation by oss-fuzz works)
5 | # - libFuzzer build (you will need clang)
6 | # - afl build (you will need afl)
7 | #
8 | #
9 | # Copyright (c) 2019 Paul Dreik
10 | #
11 | # For the license information refer to format.h.
12 |
13 | set -e
14 | me=$(basename $0)
15 | root=$(readlink -f "$(dirname "$0")/../..")
16 |
17 |
18 | echo $me: root=$root
19 |
20 | here=$(pwd)
21 |
22 | CXXFLAGSALL="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION= -g"
23 | CMAKEFLAGSALL="$root -GNinja -DCMAKE_BUILD_TYPE=Debug -DFMT_DOC=Off -DFMT_TEST=Off -DFMT_FUZZ=On -DCMAKE_CXX_STANDARD=17"
24 |
25 | CLANG=clang++-11
26 |
27 | # For performance analysis of the fuzzers.
28 | builddir=$here/build-fuzzers-perfanalysis
29 | mkdir -p $builddir
30 | cd $builddir
31 | CXX="ccache g++" CXXFLAGS="$CXXFLAGSALL -g" cmake \
32 | $CMAKEFLAGSALL \
33 | -DFMT_FUZZ_LINKMAIN=On \
34 | -DCMAKE_BUILD_TYPE=Release
35 |
36 | cmake --build $builddir
37 |
38 | # Builds the fuzzers as oss-fuzz does.
39 | builddir=$here/build-fuzzers-ossfuzz
40 | mkdir -p $builddir
41 | cd $builddir
42 | CXX=$CLANG \
43 | CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link" cmake \
44 | cmake $CMAKEFLAGSALL \
45 | -DFMT_FUZZ_LINKMAIN=Off \
46 | -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer"
47 |
48 | cmake --build $builddir
49 |
50 |
51 | # Builds fuzzers for local fuzzing with libfuzzer with asan+usan.
52 | builddir=$here/build-fuzzers-libfuzzer
53 | mkdir -p $builddir
54 | cd $builddir
55 | CXX=$CLANG \
56 | CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link,address,undefined" cmake \
57 | cmake $CMAKEFLAGSALL \
58 | -DFMT_FUZZ_LINKMAIN=Off \
59 | -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer"
60 |
61 | cmake --build $builddir
62 |
63 | # Builds a fast fuzzer for making coverage fast.
64 | builddir=$here/build-fuzzers-fast
65 | mkdir -p $builddir
66 | cd $builddir
67 | CXX=$CLANG \
68 | CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link -O3" cmake \
69 | cmake $CMAKEFLAGSALL \
70 | -DFMT_FUZZ_LINKMAIN=Off \
71 | -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer" \
72 | -DCMAKE_BUILD_TYPE=Release
73 |
74 | cmake --build $builddir
75 |
76 |
77 | # Builds fuzzers for local fuzzing with afl.
78 | builddir=$here/build-fuzzers-afl
79 | mkdir -p $builddir
80 | cd $builddir
81 | CXX="afl-g++" \
82 | CXXFLAGS="$CXXFLAGSALL -fsanitize=address,undefined" \
83 | cmake $CMAKEFLAGSALL \
84 | -DFMT_FUZZ_LINKMAIN=On
85 |
86 | cmake --build $builddir
87 |
88 |
89 | echo $me: all good
90 |
91 |
--------------------------------------------------------------------------------
/src/tuner/spsa.h:
--------------------------------------------------------------------------------
1 | #ifndef INTEGRAL_SPSA_H
2 | #define INTEGRAL_SPSA_H
3 |
4 | #include
5 | #include
6 | #include "../engine/uci/uci.h"
7 |
8 | // #define SPSA_TUNE
9 | #define PRINT_SPSA_INPUTS
10 |
11 | #ifdef SPSA_TUNE
12 | #define TUNABLE(name, value, min, max, disabled) \
13 | inline Tunable name(#name, value, min, max, (max - min) / 20, disabled)
14 |
15 | #define TUNABLE_STEP(name, value, min, max, disabled, step) \
16 | inline Tunable name(#name, value, min, max, step, disabled)
17 |
18 | constexpr double kLearningRate = 0.002;
19 |
20 | template
21 | class Tunable {
22 | public:
23 | explicit Tunable(std::string_view name,
24 | T value,
25 | T min,
26 | T max,
27 | T step = T{},
28 | bool disabled = false)
29 | : value_(value),
30 | step_(step),
31 | learning_rate_(kLearningRate) {
32 | #ifdef SPSA_TUNE
33 | if (disabled) return;
34 |
35 | if constexpr (std::is_same_v) {
36 | uci::listener.AddOption(
37 | name, value, min, max, [this](uci::Option &option) {
38 | value_ = option.GetValue();
39 | });
40 | #ifdef PRINT_SPSA_INPUTS
41 | fmt::println("{}, int, {}, {}, {}, {}, {}", name, value, min, max, step_, learning_rate_);
42 | #endif
43 | } else if constexpr (std::is_same_v) {
44 | uci::listener.AddOption(
45 | name, std::to_string(value), [this](uci::Option &option) {
46 | value_ = std::stod(option.GetValue());
47 | });
48 | #ifdef PRINT_SPSA_INPUTS
49 | fmt::println("{}, float, {}, {}, {}, {}, {}", name, value, min, max, step_, learning_rate_);
50 | #endif
51 | }
52 | #endif
53 | }
54 |
55 | constexpr operator T() const {
56 | return value_;
57 | }
58 |
59 | [[nodiscard]] T Get() const {
60 | return value_;
61 | }
62 |
63 | [[nodiscard]] T GetStep() const {
64 | return step_;
65 | }
66 |
67 | [[nodiscard]] double GetLearningRate() const {
68 | return learning_rate_;
69 | }
70 |
71 | private:
72 | T value_;
73 | T step_;
74 | double learning_rate_;
75 | };
76 | #else
77 | #define TUNABLE(name, value, min, max, disabled) \
78 | static constexpr auto name = value
79 |
80 | #define TUNABLE_STEP(name, value, min, max, disabled, step) \
81 | static constexpr auto name = value
82 |
83 | template
84 | using Tunable = T;
85 | #endif
86 |
87 | #endif // INTEGRAL_SPSA_H
--------------------------------------------------------------------------------
/third-party/fmt/doc/bootstrap/print.less:
--------------------------------------------------------------------------------
1 | /*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */
2 |
3 | // ==========================================================================
4 | // Print styles.
5 | // Inlined to avoid the additional HTTP request: h5bp.com/r
6 | // ==========================================================================
7 |
8 | @media print {
9 | *,
10 | *:before,
11 | *:after {
12 | background: transparent !important;
13 | color: #000 !important; // Black prints faster: h5bp.com/s
14 | box-shadow: none !important;
15 | text-shadow: none !important;
16 | }
17 |
18 | a,
19 | a:visited {
20 | text-decoration: underline;
21 | }
22 |
23 | a[href]:after {
24 | content: " (" attr(href) ")";
25 | }
26 |
27 | abbr[title]:after {
28 | content: " (" attr(title) ")";
29 | }
30 |
31 | // Don't show links that are fragment identifiers,
32 | // or use the `javascript:` pseudo protocol
33 | a[href^="#"]:after,
34 | a[href^="javascript:"]:after {
35 | content: "";
36 | }
37 |
38 | pre,
39 | blockquote {
40 | border: 1px solid #999;
41 | page-break-inside: avoid;
42 | }
43 |
44 | thead {
45 | display: table-header-group; // h5bp.com/t
46 | }
47 |
48 | tr,
49 | img {
50 | page-break-inside: avoid;
51 | }
52 |
53 | img {
54 | max-width: 100% !important;
55 | }
56 |
57 | p,
58 | h2,
59 | h3 {
60 | orphans: 3;
61 | widows: 3;
62 | }
63 |
64 | h2,
65 | h3 {
66 | page-break-after: avoid;
67 | }
68 |
69 | // Bootstrap specific changes start
70 | //
71 | // Chrome (OSX) fix for https://github.com/twbs/bootstrap/issues/11245
72 | // Once fixed, we can just straight up remove this.
73 | select {
74 | background: #fff !important;
75 | }
76 |
77 | // Bootstrap components
78 | .navbar {
79 | display: none;
80 | }
81 | .btn,
82 | .dropup > .btn {
83 | > .caret {
84 | border-top-color: #000 !important;
85 | }
86 | }
87 | .label {
88 | border: 1px solid #000;
89 | }
90 |
91 | .table {
92 | border-collapse: collapse !important;
93 |
94 | td,
95 | th {
96 | background-color: #fff !important;
97 | }
98 | }
99 | .table-bordered {
100 | th,
101 | td {
102 | border: 1px solid #ddd !important;
103 | }
104 | }
105 |
106 | // Bootstrap specific changes end
107 | }
108 |
--------------------------------------------------------------------------------
/third-party/fmt/test/fuzzing/fuzzer-common.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019, Paul Dreik
2 | // For the license information refer to format.h.
3 |
4 | #ifndef FUZZER_COMMON_H
5 | #define FUZZER_COMMON_H
6 |
7 | #include
8 |
9 | #include // std::uint8_t
10 | #include // memcpy
11 | #include
12 |
13 | // One can format to either a string, or a buffer. The latter is faster, but
14 | // one may be interested in formatting to a string instead to verify it works
15 | // as intended. To avoid a combinatoric explosion, select this at compile time
16 | // instead of dynamically from the fuzz data.
17 | #define FMT_FUZZ_FORMAT_TO_STRING 0
18 |
19 | // If {fmt} is given a buffer that is separately allocated, chances that address
20 | // sanitizer detects out of bound reads is much higher. However, it slows down
21 | // the fuzzing.
22 | #define FMT_FUZZ_SEPARATE_ALLOCATION 1
23 |
24 | // The size of the largest possible type in use.
25 | // To let the the fuzzer mutation be efficient at cross pollinating between
26 | // different types, use a fixed size format. The same bit pattern, interpreted
27 | // as another type, is likely interesting.
28 | constexpr auto fixed_size = 16;
29 |
30 | // Casts data to a char pointer.
31 | template inline const char* as_chars(const T* data) {
32 | return reinterpret_cast(data);
33 | }
34 |
35 | // Casts data to a byte pointer.
36 | template inline const std::uint8_t* as_bytes(const T* data) {
37 | return reinterpret_cast(data);
38 | }
39 |
40 | // Blits bytes from data to form an (assumed trivially constructible) object
41 | // of type Item.
42 | template inline Item assign_from_buf(const std::uint8_t* data) {
43 | auto item = Item();
44 | std::memcpy(&item, data, sizeof(Item));
45 | return item;
46 | }
47 |
48 | // Reads a boolean value by looking at the first byte from data.
49 | template <> inline bool assign_from_buf(const std::uint8_t* data) {
50 | return *data != 0;
51 | }
52 |
53 | struct data_to_string {
54 | #if FMT_FUZZ_SEPARATE_ALLOCATION
55 | std::vector buffer;
56 |
57 | data_to_string(const uint8_t* data, size_t size, bool add_terminator = false)
58 | : buffer(size + (add_terminator ? 1 : 0)) {
59 | if (size) {
60 | std::memcpy(buffer.data(), data, size);
61 | }
62 | }
63 |
64 | fmt::string_view get() const { return {buffer.data(), buffer.size()}; }
65 | #else
66 | fmt::string_view sv;
67 |
68 | data_to_string(const uint8_t* data, size_t size, bool = false)
69 | : str(as_chars(data), size) {}
70 |
71 | fmt::string_view get() const { return sv; }
72 | #endif
73 |
74 | const char* data() const { return get().data(); }
75 | };
76 |
77 | #endif // FUZZER_COMMON_H
78 |
--------------------------------------------------------------------------------
/third-party/fmt/support/bazel/README.md:
--------------------------------------------------------------------------------
1 | # Bazel support
2 |
3 | To get [Bazel](https://bazel.build/) working with {fmt} you can copy the files `BUILD.bazel`, `WORKSPACE.bazel`, and `.bazelversion` from this folder (`support/bazel`) to the root folder of this project. This way {fmt} gets bazelized and can be used with Bazel (e.g. doing a `bazel build //...` on {fmt}).
4 |
5 | ## Using {fmt} as a dependency
6 |
7 | The following minimal example shows how to use {fmt} as a dependency within a Bazel project.
8 |
9 | The following file structure is assumed:
10 |
11 | ```
12 | example
13 | ├── BUILD.bazel
14 | ├── main.cpp
15 | └── WORKSPACE.bazel
16 | ```
17 |
18 | *main.cpp*:
19 |
20 | ```c++
21 | #include "fmt/core.h"
22 |
23 | int main() {
24 | fmt::print("The answer is {}\n", 42);
25 | }
26 | ```
27 |
28 | The expected output of this example is `The answer is 42`.
29 |
30 | *WORKSPACE.bazel*:
31 |
32 | ```python
33 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
34 |
35 | git_repository(
36 | name = "fmt",
37 | branch = "master",
38 | remote = "https://github.com/fmtlib/fmt",
39 | patch_cmds = [
40 | "mv support/bazel/.bazelversion .bazelversion",
41 | "mv support/bazel/BUILD.bazel BUILD.bazel",
42 | "mv support/bazel/WORKSPACE.bazel WORKSPACE.bazel",
43 | ],
44 | # Windows-related patch commands are only needed in the case MSYS2 is not installed.
45 | # More details about the installation process of MSYS2 on Windows systems can be found here:
46 | # https://docs.bazel.build/versions/main/install-windows.html#installing-compilers-and-language-runtimes
47 | # Even if MSYS2 is installed the Windows related patch commands can still be used.
48 | patch_cmds_win = [
49 | "Move-Item -Path support/bazel/.bazelversion -Destination .bazelversion",
50 | "Move-Item -Path support/bazel/BUILD.bazel -Destination BUILD.bazel",
51 | "Move-Item -Path support/bazel/WORKSPACE.bazel -Destination WORKSPACE.bazel",
52 | ],
53 | )
54 | ```
55 |
56 | In the *WORKSPACE* file, the {fmt} GitHub repository is fetched. Using the attribute `patch_cmds` the files `BUILD.bazel`, `WORKSPACE.bazel`, and `.bazelversion` are moved to the root of the {fmt} repository. This way the {fmt} repository is recognized as a bazelized workspace.
57 |
58 | *BUILD.bazel*:
59 |
60 | ```python
61 | cc_binary(
62 | name = "Demo",
63 | srcs = ["main.cpp"],
64 | deps = ["@fmt"],
65 | )
66 | ```
67 |
68 | The *BUILD* file defines a binary named `Demo` that has a dependency to {fmt}.
69 |
70 | To execute the binary you can run `bazel run //:Demo`.
71 |
72 | # Using Bzlmod
73 |
74 | The [Bazel Central Registry](https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/fmt) also provides support for {fmt}.
75 |
--------------------------------------------------------------------------------
/third-party/fmt/test/fuzzing/named-arg.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019, Paul Dreik
2 | // For the license information refer to format.h.
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include "fuzzer-common.h"
11 |
12 | template
13 | void invoke_fmt(const uint8_t* data, size_t size, unsigned arg_name_size) {
14 | static_assert(sizeof(T) <= fixed_size, "fixed_size too small");
15 | if (size <= fixed_size) return;
16 | const T value = assign_from_buf(data);
17 | data += fixed_size;
18 | size -= fixed_size;
19 |
20 | if (arg_name_size <= 0 || arg_name_size >= size) return;
21 | data_to_string arg_name(data, arg_name_size, true);
22 | data += arg_name_size;
23 | size -= arg_name_size;
24 |
25 | data_to_string format_str(data, size);
26 | try {
27 | #if FMT_FUZZ_FORMAT_TO_STRING
28 | std::string message =
29 | fmt::format(format_str.get(), fmt::arg(arg_name.data(), value));
30 | #else
31 | fmt::memory_buffer out;
32 | fmt::format_to(std::back_inserter(out), format_str.get(),
33 | fmt::arg(arg_name.data(), value));
34 | #endif
35 | } catch (std::exception&) {
36 | }
37 | }
38 |
39 | // For dynamic dispatching to an explicit instantiation.
40 | template void invoke(int type, Callback callback) {
41 | switch (type) {
42 | case 0:
43 | callback(bool());
44 | break;
45 | case 1:
46 | callback(char());
47 | break;
48 | case 2:
49 | using sc = signed char;
50 | callback(sc());
51 | break;
52 | case 3:
53 | using uc = unsigned char;
54 | callback(uc());
55 | break;
56 | case 4:
57 | callback(short());
58 | break;
59 | case 5:
60 | using us = unsigned short;
61 | callback(us());
62 | break;
63 | case 6:
64 | callback(int());
65 | break;
66 | case 7:
67 | callback(unsigned());
68 | break;
69 | case 8:
70 | callback(long());
71 | break;
72 | case 9:
73 | using ul = unsigned long;
74 | callback(ul());
75 | break;
76 | case 10:
77 | callback(float());
78 | break;
79 | case 11:
80 | callback(double());
81 | break;
82 | case 12:
83 | using LD = long double;
84 | callback(LD());
85 | break;
86 | }
87 | }
88 |
89 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
90 | if (size <= 3) return 0;
91 |
92 | // Switch types depending on the first byte of the input.
93 | const auto type = data[0] & 0x0F;
94 | const unsigned arg_name_size = (data[0] & 0xF0) >> 4;
95 | data++;
96 | size--;
97 |
98 | invoke(type, [=](auto arg) {
99 | invoke_fmt(data, size, arg_name_size);
100 | });
101 | return 0;
102 | }
103 |
--------------------------------------------------------------------------------
/third-party/fmt/test/fuzzing/two-args.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019, Paul Dreik
2 | // For the license information refer to format.h.
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include "fuzzer-common.h"
11 |
12 | template
13 | void invoke_fmt(const uint8_t* data, size_t size) {
14 | static_assert(sizeof(Item1) <= fixed_size, "size1 exceeded");
15 | static_assert(sizeof(Item2) <= fixed_size, "size2 exceeded");
16 | if (size <= fixed_size + fixed_size) return;
17 |
18 | const Item1 item1 = assign_from_buf(data);
19 | data += fixed_size;
20 | size -= fixed_size;
21 |
22 | const Item2 item2 = assign_from_buf(data);
23 | data += fixed_size;
24 | size -= fixed_size;
25 |
26 | auto format_str = fmt::string_view(as_chars(data), size);
27 | #if FMT_FUZZ_FORMAT_TO_STRING
28 | std::string message = fmt::format(format_str, item1, item2);
29 | #else
30 | auto buf = fmt::memory_buffer();
31 | fmt::format_to(std::back_inserter(buf), format_str, item1, item2);
32 | #endif
33 | }
34 |
35 | // For dynamic dispatching to an explicit instantiation.
36 | template void invoke(int index, Callback callback) {
37 | switch (index) {
38 | case 0:
39 | callback(bool());
40 | break;
41 | case 1:
42 | callback(char());
43 | break;
44 | case 2:
45 | using sc = signed char;
46 | callback(sc());
47 | break;
48 | case 3:
49 | using uc = unsigned char;
50 | callback(uc());
51 | break;
52 | case 4:
53 | callback(short());
54 | break;
55 | case 5:
56 | using us = unsigned short;
57 | callback(us());
58 | break;
59 | case 6:
60 | callback(int());
61 | break;
62 | case 7:
63 | callback(unsigned());
64 | break;
65 | case 8:
66 | callback(long());
67 | break;
68 | case 9:
69 | using ul = unsigned long;
70 | callback(ul());
71 | break;
72 | case 10:
73 | callback(float());
74 | break;
75 | case 11:
76 | callback(double());
77 | break;
78 | case 12:
79 | using LD = long double;
80 | callback(LD());
81 | break;
82 | case 13:
83 | using ptr = void*;
84 | callback(ptr());
85 | break;
86 | }
87 | }
88 |
89 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
90 | if (size <= 3) return 0;
91 |
92 | // Switch types depending on the first byte of the input.
93 | const auto type1 = data[0] & 0x0F;
94 | const auto type2 = (data[0] & 0xF0) >> 4;
95 | data++;
96 | size--;
97 | try {
98 | invoke(type1, [=](auto param1) {
99 | invoke(type2, [=](auto param2) {
100 | invoke_fmt(data, size);
101 | });
102 | });
103 | } catch (std::exception&) {
104 | }
105 | return 0;
106 | }
107 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Default compiler settings
2 | CC ?= gcc
3 | CXX ?= g++
4 |
5 | # Detect the operating system
6 | ifeq ($(OS),Windows_NT)
7 | detected_OS := Windows
8 | EXE_EXT := .exe
9 | else
10 | detected_OS := $(shell uname -s)
11 | EXE_EXT :=
12 | endif
13 |
14 | # Build directory
15 | BUILD_DIR=build
16 |
17 | # CMake build option
18 | CMAKE_BUILD_OPTION ?= Release
19 | BUILD_TYPE ?= BUILD_NATIVE
20 |
21 | # Path to evaluation file (can be overridden from command line)
22 | EVALFILE ?=
23 |
24 | # Executable name (can be overridden from command line)
25 | EXE ?= integral
26 |
27 | # Whether or not datagen will be used
28 | DATAGEN ?= OFF
29 |
30 | # Standard targets
31 | .PHONY: all clean debug x86_64 x86_64_popcnt x86_64_bmi2 native
32 |
33 | all: $(BUILD_DIR)
34 | @echo Building $(EXE) with $(BUILD_TYPE)...
35 | @$(MAKE) -C $(BUILD_DIR)
36 | @echo Copying executable...
37 | @$(MAKE) copy_executable
38 |
39 | $(BUILD_DIR):
40 | ifeq ($(detected_OS),Windows)
41 | @if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)
42 | else
43 | @mkdir -p $(BUILD_DIR)
44 | endif
45 | @echo Configuring CMake with BUILD_TYPE=$(BUILD_TYPE)...
46 | @cd $(BUILD_DIR) && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_OPTION) -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX) -DEVALFILE=$(EVALFILE) -D$(BUILD_TYPE)=ON -DDATAGEN=$(DATAGEN) ..
47 |
48 | clean:
49 | ifeq ($(detected_OS),Windows)
50 | @if exist $(BUILD_DIR) rmdir /s /q $(BUILD_DIR)
51 | @del /f /q $(EXE)*$(EXE_EXT)
52 | else
53 | @rm -rf $(BUILD_DIR)
54 | @rm -f $(EXE)*$(EXE_EXT)
55 | endif
56 |
57 | copy_executable:
58 | ifeq ($(BUILD_TYPE),BUILD_DEBUG)
59 | $(eval EXE_NAME := $(EXE)_debug$(EXE_EXT))
60 | else ifeq ($(BUILD_TYPE),BUILD_X86_64_POPCNT)
61 | $(eval EXE_NAME := $(EXE)_x86_64_popcnt$(EXE_EXT))
62 | else ifeq ($(BUILD_TYPE),BUILD_X86_64_MODERN)
63 | $(eval EXE_NAME := $(EXE)_x86_64_modern$(EXE_EXT))
64 | else ifeq ($(BUILD_TYPE),BUILD_X86_64_BMI2)
65 | $(eval EXE_NAME := $(EXE)_x86_64_bmi2$(EXE_EXT))
66 | else
67 | $(eval EXE_NAME := $(EXE)$(EXE_EXT))
68 | endif
69 |
70 | ifeq ($(detected_OS),Windows)
71 | @copy $(BUILD_DIR)\integral$(EXE_EXT) $(EXE_NAME)
72 | else
73 | @cp $(BUILD_DIR)/integral$(EXE_EXT) $(EXE_NAME)
74 | endif
75 |
76 | debug:
77 | @echo Building with debug
78 | @$(MAKE) all BUILD_TYPE=BUILD_DEBUG
79 |
80 | vnni512:
81 | @echo Building with BUILD_VNNI512
82 | @$(MAKE) all BUILD_TYPE=BUILD_VNNI512
83 |
84 | avx512:
85 | @echo Building with BUILD_AVX512
86 | @$(MAKE) all BUILD_TYPE=BUILD_AVX512
87 |
88 | avx2_bmi2:
89 | @echo Building with BUILD_AVX2_BMI2
90 | @$(MAKE) all BUILD_TYPE=BUILD_AVX2_BMI2
91 |
92 | avx2:
93 | @echo Building with BUILD_AVX2
94 | @$(MAKE) all BUILD_TYPE=BUILD_AVX2
95 |
96 | sse41_popcnt:
97 | @echo Building with BUILD_SSE41_POPCNT
98 | @$(MAKE) all BUILD_TYPE=BUILD_SSE41_POPCNT
99 |
100 | native:
101 | @echo Building with native optimizations...
102 | @$(MAKE) all BUILD_TYPE=BUILD_NATIVE
--------------------------------------------------------------------------------
/third-party/fmt/doc/bootstrap/mixins/forms.less:
--------------------------------------------------------------------------------
1 | // Form validation states
2 | //
3 | // Used in forms.less to generate the form validation CSS for warnings, errors,
4 | // and successes.
5 |
6 | .form-control-validation(@text-color: #555; @border-color: #ccc; @background-color: #f5f5f5) {
7 | // Color the label and help text
8 | .help-block,
9 | .control-label,
10 | .radio,
11 | .checkbox,
12 | .radio-inline,
13 | .checkbox-inline,
14 | &.radio label,
15 | &.checkbox label,
16 | &.radio-inline label,
17 | &.checkbox-inline label {
18 | color: @text-color;
19 | }
20 | // Set the border and box shadow on specific inputs to match
21 | .form-control {
22 | border-color: @border-color;
23 | .box-shadow(inset 0 1px 1px rgba(0,0,0,.075)); // Redeclare so transitions work
24 | &:focus {
25 | border-color: darken(@border-color, 10%);
26 | @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 6px lighten(@border-color, 20%);
27 | .box-shadow(@shadow);
28 | }
29 | }
30 | // Set validation states also for addons
31 | .input-group-addon {
32 | color: @text-color;
33 | border-color: @border-color;
34 | background-color: @background-color;
35 | }
36 | // Optional feedback icon
37 | .form-control-feedback {
38 | color: @text-color;
39 | }
40 | }
41 |
42 |
43 | // Form control focus state
44 | //
45 | // Generate a customized focus state and for any input with the specified color,
46 | // which defaults to the `@input-border-focus` variable.
47 | //
48 | // We highly encourage you to not customize the default value, but instead use
49 | // this to tweak colors on an as-needed basis. This aesthetic change is based on
50 | // WebKit's default styles, but applicable to a wider range of browsers. Its
51 | // usability and accessibility should be taken into account with any change.
52 | //
53 | // Example usage: change the default blue border and shadow to white for better
54 | // contrast against a dark gray background.
55 | .form-control-focus(@color: @input-border-focus) {
56 | @color-rgba: rgba(red(@color), green(@color), blue(@color), .6);
57 | &:focus {
58 | border-color: @color;
59 | outline: 0;
60 | .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px @{color-rgba}");
61 | }
62 | }
63 |
64 | // Form control sizing
65 | //
66 | // Relative text size, padding, and border-radii changes for form controls. For
67 | // horizontal sizing, wrap controls in the predefined grid classes. `