nixpkgs/pkgs/games/katago/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
2.8 KiB
Nix
Raw Normal View History

2020-03-08 23:36:58 +00:00
{ stdenv
, boost
, cmake
, config
, cudaPackages
2021-01-14 15:41:01 +00:00
, eigen
2020-03-08 23:36:58 +00:00
, fetchFromGitHub
2021-01-14 15:41:01 +00:00
, gperftools
, lib
, libzip
, makeWrapper
, mesa
, ocl-icd
, opencl-headers
, openssl
, writeShellScriptBin
, enableAVX2 ? stdenv.hostPlatform.avx2Support
, backend ? if config.cudaSupport then "cuda" else "opencl"
2020-08-26 15:34:30 +00:00
, enableBigBoards ? false
2021-01-14 15:41:01 +00:00
, enableContrib ? false
, enableTcmalloc ? true
, enableTrtPlanCache ? false
}:
2020-03-08 23:36:58 +00:00
assert lib.assertOneOf "backend" backend [ "opencl" "cuda" "tensorrt" "eigen" ];
2020-08-23 21:00:52 +00:00
2021-12-08 17:53:25 +00:00
# N.b. older versions of cuda toolkit (e.g. 10) do not support newer versions
# of gcc. If you need to use cuda10, please override stdenv with gcc8Stdenv
stdenv.mkDerivation rec {
2020-03-08 23:36:58 +00:00
pname = "katago";
2023-12-28 07:30:52 +00:00
version = "1.14.0";
githash = "c6de1bbda837a0717eaeca46102f7326ed0da0d4";
2020-03-08 23:36:58 +00:00
src = fetchFromGitHub {
owner = "lightvector";
repo = "katago";
2020-08-23 21:00:52 +00:00
rev = "v${version}";
2023-12-28 07:30:52 +00:00
sha256 = "sha256-0WB/weQIJkLXedcOJO7D/N85oXTufvbmyfIp8XdrACg=";
2020-03-08 23:36:58 +00:00
};
2021-01-14 15:41:01 +00:00
fakegit = writeShellScriptBin "git" "echo ${githash}";
2020-03-08 23:36:58 +00:00
nativeBuildInputs = [
cmake
makeWrapper
];
buildInputs = [
libzip
boost
] ++ lib.optionals (backend == "eigen") [
2020-08-23 21:00:52 +00:00
eigen
] ++ lib.optionals (backend == "cuda") [
cudaPackages.cudnn
cudaPackages.cudatoolkit
mesa.drivers
] ++ lib.optionals (backend == "tensorrt") [
cudaPackages.cudatoolkit
cudaPackages.tensorrt
mesa.drivers
] ++ lib.optionals (backend == "opencl") [
2020-03-08 23:36:58 +00:00
opencl-headers
ocl-icd
2021-01-14 15:41:01 +00:00
] ++ lib.optionals enableContrib [
openssl
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableTcmalloc [
2020-03-08 23:36:58 +00:00
gperftools
];
cmakeFlags = [
(lib.cmakeFeature "USE_BACKEND" (lib.toUpper backend))
(lib.cmakeBool "USE_AVX2" enableAVX2)
(lib.cmakeBool "USE_TCMALLOC" enableTcmalloc)
(lib.cmakeBool "USE_BIGGER_BOARDS_EXPENSIVE" enableBigBoards)
(lib.cmakeBool "USE_CACHE_TENSORRT_PLAN" enableTrtPlanCache)
(lib.cmakeBool "NO_GIT_REVISION" (!enableContrib))
2021-01-14 15:41:01 +00:00
] ++ lib.optionals enableContrib [
(lib.cmakeBool "BUILD_DISTRIBUTED" true)
(lib.cmakeFeature "GIT_EXECUTABLE" "${fakegit}/bin/git")
2020-03-08 23:36:58 +00:00
];
preConfigure = ''
cd cpp/
'' + lib.optionalString (backend == "cuda" || backend == "tensorrt") ''
export CUDA_PATH="${cudaPackages.cudatoolkit}"
2020-03-08 23:36:58 +00:00
export EXTRA_LDFLAGS="-L/run/opengl-driver/lib"
'';
installPhase = ''
2021-03-15 14:36:53 +00:00
runHook preInstall
2020-03-08 23:36:58 +00:00
mkdir -p $out/bin; cp katago $out/bin;
'' + lib.optionalString (backend == "cuda" || backend == "tensorrt") ''
2020-03-08 23:36:58 +00:00
wrapProgram $out/bin/katago \
--prefix LD_LIBRARY_PATH : "/run/opengl-driver/lib"
2021-03-15 14:36:53 +00:00
'' + ''
runHook postInstall
2020-03-08 23:36:58 +00:00
'';
meta = with lib; {
2020-03-08 23:36:58 +00:00
description = "Go engine modeled after AlphaGo Zero";
mainProgram = "katago";
2020-03-08 23:36:58 +00:00
homepage = "https://github.com/lightvector/katago";
license = licenses.mit;
maintainers = [ maintainers.omnipotententity ];
platforms = [ "x86_64-linux" ];
};
}