1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
{ lib
, backendStdenv
, requireFile
, autoPatchelfHook
, autoAddOpenGLRunpathHook
, cudaVersion
, cudatoolkit
, cudnn
}:
{ fullVersion
, fileVersionCudnn ? null
, tarball
, sha256
, supportedCudaVersions ? [ ]
}:
assert fileVersionCudnn == null || lib.assertMsg (lib.strings.versionAtLeast cudnn.version fileVersionCudnn)
"This version of TensorRT requires at least cuDNN ${fileVersionCudnn} (current version is ${cudnn.version})";
backendStdenv.mkDerivation rec {
pname = "cudatoolkit-${cudatoolkit.majorVersion}-tensorrt";
version = fullVersion;
src = requireFile rec {
name = tarball;
inherit sha256;
message = ''
To use the TensorRT derivation, you must join the NVIDIA Developer Program and
download the ${version} Linux x86_64 TAR package for CUDA ${cudaVersion} from
${meta.homepage}.
Once you have downloaded the file, add it to the store with the following
command, and try building this derivation again.
$ nix-store --add-fixed sha256 ${name}
'';
};
outputs = [ "out" "dev" ];
nativeBuildInputs = [
autoPatchelfHook
autoAddOpenGLRunpathHook
];
# Used by autoPatchelfHook
buildInputs = [
backendStdenv.cc.cc.lib # libstdc++
cudatoolkit
cudnn
];
sourceRoot = "TensorRT-${version}";
installPhase = ''
install --directory "$dev" "$out"
mv include "$dev"
mv targets/x86_64-linux-gnu/lib "$out"
install -D --target-directory="$out/bin" targets/x86_64-linux-gnu/bin/trtexec
'';
# Tell autoPatchelf about runtime dependencies.
# (postFixup phase is run before autoPatchelfHook.)
postFixup =
let
mostOfVersion = builtins.concatStringsSep "."
(lib.take 3 (lib.versions.splitVersion version));
in
''
echo 'Patching RPATH of libnvinfer libs'
patchelf --debug --add-needed libnvinfer.so \
"$out/lib/libnvinfer.so.${mostOfVersion}" \
"$out/lib/libnvinfer_plugin.so.${mostOfVersion}" \
"$out/lib/libnvinfer_builder_resource.so.${mostOfVersion}"
'';
passthru.stdenv = backendStdenv;
meta = with lib; {
# Check that the cudatoolkit version satisfies our min/max constraints (both
# inclusive). We mark the package as broken if it fails to satisfies the
# official version constraints (as recorded in default.nix). In some cases
# you _may_ be able to smudge version constraints, just know that you're
# embarking into unknown and unsupported territory when doing so.
broken = !(elem cudaVersion supportedCudaVersions);
description = "TensorRT: a high-performance deep learning interface";
homepage = "https://developer.nvidia.com/tensorrt";
license = licenses.unfree;
platforms = [ "x86_64-linux" ];
maintainers = with maintainers; [ aidalgol ];
};
}
|