Skip to content

Commit

Permalink
Merge pull request LeelaChessZero#4 from LeelaChessZero/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
jjoshua2 authored Nov 30, 2018
2 parents f74290a + 98a80ca commit 46ab923
Show file tree
Hide file tree
Showing 57 changed files with 3,596 additions and 2,528 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ in ("Deep Learning").

For Ubuntu 18.04 you need the latest version of meson and clang-6.0 before performing the steps above:

sudo apt-get install clang-6.0 ninja-build protobuf-compiler libprotobuf-dev meson
sudo apt-get install clang-6.0 ninja-build pkg-config protobuf-compiler libprotobuf-dev meson
CC=clang-6.0 CXX=clang++-6.0 INSTALL_PREFIX=~/.local ./build.sh

Make sure that `~/.local/bin` is in your `PATH` environment variable. You can now type `lc0 --help` and start.
Expand Down Expand Up @@ -133,6 +133,7 @@ Or.
2. Install python3: `brew install python3`
3. Install meson: `brew install meson`
4. Install ninja: `brew install ninja`
5. When using Mojave install SDK headers: installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
6. Run `./build.sh`
7. The resulting binary will be in build/release

Expand Down
30 changes: 13 additions & 17 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ image:
environment:
matrix:
- NAME: cuda
OPENCL: false
BLAS: false
CUDA: true
GTEST: false
- NAME: opencl
OPENCL: true
BLAS: true
CUDA: false
GTEST: false
- NAME: blas
OPENCL: false
BLAS: true
CUDA: false
GTEST: true
install:
- cmd: IF %CUDA%==false nuget install OpenBLAS -Version 0.2.14.1 -OutputDirectory C:\cache
- cmd: IF %CUDA%==false nuget install opencl-nug -Version 0.777.12 -OutputDirectory C:\cache
- cmd: set CUDA=false
- cmd: set OPENCL=false
- cmd: set BLAS=false
- cmd: set GTEST=false
- cmd: IF %NAME%==cuda set CUDA=true
- cmd: IF %NAME%==opencl set OPENCL=true
- cmd: IF %NAME%==blas set BLAS=true
- cmd: IF %NAME%==blas set GTEST=true
- cmd: IF %BLAS%==true nuget install OpenBLAS -Version 0.2.14.1 -OutputDirectory C:\cache
- cmd: IF %OPENCL%==true nuget install opencl-nug -Version 0.777.12 -OutputDirectory C:\cache
- cmd: IF %BLAS%==true IF NOT EXIST C:\cache\ispc-v1.9.2-windows appveyor DownloadFile https://sourceforge.net/projects/ispcmirror/files/v1.9.2/ispc-v1.9.2-windows.zip
- cmd: IF %BLAS%==true IF NOT EXIST C:\cache\ispc-v1.9.2-windows 7z x ispc-v1.9.2-windows.zip -oC:\cache
- cmd: IF %BLAS%==true set PATH=C:\cache\ispc-v1.9.2-windows;%PATH%
Expand Down Expand Up @@ -55,15 +51,15 @@ cache:
- C:\projects\lc0\subprojects\packagecache
before_build:
- cmd: git submodule update --init --recursive
- cmd: meson build --backend vs2015 --buildtype release -Dgtest=%GTEST% -Dopencl=%OPENCL% -Dblas=%BLAS% -Dcudnn=%CUDA% -Dispc_native_only=false -Dpopcnt=false -Dcudnn_include="%PKG_FOLDER%\cuda\include" -Dcudnn_libdirs="%CUDA_PATH%\lib\x64","%PKG_FOLDER%\cuda\lib\x64" -Dprotobuf_include="%PKG_FOLDER%\protobuf\include" -Dprotobuf_libdir="%PKG_FOLDER%\protobuf\lib" -Dopenblas_include="%PKG_FOLDER%\OpenBLAS.0.2.14.1\lib\native\include" -Dopenblas_libdirs="%PKG_FOLDER%\OpenBLAS.0.2.14.1\lib\native\lib\x64" -Dopencl_include="%PKG_FOLDER%\opencl-nug.0.777.12\build\native\include" -Dopencl_libdirs="%PKG_FOLDER%\opencl-nug.0.777.12\build\native\lib\x64" -Ddefault_library=static
- cmd: meson build --backend vs2015 --buildtype release -Dgtest=%GTEST% -Dopencl=%OPENCL% -Dblas=%BLAS% -Dcudnn=%CUDA% -Dispc_native_only=false -Dpopcnt=false -Dcudnn_include="%CUDA_PATH%\include","%PKG_FOLDER%\cuda\include" -Dcudnn_libdirs="%CUDA_PATH%\lib\x64","%PKG_FOLDER%\cuda\lib\x64" -Dprotobuf_include="%PKG_FOLDER%\protobuf\include" -Dprotobuf_libdir="%PKG_FOLDER%\protobuf\lib" -Dopenblas_include="%PKG_FOLDER%\OpenBLAS.0.2.14.1\lib\native\include" -Dopenblas_libdirs="%PKG_FOLDER%\OpenBLAS.0.2.14.1\lib\native\lib\x64" -Dopencl_include="%PKG_FOLDER%\opencl-nug.0.777.12\build\native\include" -Dopencl_libdirs="%PKG_FOLDER%\opencl-nug.0.777.12\build\native\lib\x64" -Ddefault_library=static
build_script:
- cmd: msbuild "C:\projects\lc0\build\lc0.sln" /m /p:WholeProgramOptimization=true /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
after_build:
- cmd: IF %APPVEYOR_REPO_TAG%==true 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip %APPVEYOR_BUILD_FOLDER%\build\lc0.exe
- cmd: IF %APPVEYOR_REPO_TAG%==true appveyor DownloadFile "https://ci.appveyor.com/api/projects/LeelaChessZero/lczero-client/artifacts/client.exe?branch=release&pr=false&job=Environment%%3A%%20NAME%%3D.exe%%2C%%20GOOS%%3Dwindows"
- cmd: IF %APPVEYOR_REPO_TAG%==true 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip client.exe
- cmd: IF %APPVEYOR_REPO_TAG%==true IF %CUDA%==false 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip C:\cache\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll
- cmd: IF %APPVEYOR_REPO_TAG%==true IF %CUDA%==false IF %OPENCL%==true 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip C:\cache\opencl-nug.0.777.12\build\native\bin\OpenCL.dll
- cmd: IF %APPVEYOR_REPO_TAG%==true IF %BLAS%==true 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip C:\cache\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll
- cmd: IF %APPVEYOR_REPO_TAG%==true IF %OPENCL%==true 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip C:\cache\opencl-nug.0.777.12\build\native\bin\OpenCL.dll
- cmd: IF %APPVEYOR_REPO_TAG%==true IF %CUDA%==true 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip "%CUDA_PATH%\bin\cudart64_100.dll" "%CUDA_PATH%\bin\cublas64_100.dll"
- cmd: IF %APPVEYOR_REPO_TAG%==true IF %CUDA%==true 7z a lc0-%APPVEYOR_REPO_TAG_NAME%-windows-%NAME%.zip "%PKG_FOLDER%\cuda\bin\cudnn64_7.dll"
- cmd: IF %APPVEYOR_REPO_TAG%==true IF %CUDA%==true type COPYING |more /P > dist\COPYING
Expand Down
15 changes: 11 additions & 4 deletions build-cuda.cmd
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
rd /s build

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
meson.py build --backend vs2015 --buildtype release ^
-Dcudnn_libdirs="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\lib\x64","C:\dev\cuDNN\cuda\lib\x64" ^
rem set MSBuild="C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
set MSBuild="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
rem call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
meson.py build --backend vs2017 --buildtype release ^
-Dcuda_include="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include" ^
-Dcudnn_libdirs="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64","C:\dev\cuDNN\cuda\lib\x64" ^
-Dcudnn_include="C:\dev\cuDNN\cuda\include" ^
-Ddefault_library=static

