33 backendStdenv ,
44 buildRedist ,
55 cuda_cudart ,
6- cudnn ,
7- cuda_nvrtc ,
6+ cudaAtLeast ,
7+ cudaMajorMinorVersion ,
88 lib ,
99 libcudla , # only for Jetson
1010 patchelf ,
1111} :
1212let
13- inherit ( _cuda . lib ) majorMinorPatch ;
14- inherit ( backendStdenv ) hasJetsonCudaCapability ;
15- inherit ( lib . attrsets ) getLib ;
13+ inherit ( backendStdenv ) cudaCapabilities hostRedistSystem ;
1614 inherit ( lib . lists ) optionals ;
1715 inherit ( lib . strings ) concatStringsSep ;
1816in
1917buildRedist (
2018 finalAttrs :
2119 let
22- majorMinorPatchVersion = majorMinorPatch finalAttrs . version ;
2320 majorVersion = lib . versions . major finalAttrs . version ;
21+
22+ tensorrtAtLeast = lib . versionAtLeast finalAttrs . version ;
23+ tensorrtOlder = lib . versionOlder finalAttrs . version ;
24+
25+ # Create variables and use logical OR to allow short-circuiting.
26+ tensorrtAtLeast105 = tensorrtAtLeast "10.5.0" ;
27+ tensorrtAtLeast100 = tensorrtAtLeast105 || tensorrtAtLeast "10.0.0" ;
28+
29+ allCCNewerThan75 = lib . all ( lib . flip lib . versionAtLeast "7.5" ) cudaCapabilities ;
30+ allCCNewerThan70 = allCCNewerThan75 || lib . all ( lib . flip lib . versionAtLeast "7.0" ) cudaCapabilities ;
31+
32+ cudaCapabilitiesJSON = builtins . toJSON cudaCapabilities ;
2433 in
2534 {
2635 redistName = "tensorrt" ;
@@ -32,7 +41,12 @@ buildRedist (
3241 "dev"
3342 "include"
3443 "lib"
44+ ]
45+ # From 10.14.1, TensorRT samples are distributed through the TensorRT GitHub repository.
46+ ++ optionals ( tensorrtOlder "10.14.1" ) [
3547 "samples"
48+ ]
49+ ++ [
3650 "static"
3751 # "stubs" removed in postInstall
3852 ] ;
@@ -42,8 +56,6 @@ buildRedist (
4256 nativeBuildInputs = [ patchelf ] ;
4357
4458 buildInputs = [
45- ( getLib cudnn )
46- ( getLib cuda_nvrtc )
4759 cuda_cudart
4860 ]
4961 ++ optionals libcudla . meta . available [ libcudla ] ;
@@ -62,38 +74,44 @@ buildRedist (
6274 ''
6375 for dir in bin lib; do
6476 [[ -L "$dir" ]] || continue
65- nixLog "replacing symlink $NIX_BUILD_TOP/$sourceRoot/$ dir with $NIX_BUILD_TOP/$sourceRoot /targets/${ targetString } /$dir"
66- rm --verbose "$NIX_BUILD_TOP/$sourceRoot /$dir"
67- mv --verbose --no-clobber "$NIX_BUILD_TOP/$sourceRoot/ targets/${ targetString } /$dir" "$NIX_BUILD_TOP/$sourceRoot /$dir"
77+ nixLog "replacing symlink $PWD/$ dir with $PWD /targets/${ targetString } /$dir"
78+ rm --verbose "$PWD /$dir"
79+ mv --verbose --no-clobber "$PWD/ targets/${ targetString } /$dir" "$PWD /$dir"
6880 done
6981 unset -v dir
7082 ''
7183 # Remove symlinks if they exist
7284 + ''
7385 for dir in include samples; do
74- if [[ -L "$NIX_BUILD_TOP/$sourceRoot /targets/${ targetString } /$dir" ]]; then
75- nixLog "removing symlink $NIX_BUILD_TOP/$sourceRoot /targets/${ targetString } /$dir"
76- rm --verbose "$NIX_BUILD_TOP/$sourceRoot /targets/${ targetString } /$dir"
86+ if [[ -L "$PWD /targets/${ targetString } /$dir" ]]; then
87+ nixLog "removing symlink $PWD /targets/${ targetString } /$dir"
88+ rm --verbose "$PWD /targets/${ targetString } /$dir"
7789 fi
7890 done
7991 unset -v dir
8092
81- if [[ -d "$NIX_BUILD_TOP/$sourceRoot /targets" ]]; then
93+ if [[ -d "$PWD /targets" ]]; then
8294 nixLog "removing targets directory"
83- rm --recursive --verbose "$NIX_BUILD_TOP/$sourceRoot /targets" || {
84- nixErrorLog "could not delete $NIX_BUILD_TOP/$sourceRoot/ targets: $(ls -laR "$NIX_BUILD_TOP/$sourceRoot /targets")"
95+ rm --recursive --verbose "$PWD /targets" || {
96+ nixErrorLog "could not delete $PWD/ targets: $(ls -laR "$PWD /targets")"
8597 exit 1
8698 }
8799 fi
88100 '' ;
89101
90- autoPatchelfIgnoreMissingDeps = optionals hasJetsonCudaCapability [
91- "libnvdla_compiler.so"
92- ] ;
102+ autoPatchelfIgnoreMissingDeps =
103+ optionals ( hostRedistSystem == "linux-aarch64" ) [
104+ "libnvdla_compiler.so"
105+ ]
106+ ++ optionals ( tensorrtAtLeast "10.13.3" ) [
107+ "libcuda.so.1"
108+ ] ;
93109
94110 # Create a symlink for the Onnx header files in include/onnx
95111 # NOTE(@connorbaker): This is shared with the tensorrt-oss package, with the `out` output swapped with `include`.
96112 # When updating one, check if the other should be updated.
113+ # TODO(@connorbaker): It seems like recent versions of TensorRT have separate libs for separate capabilities;
114+ # we should remove libraries older than those necessary to support requested capabilities.
97115 postInstall = ''
98116 mkdir "'' ${!outputInclude:?}/include/onnx"
99117 pushd "'' ${!outputInclude:?}/include" >/dev/null
@@ -102,6 +120,7 @@ buildRedist (
102120 popd >/dev/null
103121 ''
104122 # Move the python directory, which contains header files, to the include output.
123+ # NOTE: Python wheels should be built from source using the TensorRT GitHub repo.
105124 + ''
106125 nixLog "moving python directory to include output"
107126 moveToOutput python "'' ${!outputInclude:?}"
@@ -115,10 +134,11 @@ buildRedist (
115134 ''
116135 # Remove the Windows library used for cross-compilation if it exists.
117136 + ''
118- if [[ -e "'' ${!outputLib:?}/lib/libnvinfer_builder_resource_win.so.${ majorMinorPatchVersion } " ]]; then
119- nixLog "removing Windows library"
120- rm --verbose "'' ${!outputLib:?}/lib/libnvinfer_builder_resource_win.so.${ majorMinorPatchVersion } "
121- fi
137+ nixLog "removing any Windows libraries"
138+ for winLib in "'' ${!outputLib:?}/lib/"*_win*; do
139+ rm --verbose "$winLib"
140+ done
141+ unset -v winLib
122142 ''
123143 # Remove the stub libraries.
124144 + ''
@@ -137,10 +157,35 @@ buildRedist (
137157 --add-needed libnvinfer_plugin.so.${ majorVersion }
138158 '' ;
139159
140- passthru = {
141- # The CUDNN used with TensorRT.
142- inherit cudnn ;
143- } ;
160+ # NOTE: Like cuDNN, NVIDIA offers forward compatibility within a major releases of CUDA.
161+ platformAssertions = [
162+ {
163+ message =
164+ "tensorrt releases since 10.0.0 (found ${ finalAttrs . version } )"
165+ + " support CUDA compute capabilities 7.0 and newer (found ${ cudaCapabilitiesJSON } )" ;
166+ assertion = tensorrtAtLeast100 -> allCCNewerThan70 ;
167+ }
168+ {
169+ message =
170+ "tensorrt releases since 10.0.0 (found ${ finalAttrs . version } )"
171+ + " support only CUDA compute capability 8.7 (Jetson Orin) for pre-Thor Jetson devices"
172+ + " (found ${ cudaCapabilitiesJSON } )" ;
173+ assertion =
174+ tensorrtAtLeast100 && hostRedistSystem == "linux-aarch64" -> cudaCapabilities == [ "8.7" ] ;
175+ }
176+ {
177+ message =
178+ "tensorrt releases since 10.0.0 (found ${ finalAttrs . version } )"
179+ + " support CUDA 12.4 and newer for pre-Thor Jetson devices (found ${ cudaMajorMinorVersion } )" ;
180+ assertion = tensorrtAtLeast100 && hostRedistSystem == "linux-aarch64" -> cudaAtLeast "12.4" ;
181+ }
182+ {
183+ message =
184+ "tensorrt releases since 10.5.0 (found ${ finalAttrs . version } )"
185+ + " support CUDA compute capabilities 7.5 and newer (found ${ cudaCapabilitiesJSON } )" ;
186+ assertion = tensorrtAtLeast105 -> allCCNewerThan75 ;
187+ }
188+ ] ;
144189
145190 meta = {
146191 description = "SDK that facilitates high-performance machine learning inference" ;
0 commit comments