-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
cuda-modules: rewrite setup hooks #302694
Draft
ConnorBaker
wants to merge
6
commits into
NixOS:master
Choose a base branch
from
ConnorBaker:feat/cudaPackages-rewrite-setup-hooks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e4b5c5
cuda-modules/setup-hooks: refactor to use sub-directories
4f9b11d
cuda-modules/setup-hooks/utilities: add common utilities for our setu…
0f937f1
cudaPackages.markForCudatoolkitRoot: rewrite and rename
050cd19
cudaPackages.setupCuda: rename hook directory/source to match name
d0efe91
cudaPackages.setupCuda: rewrite and rename
f59c481
cuda-modules: format aliases
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ let | |
cudatoolkit | ||
flags | ||
libcublas | ||
setupCudaHook | ||
; | ||
inherit (lib) getDev getLib getOutput; | ||
in | ||
|
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
pkgs/development/cuda-modules/setup-hooks/auto-add-cuda-compat-runpath/default.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# autoAddCudaCompatRunpath hook must be added AFTER `setupCuda`. Both | ||
# hooks prepend a path with `libcuda.so` to the `DT_RUNPATH` section of | ||
# patched elf files, but `cuda_compat` path must take precedence (otherwise, | ||
# it doesn't have any effect) and thus appear first. Meaning this hook must be | ||
# executed last. | ||
{ | ||
autoFixElfFiles, | ||
cuda_compat ? null, | ||
flags, | ||
lib, | ||
makeSetupHook, | ||
}: | ||
makeSetupHook { | ||
name = "auto-add-cuda-compat-runpath-hook"; | ||
propagatedBuildInputs = [ autoFixElfFiles ]; | ||
substitutions.libcudaPath = lib.optionalString flags.isJetsonBuild "${cuda_compat}/compat"; | ||
meta = { | ||
broken = !flags.isJetsonBuild; | ||
badPlatforms = lib.optionals (cuda_compat == null) lib.platforms.all; | ||
platforms = cuda_compat.meta.platforms or [ ]; | ||
}; | ||
} ./auto-add-cuda-compat-runpath.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,5 @@ | ||
final: _: { | ||
# Internal hook, used by cudatoolkit and cuda redist packages | ||
# to accommodate automatic CUDAToolkit_ROOT construction | ||
markForCudatoolkitRootHook = final.callPackage ( | ||
{ makeSetupHook }: | ||
makeSetupHook { name = "mark-for-cudatoolkit-root-hook"; } ./mark-for-cudatoolkit-root-hook.sh | ||
) { }; | ||
|
||
# Currently propagated by cuda_nvcc or cudatoolkit, rather than used directly | ||
setupCudaHook = ( | ||
final.callPackage ( | ||
{ makeSetupHook, backendStdenv }: | ||
makeSetupHook { | ||
name = "setup-cuda-hook"; | ||
|
||
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++"; | ||
} ./setup-cuda-hook.sh | ||
) { } | ||
); | ||
|
||
# autoAddCudaCompatRunpath hook must be added AFTER `setupCudaHook`. Both | ||
# hooks prepend a path with `libcuda.so` to the `DT_RUNPATH` section of | ||
# patched elf files, but `cuda_compat` path must take precedence (otherwise, | ||
# it doesn't have any effect) and thus appear first. Meaning this hook must be | ||
# executed last. | ||
autoAddCudaCompatRunpath = final.callPackage ( | ||
{ | ||
makeSetupHook, | ||
autoFixElfFiles, | ||
cuda_compat ? null, | ||
}: | ||
makeSetupHook { | ||
name = "auto-add-cuda-compat-runpath-hook"; | ||
propagatedBuildInputs = [ autoFixElfFiles ]; | ||
|
||
substitutions = { | ||
# Hotfix Ofborg evaluation | ||
libcudaPath = if final.flags.isJetsonBuild then "${cuda_compat}/compat" else null; | ||
}; | ||
|
||
meta.broken = !final.flags.isJetsonBuild; | ||
|
||
# Pre-cuda_compat CUDA release: | ||
meta.badPlatforms = final.lib.optionals (cuda_compat == null) final.lib.platforms.all; | ||
meta.platforms = cuda_compat.meta.platforms or [ ]; | ||
} ./auto-add-cuda-compat-runpath.sh | ||
) { }; | ||
autoAddCudaCompatRunpath = final.callPackage ./auto-add-cuda-compat-runpath { }; | ||
markForCudatoolkitRoot = final.callPackage ./mark-for-cudatoolkit-root { }; | ||
setupCuda = final.callPackage ./setup-cuda { }; | ||
} |
25 changes: 0 additions & 25 deletions
25
pkgs/development/cuda-modules/setup-hooks/mark-for-cudatoolkit-root-hook.sh
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
pkgs/development/cuda-modules/setup-hooks/mark-for-cudatoolkit-root/default.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Internal hook, used by cudatoolkit and cuda redist packages | ||
# to accommodate automatic CUDAToolkit_ROOT construction | ||
{ makeSetupHook }: | ||
makeSetupHook { | ||
name = "mark-for-cudatoolkit-root"; | ||
substitutions.logFromSetupHook = ../utilities/log-from-setup-hook.sh; | ||
} ./mark-for-cudatoolkit-root.sh |
64 changes: 64 additions & 0 deletions
64
...velopment/cuda-modules/setup-hooks/mark-for-cudatoolkit-root/mark-for-cudatoolkit-root.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# shellcheck shell=bash | ||
|
||
# shellcheck disable=SC1091 | ||
source "@logFromSetupHook@" | ||
|
||
# Guard helper function | ||
# Returns 0 (success) if the hook should be run, 1 (failure) otherwise. | ||
# This allows us to use short-circuit evaluation to avoid running the hook when it shouldn't be. | ||
markForCUDAToolkit_ROOTGuard() { | ||
log() { | ||
logFromSetupHook \ | ||
"${1:?}" \ | ||
"mark-for-cudatoolkit-root" \ | ||
"markForCUDAToolkit_ROOTGuard" \ | ||
"${2:?}" | ||
} | ||
local guard="Skipping" | ||
local reason="" | ||
|
||
# This hook is meant only to add a stub file to the nix-support directory of the package including it in its | ||
# nativeBuildInputs, so that the setup hook propagated by cuda_nvcc, setup-cuda, can detect it and add the | ||
# package to the CUDA toolkit root. Therefore, since it only modifies the package being built and will not be | ||
# propagated, it should only ever be included in nativeBuildInputs. | ||
if (( ${hostOffset:?} == -1 && ${targetOffset:?} == 0)); then | ||
guard="Sourcing" | ||
reason="because the hook is in nativeBuildInputs relative to the package being built" | ||
fi | ||
|
||
log "INFO" "$guard $reason" | ||
|
||
# Recall that test commands return 0 for success and 1 for failure. | ||
[[ "$guard" == Sourcing ]] | ||
return $? | ||
} | ||
|
||
# Guard against calling the hook at the wrong time. | ||
markForCUDAToolkit_ROOTGuard || return 0 | ||
|
||
markForCUDAToolkit_ROOT() { | ||
log() { | ||
logFromSetupHook \ | ||
"${1:?}" \ | ||
"mark-for-cudatoolkit-root" \ | ||
"markForCUDAToolkit_ROOT" \ | ||
"${2:?}" | ||
} | ||
log "INFO" "Running on ${prefix:?}" | ||
|
||
local markerPath="$prefix/nix-support/include-in-cudatoolkit-root" | ||
mkdir -p "$(dirname "$markerPath")" | ||
if [[ -f "$markerPath" ]]; then | ||
log "DEBUG" "$markerPath exists, skipping" | ||
return 0 | ||
fi | ||
|
||
# Always create the file, even if it's empty, since setup-cuda relies on its existence. | ||
# However, only populate it if strictDeps is not set. | ||
touch "$markerPath" | ||
if [[ -z "${strictDeps-}" ]]; then | ||
log "DEBUG" "Populating $markerPath" | ||
echo "${pname:?}-${output:?}" > "$markerPath" | ||
fi | ||
} | ||
fixupOutputHooks+=(markForCUDAToolkit_ROOT) |
122 changes: 0 additions & 122 deletions
122
pkgs/development/cuda-modules/setup-hooks/setup-cuda-hook.sh
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 remember a discussion about this, and I agree there's little point in having the suffix, and it's ok not to have it... I don't know why bother renaming old stuff, but no strong opinions here on my part