2021-02-15 17:19:00 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
cmake,
|
|
|
|
libtorch-bin,
|
|
|
|
linkFarm,
|
|
|
|
symlinkJoin,
|
2024-12-10 20:26:33 +01:00
|
|
|
|
2021-02-15 17:19:00 +01:00
|
|
|
cudaSupport,
|
2022-04-03 11:19:04 +02:00
|
|
|
cudaPackages ? { },
|
2021-02-15 17:19:00 +01:00
|
|
|
}:
|
|
|
|
let
|
2022-04-03 11:19:04 +02:00
|
|
|
inherit (cudaPackages) cudatoolkit cudnn;
|
|
|
|
|
2021-02-15 17:19:00 +01:00
|
|
|
cudatoolkit_joined = symlinkJoin {
|
|
|
|
name = "${cudatoolkit.name}-unsplit";
|
|
|
|
paths = [
|
|
|
|
cudatoolkit.out
|
|
|
|
cudatoolkit.lib
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# We do not have access to /run/opengl-driver/lib in the sandbox,
|
|
|
|
# so use a stub instead.
|
|
|
|
cudaStub = linkFarm "cuda-stub" [
|
|
|
|
{
|
|
|
|
name = "libcuda.so.1";
|
|
|
|
path = "${cudatoolkit}/lib/stubs/libcuda.so";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
2020-08-27 18:42:38 +02:00
|
|
|
pname = "libtorch-test";
|
|
|
|
version = libtorch-bin.version;
|
|
|
|
|
2024-06-17 13:30:05 -04:00
|
|
|
src = lib.fileset.toSource {
|
|
|
|
root = ./.;
|
|
|
|
fileset = lib.fileset.unions [
|
|
|
|
./CMakeLists.txt
|
|
|
|
./test.cpp
|
|
|
|
];
|
|
|
|
};
|
2020-08-27 18:42:38 +02:00
|
|
|
|
|
|
|
nativeBuildInputs = [ cmake ];
|
|
|
|
|
2021-02-15 17:19:00 +01:00
|
|
|
buildInputs = [ libtorch-bin ] ++ lib.optionals cudaSupport [ cudnn ];
|
|
|
|
|
|
|
|
cmakeFlags = lib.optionals cudaSupport [ "-DCUDA_TOOLKIT_ROOT_DIR=${cudatoolkit_joined}" ];
|
2020-08-27 18:42:38 +02:00
|
|
|
|
2020-11-07 13:50:23 +01:00
|
|
|
doCheck = true;
|
|
|
|
|
2020-08-27 18:42:38 +02:00
|
|
|
installPhase = ''
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
2021-05-01 11:41:47 +02:00
|
|
|
checkPhase =
|
|
|
|
lib.optionalString cudaSupport ''
|
2021-02-15 17:19:00 +01:00
|
|
|
LD_LIBRARY_PATH=${cudaStub}''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH \
|
2021-05-01 11:41:47 +02:00
|
|
|
''
|
|
|
|
+ ''
|
|
|
|
./test
|
2020-08-27 18:42:38 +02:00
|
|
|
'';
|
|
|
|
}
|