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
20 changes: 10 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@
};
}
);
} // defaultBuildPerSystem;
}
// defaultBuildPerSystem;
in
flake-utils.lib.eachSystem systems (
system:
Expand Down
13 changes: 6 additions & 7 deletions lib/torch-extension-noarch/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ stdenv.mkDerivation (prevAttrs: {
# also get torch as a build input.
buildInputs = [ torch ];

nativeBuildInputs =
[
build2cmake
]
++ lib.optionals doGetKernelCheck [
get-kernel-check
];
nativeBuildInputs = [
build2cmake
]
++ lib.optionals doGetKernelCheck [
get-kernel-check
];

dontBuild = true;

Expand Down
158 changes: 77 additions & 81 deletions lib/torch-extension/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,50 +82,48 @@ stdenv.mkDerivation (prevAttrs: {
chmod -R u+w .
'';

nativeBuildInputs =
nativeBuildInputs = [
kernel-abi-check
cmake
ninja
build2cmake
]
++ lib.optionals doGetKernelCheck [
get-kernel-check
]
++ lib.optionals cudaSupport [
cmakeNvccThreadsHook
cudaPackages.cuda_nvcc
]
++ lib.optionals rocmSupport [
clr
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
rewrite-nix-paths-macho
];

buildInputs = [
torch
torch.cxxdev
]
++ lib.optionals cudaSupport (
with cudaPackages;
[
kernel-abi-check
cmake
ninja
build2cmake
cuda_cudart

# Make dependent on build configuration dependencies once
# the Torch dependency is gone.
cuda_cccl
libcublas
libcusolver
libcusparse
]
++ lib.optionals doGetKernelCheck [
get-kernel-check
]
++ lib.optionals cudaSupport [
cmakeNvccThreadsHook
cudaPackages.cuda_nvcc
]
++ lib.optionals rocmSupport [
clr
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
rewrite-nix-paths-macho
];

buildInputs =
[
torch
torch.cxxdev
]
++ lib.optionals cudaSupport (
with cudaPackages;
[
cuda_cudart

# Make dependent on build configuration dependencies once
# the Torch dependency is gone.
cuda_cccl
libcublas
libcusolver
libcusparse
]
)
++ lib.optionals rocmSupport (with rocmPackages; [ hipsparselt ])
++ lib.optionals stdenv.hostPlatform.isDarwin [
apple-sdk_15
]
++ extraDeps;
)
++ lib.optionals rocmSupport (with rocmPackages; [ hipsparselt ])
++ lib.optionals stdenv.hostPlatform.isDarwin [
apple-sdk_15
]
++ extraDeps;

env =
lib.optionalAttrs cudaSupport {
Expand All @@ -143,45 +141,43 @@ stdenv.mkDerivation (prevAttrs: {
# If we use the default setup, CMAKE_CUDA_HOST_COMPILER gets set to nixpkgs g++.
dontSetupCUDAToolkitCompilers = true;

cmakeFlags =
[
(lib.cmakeFeature "Python_EXECUTABLE" "${python3.withPackages (ps: [ torch ])}/bin/python")
]
++ lib.optionals cudaSupport [
(lib.cmakeFeature "CMAKE_CUDA_HOST_COMPILER" "${stdenv.cc}/bin/g++")
]
++ lib.optionals rocmSupport [
# Ensure sure that we use HIP from our CLR override and not HIP from
# the symlink-joined ROCm toolkit.
(lib.cmakeFeature "CMAKE_HIP_COMPILER_ROCM_ROOT" "${clr}")
(lib.cmakeFeature "HIP_ROOT_DIR" "${clr}")
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# Use host compiler for Metal. Not included in the redistributable SDK.
(lib.cmakeFeature "METAL_COMPILER" "${xcrunHost}/bin/xcrunHost")
];

postInstall =
''
(
cd ..
cp -r torch-ext/${extensionName} $out/
)
cp $out/_${extensionName}_*/* $out/${extensionName}
rm -rf $out/_${extensionName}_*
''
+ (lib.optionalString (stripRPath && stdenv.hostPlatform.isLinux)) ''
find $out/${extensionName} -name '*.so' \
-exec patchelf --set-rpath "" {} \;
''
+ (lib.optionalString (stripRPath && stdenv.hostPlatform.isDarwin)) ''
find $out/${extensionName} -name '*.so' \
-exec rewrite-nix-paths-macho {} \;

# Stub some rpath.
find $out/${extensionName} -name '*.so' \
-exec install_name_tool -add_rpath "@loader_path/lib" {} \;
'';
cmakeFlags = [
(lib.cmakeFeature "Python_EXECUTABLE" "${python3.withPackages (ps: [ torch ])}/bin/python")
]
++ lib.optionals cudaSupport [
(lib.cmakeFeature "CMAKE_CUDA_HOST_COMPILER" "${stdenv.cc}/bin/g++")
]
++ lib.optionals rocmSupport [
# Ensure sure that we use HIP from our CLR override and not HIP from
# the symlink-joined ROCm toolkit.
(lib.cmakeFeature "CMAKE_HIP_COMPILER_ROCM_ROOT" "${clr}")
(lib.cmakeFeature "HIP_ROOT_DIR" "${clr}")
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# Use host compiler for Metal. Not included in the redistributable SDK.
(lib.cmakeFeature "METAL_COMPILER" "${xcrunHost}/bin/xcrunHost")
];

postInstall = ''
(
cd ..
cp -r torch-ext/${extensionName} $out/
)
cp $out/_${extensionName}_*/* $out/${extensionName}
rm -rf $out/_${extensionName}_*
''
+ (lib.optionalString (stripRPath && stdenv.hostPlatform.isLinux)) ''
find $out/${extensionName} -name '*.so' \
-exec patchelf --set-rpath "" {} \;
''
+ (lib.optionalString (stripRPath && stdenv.hostPlatform.isDarwin)) ''
find $out/${extensionName} -name '*.so' \
-exec rewrite-nix-paths-macho {} \;

# Stub some rpath.
find $out/${extensionName} -name '*.so' \
-exec install_name_tool -add_rpath "@loader_path/lib" {} \;
'';

doInstallCheck = true;

Expand Down
17 changes: 4 additions & 13 deletions pkgs/stdenv-glibc-2_27/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
system,
wrapBintoolsWith,
wrapCCWith,
writeClosure,
gcc12Stdenv,
stdenv,
bintools-unwrapped,
Expand All @@ -33,11 +32,9 @@ let

outputs = prevAttrs.outputs ++ [ "getent" ];

postInstall =
prevAttrs.postInstall
+ ''
install -Dm755 $bin/bin/getent -t $getent/bin
'';
postInstall = prevAttrs.postInstall + ''
install -Dm755 $bin/bin/getent -t $getent/bin
'';

passthru = prevAttrs.passthru // {
# Should be stdenv's gcc, but we don't have access to it.
Expand Down Expand Up @@ -72,11 +69,5 @@ let
in
overrideCC stdenv compilerWrapped;

# Workaround for: https://github.com/NixOS/nixpkgs/issues/428546
ccWithoutHook = ((if cudaSupport then cudaPackages.backendStdenv else gcc12Stdenv).cc.cc).override {
# Just some null derivation to disable the hook.
sanitiseHeaderPathsHook = writeClosure [ ];
};

in
stdenvWith glibc_2_27 ccWithoutHook stdenv
stdenvWith glibc_2_27 (if cudaSupport then cudaPackages.backendStdenv else gcc12Stdenv).cc.cc stdenv
Loading