pause


cd build

"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" ^
%MSBuild% ^
/p:Configuration=Release ^
/p:Platform=x64 ^
/p:PreferredToolArchitecture=x64 lc0.sln ^
Expand Down
7 changes: 7 additions & 0 deletions checkdir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/python

import sys
import os
if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
exit(0)
exit(1)
2 changes: 1 addition & 1 deletion libs/lczero-common
121 changes: 74 additions & 47 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ else
protobuf_dep = protobuf_lib
endif
protoc = find_program('protoc', required : false)
if not protobuf_dep.found() or not protoc.found()
# For tensorflow skip system protobuf, chances are it will not work.
if not protobuf_dep.found() or not protoc.found() or get_option('tensorflow')
deps += subproject('protobuf').get_variable('protobuf_dep')
protoc = subproject('protobuf').get_variable('protoc')
else
Expand Down Expand Up @@ -81,6 +82,7 @@ files += [
'src/neural/factory.cc',
'src/neural/loader.cc',
'src/neural/network_check.cc',
'src/neural/network_legacy.cc',
'src/neural/network_mux.cc',
'src/neural/network_random.cc',
'src/neural/network_st_batch.cc',
Expand All @@ -98,6 +100,7 @@ files += [
'src/utils/random.cc',
'src/utils/string.cc',
'src/utils/transpose.cc',
'src/utils/weights_adapter.cc',
]
includes += include_directories('src')

Expand Down Expand Up @@ -152,6 +155,8 @@ if get_option('build_backends')
## Blas
## ~~~~~

shared_files = []

has_blas = false

accelerate_lib = dependency('Accelerate', required: false)
Expand All @@ -165,7 +170,7 @@ if get_option('build_backends')
openblas_lib = cc.find_library('openblas', dirs: openblas_libdirs, required: false)
endif

if get_option('blas') or get_option('opencl')
if get_option('blas')
if get_option('mkl') and mkl_lib.found()
add_project_arguments('-DUSE_MKL', language : 'cpp')
includes += include_directories(get_option('mkl_include'))
Expand Down Expand Up @@ -201,14 +206,6 @@ if get_option('build_backends')
has_blas = true
endif

if has_blas
blas_files = [
'src/neural/blas/batchnorm.cc',
'src/neural/blas/fully_connected_layer.cc',
'src/neural/blas/winograd_convolution3.cc'
]
endif

ispc = find_program('ispc', required: false)
ispc_extra_args = []
if has_blas and get_option('ispc') and ispc.found()
Expand Down Expand Up @@ -247,9 +244,18 @@ if get_option('build_backends')

if get_option('blas') and has_blas

blas_files += [
blas_files = [
'src/neural/blas/convolution1.cc',
'src/neural/blas/network_blas.cc'
'src/neural/blas/fully_connected_layer.cc',
'src/neural/blas/se_unit.cc',
'src/neural/blas/network_blas.cc',
'src/neural/blas/winograd_convolution3.cc'
]

shared_files = [
'src/neural/shared/activation.cc',
'src/neural/shared/batchnorm.cc',
'src/neural/shared/winograd_filter.cc',
]

files += blas_files
Expand Down Expand Up @@ -284,29 +290,28 @@ if get_option('build_backends')

endif


if get_option('opencl') and has_opencl

if has_blas
opencl_files = [
opencl_files = [
'src/neural/opencl/network_opencl.cc',
'src/neural/opencl/OpenCL.cc',
'src/neural/opencl/OpenCLTuner.cc',
'src/neural/opencl/network_opencl.cc',
]
'src/neural/opencl/OpenCLBuffers.cc',
]

if not get_option('blas')
opencl_files += blas_files
endif
shared_files = [
'src/neural/shared/activation.cc',
'src/neural/shared/batchnorm.cc',
'src/neural/shared/winograd_filter.cc',
]

includes += include_directories(get_option('opencl_include'))
files += opencl_files
has_backends = true
else
warning('The OpenCL backend requires a BLAS library')
endif
includes += include_directories(get_option('opencl_include'))
files += opencl_files
has_backends = true

endif

files += shared_files

## ~~~~~
## cuDNN
Expand All @@ -316,32 +321,54 @@ if get_option('build_backends')
cu_dnn = cc.find_library('cudnn', dirs: cudnn_libdirs, required: false)
cu_dart = cc.find_library('cudart', dirs: cudnn_libdirs, required: false)
nvcc = find_program('/usr/local/cuda/bin/nvcc', 'nvcc', required: false)

#.cc files
cuda_files = [
'src/neural/network_cudnn.cu',
'src/neural/cuda/network_cudnn.cc',
'src/neural/cuda/layers.cc',
]

# .cu files compiled without any specific sm version
cuda_files_nvcc_common = [
'src/neural/cuda/common_kernels.cu',
]

# .cu files compiled with sm_70 (volta+). Only used by cudnn-fp16
cuda_files_nvcc_fp16 = [
'src/neural/cuda/fp16_kernels.cu',
]

if get_option('cudnn') and cu_blas.found() and cu_dnn.found() and cu_dart.found() and nvcc.found()
deps += [cu_blas, cu_dnn, cu_dart]
cuda_arguments = ['-c', '@INPUT@', '-o', '@OUTPUT@',
'-I', meson.current_source_dir() + '/src']
if host_machine.system() == 'windows'
cuda_arguments += ['-Xcompiler', '-MD']
else
cuda_arguments += ['--std=c++14', '-Xcompiler', '-fPIC']
endif
foreach x : get_option('cudnn_include')
cuda_arguments += ['-I', x]
endforeach
if host_machine.system() == 'windows'
outputname = '@[email protected]'
else
outputname = '@[email protected]'
endif
cuda_gen = generator(nvcc,
output: outputname,
arguments: cuda_arguments,
)
files += cuda_gen.process(cuda_files)
foreach d : get_option('cudnn_include')
if run_command('checkdir.py', d).returncode() == 0
includes += include_directories(d)
endif
endforeach
includes += include_directories('src/neural/cuda/')

cuda_arguments = ['@EXTRA_ARGS@', '-c', '@INPUT@', '-o', '@OUTPUT@',
'-I', meson.current_source_dir() + '/src']
if host_machine.system() == 'windows'
cuda_arguments += ['-Xcompiler', '-MD']
else
cuda_arguments += ['--std=c++14', '-Xcompiler', '-fPIC']
endif
foreach x : get_option('cudnn_include')
cuda_arguments += ['-I', x]
endforeach
if host_machine.system() == 'windows'
outputname = '@[email protected]'
else
outputname = '@[email protected]'
endif
cuda_gen = generator(nvcc,
output: outputname,
arguments: cuda_arguments,
)
files += cuda_files
files += cuda_gen.process(cuda_files_nvcc_common)
files += cuda_gen.process(cuda_files_nvcc_fp16, extra_args: ['-arch=compute_70', '-code=sm_70'])
has_backends = true
endif

Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ option('mkl_include',

option('cudnn_include',
type: 'array',
value: ['/usr/local/cuda/include/'],
value: ['/opt/cuda/include/', '/usr/local/cuda/include/'],
description: 'Paths to cudnn include directory')

option('build_backends',
Expand Down
4 changes: 2 additions & 2 deletions src/chess/uciloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
namespace lczero {

struct GoParams {
std::int64_t wtime = -1;
std::int64_t btime = -1;
optional<std::int64_t> wtime;
optional<std::int64_t> btime;
std::int64_t winc = -1;
std::int64_t binc = -1;
int movestogo = -1;
Expand Down
Loading

0 comments on commit 46ab923

Please sign in to comment.