diff --git a/lc0/.clang-format b/lc0/.clang-format new file mode 100644 index 000000000..d83d6e47a --- /dev/null +++ b/lc0/.clang-format @@ -0,0 +1,117 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 2 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +RawStringFormats: + - Delimiter: pb + Language: TextProto + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 8 +UseTab: Never +... + diff --git a/lc0/CMakeLists.txt b/lc0/CMakeLists.txt new file mode 100644 index 000000000..c57524d67 --- /dev/null +++ b/lc0/CMakeLists.txt @@ -0,0 +1,74 @@ +# This file is part of Leela Chess Zero. +# Copyright (C) 2018 The LCZero Authors +# +# Leela Chess is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leela Chess is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Leela Chess. If not, see . + +project (lc0 CXX C) +cmake_minimum_required (VERSION 3.1) + + +#------------------------------------------------------------------------------- +# General Settings +#------------------------------------------------------------------------------- +set (CMAKE_CXX_STANDARD 14) + +if (NOT CMAKE_BUILD_TYPE) + set (CMAKE_BUILD_TYPE "Release") +endif (NOT CMAKE_BUILD_TYPE) + +# See if we can set optimization flags as expected. +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set (GccSpecificFlags 1) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + set (GccSpecificFlags 1) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set (GccSpecificFlags 1) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + set (GccSpecificFlags 0) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set (GccSpecificFlags 0) +endif() + +list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") + +if (GccSpecificFlags) + set (CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -pipe") + set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g") + set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -ffast-math -march=native -mtune=native") + set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") + set (CMAKE_EXE_LINKER_FLAGS -Wl,--no-as-needed) +endif(GccSpecificFlags) + + +#------------------------------------------------------------------------------- +# Find packages +#------------------------------------------------------------------------------- +find_package (Threads REQUIRED) +find_package (Boost REQUIRED filesystem) +find_package (GTest) +find_package (CUDA) +find_package (CUDNN) + +#------------------------------------------------------------------------------- +# Testing +#------------------------------------------------------------------------------- +if (GTEST_FOUND) + enable_testing () +endif (GTEST_FOUND) + +include_directories( + ${PROJECT_SOURCE_DIR}/src +) + +add_subdirectory (src) diff --git a/lc0/LC0VSProj/LC0VSProj.sln b/lc0/LC0VSProj/LC0VSProj.sln deleted file mode 100644 index 5918405e6..000000000 --- a/lc0/LC0VSProj/LC0VSProj.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.15 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LC0VSProj", "LC0VSProj.vcxproj", "{CBA46B8C-63B8-4F7F-A35D-E1464246DC72}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CBA46B8C-63B8-4F7F-A35D-E1464246DC72}.Debug|x64.ActiveCfg = Debug|x64 - {CBA46B8C-63B8-4F7F-A35D-E1464246DC72}.Debug|x64.Build.0 = Debug|x64 - {CBA46B8C-63B8-4F7F-A35D-E1464246DC72}.Release|x64.ActiveCfg = Release|x64 - {CBA46B8C-63B8-4F7F-A35D-E1464246DC72}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/lc0/LC0VSProj/LC0VSProj.vcxproj b/lc0/LC0VSProj/LC0VSProj.vcxproj deleted file mode 100644 index 16f0ecf5d..000000000 --- a/lc0/LC0VSProj/LC0VSProj.vcxproj +++ /dev/null @@ -1,161 +0,0 @@ - - - - - Debug - x64 - - - Release - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {CBA46B8C-63B8-4F7F-A35D-E1464246DC72} - LC0VSProj - 10.0.15063.0 - - - - Application - true - MultiByte - v141 - - - Application - false - true - MultiByte - v141 - - - - - - - - - - - - - - true - $(ProjectDir)\..\src;$(VC_IncludePath);$(WindowsSDK_IncludePath);..\CUDA_NN\7.1 - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;..\CUDA_NN\7.1 - - - $(ProjectDir)\..\src;$(VC_IncludePath);$(WindowsSDK_IncludePath);..\CUDA_NN\7.1 - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;..\CUDA_NN\7.1 - lc0-cudnn - - - - Level3 - Disabled - WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - MultiThreadedDebug - - - true - Console - cublas.lib;cudnn.lib;cudart.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - echo copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" -copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" - - - 64 - - - - - Level3 - MaxSpeed - true - true - WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - MultiThreaded - - - true - true - true - Console - cublas.lib;cudnn.lib;cudart.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - echo copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" -copy "$(CudaToolkitBinDir)\cudart*.dll" "$(OutDir)" - - - 64 - - - - - - - \ No newline at end of file diff --git a/lc0/build.sh b/lc0/build.sh index 00c52ff8a..96df8ed71 100755 --- a/lc0/build.sh +++ b/lc0/build.sh @@ -1,9 +1,10 @@ #!/bin/bash rm -fr build -CC=clang CXX=clang++ meson build --buildtype release # -Db_ndebug=true -# CC=clang CXX=clang++ meson build --buildtype debugoptimized -Db_asneeded=false -# CC=clang CXX=clang++ meson build --buildtype debug -cp testdata/* build -cd build -ninja +mkdir build +pushd build +cmake .. -DCMAKE_BUILD_TYPE=Release +#cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo +#cmake .. -DCMAKE_BUILD_TYPE=Debug +make +popd diff --git a/lc0/cmake/modules/FindCUDNN.cmake b/lc0/cmake/modules/FindCUDNN.cmake new file mode 100644 index 000000000..a8304917d --- /dev/null +++ b/lc0/cmake/modules/FindCUDNN.cmake @@ -0,0 +1,55 @@ +# Taken from Caffe2 + +# - Try to find cuDNN +# +# The following variables are optionally searched for defaults +# CUDNN_ROOT_DIR: Base directory where all cuDNN components are found +# +# The following are set after configuration is done: +# CUDNN_FOUND +# CUDNN_INCLUDE_DIRS +# CUDNN_LIBRARIES +# CUDNN_LIBRARY_DIRS + +include(FindPackageHandleStandardArgs) + +set(CUDNN_ROOT_DIR "" CACHE PATH "Folder contains NVIDIA cuDNN") + +find_path(CUDNN_INCLUDE_DIR cudnn.h + HINTS ${CUDNN_ROOT_DIR} ${CUDA_TOOLKIT_ROOT_DIR} + PATH_SUFFIXES cuda/include include) + +find_library(CUDNN_LIBRARY cudnn + HINTS ${CUDNN_ROOT_DIR} ${CUDA_TOOLKIT_ROOT_DIR} + PATH_SUFFIXES lib lib64 cuda/lib cuda/lib64 lib/x64) + +find_package_handle_standard_args( + CUDNN DEFAULT_MSG CUDNN_INCLUDE_DIR CUDNN_LIBRARY) + +if(CUDNN_FOUND) + # get cuDNN version + file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_HEADER_CONTENTS) + string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)" + CUDNN_VERSION_MAJOR "${CUDNN_HEADER_CONTENTS}") + string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1" + CUDNN_VERSION_MAJOR "${CUDNN_VERSION_MAJOR}") + string(REGEX MATCH "define CUDNN_MINOR * +([0-9]+)" + CUDNN_VERSION_MINOR "${CUDNN_HEADER_CONTENTS}") + string(REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1" + CUDNN_VERSION_MINOR "${CUDNN_VERSION_MINOR}") + string(REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)" + CUDNN_VERSION_PATCH "${CUDNN_HEADER_CONTENTS}") + string(REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1" + CUDNN_VERSION_PATCH "${CUDNN_VERSION_PATCH}") + # Assemble cuDNN version + if(NOT CUDNN_VERSION_MAJOR) + set(CUDNN_VERSION "?") + else() + set(CUDNN_VERSION "${CUDNN_VERSION_MAJOR}.${CUDNN_VERSION_MINOR}.${CUDNN_VERSION_PATCH}") + endif() + + set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR}) + set(CUDNN_LIBRARIES ${CUDNN_LIBRARY}) + message(STATUS "Found cuDNN: v${CUDNN_VERSION} (include: ${CUDNN_INCLUDE_DIR}, library: ${CUDNN_LIBRARY})") + mark_as_advanced(CUDNN_ROOT_DIR CUDNN_LIBRARY CUDNN_INCLUDE_DIR) +endif() diff --git a/lc0/meson.build b/lc0/meson.build deleted file mode 100644 index e6ffd58c2..000000000 --- a/lc0/meson.build +++ /dev/null @@ -1,91 +0,0 @@ -project('lc0', 'cpp', default_options : ['cpp_std=c++14']) - -add_global_arguments('-Wthread-safety', language : 'cpp') -cc = meson.get_compiler('cpp') - -# Installed from https://github.com/FloopCZ/tensorflow_cc -tensorflow_cc = declare_dependency( - include_directories: include_directories( - '/usr/local/include/tensorflow', - '/usr/local/include/tensorflow/bazel-genfiles', - '/usr/local/include/tensorflow/tensorflow/contrib/makefile/downloads', - '/usr/local/include/tensorflow/tensorflow/contrib/makefile/downloads/eigen', - '/usr/local/include/tensorflow/tensorflow/contrib/makefile/downloads/gemmlowp', - '/usr/local/include/tensorflow/tensorflow/contrib/makefile/downloads/nsync/public', - '/usr/local/include/tensorflow/tensorflow/contrib/makefile/gen/protobuf-host/include', - ), - dependencies: [ - cc.find_library('libtensorflow_cc', dirs: '/usr/local/lib/tensorflow_cc/'), - cc.find_library('dl'), - cc.find_library('pthread'), - cc.find_library('libprotobuf', dirs: '/usr/local/lib/tensorflow_cc/'), - ], -) - -deps = [] -deps += tensorflow_cc -deps += cc.find_library('stdc++fs') -deps += cc.find_library('pthread') -deps += cc.find_library('libcublas', dirs: ['/opt/cuda/lib64/', '/usr/local/cuda/lib64/']) -deps += cc.find_library('libcudnn', dirs: ['/opt/cuda/lib64/', '/usr/local/cuda/lib64/']) -deps += cc.find_library('libcudart', dirs: ['/opt/cuda/lib64/', '/usr/local/cuda/lib64/']) -# deps += cc.find_library('libprofiler', dirs: ['/usr/local/lib']) - -nvcc = find_program('nvcc') -cuda_files = [ - 'src/neural/network_cudnn.cu', -] - -cuda_gen = generator(nvcc, - output: '@BASENAME@.o', - arguments: ['--std=c++14', '-c', '@INPUT@', '-o', '@OUTPUT@', '-I', '../src'], -) - -files = [ - 'src/chess/bitboard.cc', - 'src/chess/board.cc', - 'src/chess/position.cc', - 'src/mcts/node.cc', - 'src/mcts/search.cc', - 'src/neural/cache.cc', - 'src/neural/encoder.cc', - 'src/neural/factory.cc', - 'src/neural/loader.cc', - 'src/neural/writer.cc', - 'src/neural/network_mux.cc', - 'src/neural/network_random.cc', - 'src/neural/network_tf.cc', - 'src/utils/transpose.cc', - 'src/utils/commandline.cc', - 'src/utils/optionsdict.cc', - 'src/utils/random.cc', - 'src/engine.cc', - 'src/optionsparser.cc', - 'src/selfplay/game.cc', - 'src/selfplay/tournament.cc', - 'src/selfplay/loop.cc', - 'src/uciloop.cc', - cuda_gen.process(cuda_files) -] - -includes = [] -includes += include_directories('src') - -executable('lc0', 'src/main.cc', - files, include_directories: includes, dependencies: deps) - - -### Tests - -test_deps = deps -test_deps += dependency('gtest') - -test('ChessBoard', - executable('chessboard_test', 'src/chess/board_test.cc', - files, include_directories: includes, dependencies: test_deps -)) - -test('HashCat', - executable('hashcat_test', 'src/utils/hashcat_test.cc', - files, include_directories: includes, dependencies: test_deps -)) diff --git a/lc0/src/CMakeLists.txt b/lc0/src/CMakeLists.txt new file mode 100644 index 000000000..4fa41a584 --- /dev/null +++ b/lc0/src/CMakeLists.txt @@ -0,0 +1,25 @@ +add_subdirectory (chess) +add_subdirectory (utils) +add_subdirectory (mcts) +add_subdirectory (selfplay) +add_subdirectory (neural) + +add_executable (lc0 + engine.h + optionsparser.h + uciloop.h + engine.cc + main.cc + optionsparser.cc + uciloop.cc +) + +target_link_libraries (lc0 + utils + chess + mcts + neural + selfplay + ${CMAKE_THREAD_LIBS_INIT} + ${Boost_LIBRARIES} +) diff --git a/lc0/src/chess/CMakeLists.txt b/lc0/src/chess/CMakeLists.txt new file mode 100644 index 000000000..fcfcb5d91 --- /dev/null +++ b/lc0/src/chess/CMakeLists.txt @@ -0,0 +1,21 @@ +add_library (chess SHARED + bitboard.cc + board.cc + position.cc + bitboard.h + board.h + position.h +) + +if (GTEST_FOUND) + file (GLOB TEST_SOURCES test/*) + add_executable (chess_test ${TEST_SOURCES}) + + target_link_libraries (chess_test + chess + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ) + + add_test (chess_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/chess_test) +endif (GTEST_FOUND) \ No newline at end of file diff --git a/lc0/src/chess/board.cc b/lc0/src/chess/board.cc index ed184ba65..c14183c69 100644 --- a/lc0/src/chess/board.cc +++ b/lc0/src/chess/board.cc @@ -169,6 +169,8 @@ static const Move::Promotion kPromotions[] = { Move::Promotion::Knight, }; +const BitBoard kPawnMask = 0x00FFFFFFFFFFFF00ULL; + } // namespace MoveList ChessBoard::GeneratePseudolegalMoves() const { @@ -769,4 +771,8 @@ string ChessBoard::DebugString() const { return result; } + BitBoard ChessBoard::pawns() const { + return pawns_ * kPawnMask; + } + } // namespace lczero diff --git a/lc0/src/chess/board.h b/lc0/src/chess/board.h index 2d7562ad4..3a37b4ab2 100644 --- a/lc0/src/chess/board.h +++ b/lc0/src/chess/board.h @@ -115,7 +115,7 @@ class ChessBoard { BitBoard ours() const { return our_pieces_; } BitBoard theirs() const { return their_pieces_; } - BitBoard pawns() const { return pawns_ * kPawnMask; } + BitBoard pawns() const; BitBoard bishops() const { return bishops_ - rooks_; } BitBoard rooks() const { return rooks_ - bishops_; } BitBoard queens() const { return rooks_ * bishops_; } @@ -142,8 +142,6 @@ class ChessBoard { bool operator!=(const ChessBoard& other) const { return !operator==(other); } private: - static constexpr BitBoard kPawnMask = 0x00FFFFFFFFFFFF00ULL; - // All white pieces. BitBoard our_pieces_; // All black pieces. diff --git a/lc0/src/chess/board_test.cc b/lc0/src/chess/test/board_test.cc similarity index 99% rename from lc0/src/chess/board_test.cc rename to lc0/src/chess/test/board_test.cc index fe01148d0..69cb397df 100644 --- a/lc0/src/chess/board_test.cc +++ b/lc0/src/chess/test/board_test.cc @@ -19,8 +19,8 @@ #include #include -#include "src/chess/bitboard.h" -#include "src/chess/board.h" +#include "chess/bitboard.h" +#include "chess/board.h" namespace lczero { diff --git a/lc0/src/mcts/CMakeLists.txt b/lc0/src/mcts/CMakeLists.txt new file mode 100644 index 000000000..d214a6d51 --- /dev/null +++ b/lc0/src/mcts/CMakeLists.txt @@ -0,0 +1,11 @@ +add_library (mcts SHARED + callbacks.h + node.h + search.h + node.cc + search.cc +) + +target_link_libraries (mcts + chess +) diff --git a/lc0/src/neural/CMakeLists.txt b/lc0/src/neural/CMakeLists.txt new file mode 100644 index 000000000..0db70be83 --- /dev/null +++ b/lc0/src/neural/CMakeLists.txt @@ -0,0 +1,37 @@ +if (CUDA_FOUND) + add_subdirectory (cuda) +endif (CUDA_FOUND) + +add_library (neural SHARED + cache.h + encoder.h + factory.h + loader.h + network.h + writer.h + cache.cc + encoder.cc + factory.cc + loader.cc + network_mux.cc + network_random.cc + writer.cc +) + +target_link_libraries (neural + utils + ${CMAKE_THREAD_LIBS_INIT} + ${Boost_LIBRARIES} +) + +if (CUDNN_FOUND) + target_link_libraries(neural + neural_cudnn + ) +endif(CUDNN_FOUND) + +if (TENSORRT_FOUND) + target_link_libraries(neural + neural_tensorrt + ) +endif (TENSORRT_FOUND) \ No newline at end of file diff --git a/lc0/src/neural/cuda/CMakeLists.txt b/lc0/src/neural/cuda/CMakeLists.txt new file mode 100644 index 000000000..cd4f7b85d --- /dev/null +++ b/lc0/src/neural/cuda/CMakeLists.txt @@ -0,0 +1,15 @@ +if (CUDNN_FOUND) + cuda_add_library (neural_cudnn SHARED + network_cudnn.cu + ) + + target_link_libraries(neural_cudnn + ${CUDA_LIBRARIES} + ${CUDA_CUBLAS_LIBRARIES} + ${CUDNN_LIBRARY} + utils + ) +endif (CUDNN_FOUND) + +if (TENSORRT_FOUND) +endif (TENSORRT_FOUND) diff --git a/lc0/src/neural/network_cudnn.cu b/lc0/src/neural/cuda/network_cudnn.cu similarity index 99% rename from lc0/src/neural/network_cudnn.cu rename to lc0/src/neural/cuda/network_cudnn.cu index bae19f555..b8ce7201f 100644 --- a/lc0/src/neural/network_cudnn.cu +++ b/lc0/src/neural/cuda/network_cudnn.cu @@ -18,6 +18,7 @@ #include #include #include +#include #include "neural/factory.h" #include "utils/bititer.h" #include "utils/exception.h" @@ -921,7 +922,7 @@ class CudnnNetwork : public Network { } // get rid of the BN layer by adjusting weights and biases of the - // convolution idea proposed by Henrik Forstén and first implemented in + // convolution idea proposed by Henrik Forstén and first implemented in // leela go zero if (foldBNLayer) { const int outputs = block.biases.size(); diff --git a/lc0/src/neural/loader.cc b/lc0/src/neural/loader.cc index bdd988b2c..b9331584f 100644 --- a/lc0/src/neural/loader.cc +++ b/lc0/src/neural/loader.cc @@ -20,10 +20,10 @@ #include #include #include -#include #include #include #include +#include #include "utils/commandline.h" #include "utils/exception.h" @@ -127,15 +127,15 @@ Weights LoadWeightsFromFile(const std::string& filename) { std::string DiscoveryWeightsFile() { const int kMinFileSize = 30000000; - using namespace std::experimental::filesystem; + using namespace boost::filesystem; std::string path = CommandLine::BinaryDirectory(); - std::vector> candidates; + std::vector> candidates; for (const auto& file : recursive_directory_iterator(path)) { if (!is_regular_file(file.path())) continue; if (file_size(file.path()) < kMinFileSize) continue; candidates.emplace_back(last_write_time(file.path()), - file.path().generic_u8string()); + file.path().string()); } std::sort(candidates.rbegin(), candidates.rend()); diff --git a/lc0/src/neural/writer.cc b/lc0/src/neural/writer.cc index 40b02ae8f..4fbe2698a 100644 --- a/lc0/src/neural/writer.cc +++ b/lc0/src/neural/writer.cc @@ -18,7 +18,7 @@ #include "neural/writer.h" -#include +#include #include #include #include "utils/commandline.h" @@ -27,7 +27,7 @@ namespace lczero { TrainingDataWriter::TrainingDataWriter(int game_id) { - using namespace std::experimental::filesystem; + using namespace boost::filesystem; static std::string directory = CommandLine::BinaryDirectory() + "/data-" + Random::Get().GetString(12); // It's fine if it already exists. diff --git a/lc0/src/selfplay/CMakeLists.txt b/lc0/src/selfplay/CMakeLists.txt new file mode 100644 index 000000000..a5cff7ebd --- /dev/null +++ b/lc0/src/selfplay/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library (selfplay SHARED + game.h + loop.h + tournament.h + game.cc + loop.cc + tournament.cc +) + +target_link_libraries(selfplay + chess + utils + mcts + neural +) diff --git a/lc0/src/utils/CMakeLists.txt b/lc0/src/utils/CMakeLists.txt new file mode 100644 index 000000000..06eccb534 --- /dev/null +++ b/lc0/src/utils/CMakeLists.txt @@ -0,0 +1,32 @@ +add_library (utils SHARED + bititer.h + cache-old.h + cache.h + commandline.h + cppattributes.h + exception.h + hashcat.h + mutex.h + optional.h + optionsdict.h + random.h + smallarray.h + transpose.h + commandline.cc + optionsdict.cc + random.cc + transpose.cc +) + +if (GTEST_FOUND) + file (GLOB TEST_SOURCES test/*) + add_executable (utils_test ${TEST_SOURCES}) + + target_link_libraries (utils_test + utils + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ) + + add_test (utils_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/utils_test) +endif (GTEST_FOUND) \ No newline at end of file diff --git a/lc0/src/utils/hashcat_test.cc b/lc0/src/utils/test/hashcat_test.cc similarity index 100% rename from lc0/src/utils/hashcat_test.cc rename to lc0/src/utils/test/hashcat_test.cc diff --git a/lc0/src/utils/transpose.cc b/lc0/src/utils/transpose.cc index b5548b297..5b4206f33 100644 --- a/lc0/src/utils/transpose.cc +++ b/lc0/src/utils/transpose.cc @@ -26,7 +26,7 @@ void TransposeTensor(const std::vector& dims, std::vector order, } std::vector cur_idx(dims.size()); for (int _ = 0; _ < from.size(); ++_) { - size_t from_idx = 0; + int from_idx = 0; for (int i : order) { from_idx *= dims[i]; from_idx += cur_idx[i];