-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cudaPackages: use the same libstdc++ as the rest of nixpkgs #223664
Changes from all commits
bd62420
ab9c46d
13c47d6
3af299f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,17 @@ final: prev: let | |
finalVersion = cudatoolkitVersions.${final.cudaVersion}; | ||
|
||
# Exposed as cudaPackages.backendStdenv. | ||
# We don't call it just "stdenv" to avoid confusion: e.g. this toolchain doesn't contain nvcc. | ||
# Instead, it's the back-end toolchain for nvcc to use. | ||
# We also use this to link a compatible libstdc++ (backendStdenv.cc.cc.lib) | ||
# This is what nvcc uses as a backend, | ||
# and it has to be an officially supported one (e.g. gcc11 for cuda11). | ||
# | ||
# It, however, propagates current stdenv's libstdc++ to avoid "GLIBCXX_* not found errors" | ||
# when linked with other C++ libraries. | ||
# E.g. for cudaPackages_11_8 we use gcc11 with gcc12's libstdc++ | ||
Comment on lines
+13
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for explaining! these comments are super useful! |
||
# Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context | ||
backendStdenv = prev.pkgs."${finalVersion.gcc}Stdenv"; | ||
backendStdenv = final.callPackage ./stdenv.nix { | ||
nixpkgsStdenv = prev.pkgs.stdenv; | ||
nvccCompatibleStdenv = prev.pkgs.buildPackages."${finalVersion.gcc}Stdenv"; | ||
}; | ||
|
||
### Add classic cudatoolkit package | ||
cudatoolkit = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ lib | ||
, stdenv | ||
, backendStdenv | ||
, fetchurl | ||
, autoPatchelfHook | ||
|
@@ -30,11 +31,11 @@ backendStdenv.mkDerivation { | |
]; | ||
|
||
buildInputs = [ | ||
# autoPatchelfHook will search for a libstdc++ and we're giving it a | ||
# "compatible" libstdc++ from the same toolchain that NVCC uses. | ||
# | ||
# autoPatchelfHook will search for a libstdc++ and we're giving it | ||
# one that is compatible with the rest of nixpkgs, even when | ||
# nvcc forces us to use an older gcc | ||
# NB: We don't actually know if this is the right thing to do | ||
backendStdenv.cc.cc.lib | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I probably should leave a warning somewhere, but if one accidentally uses |
||
stdenv.cc.cc.lib | ||
]; | ||
|
||
dontBuild = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this need to live in its own file? AFAICT it's only used in one place -- why not just inline it there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, so the idea seems to be that we eventually want to construct our own There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohhh ok, makes sense |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ nixpkgsStdenv | ||
, nvccCompatibleStdenv | ||
, overrideCC | ||
, wrapCCWith | ||
}: | ||
|
||
overrideCC nixpkgsStdenv (wrapCCWith { | ||
cc = nvccCompatibleStdenv.cc.cc; | ||
|
||
# This option is for clang's libcxx, but we (ab)use it for gcc's libstdc++. | ||
# Note that libstdc++ maintains forward-compatibility: if we load a newer | ||
# libstdc++ into the process, we can still use libraries built against an | ||
# older libstdc++. This, in practice, means that we should use libstdc++ from | ||
# the same stdenv that the rest of nixpkgs uses. | ||
# We currently do not try to support anything other than gcc and linux. | ||
libcxx = nixpkgsStdenv.cc.cc.lib; | ||
}) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,17 +25,19 @@ | |||||
builtins.head optLevels | ||||||
, faiss # To run demos in the tests | ||||||
, runCommand | ||||||
}: | ||||||
}@inputs: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This causes infinite recursion in (whatever version of Nix I've tried this with a month ago) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about something like effectiveStdenv = if cudaSupport then backendStdenv else stdenv; ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that earlier in tensorflow, I think. Sandro pointed out that this way it's really easy for someone to accidentally refer to the old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok that's a fair point. I'm happy to go either way |
||||||
|
||||||
assert cudaSupport -> nvidia-thrust.cudaSupport; | ||||||
|
||||||
let | ||||||
pname = "faiss"; | ||||||
version = "1.7.2"; | ||||||
|
||||||
inherit (cudaPackages) cudaFlags; | ||||||
inherit (cudaPackages) cudaFlags backendStdenv; | ||||||
inherit (cudaFlags) cudaCapabilities dropDot; | ||||||
|
||||||
stdenv = if cudaSupport then backendStdenv else inputs.stdenv; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samuela look, this worked 😆 😅 import faiss
import zmq works now. So yeah, further on the roadmap is to add hooks for nvcc and FindCUDAToolkit.cmake, and rename this into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
cudaJoined = symlinkJoin { | ||||||
name = "cuda-packages-unsplit"; | ||||||
paths = with cudaPackages; [ | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we just did a bunch of work refactoring so that we could use
backendStdenv
'slib
? why are we reverting?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
backendStdenv
results in linking against the new libstdc++ as long as no one tries to manually add somecc.cc.lib
intobuildInputs
or otherwise override anything. However,backendStdenv.cc.cc.lib
is still an "output" of thecc.cc
derivation, andbackendStdenv.cc.cc
is gcc11...I'm sorry I don't know how to make this cleaner at the moment, but for things at least to work we need to explicitly link normal stdenv's libstdc++
also it's time to ditch
cudaPackages.cudatoolkit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok thanks for explaining... so can we get rid of
backendStdenv
entirely then? IIUC it should no longer be used after this PR?