···1111, fetchurl
1212, fontconfig
1313, freetype
1414-, gcc
1414+, gcc # :: String
1515, gdk-pixbuf
1616, glib
1717, glibc
···2222, perl
2323, python3
2424, requireFile
2525-, stdenv
2525+, backendStdenv # E.g. gcc11Stdenv, set in extension.nix
2626, unixODBC
2727, xorg
2828, zlib
2929}:
30303131-stdenv.mkDerivation rec {
3131+backendStdenv.mkDerivation rec {
3232 pname = "cudatoolkit";
3333 inherit version runPatches;
3434···146146147147 # Fix builds with newer glibc version
148148 sed -i "1 i#define _BITS_FLOATN_H" "$out/include/host_defines.h"
149149-150150- # Ensure that cmake can find CUDA.
149149+ '' +
150150+ # Point NVCC at a compatible compiler
151151+ # FIXME: redist cuda_nvcc copy-pastes this code
152152+ # Refer to comments in the overrides for cuda_nvcc for explanation
153153+ # CUDA_TOOLKIT_ROOT_DIR is legacy,
154154+ # Cf. https://cmake.org/cmake/help/latest/module/FindCUDA.html#input-variables
155155+ ''
151156 mkdir -p $out/nix-support
152152- echo "cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'" >> $out/nix-support/setup-hook
153153-154154- # Set the host compiler to be used by nvcc.
155155- # FIXME: redist cuda_nvcc copy-pastes this code
156156-157157- # For CMake-based projects:
158158- # https://cmake.org/cmake/help/latest/module/FindCUDA.html#input-variables
159159- # https://cmake.org/cmake/help/latest/envvar/CUDAHOSTCXX.html
160160- # https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_HOST_COMPILER.html
161161-162162- # For non-CMake projects:
163163- # FIXME: results in "incompatible redefinition" warnings ...but we keep
164164- # both this and cmake variables until we come up with a more general
165165- # solution
166166- # https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#compiler-bindir-directory-ccbin
167167-168157 cat <<EOF >> $out/nix-support/setup-hook
169169-170170- cmakeFlags+=' -DCUDA_HOST_COMPILER=${gcc}/bin'
171171- cmakeFlags+=' -DCMAKE_CUDA_HOST_COMPILER=${gcc}/bin'
158158+ cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'
159159+ cmakeFlags+=' -DCUDA_HOST_COMPILER=${backendStdenv.cc}/bin'
160160+ cmakeFlags+=' -DCMAKE_CUDA_HOST_COMPILER=${backendStdenv.cc}/bin'
172161 if [ -z "\''${CUDAHOSTCXX-}" ]; then
173173- export CUDAHOSTCXX=${gcc}/bin;
162162+ export CUDAHOSTCXX=${backendStdenv.cc}/bin;
174163 fi
175175-176176- export NVCC_PREPEND_FLAGS+=' --compiler-bindir=${gcc}/bin'
164164+ export NVCC_PREPEND_FLAGS+=' --compiler-bindir=${backendStdenv.cc}/bin'
177165 EOF
178178-179166180167 # Move some libraries to the lib output so that programs that
181168 # depend on them don't pull in this entire monstrosity.
···212199213200 # The path to libstdc++ and such
214201 #
215215- # NB:
216216- # 1. "gcc" (gcc-wrapper) here is what's exposed as cudaPackages.cudatoolkit.cc
217217- # 2. "gcc.cc" is the unwrapped gcc
218218- # 3. "gcc.cc.lib" is one of its outputs
219219- "${gcc.cc.lib}/lib64"
202202+ # `backendStdenv` is the cuda-compatible toolchain that we pick in
203203+ # extension.nix; we hand it to NVCC to use as a back-end, and we link
204204+ # cudatoolkit's binaries against its libstdc++
205205+ "${backendStdenv.cc.cc.lib}/lib64"
220206221207 "$out/jre/lib/amd64/jli"
222208 "$out/lib64"
···286272 popd
287273 '';
288274 passthru = {
289289- cc = gcc;
275275+ cc = backendStdenv.cc;
290276 majorMinorVersion = lib.versions.majorMinor version;
291277 majorVersion = lib.versions.majorMinor version;
292278 };
···11{ lib
22-, stdenv
22+, backendStdenv
33, fetchurl
44, autoPatchelfHook
55, autoAddOpenGLRunpathHook
···1111let
1212 arch = "linux-x86_64";
1313in
1414-stdenv.mkDerivation {
1414+backendStdenv.mkDerivation {
1515 inherit pname;
1616 inherit (attrs) version;
1717···3333 # autoPatchelfHook will search for a libstdc++ and we're giving it a
3434 # "compatible" libstdc++ from the same toolchain that NVCC uses.
3535 #
3636- # E.g. it might happen that stdenv=gcc12Stdenv, but we build against cuda11
3737- # that only "supports" gcc11. Linking against gcc12's libraries we might
3838- # sometimes actually sometimes encounter dynamic linkage errors at runtime
3936 # NB: We don't actually know if this is the right thing to do
4040- cudatoolkit.cc.cc.lib
3737+ backendStdenv.cc.cc.lib
4138 ];
42394340 dontBuild = true;
···5148 runHook postInstall
5249 '';
53505454- passthru.stdenv = stdenv;
5151+ passthru.stdenv = backendStdenv;
55525653 meta = {
5754 description = attrs.name;
···3232}:
33333434let
3535+ originalStdenv = stdenv;
3636+in
3737+let
3838+ # Tensorflow looks at many toolchain-related variables which may diverge.
3939+ #
4040+ # Toolchain for cuda-enabled builds.
4141+ # We want to achieve two things:
4242+ # 1. NVCC should use a compatible back-end (e.g. gcc11 for cuda11)
4343+ # 2. Normal C++ files should be compiled with the same toolchain,
4444+ # to avoid potential weird dynamic linkage errors at runtime.
4545+ # This may not be necessary though
4646+ #
4747+ # Toolchain for Darwin:
4848+ # clang 7 fails to emit a symbol for
4949+ # __ZN4llvm11SmallPtrSetIPKNS_10AllocaInstELj8EED1Ev in any of the
5050+ # translation units, so the build fails at link time
5151+ stdenv =
5252+ if cudaSupport then cudaPackages.backendStdenv
5353+ else if originalStdenv.isDarwin then llvmPackages_11.stdenv
5454+ else originalStdenv;
3555 inherit (cudaPackages) cudatoolkit cudnn nccl;
3656in
3757···4464let
4565 withTensorboard = (pythonOlder "3.6") || tensorboardSupport;
46666767+ # FIXME: migrate to redist cudaPackages
4768 cudatoolkit_joined = symlinkJoin {
4869 name = "${cudatoolkit.name}-merged";
4970 paths = [
···5677 ];
5778 };
58798080+ # Tensorflow expects bintools at hard-coded paths, e.g. /usr/bin/ar
8181+ # The only way to overcome that is to set GCC_HOST_COMPILER_PREFIX,
8282+ # but that path must contain cc as well, so we merge them
5983 cudatoolkit_cc_joined = symlinkJoin {
6060- name = "${cudatoolkit.cc.name}-merged";
8484+ name = "${stdenv.cc.name}-merged";
6185 paths = [
6262- cudatoolkit.cc
8686+ stdenv.cc
6387 binutils.bintools # for ar, dwp, nm, objcopy, objdump, strip
6488 ];
6589 };
···175199 '';
176200 }) else _bazel-build;
177201178178- _bazel-build = (buildBazelPackage.override (lib.optionalAttrs stdenv.isDarwin {
179179- # clang 7 fails to emit a symbol for
180180- # __ZN4llvm11SmallPtrSetIPKNS_10AllocaInstELj8EED1Ev in any of the
181181- # translation units, so the build fails at link time
182182- stdenv = llvmPackages_11.stdenv;
183183- })) {
202202+ _bazel-build = buildBazelPackage.override { inherit stdenv; } {
184203 name = "${pname}-${version}";
185204 bazel = bazel_5;
186205···211230 flatbuffers-core
212231 giflib
213232 grpc
214214- icu
233233+ # Necessary to fix the "`GLIBCXX_3.4.30' not found" error
234234+ (icu.override { inherit stdenv; })
215235 jsoncpp
216236 libjpeg_turbo
217237 libpng
218238 lmdb-core
219219- pybind11
239239+ (pybind11.overridePythonAttrs (_: { inherit stdenv; }))
220240 snappy
221241 sqlite
222242 ] ++ lib.optionals cudaSupport [
···301321302322 TF_NEED_CUDA = tfFeature cudaSupport;
303323 TF_CUDA_PATHS = lib.optionalString cudaSupport "${cudatoolkit_joined},${cudnn},${nccl}";
304304- GCC_HOST_COMPILER_PREFIX = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin";
305305- GCC_HOST_COMPILER_PATH = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin/gcc";
306324 TF_CUDA_COMPUTE_CAPABILITIES = lib.concatStringsSep "," cudaCapabilities;
325325+326326+ # Needed even when we override stdenv: e.g. for ar
327327+ GCC_HOST_COMPILER_PREFIX = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin";
328328+ GCC_HOST_COMPILER_PATH = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin/cc";
307329308330 postPatch = ''
309331 # bazel 3.3 should work just as well as bazel 3.1