nixpkgs/pkgs/games/katago/default.nix

113 lines
2.4 KiB
Nix
Raw Normal View History

2020-03-08 23:36:58 +00:00
{ stdenv
, gcc8Stdenv
, boost
, cmake
2021-01-14 15:41:01 +00:00
, cudatoolkit
, cudnn
, eigen
2020-03-08 23:36:58 +00:00
, fetchFromGitHub
2020-05-12 16:03:33 +00:00
, fetchpatch
2021-01-14 15:41:01 +00:00
, gperftools
, lib
, libzip
, makeWrapper
, mesa
, ocl-icd
, opencl-headers
, openssl
, writeShellScriptBin
, enableAVX2 ? stdenv.hostPlatform.avx2Support
2020-08-26 15:34:30 +00:00
, enableBigBoards ? false
, enableCuda ? false
2021-01-14 15:41:01 +00:00
, enableContrib ? false
2020-08-26 15:34:30 +00:00
, enableGPU ? true
, enableTcmalloc ? true
}:
2020-03-08 23:36:58 +00:00
2020-08-26 15:34:30 +00:00
assert !enableGPU -> (
!enableCuda);
2020-08-23 21:00:52 +00:00
2020-03-08 23:36:58 +00:00
let
2020-08-26 15:34:30 +00:00
env = if enableCuda
2020-03-08 23:36:58 +00:00
then gcc8Stdenv
else stdenv;
in env.mkDerivation rec {
pname = "katago";
2021-01-14 15:41:01 +00:00
version = "1.8.0";
githash = "8ffda1fe05c69c67342365013b11225d443445e8";
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}";
2021-01-14 15:41:01 +00:00
sha256 = "18r75xjj6vv2gbl92k9aa5bd0cxf09zl1vxlji148y0xbvgv6p8c";
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
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (!enableGPU) [
2020-08-23 21:00:52 +00:00
eigen
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && enableCuda) [
2020-03-08 23:36:58 +00:00
cudnn
mesa.drivers
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && !enableCuda) [
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 = [
"-DNO_GIT_REVISION=ON"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (!enableGPU) [
2020-08-23 21:00:52 +00:00
"-DUSE_BACKEND=EIGEN"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableAVX2 [
2020-08-23 21:00:52 +00:00
"-DUSE_AVX2=ON"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && enableCuda) [
2020-03-08 23:36:58 +00:00
"-DUSE_BACKEND=CUDA"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && !enableCuda) [
2020-03-08 23:36:58 +00:00
"-DUSE_BACKEND=OPENCL"
2021-01-14 15:41:01 +00:00
] ++ lib.optionals enableContrib [
"-DBUILD_DISTRIBUTED=1"
"-DNO_GIT_REVISION=OFF"
"-DGIT_EXECUTABLE=${fakegit}/bin/git"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableTcmalloc [
2020-03-08 23:36:58 +00:00
"-DUSE_TCMALLOC=ON"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableBigBoards [
"-DUSE_BIGGER_BOARDS_EXPENSIVE=ON"
2020-03-08 23:36:58 +00:00
];
preConfigure = ''
cd cpp/
2020-08-26 15:34:30 +00:00
'' + lib.optionalString enableCuda ''
2020-03-08 23:36:58 +00:00
export CUDA_PATH="${cudatoolkit}"
export EXTRA_LDFLAGS="-L/run/opengl-driver/lib"
'';
installPhase = ''
mkdir -p $out/bin; cp katago $out/bin;
2020-08-26 15:34:30 +00:00
'' + lib.optionalString enableCuda ''
2020-03-08 23:36:58 +00:00
wrapProgram $out/bin/katago \
--prefix LD_LIBRARY_PATH : "/run/opengl-driver/lib"
'';
meta = with lib; {
2020-03-08 23:36:58 +00:00
description = "Go engine modeled after AlphaGo Zero";
homepage = "https://github.com/lightvector/katago";
license = licenses.mit;
maintainers = [ maintainers.omnipotententity ];
platforms = [ "x86_64-linux" ];
};
}