Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pkgs/development/cuda-modules/packages/cuda_nvcc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
cuda_cccl,
lib,
libnvvm,
makeBinaryWrapper,
}:
buildRedist (finalAttrs: {
redistName = "cuda";
Expand All @@ -22,6 +23,10 @@ buildRedist (finalAttrs: {
# The nvcc and cicc binaries contain hard-coded references to /usr
allowFHSReferences = true;

nativeBuildInputs = [
makeBinaryWrapper
];

# Entries here will be in nativeBuildInputs when cuda_nvcc is in nativeBuildInputs
propagatedBuildInputs = [ setupCudaHook ];

Expand Down Expand Up @@ -144,13 +149,19 @@ buildRedist (finalAttrs: {
EOF
''
# Add the dependency on backendStdenv.cc to the nvcc.profile.
# NOTE: NVCC explodes in horrifying fashion if GCC is not on PATH -- it fails even before
# reading nvcc.profile!
+ ''
nixLog "adding backendStdenv.cc to nvcc.profile"
nixLog "setting compiler-bindir to backendStdenv.cc in nvcc.profile"
cat << EOF >> "''${!outputBin:?}/bin/nvcc.profile"

# Fix a compatible backend compiler
PATH += "${backendStdenv.cc}/bin":
compiler-bindir = ${backendStdenv.cc}/bin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah damn this is off by 1 again: nvcc here is hostTarget, and cc - buildHost

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH, we never made cross actually work, might as well postpone the larping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc is unspliced but backendStdenv is spliced and from pkgsHostTarget (the default package set drawn from by callPackage) so I would hope cc is also from hostTarget.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nooo that's the thing about stdenvs, they're always offset by -1:

$ nix eval -f "<nixpkgs>" --argstr crossSystem aarch64-linux stdenv.cc.name
"aarch64-unknown-linux-gnu-gcc-wrapper-14.3.0"

But maybe we should merge regardless and fix whenever

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah screw it

EOF

nixLog "wrapping nvcc to add backendStdenv.cc to its PATH"
wrapProgramBinary \
"''${!outputBin:?}/bin/nvcc" \
--prefix PATH : ${lib.makeBinPath [ backendStdenv.cc ]}
''
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ makeSetupHook {

substitutions.setupCudaHook = placeholder "out";

# Point NVCC at a compatible compiler
substitutions.ccRoot = "${backendStdenv.cc}";

# Required in addition to ccRoot as otherwise bin/gcc is looked up
# when building CMakeCUDACompilerId.cu
substitutions.ccFullPath = "${backendStdenv.cc}/bin/${backendStdenv.cc.targetPrefix}c++";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ setupCUDAToolkitCompilers() {
export CUDAHOSTCXX="@ccFullPath@"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to break up the hook's dependency on the cc too 🤔 Because now we have 3 references all from different places

fi

appendToVar NVCC_PREPEND_FLAGS "--compiler-bindir=@ccRoot@/bin"

# NOTE: We set -Xfatbin=-compress-all, which reduces the size of the compiled
# binaries. If binaries grow over 2GB, they will fail to link. This is a problem for us, as
# the default set of CUDA capabilities we build can regularly cause this to occur (for
Expand Down
Loading