├── .circleci
├── Dockerfile
└── config.yml
├── .clang-format
├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── .gitmodules
├── AUTHORS
├── CITATION.cff
├── CONTRIBUTING.md
├── COPYING
├── FLAGS.md
├── OpenBench
└── Makefile
├── README.md
├── appveyor.yml
├── build-sycl.cmd
├── build.cmd
├── build.sh
├── build_rescorer.cmd
├── changelog.txt
├── cross-files
├── aarch64-darwin
├── aarch64-linux-android
├── armv7a-linux-android
└── x86_64-darwin
├── dist
├── README-cuda.txt
├── README-onnx-dml.txt
└── install-dml.cmd
├── install_openSUSE_lc0.sh
├── meson.build
├── meson_options.txt
├── openSUSE_install.md
├── pyproject.toml
├── scripts
├── appveyor_android_build.cmd
├── appveyor_android_package.cmd
├── appveyor_win_build.cmd
├── appveyor_win_package.cmd
├── bumpversion.py
├── check_dx.bat
├── check_opencl.bat
├── checkdir.py
├── compile_proto.py
├── gen_py_bindings.py
├── pybind
│ ├── __init__.py
│ ├── core.py
│ ├── exceptions.py
│ ├── functions.py
│ ├── parameters.py
│ ├── retval.py
│ └── writer.py
└── sycl_build_hack.py
├── src
├── chess
│ ├── bitboard.h
│ ├── board.cc
│ ├── board.h
│ ├── board_test.cc
│ ├── callbacks.h
│ ├── gamestate.cc
│ ├── gamestate.h
│ ├── pgn.h
│ ├── position.cc
│ ├── position.h
│ ├── position_test.cc
│ ├── types.h
│ ├── uciloop.cc
│ └── uciloop.h
├── engine.cc
├── engine.h
├── engine_loop.cc
├── engine_loop.h
├── engine_test.cc
├── main.cc
├── neural
│ ├── backend.cc
│ ├── backend.h
│ ├── backends
│ │ ├── blas
│ │ │ ├── README.md
│ │ │ ├── blas.h
│ │ │ ├── convolution1.cc
│ │ │ ├── convolution1.h
│ │ │ ├── encoder.h
│ │ │ ├── fully_connected_layer.cc
│ │ │ ├── fully_connected_layer.h
│ │ │ ├── layer_norm.ispc
│ │ │ ├── network_blas.cc
│ │ │ ├── se_unit.cc
│ │ │ ├── se_unit.h
│ │ │ ├── winograd_convolution3.cc
│ │ │ ├── winograd_convolution3.h
│ │ │ └── winograd_transform.ispc
│ │ ├── cuda
│ │ │ ├── common_kernels.cu
│ │ │ ├── cuda_common.h
│ │ │ ├── fp16_kernels.cu
│ │ │ ├── inputs_outputs.h
│ │ │ ├── kernels.h
│ │ │ ├── layers.cc
│ │ │ ├── layers.h
│ │ │ ├── network_cuda.cc
│ │ │ ├── network_cudnn.cc
│ │ │ ├── readme.txt
│ │ │ └── winograd_helper.inc
│ │ ├── dx
│ │ │ ├── MetaCommand.h
│ │ │ ├── dx_common.h
│ │ │ ├── layers_dx.cc
│ │ │ ├── layers_dx.h
│ │ │ ├── network_dx.cc
│ │ │ ├── network_dx.h
│ │ │ ├── shader_wrapper.cc
│ │ │ ├── shader_wrapper.h
│ │ │ └── shaders
│ │ │ │ ├── AddVectors.hlsl
│ │ │ │ ├── Conv1x1.hlsl
│ │ │ │ ├── ExpandPlanes.hlsl
│ │ │ │ ├── Gemm.hlsl
│ │ │ │ ├── PolicyMap.hlsl
│ │ │ │ ├── SE.hlsl
│ │ │ │ ├── WinogradCommon.h
│ │ │ │ ├── WinogradTransform.hlsl
│ │ │ │ ├── WinogradTransformSE.hlsl
│ │ │ │ ├── dxc_helper.py
│ │ │ │ ├── meson.build
│ │ │ │ ├── shader_shared.h
│ │ │ │ └── shaders.h
│ │ ├── metal
│ │ │ ├── metal_common.h
│ │ │ ├── mps
│ │ │ │ ├── MetalNetworkBuilder.h
│ │ │ │ ├── MetalNetworkBuilder.mm
│ │ │ │ ├── NetworkGraph.h
│ │ │ │ └── NetworkGraph.mm
│ │ │ ├── network_metal.cc
│ │ │ └── network_metal.h
│ │ ├── network_check.cc
│ │ ├── network_demux.cc
│ │ ├── network_mux.cc
│ │ ├── network_onnx.cc
│ │ ├── network_random.cc
│ │ ├── network_record.cc
│ │ ├── network_rr.cc
│ │ ├── network_tf_cc.cc
│ │ ├── network_trivial.cc
│ │ ├── onednn
│ │ │ ├── layers.cc
│ │ │ ├── layers.h
│ │ │ └── network_onednn.cc
│ │ ├── opencl
│ │ │ ├── OpenCL.cc
│ │ │ ├── OpenCL.h
│ │ │ ├── OpenCLBuffers.cc
│ │ │ ├── OpenCLBuffers.h
│ │ │ ├── OpenCLParams.h
│ │ │ ├── OpenCLTuner.cc
│ │ │ ├── OpenCLTuner.h
│ │ │ ├── README.md
│ │ │ ├── clblast_level3
│ │ │ │ ├── common.opencl
│ │ │ │ ├── xgemm_batched.opencl
│ │ │ │ ├── xgemm_part1.opencl
│ │ │ │ ├── xgemm_part2.opencl
│ │ │ │ ├── xgemm_part3.opencl
│ │ │ │ └── xgemv.opencl
│ │ │ ├── clsource
│ │ │ │ ├── config.opencl
│ │ │ │ ├── convolve1.opencl
│ │ │ │ ├── convolve3.opencl
│ │ │ │ ├── policymap.opencl
│ │ │ │ └── se.opencl
│ │ │ └── network_opencl.cc
│ │ ├── shared
│ │ │ ├── activation.cc
│ │ │ ├── activation.h
│ │ │ ├── activation.ispc
│ │ │ ├── winograd_filter.cc
│ │ │ └── winograd_filter.h
│ │ ├── sycl
│ │ │ ├── common_kernels.dp.cpp
│ │ │ ├── cuBlasContext.h
│ │ │ ├── fp16_kernels.dp.cpp
│ │ │ ├── inputs_outputs.h
│ │ │ ├── kernels.h
│ │ │ ├── layers.cc.dp.cpp
│ │ │ ├── layers.h
│ │ │ ├── network_sycl.cc.dp.cpp
│ │ │ ├── sycl_common.h
│ │ │ └── winograd_helper.h
│ │ └── xla
│ │ │ ├── network_xla.cc
│ │ │ ├── pjrt.cc
│ │ │ ├── pjrt.h
│ │ │ ├── xla_runner.cc
│ │ │ └── xla_runner.h
│ ├── batchsplit.cc
│ ├── batchsplit.h
│ ├── decoder.cc
│ ├── decoder.h
│ ├── encoder.cc
│ ├── encoder.h
│ ├── encoder_test.cc
│ ├── factory.cc
│ ├── factory.h
│ ├── loader.cc
│ ├── loader.h
│ ├── memcache.cc
│ ├── memcache.h
│ ├── mock_backend.h
│ ├── network.h
│ ├── network_legacy.cc
│ ├── network_legacy.h
│ ├── onnx
│ │ ├── adapters.cc
│ │ ├── adapters.h
│ │ ├── builder.cc
│ │ ├── builder.h
│ │ ├── converter.cc
│ │ ├── converter.h
│ │ └── onnx.proto
│ ├── register.cc
│ ├── register.h
│ ├── shared_params.cc
│ ├── shared_params.h
│ ├── tables
│ │ ├── activation_function.h
│ │ ├── attention_policy_map.h
│ │ └── policy_map.h
│ ├── wrapper.cc
│ ├── wrapper.h
│ └── xla
│ │ ├── hlo.proto
│ │ ├── hlo_builder.cc
│ │ ├── hlo_builder.h
│ │ ├── onnx2hlo.cc
│ │ ├── onnx2hlo.h
│ │ ├── print_hlo.cc
│ │ ├── print_hlo.h
│ │ ├── xla_tensor.cc
│ │ └── xla_tensor.h
├── python
│ └── weights.h
├── rescorer_main.cc
├── search
│ ├── artifacts.h
│ ├── classic
│ │ ├── node.cc
│ │ ├── node.h
│ │ ├── params.cc
│ │ ├── params.h
│ │ ├── search.cc
│ │ ├── search.h
│ │ ├── stoppers
│ │ │ ├── alphazero.cc
│ │ │ ├── alphazero.h
│ │ │ ├── common.cc
│ │ │ ├── common.h
│ │ │ ├── factory.cc
│ │ │ ├── factory.h
│ │ │ ├── legacy.cc
│ │ │ ├── legacy.h
│ │ │ ├── simple.cc
│ │ │ ├── simple.h
│ │ │ ├── smooth.cc
│ │ │ ├── smooth.h
│ │ │ ├── stoppers.cc
│ │ │ ├── stoppers.h
│ │ │ ├── timemgr.cc
│ │ │ └── timemgr.h
│ │ └── wrapper.cc
│ ├── dag_classic
│ │ ├── node.cc
│ │ ├── node.h
│ │ ├── params.h
│ │ ├── search.cc
│ │ ├── search.h
│ │ ├── stoppers
│ │ │ ├── alphazero.cc
│ │ │ ├── alphazero.h
│ │ │ ├── common.cc
│ │ │ ├── common.h
│ │ │ ├── factory.cc
│ │ │ ├── factory.h
│ │ │ ├── legacy.cc
│ │ │ ├── legacy.h
│ │ │ ├── simple.cc
│ │ │ ├── simple.h
│ │ │ ├── smooth.cc
│ │ │ ├── smooth.h
│ │ │ ├── stoppers.cc
│ │ │ ├── stoppers.h
│ │ │ ├── timemgr.cc
│ │ │ └── timemgr.h
│ │ └── wrapper.cc
│ ├── instamove
│ │ └── instamove.cc
│ ├── mock_search.h
│ ├── register.cc
│ ├── register.h
│ └── search.h
├── selfplay
│ ├── game.cc
│ ├── game.h
│ ├── loop.cc
│ ├── loop.h
│ ├── multigame.cc
│ ├── multigame.h
│ ├── tournament.cc
│ └── tournament.h
├── syzygy
│ ├── syzygy.cc
│ ├── syzygy.h
│ └── syzygy_test.cc
├── tools
│ ├── backendbench.cc
│ ├── backendbench.h
│ ├── benchmark.cc
│ ├── benchmark.h
│ ├── describenet.cc
│ ├── describenet.h
│ ├── leela2onnx.cc
│ ├── leela2onnx.h
│ ├── onnx2leela.cc
│ └── onnx2leela.h
├── trainingdata
│ ├── reader.cc
│ ├── reader.h
│ ├── rescorer.cc
│ ├── rescorer.h
│ ├── trainingdata.cc
│ ├── trainingdata.h
│ ├── writer.cc
│ └── writer.h
├── utils
│ ├── atomic_vector.h
│ ├── bf16_utils.h
│ ├── bititer.h
│ ├── cache-old.h
│ ├── cache.h
│ ├── commandline.cc
│ ├── commandline.h
│ ├── configfile.cc
│ ├── configfile.h
│ ├── cppattributes.h
│ ├── esc_codes.cc
│ ├── esc_codes.h
│ ├── exception.h
│ ├── fastmath.h
│ ├── files.cc
│ ├── files.h
│ ├── filesystem.h
│ ├── filesystem.posix.cc
│ ├── filesystem.win32.cc
│ ├── fp16_utils.h
│ ├── fp8_utils.h
│ ├── hashcat.h
│ ├── hashcat_test.cc
│ ├── histogram.cc
│ ├── histogram.h
│ ├── logging.cc
│ ├── logging.h
│ ├── mutex.h
│ ├── numa.cc
│ ├── numa.h
│ ├── optionsdict.cc
│ ├── optionsdict.h
│ ├── optionsparser.cc
│ ├── optionsparser.h
│ ├── optionsparser_test.cc
│ ├── protomessage.cc
│ ├── protomessage.h
│ ├── random.cc
│ ├── random.h
│ ├── smallarray.h
│ ├── spinhelper.h
│ ├── string.cc
│ ├── string.h
│ ├── transpose.h
│ ├── weights_adapter.cc
│ └── weights_adapter.h
├── version.cc
├── version.h
└── version.inc
├── subprojects
├── abseil-cpp.wrap
├── eigen.wrap
├── gaviotatb.wrap
├── gtest.wrap
├── packagefiles
│ └── gaviotatb
│ │ └── meson.build
├── protobuf-3.6.0.wrap
├── protobuf.wrap
└── zlib.wrap
├── tensorflow.md
├── third_party
├── d3dx12.h
├── opencl.hpp
└── pjrt_c_api.h
└── windows_build.md
/.circleci/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM floopcz/tensorflow_cc:ubuntu-shared-cuda
2 | ARG DEBIAN_FRONTEND=noninteractive
3 |
4 | RUN wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB && apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB && sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list' && apt-get update && apt-get install -y intel-mkl-64bit-2018.2-046
5 | RUN apt-get install -y clang ninja-build python3-pip nvidia-opencl-dev libopenblas-dev libboost-dev libgtest-dev git ssh tar gzip ca-certificates libeigen3-dev sudo
6 | RUN apt-get install -y g++-8
7 | RUN apt-get install -y cuda
8 | RUN pip3 install meson
9 | RUN ln -s /usr/include/ /usr/include/openblas
10 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | docker:
5 | - image: nvidia/cuda:11.6.1-cudnn8-devel-ubuntu20.04
6 | steps:
7 | - checkout
8 | - run:
9 | name: Install build tools
10 | command: |
11 | apt-get update
12 | apt-get -y install git python3-pip gcc-10 g++-10 clang-12 zlib1g zlib1g-dev
13 | pip3 install meson==0.63
14 | pip3 install ninja
15 | - run:
16 | name: "Pull Submodules"
17 | command: git submodule update --init
18 | - run:
19 | name: Meson GCC
20 | environment:
21 | CC: gcc-10
22 | CXX: g++-10
23 | command: meson build-gcc -Dgtest=false
24 | - run:
25 | name: Meson Clang
26 | environment:
27 | CC: clang-12
28 | CXX: clang++-12
29 | command: meson build-clang -Dgtest=false -Db_lto=false
30 | - run:
31 | name: Build GCC
32 | command: |
33 | cd build-gcc
34 | ninja -j 4
35 | - run:
36 | name: Build Clang
37 | command: |
38 | cd build-clang
39 | ninja -j 4
40 | "mac":
41 | macos:
42 | xcode: 14.1.0
43 | resource_class: macos.m1.medium.gen1
44 | steps:
45 | - checkout
46 | - run:
47 | name: "Pull Submodules"
48 | command: git submodule update --init
49 | - run:
50 | name: Install build tools
51 | command: |
52 | pip3 install meson==1.3.0
53 | pip3 install ninja
54 | curl -LJOs https://github.com/ispc/ispc/releases/download/v1.21.0/ispc-v1.21.0-macOS.universal.tar.gz
55 | tar xf ispc-v1.21.0-macOS.universal.tar.gz
56 | cp ispc-v1.21.0-macOS.universal/bin/ispc /usr/local/bin
57 | - run:
58 | name: Build lc0
59 | command: |
60 | meson build --buildtype=release -Dgtest=false -Dopencl=false --cross-file cross-files/x86_64-darwin
61 | cd build
62 | ninja
63 | - run:
64 | name: Build lc0 arm
65 | command: |
66 | meson build-arm --buildtype=release -Dgtest=false -Dopencl=false
67 | cd build-arm
68 | ninja
69 | - run:
70 | name: Make universal binary
71 | command: lipo -create -o /tmp/lc0 build/lc0 build-arm/lc0
72 | - store_artifacts:
73 | path: /tmp/lc0
74 | destination: lc0-macos_12.6.1
75 | workflows:
76 | version: 2
77 | builds:
78 | jobs:
79 | - build
80 | - "mac"
81 |
--------------------------------------------------------------------------------
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 | BasedOnStyle: Google
4 | DerivePointerAlignment: false
5 | ---
6 | Language: Proto
7 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **WARNING: Please only use GitHub issues for BUG REPORTS and FEATURE REQUESTS**
11 | Lengthy algorithm discussions etc are fine too, but also consider creating a wiki page or a page on website.
12 |
13 | Here is what to do with other types of questions:
14 | 1. Build problems: ask in #help channel in our discord: https://discord.gg/pKujYxD
15 | 2. Configuration questions: ask in #help channel in our discord: https://discord.gg/pKujYxD
16 | 3. Running problems: ask in #help channel in our discord: https://discord.gg/pKujYxD
17 |
18 |
19 | If you are filing a bug report, please fill the fields below.
20 | Otherwise, feel free to remove this text and type a free-form issue as usual.
21 |
22 | BUG REPORT
23 |
24 | **Describe the bug**
25 | A clear and concise description of what the bug is.
26 |
27 | **Steps to Reproduce**
28 | 1.
29 | 2.
30 | 3.
31 | 4.
32 | Expected behavior:
33 | Observed behavior:
34 |
35 | **Lc0 version**
36 | Include Lc0 version/operating system/backend type.
37 |
38 | **Lc0 parameters**
39 | Command line, if not default.
40 | Include screenshot of configuration window, if using through GUI.
41 |
42 | **Hardware**
43 | * Number and model of GPUs that you use.
44 | * Amount of RAM in the system
45 | * Other specs (CPU etc) if it may be relevant
46 |
47 | **Lc0 logs**
48 | Please attach Lc0 logs. Here is how to produce them (e.g. for D:\logfile.txt):
49 |
50 | Set the following UCI option:
51 | **Logfile:** D:\\logfile.txt
52 | OR
53 | pass this as a command line argument:
54 | `--logfile=D:\logfile.txt`
55 | OR
56 | Create **lc0.config** file in the same directory as your **lc0.exe** is located, with the following contents:
57 | ```
58 | logfile=D:\logfile.txt
59 | ```
60 |
61 | After running Lc0, **D:\logfile.txt** should appear.
62 |
63 |
64 | **Chess GUI logs**
65 | If there is a problem with particular GUI (cutechess/arena/etc), also attach logs of that program.
66 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | !subprojects/*.wrap
2 | *.swp
3 | .clang_complete
4 | .DS_Store
5 | .cache/
6 | .clangd/
7 | build/
8 | builddir/
9 | __pycache__/
10 | compile_commands.json
11 | CUDA_NN/
12 | lc0.xcodeproj/
13 | LC0VSProj/
14 | src/.vs/
15 | subprojects/*
16 | testdata/
17 | xcuserdata
18 | .clang-tidy
19 | compile_flags.txt
20 | .vscode
21 | .mesonpy*
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "libs/lczero-common"]
2 | path = libs/lczero-common
3 | url = https://github.com/LeelaChessZero/lczero-common.git
4 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | A-childs-encyclopedia
2 | Adam Treat
3 | Alex Greason
4 | Alexander Lyashuk
5 | Alexis Olson
6 | alice
7 | almaudoh
8 | Aloril
9 | Andrew Grant
10 | Andy Olsen
11 | Ankan
12 | Ankan Banerjee
13 | Anson Hu
14 | Asger Alstrup Palm
15 | baum
16 | benini
17 | borg323
18 | Boštjan Mejak
19 | Brandon Lin
20 | Brett Holman
21 | Carlo Wood
22 | cn4750
23 | Cong
24 | Contrad Namiseb (Bonan)
25 | cwbriscoe
26 | danegraphics
27 | Daniel Monroe
28 | Daniel Uranga
29 | Dieter Dobbelaere
30 | dje-dev
31 | Dominik Schlösser
32 | DU-jdto
33 | dubslow
34 | Dubslow
35 | Ed Lee
36 | Epanek
37 | Error323
38 | evalon32
39 | exa
40 | exoticorn
41 | F. Huizinga
42 | fischerandom
43 | fohristiwhirl
44 | Francis
45 | Francis Li
46 | Francois
47 | Francois Pays
48 | François Pays
49 | Ganesh Krishnan
50 | GBeauregard
51 | Gian-Carlo Pascutto
52 | gmorenz
53 | Google LLC
54 | gsobala
55 | Hace
56 | Hans Ekbrand
57 | Henrik Forstén
58 | Ikko Eltociear Ashimine
59 | Jack Thomson
60 | James Horsfall Thomas
61 | jjoshua2
62 | John Newlin
63 | Karl Kfoury
64 | kiilas
65 | Kip Hamiltons
66 | Kovax
67 | Leandro Álvarez González
68 | Linmiao Xu
69 | Lisa Butterfly
70 | Luka Rahne
71 | Marcin Stefaniuk
72 | Martin
73 | Martin Senft
74 | masterkni6
75 | masterkni666
76 | Mike Roberts
77 | Naphthalin
78 | nathan-lc0
79 | Neelesh Jain
80 | nguyenpham
81 | noobpwnftw
82 | Ofek Shochat
83 | oscardssmith
84 | Pan
85 | patrik-ha
86 | PaulJeFi
87 | Pratik Dixit
88 | QxC4eva
89 | Raj
90 | Reece H. Dunn
91 | Ron Wolf
92 | Sami Kiminki
93 | Shreyas Kapur
94 | shtayerc
95 | Simon
96 | slash
97 | students
98 | SunnyWar
99 | TesseractA
100 | Tilps
101 | Timofey Kondrashov
102 | Ting-Hsuan Huang
103 | Tony Su
104 | trre123
105 | Usman Haider
106 | uyhcire
107 | Valentin
108 | Valeriy Huz
109 | Victor Popovici
110 | Videodr0me
111 | Viren6
112 | Yan Zhang
113 | zz4032
--------------------------------------------------------------------------------
/CITATION.cff:
--------------------------------------------------------------------------------
1 | cff-version: 1.2.0
2 | title: LeelaChessZero
3 | type: software
4 | authors:
5 | - name: The LCZero Authors
6 | repository-code: 'https://github.com/LeelaChessZero/lc0'
7 | url: 'https://lczero.org/'
8 | repository-artifact: 'https://github.com/LeelaChessZero/lc0/releases/'
9 | abstract: >-
10 | Lc0 is a UCI-compliant chess engine designed to play chess
11 | via neural network, specifically those of the
12 | LeelaChessZero project.
13 | keywords:
14 | - chess
15 | - neural networks (NN)
16 | - artificial intelligence (AI)
17 | license: GPL-3.0
18 |
--------------------------------------------------------------------------------
/OpenBench/Makefile:
--------------------------------------------------------------------------------
1 | ifndef EXE
2 | EXE = $(CURDIR)/lc0
3 | endif
4 |
5 | BUILD_FLAGS =
6 | ifdef EVALFILE
7 | BUILD_FLAGS += -Dembed=true
8 | endif
9 | ifdef SEARCH
10 | BUILD_FLAGS += -Ddefault_search=$(SEARCH)
11 | endif
12 |
13 | POST_BUILD_COMMANDS =
14 | ifdef EVALFILE
15 | POST_BUILD_COMMANDS = \
16 | cat $(EVALFILE) >> $(EXE); \
17 | perl -e "printf '%sLc0!', pack('V', -s '$(EVALFILE)')" >> $(EXE)
18 | endif
19 |
20 | .PHONY: all
21 | all:
22 | chmod +x ../build.sh
23 | ../build.sh $(BUILD_FLAGS) && mv ../build/release/lc0 $(EXE)
24 | $(POST_BUILD_COMMANDS)
--------------------------------------------------------------------------------
/build-sycl.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 |
4 | rem 1. Set the following for the options you want to build.
5 | rem SYCL can be off, l0, amd or nvidia.
6 | set SYCL=l0
7 | set CUDNN=true
8 | set CUDA=true
9 | set DX12=false
10 | set OPENCL=false
11 | set MKL=false
12 | set DNNL=true
13 | set OPENBLAS=false
14 | set EIGEN=false
15 | set TEST=false
16 |
17 | rem 2. Edit the paths for the build dependencies.
18 | set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
19 | set CUDNN_PATH=%CUDA_PATH%
20 | set OPENBLAS_PATH=C:\OpenBLAS
21 | set MKL_PATH=C:\Program Files (x86)\Intel\oneAPI\mkl\latest\
22 | set DNNL_PATH=C:\Program Files (x86)\Intel\oneAPI\dnnl\latest\cpu_iomp
23 | set OPENCL_LIB_PATH=%CUDA_PATH%\lib\x64
24 | set OPENCL_INCLUDE_PATH=%CUDA_PATH%\include
25 |
26 | rem 3. In most cases you won't need to change anything further down.
27 | echo Deleting build directory:
28 | rd /s build
29 |
30 | rem Use cl for C files to get a resource compiler as needed for zlib.
31 | set CC=cl
32 | set CXX=icx
33 |
34 | set BLAS=true
35 | if %MKL%==false if %DNNL%==false if %OPENBLAS%==false if %EIGEN%==false set BLAS=false
36 |
37 | if "%CUDA_PATH%"=="%CUDNN_PATH%" (
38 | set CUDNN_LIB_PATH=%CUDNN_PATH%\lib\x64
39 | set CUDNN_INCLUDE_PATH=%CUDNN_PATH%\include
40 | ) else (
41 | set CUDNN_LIB_PATH=%CUDA_PATH%\lib\x64,%CUDNN_PATH%\lib\x64
42 | set CUDNN_INCLUDE_PATH=%CUDA_PATH%\include,%CUDNN_PATH%\include
43 | )
44 |
45 | if %CUDNN%==true set PATH=%CUDA_PATH%\bin;%PATH%
46 |
47 | meson setup build --buildtype release -Ddx=%DX12% -Dcudnn=%CUDNN% -Dplain_cuda=%CUDA% ^
48 | -Dopencl=%OPENCL% -Dblas=%BLAS% -Dmkl=%MKL% -Dopenblas=%OPENBLAS% -Ddnnl=%DNNL% -Dgtest=%TEST% ^
49 | -Dcudnn_include="%CUDNN_INCLUDE_PATH%" -Dcudnn_libdirs="%CUDNN_LIB_PATH%" ^
50 | -Dmkl_include="%MKL_PATH%\include" -Dmkl_libdirs="%MKL_PATH%\lib\intel64" -Ddnnl_dir="%DNNL_PATH%" ^
51 | -Dopencl_libdirs="%OPENCL_LIB_PATH%" -Dopencl_include="%OPENCL_INCLUDE_PATH%" ^
52 | -Dopenblas_include="%OPENBLAS_PATH%\include" -Dopenblas_libdirs="%OPENBLAS_PATH%\lib" ^
53 | -Ddefault_library=static -Dsycl=%SYCL% -Db_vscrt=md
54 |
55 | if errorlevel 1 exit /b
56 |
57 | pause
58 |
59 | cd build
60 |
61 | ninja
--------------------------------------------------------------------------------
/build.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 |
4 | rem 1. Set the following for the options you want to build.
5 | set CUDNN=true
6 | set CUDA=true
7 | set DX12=false
8 | set OPENCL=false
9 | set MKL=false
10 | set DNNL=false
11 | set OPENBLAS=false
12 | set EIGEN=false
13 | set TEST=false
14 |
15 | rem 2. Edit the paths for the build dependencies.
16 | set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
17 | set CUDNN_PATH=%CUDA_PATH%
18 | set OPENBLAS_PATH=C:\OpenBLAS
19 | set MKL_PATH=C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl
20 | set DNNL_PATH=C:\dnnl_win_1.1.1_cpu_vcomp
21 | set OPENCL_LIB_PATH=%CUDA_PATH%\lib\x64
22 | set OPENCL_INCLUDE_PATH=%CUDA_PATH%\include
23 |
24 | rem 3. In most cases you won't need to change anything further down.
25 | echo Deleting build directory:
26 | rd /s build
27 |
28 | set CC=cl
29 | set CXX=cl
30 | set CC_LD=link
31 | set CXX_LD=link
32 |
33 | if exist "C:\Program Files\Microsoft Visual Studio\2022" (
34 | where /q cl
35 | if errorlevel 1 call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
36 | set backend=vs2022
37 | ) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019" (
38 | where /q cl
39 | if errorlevel 1 call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
40 | set backend=vs2019
41 | ) else (
42 | where /q cl
43 | if errorlevel 1 call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
44 | set backend=vs2017
45 | )
46 |
47 | set BLAS=true
48 | if %MKL%==false if %DNNL%==false if %OPENBLAS%==false if %EIGEN%==false set BLAS=false
49 |
50 | if "%CUDA_PATH%"=="%CUDNN_PATH%" (
51 | set CUDNN_LIB_PATH=%CUDNN_PATH%\lib\x64
52 | set CUDNN_INCLUDE_PATH=%CUDNN_PATH%\include
53 | ) else (
54 | set CUDNN_LIB_PATH=%CUDA_PATH%\lib\x64,%CUDNN_PATH%\lib\x64
55 | set CUDNN_INCLUDE_PATH=%CUDA_PATH%\include,%CUDNN_PATH%\include
56 | )
57 |
58 | if %CUDNN%==true set PATH=%CUDA_PATH%\bin;%PATH%
59 |
60 | meson setup build --backend %backend% --buildtype release -Ddx=%DX12% -Dcudnn=%CUDNN% -Dplain_cuda=%CUDA% ^
61 | -Dopencl=%OPENCL% -Dblas=%BLAS% -Dmkl=%MKL% -Dopenblas=%OPENBLAS% -Ddnnl=%DNNL% -Dgtest=%TEST% ^
62 | -Dcudnn_include="%CUDNN_INCLUDE_PATH%" -Dcudnn_libdirs="%CUDNN_LIB_PATH%" ^
63 | -Dmkl_include="%MKL_PATH%\include" -Dmkl_libdirs="%MKL_PATH%\lib\intel64" -Ddnnl_dir="%DNNL_PATH%" ^
64 | -Dopencl_libdirs="%OPENCL_LIB_PATH%" -Dopencl_include="%OPENCL_INCLUDE_PATH%" ^
65 | -Dopenblas_include="%OPENBLAS_PATH%\include" -Dopenblas_libdirs="%OPENBLAS_PATH%\lib" ^
66 | -Ddefault_library=static
67 |
68 | if errorlevel 1 exit /b
69 |
70 | pause
71 |
72 | cd build
73 |
74 | msbuild /m /p:Configuration=Release /p:Platform=x64 /p:WholeProgramOptimization=true ^
75 | /p:PreferredToolArchitecture=x64 lc0.sln /filelogger
76 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 |
5 | # Move to this script's directory.
6 | CDPATH= cd -- "$(dirname -- "$0")"
7 |
8 | case $1 in
9 | plain|debug|debugoptimized|release|minsize)
10 | BUILDTYPE=$1
11 | shift
12 | ;;
13 | *)
14 | BUILDTYPE=release
15 | ;;
16 | esac
17 |
18 | BUILDDIR=build/${BUILDTYPE}
19 |
20 | MESON=$(PATH="${PATH}:${HOME}/.local/bin" command -v meson || :)
21 | MESON=${MESON:?"Could not find meson. Is it installed and in PATH?"}
22 |
23 | if [ -f "${BUILDDIR}/build.ninja" ]
24 | then
25 | "${MESON}" configure "${BUILDDIR}" -Dbuildtype="${BUILDTYPE}" -Dprefix="${INSTALL_PREFIX:-/usr/local}" "$@"
26 | else
27 | "${MESON}" "${BUILDDIR}" --buildtype "${BUILDTYPE}" --prefix "${INSTALL_PREFIX:-/usr/local}" "$@"
28 | fi
29 |
30 | "${MESON}" compile -C "${BUILDDIR}"
31 |
32 | if [ -n "${INSTALL_PREFIX}" ]
33 | then
34 | "${MESON}" install -C "${BUILDDIR}"
35 | fi
36 |
--------------------------------------------------------------------------------
/build_rescorer.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 |
4 | echo Deleting build directory:
5 | rd /s build
6 |
7 | set CC=cl
8 | set CXX=cl
9 | set CC_LD=link
10 | set CXX_LD=link
11 |
12 | if exist "C:\Program Files\Microsoft Visual Studio\2022" (
13 | where /q cl
14 | if errorlevel 1 call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
15 | set backend=vs2022
16 | ) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019" (
17 | where /q cl
18 | if errorlevel 1 call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
19 | set backend=vs2019
20 | ) else (
21 | where /q cl
22 | if errorlevel 1 call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
23 | set backend=vs2017
24 | )
25 |
26 | meson setup build --backend %backend% --buildtype release -Drescorer=true -Dlc0=false -Dgtest=false -Ddefault_library=static
27 |
28 | if errorlevel 1 exit /b
29 |
30 | pause
31 |
32 | cd build
33 |
34 | msbuild /m /p:Configuration=Release /p:Platform=x64 /p:WholeProgramOptimization=true ^
35 | /p:PreferredToolArchitecture=x64 lc0.sln /filelogger
36 |
--------------------------------------------------------------------------------
/cross-files/aarch64-darwin:
--------------------------------------------------------------------------------
1 |
2 | [host_machine]
3 | system = 'darwin'
4 | cpu_family = 'aarch64'
5 | cpu = 'aarch64'
6 | endian = 'little'
7 |
8 | [properties]
9 |
10 |
11 | [binaries]
12 | c = 'clang'
13 | cpp = 'clang++'
14 | objc = 'clang'
15 | objcpp = 'clang++'
16 | ar = 'ar'
17 | ld = 'ld'
18 |
19 | [built-in options]
20 | c_args = ['-arch', 'arm64']
21 | cpp_args = ['-arch', 'arm64']
22 | objc_args = ['-arch', 'arm64']
23 | objcpp_args = ['-arch', 'arm64']
24 | c_link_args = ['-arch', 'arm64']
25 | cpp_link_args = ['-arch', 'arm64']
26 | objc_link_args = ['-arch', 'arm64']
27 | objcpp_link_args = ['-arch', 'arm64']
28 |
--------------------------------------------------------------------------------
/cross-files/aarch64-linux-android:
--------------------------------------------------------------------------------
1 |
2 | # Tested with Android NDK r27c, default toolchain
3 | # Targeting API level 21
4 |
5 | # Set the toolchain path on your environment
6 | # export PATH="$HOME/.local/share/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
7 |
8 | [host_machine]
9 | system = 'android'
10 | cpu_family = 'aarch64'
11 | cpu = 'aarch64'
12 | endian = 'little'
13 |
14 | [properties]
15 | cpp_link_args = ['-llog', '-static-libstdc++']
16 |
17 | [binaries]
18 | c = 'aarch64-linux-android21-clang'
19 | cpp = 'aarch64-linux-android21-clang++'
20 | ar = 'llvm-ar'
21 | strip = 'llvm-strip'
22 | ld = 'ld'
23 | ranlib = 'llvm-ranlib'
24 | as = 'aarch64-linux-android21-clang'
25 |
--------------------------------------------------------------------------------
/cross-files/armv7a-linux-android:
--------------------------------------------------------------------------------
1 |
2 | # Tested with Android NDK r27c, default toolchain
3 | # Targeting API level 21
4 |
5 | # When targeting API levels < 24 the build fails unless _FILE_OFFSET_BITS is unset.
6 | # Meson passes _FILE_OFFSET_BITS=64 but recent NDK toolchains have issues building
7 | # for 32-bit ABIs when such macro it set. Relevant links:
8 | # https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
9 | # https://github.com/mesonbuild/meson/pull/2996#issuecomment-384045808
10 |
11 | # Set the toolchain path on your environment
12 | # export PATH="$HOME/.local/share/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
13 |
14 | [host_machine]
15 | system = 'android'
16 | cpu_family = 'arm'
17 | cpu = 'armv7a'
18 | endian = 'little'
19 |
20 | [properties]
21 | cpp_args = ['-U_FILE_OFFSET_BITS']
22 | cpp_link_args = ['-llog', '-static-libstdc++']
23 |
24 | [binaries]
25 | c = 'armv7a-linux-androideabi21-clang'
26 | cpp = 'armv7a-linux-androideabi21-clang++'
27 | ar = 'llvm-ar'
28 | strip = 'llvm-strip'
29 | ld = 'ld'
30 | ranlib = 'llvm-ranlib'
31 | as = 'armv7a-linux-androideabi21-clang'
32 |
--------------------------------------------------------------------------------
/cross-files/x86_64-darwin:
--------------------------------------------------------------------------------
1 |
2 | [host_machine]
3 | system = 'darwin'
4 | cpu_family = 'x86_64'
5 | cpu = 'x86_64'
6 | endian = 'little'
7 |
8 | [properties]
9 |
10 |
11 | [binaries]
12 | c = 'clang'
13 | cpp = 'clang++'
14 | objc = 'clang'
15 | objcpp = 'clang++'
16 | ar = 'ar'
17 | ld = 'ld'
18 |
19 | [built-in options]
20 | c_args = ['-arch', 'x86_64']
21 | cpp_args = ['-arch', 'x86_64']
22 | objc_args = ['-arch', 'x86_64']
23 | objcpp_args = ['-arch', 'x86_64']
24 | c_link_args = ['-arch', 'x86_64']
25 | cpp_link_args = ['-arch', 'x86_64']
26 | objc_link_args = ['-arch', 'x86_64']
27 | objcpp_link_args = ['-arch', 'x86_64']
28 |
--------------------------------------------------------------------------------
/dist/README-cuda.txt:
--------------------------------------------------------------------------------
1 | Lc0
2 |
3 | Lc0 is a UCI-compliant chess engine designed to play chess via
4 | neural network, specifically those of the LeelaChessZero project
5 | (https://lczero.org).
6 |
7 | This binary uses CUDA and cuDNN dynamic link libraries copyrighted
8 | by Nvidia corporation (http://www.nvidia.com), and redistributed as
9 | permitted by the respective license file (see CUDA.txt section 2.2
10 | and CUDNN.txt section "CUDNN DISTRIBUTION" for details). You are
11 | authorized to redistribute these libraries together with this
12 | package as a whole but not individually.
13 |
14 |
15 | License
16 |
17 | Leela Chess is free software: you can redistribute it and/or modify
18 | it under the terms of the GNU General Public License as published by
19 | the Free Software Foundation, either version 3 of the License, or
20 | (at your option) any later version.
21 |
22 | Leela Chess is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with Leela Chess. If not, see .
29 |
30 | Additional permission under GNU GPL version 3 section 7
31 |
32 | If you modify this Program, or any covered work, by linking or
33 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
34 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
35 | modified version of those libraries), containing parts covered by the
36 | terms of the respective license agreement, the licensors of this
37 | Program grant you additional permission to convey the resulting work.
38 |
39 |
--------------------------------------------------------------------------------
/dist/README-onnx-dml.txt:
--------------------------------------------------------------------------------
1 | Lc0
2 |
3 | Lc0 is a UCI-compliant chess engine designed to play chess via
4 | neural network, specifically those of the LeelaChessZero project
5 | (https://lczero.org).
6 |
7 | To run this version you will most likely need a very recent DirectML dll,
8 | which you can get by running the included `install.cmd` script. Alternatively,
9 | you can download the currently latest nuget installer package from
10 | .
11 | If you don't know how to use nuget installer packages, you can change the
12 | extension to .zip and open it as a normal zip file, the dll you need is
13 | `/bin/x64-win/DirectML.dll`.
14 |
15 | License
16 |
17 | Leela Chess is free software: you can redistribute it and/or modify
18 | it under the terms of the GNU General Public License as published by
19 | the Free Software Foundation, either version 3 of the License, or
20 | (at your option) any later version.
21 |
22 | Leela Chess is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with Leela Chess. If not, see .
29 |
30 | Additional permission under GNU GPL version 3 section 7
31 |
32 | If you modify this Program, or any covered work, by linking or
33 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
34 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
35 | modified version of those libraries), containing parts covered by the
36 | terms of the respective license agreement, the licensors of this
37 | Program grant you additional permission to convey the resulting work.
38 |
39 |
--------------------------------------------------------------------------------
/dist/install-dml.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | where /q tar
3 | if errorlevel 1 goto error
4 |
5 | cd /d %~dp0
6 |
7 | cls
8 | echo Installing the DirectML.dll version required by the Lc0 onnx-dml backend.
9 | curl -# --ssl-no-revoke -o tmp_directml.zip https://globalcdn.nuget.org/packages/microsoft.ai.directml.1.10.0.nupkg"
10 | if errorlevel 1 goto error
11 |
12 | tar -xzOf tmp_directml.zip bin/x64-win/DirectML.dll >DirectML.dll
13 | if errorlevel 1 goto error
14 |
15 | del /q tmp_directml.zip
16 | echo Installation successful.
17 | pause
18 | exit /b
19 |
20 | :error
21 | cls
22 | echo Installation failed - see the README for an alternative approach.
23 | pause
24 |
25 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["meson-python"]
3 | build-backend = "mesonpy"
4 |
5 | [project]
6 | name = "lczero_bindings"
7 | version = "0.1.0"
8 | description = "Leela Chess Zero Python bindings"
9 | authors = [{ name = "The LCZero Authors" }]
10 | license = {file = "COPYING"}
11 | readme = "README.md"
12 | requires-python = ">=3.7"
13 | classifiers = [
14 | "Programming Language :: Python :: 3",
15 | "Topic :: Games/Entertainment :: Board Games",
16 | "Topic :: Scientific/Engineering :: Artificial Intelligence",
17 | "Environment :: GPU"
18 | ]
19 |
20 | [project.urls]
21 | homepage = "https://github.com/LeelaChessZero/lc0"
22 |
23 | [tool.meson-python.args]
24 | dist = []
25 | setup = ["-Dpython_bindings=true"]
26 | compile = []
27 | install = []
--------------------------------------------------------------------------------
/scripts/appveyor_android_build.cmd:
--------------------------------------------------------------------------------
1 | cd arm64-v8a
2 | ninja
3 | llvm-strip lc0
4 | cd C:\projects\lc0
5 | cd armeabi-v7a
6 | ninja
7 | llvm-strip lc0
8 |
--------------------------------------------------------------------------------
/scripts/appveyor_android_package.cmd:
--------------------------------------------------------------------------------
1 | git clone https://github.com/LeelaChessZero/chessenginesupport-androidlib.git --branch lc0 --single-branch oex
2 | cd oex
3 | git checkout 0c02a8893b9c57ec57b40569ba60625912c6d32f
4 | cd ..
5 | perl -e "printf '%%sLc0!', pack('V', -s 'c:/cache/%NET%.pb.gz')" >tail.bin
6 | copy /y /b arm64-v8a\lc0+c:\cache\%NET%.pb.gz+tail.bin oex\LeelaChessEngine\leelaChessEngine\src\main\jniLibs\arm64-v8a\liblc0.so
7 | copy /y /b armeabi-v7a\lc0+c:\cache\%NET%.pb.gz+tail.bin oex\LeelaChessEngine\leelaChessEngine\src\main\jniLibs\armeabi-v7a\liblc0.so
8 | set ANDROID_HOME=C:\android-sdk-windows
9 | appveyor DownloadFile https://dl.google.com/android/repository/sdk-tools-windows-3859397.zip
10 | 7z x sdk-tools-windows-3859397.zip -oC:\android-sdk-windows > nul
11 | yes | C:\android-sdk-windows\tools\bin\sdkmanager.bat --licenses
12 | cd oex\LeelaChessEngine
13 | sed -i "s/591226/%NET%/" leelaChessEngine/src/main/res/values/strings.xml
14 | sed -i "/versionCode/ s/1/%APPVEYOR_BUILD_NUMBER%/" leelaChessEngine/src/main/AndroidManifest.xml
15 | sed -i "s/0.25dev/%APPVEYOR_REPO_TAG_NAME%/" leelaChessEngine/src/main/AndroidManifest.xml
16 | call gradlew.bat assemble
17 | copy leelaChessEngine\build\outputs\apk\debug\leelaChessEngine-debug.apk ..\..\lc0-%APPVEYOR_REPO_TAG_NAME%-android.apk
18 |
--------------------------------------------------------------------------------
/scripts/appveyor_win_build.cmd:
--------------------------------------------------------------------------------
1 | SET PGO=false
2 | IF %APPVEYOR_REPO_TAG%==true IF %DX%==false IF %ONNX_DML%==false SET PGO=true
3 | IF %PGO%==false msbuild "C:\projects\lc0\build\lc0.sln" /m /p:WholeProgramOptimization=true /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
4 | IF EXIST build\lc0.pdb del build\lc0.pdb
5 | IF %PGO%==true msbuild "C:\projects\lc0\build\lc0.sln" /m /p:WholeProgramOptimization=PGInstrument /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
6 | IF ERRORLEVEL 1 EXIT
7 | cd build
8 | IF %NAME%==cpu-openblas copy C:\cache\OpenBLAS\dist64\bin\libopenblas.dll
9 | IF %NAME%==cpu-dnnl copy C:\cache\%DNNL_NAME%\bin\dnnl.dll
10 | IF %NAME%==onednn copy C:\cache\%DNNL_NAME%\bin\dnnl.dll
11 | IF %NAME%==onednn copy dnnl.dll ..
12 | copy "%MIMALLOC_PATH%"\out\msvc-x64\Release\mimalloc-override.dll
13 | copy "%MIMALLOC_PATH%"\out\msvc-x64\Release\mimalloc-redirect.dll
14 | IF %PGO%==true (
15 | IF %OPENCL%==true copy C:\cache\opencl-nug.0.777.77\build\native\bin\OpenCL.dll
16 | IF %CUDA%==true copy "%CUDA_PATH%"\bin\*.dll
17 | IF %CUDNN%==true copy "%CUDA_PATH%"\cuda\bin\cudnn64_7.dll
18 | lc0 benchmark --num-positions=1 --backend=trivial --movetime=10000
19 | )
20 | cd ..
21 | IF %PGO%==true msbuild "C:\projects\lc0\build\lc0.sln" /m /p:WholeProgramOptimization=PGOptimize /p:DebugInformationFormat=ProgramDatabase /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
22 |
--------------------------------------------------------------------------------
/scripts/bumpversion.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import argparse
4 | import os
5 |
6 |
7 | VERSION_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../src/version.inc")
8 | VERSION_CONTENT = """
9 | #define LC0_VERSION_MAJOR {}
10 | #define LC0_VERSION_MINOR {}
11 | #define LC0_VERSION_PATCH {}
12 | #define LC0_VERSION_POSTFIX "{}"
13 | """
14 | VERSION_CONTENT = VERSION_CONTENT.strip()
15 |
16 |
17 | def get_version():
18 | with open(VERSION_FILE, 'r') as f:
19 | major = int(f.readline().split()[2])
20 | minor = int(f.readline().split()[2])
21 | patch = int(f.readline().split()[2])
22 | postfix = f.readline().split()[2]
23 |
24 | postfix = postfix.replace('"', '')
25 | return major, minor, patch, postfix
26 |
27 |
28 | def set_version(major, minor, patch, postfix=""):
29 | version_inc = VERSION_CONTENT.format(major, minor, patch, postfix)
30 |
31 | with open(VERSION_FILE, 'w') as f:
32 | f.write(version_inc)
33 |
34 |
35 | def update(major, minor, patch, postfix=""):
36 | set_version(major, minor, patch, postfix)
37 |
38 |
39 | def main(argv):
40 | major, minor, patch, postfix = get_version()
41 |
42 | if argv.major:
43 | major += 1
44 | minor = 0
45 | patch = 0
46 | postfix = ""
47 | update(major, minor, patch)
48 | if argv.minor:
49 | minor += 1
50 | patch = 0
51 | postfix = ""
52 | update(major, minor, patch)
53 | if argv.patch:
54 | patch += 1
55 | postfix = ""
56 | update(major, minor, patch)
57 | if argv.postfix and len(argv.postfix) > 0:
58 | postfix = argv.postfix
59 | update(major, minor, patch, postfix)
60 |
61 | if len(postfix) == 0:
62 | print('v{}.{}.{}'.format(major, minor, patch))
63 | else:
64 | print('v{}.{}.{}-{}'.format(major, minor, patch, postfix))
65 |
66 |
67 | if __name__ == "__main__":
68 | argparser = argparse.ArgumentParser(description=\
69 | 'Set or read current version.')
70 | argparser.add_argument('--major', action='store_true',
71 | help='bumps major version')
72 | argparser.add_argument('--minor', action='store_true',
73 | help='bumps minor version')
74 | argparser.add_argument('--patch', action='store_true',
75 | help='bumps patch')
76 | argparser.add_argument('--postfix', type=str,
77 | help='set postfix')
78 | argv = argparser.parse_args()
79 | main(argv)
80 |
81 |
--------------------------------------------------------------------------------
/scripts/check_dx.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | ECHO Sanity checking the dx12 driver.
3 | lc0 benchmark --num-positions=1 --backend=check --backend-opts=mode=check,freq=1.0,atol=5e-1,dx12 %*
4 | PAUSE
5 |
6 |
--------------------------------------------------------------------------------
/scripts/check_opencl.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | ECHO Sanity checking the opencl driver.
3 | lc0 benchmark --num-positions=1 --backend=check --backend-opts=mode=check,freq=1.0,opencl %*
4 | PAUSE
5 |
6 |
--------------------------------------------------------------------------------
/scripts/checkdir.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import sys
4 | import os
5 | if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
6 | sys.exit(0)
7 | sys.exit(1)
8 |
--------------------------------------------------------------------------------
/scripts/pybind/core.py:
--------------------------------------------------------------------------------
1 | # This file is part of Leela Chess Zero.
2 | # Copyright (C) 2020 The LCZero Authors
3 | #
4 | # Leela Chess is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # Leela Chess is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with Leela Chess. If not, see .
16 | #
17 | # Additional permission under GNU GPL version 3 section 7
18 | #
19 | # If you modify this Program, or any covered work, by linking or
20 | # combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
21 | # Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
22 | # modified version of those libraries), containing parts covered by the
23 | # terms of the respective license agreement, the licensors of this
24 | # Program grant you additional permission to convey the resulting work.
25 |
26 |
27 | class PyObject:
28 | def __init__(self, name):
29 | self.name = name
30 |
31 | def BuildDocString(self):
32 | return "nullptr"
33 |
--------------------------------------------------------------------------------
/scripts/pybind/exceptions.py:
--------------------------------------------------------------------------------
1 | # This file is part of Leela Chess Zero.
2 | # Copyright (C) 2020 The LCZero Authors
3 | #
4 | # Leela Chess is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # Leela Chess is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with Leela Chess. If not, see .
16 | #
17 | # Additional permission under GNU GPL version 3 section 7
18 | #
19 | # If you modify this Program, or any covered work, by linking or
20 | # combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
21 | # Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
22 | # modified version of those libraries), containing parts covered by the
23 | # terms of the respective license agreement, the licensors of this
24 | # Program grant you additional permission to convey the resulting work.
25 |
26 | from .core import PyObject
27 |
28 |
29 | class CppException(PyObject):
30 | def __init__(self, name, cpp_name, *args, **kwargs):
31 | self.cpp_name = cpp_name
32 | super().__init__(name, *args, **kwargs)
33 |
34 | def type_struct_name(self):
35 | return f'T{self.name}ExceptionType'
36 |
37 | def Generate(self, w):
38 | w.Write(f'PyObject *{self.type_struct_name()};')
39 |
40 | def GenerateRegister(self, w, module):
41 | w.Write(f'{self.type_struct_name()} = PyErr_NewException('
42 | f'"{module.name}.{self.name}", nullptr, nullptr);')
43 | w.Write(f'if ({self.type_struct_name()} == nullptr) return nullptr;')
44 | w.Write(f'Py_INCREF({self.type_struct_name()});')
45 | w.Write(f'PyModule_AddObject(module, "{self.name}", '
46 | f'{self.type_struct_name()});')
47 |
48 | def GenerateHandle(self, w, func):
49 | w.Unindent()
50 | w.Open(f'}} catch (const {self.cpp_name} &ex) {{')
51 | w.Write(f'PyErr_SetString({self.type_struct_name()}, ex.what());')
52 | w.Write(f'return {func._failure()};')
53 |
--------------------------------------------------------------------------------
/scripts/pybind/writer.py:
--------------------------------------------------------------------------------
1 | # This file is part of Leela Chess Zero.
2 | # Copyright (C) 2020 The LCZero Authors
3 | #
4 | # Leela Chess is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # Leela Chess is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with Leela Chess. If not, see .
16 | #
17 | # Additional permission under GNU GPL version 3 section 7
18 | #
19 | # If you modify this Program, or any covered work, by linking or
20 | # combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
21 | # Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
22 | # modified version of those libraries), containing parts covered by the
23 | # terms of the respective license agreement, the licensors of this
24 | # Program grant you additional permission to convey the resulting work.
25 |
26 |
27 | class Writer:
28 | '''A helper class for writing file line by line with indent.'''
29 | def __init__(self, fo):
30 | self.fo = fo
31 | self.indent = 0
32 |
33 | def Indent(self):
34 | self.indent += 2
35 |
36 | def Unindent(self):
37 | self.indent -= 2
38 |
39 | def Write(self, text):
40 | for line in text.split('\n'):
41 | if line:
42 | self.fo.write(' ' * self.indent + line + '\n')
43 | else:
44 | self.fo.write('\n')
45 |
46 | def Open(self, text='{'):
47 | self.Write(text)
48 | self.Indent()
49 |
50 | def Close(self, text='}'):
51 | self.Unindent()
52 | self.Write(text)
53 |
--------------------------------------------------------------------------------
/scripts/sycl_build_hack.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import os
4 |
5 | dir = os.getenv('MESON_BUILD_ROOT')
6 |
7 | with open(dir + '/build.ninja', 'r') as file:
8 | lines = file.readlines()
9 |
10 | updated = []
11 | dep_flag = False
12 | link_flag = False
13 |
14 | for line in lines:
15 | # Replace xilink with icx -fsycl as the linker.
16 | if not link_flag:
17 | link_flag = 'xilink.exe' in line
18 | if link_flag:
19 | line = line.replace('xilink.exe', 'icx')
20 | line = line.replace('/MACHINE:x64', '-fsycl')
21 | line = line.replace('/OUT:', '-o ')
22 | line = line.replace('/SUBSYSTEM:CONSOLE', '')
23 | line = line.replace('/OPT:REF', '')
24 | line = line.replace('/PDB:', '/Fd')
25 | # Replace msvc compatible dependencies with gcc ones as icx output with /showincludes includes
26 | # temporary header files causing full project rebuilds.
27 | if line.startswith('rule') or line.startswith('build'):
28 | dep_flag = 'cpp_COMPILER' in line
29 | if dep_flag:
30 | line = line.replace('deps = msvc', 'deps = gcc\n depfile = $out.d')
31 | line = line.replace('/showIncludes', '/QMD')
32 | if 'icx' in line:
33 | line = line.replace('/Fo$out', '/Fo$out /QMF$out.d')
34 | updated.append(line)
35 |
36 | with open(dir + '/build.ninja', 'w') as file:
37 | file.writelines(updated)
38 |
--------------------------------------------------------------------------------
/src/chess/gamestate.cc:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2024 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 |
28 | #include "chess/gamestate.h"
29 |
30 | #include
31 | #include
32 |
33 | namespace lczero {
34 |
35 | Position GameState::CurrentPosition() const {
36 | return std::accumulate(
37 | moves.begin(), moves.end(), startpos,
38 | [](const Position& pos, Move m) { return Position(pos, m); });
39 | }
40 |
41 | std::vector GameState::GetPositions() const {
42 | std::vector positions;
43 | positions.reserve(moves.size() + 1);
44 | positions.push_back(startpos);
45 | std::transform(moves.begin(), moves.end(), std::back_inserter(positions),
46 | [&](Move m) {
47 | return Position(positions.back(), m);
48 | });
49 | return positions;
50 | }
51 |
52 | } // namespace lczero
53 |
--------------------------------------------------------------------------------
/src/chess/gamestate.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2024 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 |
28 | #pragma once
29 |
30 | #include
31 |
32 | #include "chess/position.h"
33 |
34 | namespace lczero {
35 |
36 | // A structure that is passed to Search/SearchEnvironment to provide the game
37 | // state. Somewhat mirrors usi `position moves ...` command.
38 | struct GameState {
39 | Position startpos;
40 | std::vector moves;
41 |
42 | // Returns the position of the last move in the list.
43 | Position CurrentPosition() const;
44 | // Returns positions after all moves, including the starting and the last one.
45 | std::vector GetPositions() const;
46 | };
47 |
48 | } // namespace lczero
--------------------------------------------------------------------------------
/src/engine_loop.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2018-2025 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 |
28 | #pragma once
29 |
30 | #include
31 | #include
32 |
33 | #include "chess/uciloop.h"
34 | #include "search/search.h"
35 | #include "utils/optionsparser.h"
36 |
37 | namespace lczero {
38 |
39 | // Runs the stdin/stdout UCI loop for the engine.
40 | void RunEngine(SearchFactory* factory);
41 |
42 | } // namespace lczero
--------------------------------------------------------------------------------
/src/neural/backend.cc:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2024 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 |
28 | #include "neural/backend.h"
29 |
30 | namespace lczero {
31 |
32 | std::vector Backend::EvaluateBatch(
33 | std::span positions) {
34 | std::vector results;
35 | results.reserve(positions.size());
36 | std::unique_ptr computation = CreateComputation();
37 | for (const EvalPosition& pos : positions) {
38 | results.emplace_back();
39 | EvalResult& result = results.back();
40 | result.p.resize(pos.legal_moves.size());
41 | computation->AddInput(
42 | pos, EvalResultPtr{&result.q, &result.d, &result.m,
43 | std::span(result.p.data(), result.p.size())});
44 | }
45 | computation->ComputeBlocking();
46 | return results;
47 | }
48 |
49 | } // namespace lczero
--------------------------------------------------------------------------------
/src/neural/backends/blas/README.md:
--------------------------------------------------------------------------------
1 | The files in this directory comprise the BLAS backend of Lc0.
2 |
3 | ## License
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | **The source files of this directory are not covered by any additional
19 | permission.**
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/neural/backends/blas/convolution1.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2018 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include
22 | #include
23 |
24 | namespace lczero {
25 |
26 | // Convolution 1x1
27 | template
28 | class Convolution1 {
29 | public:
30 | Convolution1() = delete;
31 |
32 | // Batched forward inference.
33 | static void Forward(const size_t batch_size, const size_t input_channels,
34 | const size_t output_channels, const float* input,
35 | const float* weights, float* output);
36 |
37 | private:
38 | static constexpr auto kWidth = 8;
39 | static constexpr auto kHeight = 8;
40 | static constexpr auto kSquares = kWidth * kHeight;
41 | };
42 | } // namespace lczero
43 |
--------------------------------------------------------------------------------
/src/neural/backends/blas/encoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2022-2023 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include
22 |
23 | #ifdef USE_ISPC
24 | #include "layer_norm_ispc.h"
25 | #endif
26 |
27 | namespace lczero {
28 |
29 | void LayerNorm2DWithSkipConnection(const size_t batch_size,
30 | const size_t channels, float* data,
31 | const float alpha, const float* skip,
32 | const float* gammas, const float* betas,
33 | float epsilon) {
34 | for (size_t i = 0; i < batch_size; i++) {
35 | #ifndef USE_ISPC
36 | // Mean taken in dimension C.
37 | float mean = 0;
38 | if (skip != nullptr) {
39 | for (size_t c = 0; c < channels; ++c) {
40 | data[i * channels + c] =
41 | data[i * channels + c] * alpha + skip[i * channels + c];
42 | mean += data[i * channels + c];
43 | }
44 | } else {
45 | for (size_t c = 0; c < channels; ++c) {
46 | data[i * channels + c] *= alpha;
47 | mean += data[i * channels + c];
48 | }
49 | }
50 | mean /= channels;
51 |
52 | // Variance.
53 | float var = 0;
54 | for (size_t c = 0; c < channels; ++c) {
55 | auto diff = data[i * channels + c] - mean;
56 | var += diff * diff;
57 | }
58 | var /= channels;
59 |
60 | // Norm.
61 | float den = 1.0f / std::sqrt(var + epsilon);
62 | for (size_t c = 0; c < channels; ++c) {
63 | data[i * channels + c] =
64 | betas[c] + gammas[c] * (data[i * channels + c] - mean) * den;
65 | }
66 | #else
67 | if (skip != nullptr) {
68 | ispc::LayerNorm2DWithSkipConnection(channels, data + i * channels, alpha,
69 | skip + i * channels, gammas, betas,
70 | epsilon);
71 | } else {
72 | ispc::LayerNorm2DWithSkipConnection(channels, data + i * channels, alpha,
73 | nullptr, gammas, betas, epsilon);
74 | }
75 |
76 | #endif
77 | }
78 | }
79 |
80 | } // namespace lczero
81 |
--------------------------------------------------------------------------------
/src/neural/backends/blas/fully_connected_layer.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2018 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "neural/backends/shared/activation.h"
22 |
23 | #include
24 | #include
25 |
26 | namespace lczero {
27 |
28 | template
29 | class FullyConnectedLayer {
30 | public:
31 | FullyConnectedLayer() = delete;
32 |
33 | // Forward inference, batched, from input_size to output_size
34 | static void Forward1D(const size_t batch_size, const size_t input_size,
35 | const size_t output_size, const float* input,
36 | const float* weights, const float* biases,
37 | const ActivationFunction activation, float* output);
38 |
39 | // Forward inference, no batched, from input_size to scalar
40 | static float Forward0D(const size_t input_size, const float* input,
41 | const float* weights);
42 |
43 | };
44 |
45 | } // namespace lczero
46 |
--------------------------------------------------------------------------------
/src/neural/backends/blas/layer_norm.ispc:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2023 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 | */
18 |
19 | export void LayerNorm2DWithSkipConnection(uniform const size_t channels,
20 | uniform float data[],
21 | const uniform float alpha,
22 | const uniform float skip[],
23 | const uniform float gammas[],
24 | const uniform float betas[],
25 | uniform const float epsilon) {
26 | #if 0
27 | // Faster but potentially less stable version for future testing.
28 | // One pass mean and variance taken in dimension C. Uses shifted variance calculation.
29 | float imean = 0;
30 | float ivar = 0;
31 | float k = data[0] * alpha;
32 | if (skip != NULL) {
33 | k += skip[0];
34 | foreach (c = 0 ... channels) {
35 | float t = data[c] * alpha + skip[c];
36 | data[c] = t;
37 | t -= k;
38 | imean += t;
39 | ivar += t * t;
40 | }
41 | } else {
42 | foreach (c = 0 ... channels) {
43 | float t = data[c] * alpha;
44 | data[c] = t;
45 | t -= k;
46 | imean += t;
47 | ivar += t * t;
48 | }
49 | }
50 | float mean = reduce_add(imean) / channels;
51 | float var = (reduce_add(ivar) - channels * mean * mean) / channels;
52 | mean += k;
53 | #else
54 | // Mean taken in dimension C.
55 | float imean = 0;
56 | if (skip != NULL) {
57 | foreach (c = 0 ... channels) {
58 | data[c] = data[c] * alpha + skip[c];
59 | imean += data[c];
60 | }
61 | } else {
62 | foreach (c = 0 ... channels) {
63 | data[c] *= alpha;
64 | imean += data[c];
65 | }
66 | }
67 | float mean = reduce_add(imean) / channels;
68 |
69 | // Variance.
70 | float ivar = 0;
71 | foreach (c = 0 ... channels) {
72 | float diff = data[c] - mean;
73 | ivar += diff * diff;
74 | }
75 | float var = reduce_add(ivar) / channels;
76 | #endif
77 |
78 | float den = rsqrt(var + epsilon);
79 | foreach (c = 0 ... channels) {
80 | data[c] = betas[c] + gammas[c] * (data[c] - mean) * den;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/neural/backends/blas/se_unit.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2018 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "neural/backends/shared/activation.h"
22 |
23 | #include
24 |
25 | namespace lczero {
26 |
27 | template
28 | void ApplySEUnit(const size_t batch_size, const size_t channels,
29 | const size_t se_fc_outputs, const float* input,
30 | const float* bias, const float* residual,
31 | const float* weights_w1, const float* weights_b1,
32 | const float* weights_w2, const float* weights_b2,
33 | float* output, const ActivationFunction activation);
34 |
35 | } // namespace lczero
36 |
--------------------------------------------------------------------------------
/src/neural/backends/blas/winograd_convolution3.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2018 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include
22 | #include
23 |
24 | namespace lczero {
25 |
26 | // Convolution 3x3 on a 8x8 board using the Winograd algorithm.
27 | //
28 | // Ref:
29 | //
30 | // Fast Algorithms for Convolutional Neural Networks
31 | // https://arxiv.org/abs/1509.09308
32 | //
33 | // https://ai.intel.com/winograd/
34 | // https://ai.intel.com/winograd-2/
35 |
36 | // Convolution 3x3 using the Winograd algorithm
37 | template
38 | class WinogradConvolution3 {
39 | public:
40 | // The instance will allocate memory resources for the
41 | // largest batch size, and the largest input and output
42 | // layers.
43 | WinogradConvolution3(const size_t max_batch_size,
44 | const size_t max_input_layers,
45 | const size_t max_output_layers);
46 |
47 | // Forward inference, batched.
48 | void Forward(const size_t batch_size, const size_t input_channels,
49 | const size_t output_channels, const float* input,
50 | const float* weights, float* output);
51 |
52 | private:
53 | void TransformIn(const size_t batch_size, const float* input,
54 | const size_t channels);
55 |
56 | void Sgemm(const size_t batch_size, const float* weights,
57 | const size_t input_channels, const size_t output_channels);
58 |
59 | void TransformOut(const size_t batch_size, float* output,
60 | const size_t channels);
61 |
62 | static constexpr auto kWidth = 8;
63 | static constexpr auto kHeight = 8;
64 | static constexpr auto kSquares = kWidth * kHeight;
65 |
66 | static constexpr auto kWtiles = (kWidth + 1) / 2; // 4
67 | static constexpr auto kTiles = kWtiles * kWtiles; // 16
68 |
69 | static constexpr auto kWinogradAlpha = 4;
70 | static constexpr auto kWinogradTile = kWinogradAlpha * kWinogradAlpha;
71 |
72 | std::vector V_;
73 | std::vector M_;
74 | };
75 | } // namespace lczero
76 |
--------------------------------------------------------------------------------
/src/neural/backends/cuda/readme.txt:
--------------------------------------------------------------------------------
1 | cuda/cudnn backend for lc0. Here is a brief description of various files:
2 |
3 | 1. network_cudnn.cc -> cpp file containing network, computation, etc stuff related to lc0
4 | 2. layers.cc -> cpp files containing layer classes
5 | 3. layers.h -> header file for layer classes.
6 | 4. kernels.h -> header file for cuda kernels
7 | 5. common_kernels.cu -> common kernels (fp32, and fp16 that can work with old GPUs)
8 | 6. fp16_kernels.cu -> fp16 specific kernels (not used on other GPUs)
9 | 7. cuda_common.h -> header for common cuda stuff like ReportCUDAErrors, etc.
10 | 8. readme.txt -> this file
11 |
12 | High level overview: network is built of layer objects, layers are either implemented using cudnn/cublas libraries, or custom cuda kernels.
13 |
14 | lc0 search -> network_cudnn -> layers -> kernels
--------------------------------------------------------------------------------
/src/neural/backends/dx/dx_common.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2020 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 | #pragma once
28 |
29 | #include
30 | #include
31 | #include
32 |
33 | #include
34 |
35 | #include "d3dx12.h"
36 | #include "utils/fp16_utils.h"
37 |
38 | #define DEFAULT_FP16 true
39 |
40 | // To debug in case some GPUs can't read from sysmem directly in shader.
41 | //#define COPY_BEFORE_SHADER_READ
42 | // Dump per-layer debug data to find where things go wrong.
43 | //#define DEBUG_DUMP_PER_LAYER_DATA
44 |
45 | namespace lczero {
46 |
47 | namespace dx_backend {
48 |
49 | void DxError(HRESULT status, const char* file, const int& line);
50 | #define ReportDxErrors(status) DxError(status, __FILE__, __LINE__)
51 |
52 | struct DXAlloc {
53 | ID3D12Resource* resource;
54 | uint32_t offset;
55 | // Various ways of binding an allocation to shader:
56 | // 1. RAW/Structured buffer bound as root UAV, use gpu_va directly.
57 | // 2. Typed buffer UAV bound as 4-component typed format (e.g:
58 | // R16G16B16A16_FLOAT)
59 | // 3. Typed buffer UAV bound as single component scalar typed format (e.g:
60 | // R16_FLOAT)
61 |
62 | uint64_t gpu_va;
63 |
64 | // Handle of UAV created as 4-component vector type.
65 | D3D12_GPU_DESCRIPTOR_HANDLE desc_handle_vector;
66 |
67 | // Handle of UAV created as scalar type.
68 | D3D12_GPU_DESCRIPTOR_HANDLE desc_handle_scalar;
69 | };
70 |
71 | typedef uint16_t dx_half;
72 |
73 | inline int DivUp(int a, int b) { return (a + b - 1) / b; }
74 |
75 | } // namespace dx_backend
76 | } // namespace lczero
77 |
--------------------------------------------------------------------------------
/src/neural/backends/dx/shaders/PolicyMap.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2020 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 |
28 | #include "shader_shared.h"
29 |
30 | // ------------------- Policy Map Shader -----------------------------//
31 | RWBuffer input : register(u8);
32 |
33 | // Output is always fp32.
34 | RWStructuredBuffer output : register(u1);
35 |
36 | // Weights are always int32.
37 | RWStructuredBuffer indices : register(u2);
38 |
39 | cbuffer PolicyMapConsts : register(b0) {
40 | uint N;
41 | uint inputSize;
42 | uint usedSize;
43 | uint outputSize;
44 | };
45 |
46 | [numthreads(kPolicyMapBlockSize, 1, 1)]
47 | void PolicyMapShader
48 | (
49 | uint3 globalThreadIdx : SV_DispatchThreadID
50 | )
51 | {
52 | int tid = globalThreadIdx.x;
53 | int n = tid / usedSize;
54 | int i = tid % usedSize;
55 |
56 | if (n >= N) return;
57 |
58 | int j = indices[i];
59 |
60 | if (j >= 0) {
61 | output[n * outputSize + j] = input[n * inputSize + i];
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/neural/backends/dx/shaders/dxc_helper.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # Call dxc with absolute paths where '/' are converted to '\' (in windows).
3 | import sys
4 | import os
5 | import re
6 |
7 | x = sys.argv
8 | x.pop(0)
9 | for i in range(len(x)):
10 | if re.match(r"[a-zA-Z]:/", x[i]):
11 | x[i] = os.path.normpath(x[i])
12 | # We asssume dxc is already on the path.
13 | os.system('dxc ' + '"{}"'.format('" "'.join(x)))
14 |
15 |
--------------------------------------------------------------------------------
/src/neural/backends/dx/shaders/shader_shared.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2020 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 |
28 | #pragma once
29 |
30 | #define kExpandPlanesElementsPerBlock 256
31 | #define kExpandPlanesFp32BlockSize kExpandPlanesElementsPerBlock
32 | #define kExpandPlanesFp16BlockSize (kExpandPlanesElementsPerBlock / 2)
33 |
34 | // for both input transform and output transform shaders
35 | #define kWinogradTransformShaderBlockSize 64
36 |
37 | #define kConv1x1BlockSize 64
38 |
39 | #define kAddVectorsBlockSize 512
40 |
41 | #define kPolicyMapBlockSize 256
42 |
43 |
44 | // Constants for GEMM shader.
45 | #define kGemmBlockWidth 16
46 | #define kGemmBlockHeight 16
47 |
48 | #define kGemmElPerThreadX 8
49 | #define kGemmElPerThreadY 8
50 |
51 | #define kGemmElPerBlockX (kGemmElPerThreadX * kGemmBlockWidth)
52 | #define kGemmElPerBlockY (kGemmElPerThreadY * kGemmBlockHeight)
53 |
54 | #define kGemmShMemKChunk 16
--------------------------------------------------------------------------------
/src/neural/backends/dx/shaders/shaders.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2020 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 |
28 | #pragma once
29 |
30 | #include "ExpandPlanes_shader_fp32.h"
31 | #include "ExpandPlanes_shader_fp16.h"
32 | #include "input_transform_shader_fp32.h"
33 | #include "output_transform_shader_fp32.h"
34 | #include "conv_1x1_shader_fp32.h"
35 | #include "add_vectors_shader.h"
36 | #include "policy_map_shader_fp32.h"
37 |
38 | #include "output_transform_shader_fp32_se_128.h"
39 | #include "output_transform_shader_fp32_se_256.h"
40 | #include "output_transform_shader_fp32_se_320.h"
41 | #include "output_transform_shader_fp32_se_384.h"
42 | #include "output_transform_shader_fp32_se_512.h"
43 | #include "output_transform_shader_fp32_se_640.h"
44 | #include "output_transform_shader_fp32_se_768.h"
45 | #include "output_transform_shader_fp32_se_1024.h"
46 |
47 | #include "se_128.h"
48 | #include "se_256.h"
49 | #include "se_320.h"
50 | #include "se_384.h"
51 | #include "se_512.h"
52 | #include "se_640.h"
53 | #include "se_768.h"
54 | #include "se_1024.h"
55 |
56 | #include "MatrixMul_Fp32.h"
57 | #include "MatrixMul_Fp16.h"
58 |
--------------------------------------------------------------------------------
/src/neural/backends/metal/mps/MetalNetworkBuilder.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Leela Chess Zero.
3 | Copyright (C) 2021 The LCZero Authors
4 |
5 | Leela Chess is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Leela Chess is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Leela Chess. If not, see .
17 |
18 | Additional permission under GNU GPL version 3 section 7
19 |
20 | If you modify this Program, or any covered work, by linking or
21 | combining it with NVIDIA Corporation's libraries from the NVIDIA CUDA
22 | Toolkit and the NVIDIA CUDA Deep Neural Network library (or a
23 | modified version of those libraries), containing parts covered by the
24 | terms of the respective license agreement, the licensors of this
25 | Program grant you additional permission to convey the resulting work.
26 | */
27 | #pragma once
28 |
29 | #include
30 | #include
31 |
32 | namespace lczero {
33 | namespace metal_backend {
34 |
35 | struct Activations {
36 | std::string default_activation = "relu";
37 | std::string smolgen_activation = "swish";
38 | std::string ffn_activation = "relu_2";
39 | };
40 |
41 | class MetalNetworkBuilder {
42 | public:
43 | MetalNetworkBuilder(void);
44 | ~MetalNetworkBuilder(void);
45 |
46 | std::string init(int gpu_id);
47 |
48 | void build(int kInputPlanes, MultiHeadWeights& weights,
49 | InputEmbedding embedding, bool attn_body, bool attn_policy,
50 | bool conv_policy, bool wdl, bool moves_left,
51 | Activations& activations, std::string& policy_head,
52 | std::string& value_head);
53 |
54 | void forwardEval(float* inputs, int batchSize,
55 | std::vector output_mems);
56 |
57 | private:
58 | int gpu_id;
59 | };
60 |
61 | } // namespace metal_backend
62 | } // namespace lczero
63 |
--------------------------------------------------------------------------------
/src/neural/backends/opencl/OpenCLParams.h:
--------------------------------------------------------------------------------
1 | /*
2 | Originally from the Leela Zero project.
3 | Copyright (C) 2017 Gian-Carlo Pascutto
4 |
5 | This file is part of Leela Chess Zero.
6 | Copyright (C) 2018 The LCZero Authors
7 |
8 | Leela Chess is free software: you can redistribute it and/or modify
9 | it under the terms of the GNU General Public License as published by
10 | the Free Software Foundation, either version 3 of the License, or
11 | (at your option) any later version.
12 |
13 | Leela Chess is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with Leela Chess. If not, see .
20 | */
21 |
22 | #pragma once
23 |
24 | struct OpenCLParams {
25 | int gpuId = -1;
26 |
27 | bool tune_only = false;
28 | bool force_tune = false;
29 | bool tune_exhaustive = false;
30 | int tune_batch_size = 1;
31 | std::string tuner_file;
32 | };
33 |
--------------------------------------------------------------------------------
/src/neural/backends/opencl/OpenCLTuner.h:
--------------------------------------------------------------------------------
1 | /*
2 | Originally from the Leela Zero project.
3 | Copyright (C) 2017 Gian-Carlo Pascutto
4 |
5 | This file is part of Leela Chess Zero.
6 | Copyright (C) 2018 The LCZero Authors
7 |
8 | Leela Chess is free software: you can redistribute it and/or modify
9 | it under the terms of the GNU General Public License as published by
10 | the Free Software Foundation, either version 3 of the License, or
11 | (at your option) any later version.
12 |
13 | Leela Chess is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with Leela Chess. If not, see .
20 | */
21 |
22 | #pragma once
23 |
24 | #include