summary refs log tree commit diff
path: root/pkgs/development/compilers/cudatoolkit/common.nix
diff options
context:
space:
mode:
authorSomeone Serge <sergei.kozlukov@aalto.fi>2023-02-25 16:32:55 +0200
committerSomeone Serge <sergei.kozlukov@aalto.fi>2023-03-04 00:59:20 +0200
commit94bbbb047180b59ef6f25f4d89e7a12b5fc6db63 (patch)
tree8c1dc56c0104ae7157d53050bc2f19135072fdae /pkgs/development/compilers/cudatoolkit/common.nix
parent2fa2627ca9ce1ca0e622632df289a8655e6feac2 (diff)
downloadnixpkgs-94bbbb047180b59ef6f25f4d89e7a12b5fc6db63.tar
nixpkgs-94bbbb047180b59ef6f25f4d89e7a12b5fc6db63.tar.gz
nixpkgs-94bbbb047180b59ef6f25f4d89e7a12b5fc6db63.tar.bz2
nixpkgs-94bbbb047180b59ef6f25f4d89e7a12b5fc6db63.tar.lz
nixpkgs-94bbbb047180b59ef6f25f4d89e7a12b5fc6db63.tar.xz
nixpkgs-94bbbb047180b59ef6f25f4d89e7a12b5fc6db63.tar.zst
nixpkgs-94bbbb047180b59ef6f25f4d89e7a12b5fc6db63.zip
cudaPackages: point nvcc at a compatible -ccbin
This is a hot-fix to un-break cuda-enabled packages (like tensorflow,
jaxlib, faiss, opencv, ...) after the gcc11->gcc12 bump. We should
probably build the whole downstream packages with a compatible stdenv
(such as gcc11Stdenv for cudaPackages_11), but just pointing nvcc at the
right compiler seems to do the trick

We already used this hack for non-redist cudatoolkit. Now we use it more
consistently.

This commit also re-links cuda packages against libstdc++ from the same
"compatible" gcc, rather than the current stdenv. We didn't test if this
is necessary -> need to revise in further PRs.

NOTE: long-term we should make it possible to override -ccbin and use
e.g. clang
Diffstat (limited to 'pkgs/development/compilers/cudatoolkit/common.nix')
-rw-r--r--pkgs/development/compilers/cudatoolkit/common.nix40
1 files changed, 33 insertions, 7 deletions
diff --git a/pkgs/development/compilers/cudatoolkit/common.nix b/pkgs/development/compilers/cudatoolkit/common.nix
index e986ae2dc14..a94f6fbdaf7 100644
--- a/pkgs/development/compilers/cudatoolkit/common.nix
+++ b/pkgs/development/compilers/cudatoolkit/common.nix
@@ -151,9 +151,31 @@ stdenv.mkDerivation rec {
     mkdir -p $out/nix-support
     echo "cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'" >> $out/nix-support/setup-hook
 
-    # Set the host compiler to be used by nvcc for CMake-based projects:
+    # Set the host compiler to be used by nvcc.
+    # FIXME: redist cuda_nvcc copy-pastes this code
+
+    # For CMake-based projects:
     # https://cmake.org/cmake/help/latest/module/FindCUDA.html#input-variables
-    echo "cmakeFlags+=' -DCUDA_HOST_COMPILER=${gcc}/bin'" >> $out/nix-support/setup-hook
+    # https://cmake.org/cmake/help/latest/envvar/CUDAHOSTCXX.html
+    # https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_HOST_COMPILER.html
+
+    # For non-CMake projects:
+    # FIXME: results in "incompatible redefinition" warnings ...but we keep
+    # both this and cmake variables until we come up with a more general
+    # solution
+    # https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#compiler-bindir-directory-ccbin
+
+    cat <<EOF >> $out/nix-support/setup-hook
+
+    cmakeFlags+=' -DCUDA_HOST_COMPILER=${gcc}/bin'
+    cmakeFlags+=' -DCMAKE_CUDA_HOST_COMPILER=${gcc}/bin'
+    if [ -z "\''${CUDAHOSTCXX-}" ]; then
+      export CUDAHOSTCXX=${gcc}/bin;
+    fi
+
+    export NVCC_PREPEND_FLAGS+=' --compiler-bindir=${gcc}/bin'
+    EOF
+
 
     # Move some libraries to the lib output so that programs that
     # depend on them don't pull in this entire monstrosity.
@@ -167,10 +189,6 @@ stdenv.mkDerivation rec {
       mv $out/extras/CUPTI/lib64/libcupti* $out/lib
     ''}
 
-    # Set compiler for NVCC.
-    wrapProgram $out/bin/nvcc \
-      --prefix PATH : ${gcc}/bin
-
     # nvprof do not find any program to profile if LD_LIBRARY_PATH is not set
     wrapProgram $out/bin/nvprof \
       --prefix LD_LIBRARY_PATH : $out/lib
@@ -191,7 +209,15 @@ stdenv.mkDerivation rec {
   preFixup =
     let rpath = lib.concatStringsSep ":" [
       (lib.makeLibraryPath (runtimeDependencies ++ [ "$lib" "$out" "$out/nvvm" ]))
-      "${stdenv.cc.cc.lib}/lib64"
+
+      # The path to libstdc++ and such
+      #
+      # NB:
+      # 1. "gcc" (gcc-wrapper) here is what's exposed as cudaPackages.cudatoolkit.cc
+      # 2. "gcc.cc" is the unwrapped gcc
+      # 3. "gcc.cc.lib" is one of its outputs
+      "${gcc.cc.lib}/lib64"
+
       "$out/jre/lib/amd64/jli"
       "$out/lib64"
       "$out/nvvm/lib64"