1 { stdenv, boost, cmake, config, cudaPackages, eigen, fetchFromGitHub, gperftools
2 , lib, libzip, makeWrapper, ocl-icd, opencl-headers, openssl
3 , writeShellScriptBin, enableAVX2 ? stdenv.hostPlatform.avx2Support
4 , backend ? if config.cudaSupport then "cuda" else "opencl"
5 , enableBigBoards ? false, enableContrib ? false, enableTcmalloc ? true
6 , enableTrtPlanCache ? false }:
8 assert lib.assertOneOf "backend" backend [ "opencl" "cuda" "tensorrt" "eigen" ];
10 # N.b. older versions of cuda toolkit (e.g. 10) do not support newer versions
11 # of gcc. If you need to use cuda10, please override stdenv with gcc8Stdenv
13 githash = "cd0ed6c0712088ddb901be68189ba7fa1439a9e7";
14 fakegit = writeShellScriptBin "git" "echo ${githash}";
15 in stdenv.mkDerivation rec {
19 src = fetchFromGitHub {
20 owner = "lightvector";
23 sha256 = "sha256-hZc8LlOxnVqJqyqOSIWKv3550QOaGr79xgqsAQ8B8SM=";
26 nativeBuildInputs = [ cmake makeWrapper ];
28 buildInputs = [ libzip boost ] ++ lib.optionals (backend == "eigen") [ eigen ]
29 ++ lib.optionals (backend == "cuda") [
31 cudaPackages.cudatoolkit
32 ] ++ lib.optionals (backend == "tensorrt") [
33 cudaPackages.cudatoolkit
35 ] ++ lib.optionals (backend == "opencl") [ opencl-headers ocl-icd ]
36 ++ lib.optionals enableContrib [ openssl ]
37 ++ lib.optionals enableTcmalloc [ gperftools ];
40 (lib.cmakeFeature "USE_BACKEND" (lib.toUpper backend))
41 (lib.cmakeBool "USE_AVX2" enableAVX2)
42 (lib.cmakeBool "USE_TCMALLOC" enableTcmalloc)
43 (lib.cmakeBool "USE_BIGGER_BOARDS_EXPENSIVE" enableBigBoards)
44 (lib.cmakeBool "USE_CACHE_TENSORRT_PLAN" enableTrtPlanCache)
45 (lib.cmakeBool "NO_GIT_REVISION" (!enableContrib))
46 ] ++ lib.optionals enableContrib [
47 (lib.cmakeBool "BUILD_DISTRIBUTED" true)
48 (lib.cmakeFeature "GIT_EXECUTABLE" "${fakegit}/bin/git")
53 '' + lib.optionalString (backend == "cuda" || backend == "tensorrt") ''
54 export CUDA_PATH="${cudaPackages.cudatoolkit}"
55 export EXTRA_LDFLAGS="-L/run/opengl-driver/lib"
60 mkdir -p $out/bin; cp katago $out/bin;
61 '' + lib.optionalString (backend == "cuda" || backend == "tensorrt") ''
62 wrapProgram $out/bin/katago \
63 --prefix LD_LIBRARY_PATH : "/run/opengl-driver/lib"
69 description = "Go engine modeled after AlphaGo Zero";
70 mainProgram = "katago";
71 homepage = "https://github.com/lightvector/katago";
72 license = licenses.mit;
73 maintainers = [ maintainers.omnipotententity ];
74 platforms = [ "x86_64-linux" ];