Skip to content
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

treewide: CUDA reformat with nixfmt-rfc-style #299578

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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ fb0e5be84331188a69b3edd31679ca6576edb75a

# systemd: break too long lines of Nix code
67643f8ec84bef1482204709073e417c9f07eb87

# {pkgs/development/cuda-modules,pkgs/test/cuda,pkgs/top-level/cuda-packages.nix}: reformat all CUDA files with nixfmt-rfc-style 2023-03-01
802a1b4d3338f24cbc4efd704616654456d75a94
50 changes: 50 additions & 0 deletions .github/workflows/check-nix-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file was copied mostly from check-maintainers-sorted.yaml.
# NOTE: Formatting with the RFC-style nixfmt command is not yet stable. See
# https://github.com/NixOS/rfcs/pull/166.
# Because of this, this action is not yet enabled for all files -- only for
# those who have opted in.
name: Check that Nix files are formatted

on:
pull_request_target:
permissions:
contents: read

jobs:
nixos:
runs-on: ubuntu-latest
if: github.repository_owner == 'NixOS'
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
# pull_request_target checks out the base branch by default
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
# explicitly enable sandbox
extra_nix_config: sandbox = true
- name: Install nixfmt
run: nix-env -f default.nix -iAP nixfmt-rfc-style
- name: Check that Nix files are formatted according to the RFC style
# Each environment variable beginning with NIX_FMT_PATHS_ is a list of
# paths to check with nixfmt.
env:
# Format paths related to the Nixpkgs CUDA ecosystem.
NIX_FMT_PATHS_CUDA: |
pkgs/development/cuda-modules
pkgs/test/cuda
pkgs/top-level/cuda-packages.nix
# Iterate over all environment variables beginning with NIX_FMT_PATHS_.
run: |
for env_var in "${!NIX_FMT_PATHS_@}"; do
ConnorBaker marked this conversation as resolved.
Show resolved Hide resolved
readarray -t paths <<< "${!env_var}"
if [[ "${paths[*]}" == "" ]]; then
echo "Error: $env_var is empty."
exit 1
fi
echo "Checking paths: ${paths[@]}"
if ! nixfmt --check "${paths[@]}"; then
echo "Error: nixfmt failed."
exit 1
fi
done
2 changes: 1 addition & 1 deletion pkgs/development/cuda-modules/backend-stdenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ let
assertCondition = true;
in

/* TODO: Consider testing whether we in fact use the newer libstdc++ */
# TODO: Consider testing whether we in fact use the newer libstdc++

lib.extendDerivation assertCondition passthruExtra cudaStdenv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{hostPlatform, lib}:
{ hostPlatform, lib }:
let
# Samples are built around the CUDA Toolkit, which is not available for
# aarch64. Check for both CUDA version and platform.
Expand All @@ -8,7 +8,7 @@ let
extension =
final: _:
lib.attrsets.optionalAttrs platformIsSupported {
cuda-library-samples = final.callPackage ./generic.nix {};
cuda-library-samples = final.callPackage ./generic.nix { };
};
in
extension
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let
cmake
addOpenGLRunpath
];
buildInputs = [cudatoolkit];
buildInputs = [ cudatoolkit ];
postFixup = ''
for exe in $out/bin/*; do
addOpenGLRunpath $exe
Expand All @@ -36,7 +36,7 @@ let
cuSPARSE, cuSOLVER, cuFFT, cuRAND, NPP and nvJPEG.
'';
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [obsidian-systems-maintenance] ++ lib.teams.cuda.members;
maintainers = with lib.maintainers; [ obsidian-systems-maintenance ] ++ lib.teams.cuda.members;
};
};
in
Expand Down Expand Up @@ -69,9 +69,9 @@ in

src = "${src}/cuTENSOR";

buildInputs = [cutensor];
buildInputs = [ cutensor ];

cmakeFlags = ["-DCUTENSOR_EXAMPLE_BINARY_INSTALL_DIR=${builtins.placeholder "out"}/bin"];
cmakeFlags = [ "-DCUTENSOR_EXAMPLE_BINARY_INSTALL_DIR=${builtins.placeholder "out"}/bin" ];

# CUTENSOR_ROOT is double escaped
postPatch = ''
Expand Down
98 changes: 48 additions & 50 deletions pkgs/development/cuda-modules/cuda-samples/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,63 @@
let
inherit (lib) lists strings;
in
backendStdenv.mkDerivation (
finalAttrs: {
strictDeps = true;
backendStdenv.mkDerivation (finalAttrs: {
strictDeps = true;

pname = "cuda-samples";
version = cudaVersion;
pname = "cuda-samples";
version = cudaVersion;

src = fetchFromGitHub {
owner = "NVIDIA";
repo = finalAttrs.pname;
rev = "v${finalAttrs.version}";
inherit hash;
};
src = fetchFromGitHub {
owner = "NVIDIA";
repo = finalAttrs.pname;
rev = "v${finalAttrs.version}";
inherit hash;
};

nativeBuildInputs =
[
autoAddDriverRunpath
pkg-config
]
# CMake has to run as a native, build-time dependency for libNVVM samples.
# However, it's not the primary build tool -- that's still make.
# As such, we disable CMake's build system.
++ lists.optionals (strings.versionAtLeast finalAttrs.version "12.2") [cmake];
nativeBuildInputs =
[
autoAddDriverRunpath
pkg-config
]
# CMake has to run as a native, build-time dependency for libNVVM samples.
# However, it's not the primary build tool -- that's still make.
# As such, we disable CMake's build system.
++ lists.optionals (strings.versionAtLeast finalAttrs.version "12.2") [ cmake ];

dontUseCmakeConfigure = true;
dontUseCmakeConfigure = true;

buildInputs = [
cudatoolkit
freeimage
glfw3
];
buildInputs = [
cudatoolkit
freeimage
glfw3
];

# See https://github.com/NVIDIA/cuda-samples/issues/75.
patches = lib.optionals (finalAttrs.version == "11.3") [
(fetchpatch {
url = "https://github.com/NVIDIA/cuda-samples/commit/5c3ec60faeb7a3c4ad9372c99114d7bb922fda8d.patch";
hash = "sha256-0XxdmNK9MPpHwv8+qECJTvXGlFxc+fIbta4ynYprfpU=";
})
];
# See https://github.com/NVIDIA/cuda-samples/issues/75.
patches = lib.optionals (finalAttrs.version == "11.3") [
(fetchpatch {
url = "https://github.com/NVIDIA/cuda-samples/commit/5c3ec60faeb7a3c4ad9372c99114d7bb922fda8d.patch";
hash = "sha256-0XxdmNK9MPpHwv8+qECJTvXGlFxc+fIbta4ynYprfpU=";
})
];

enableParallelBuilding = true;
enableParallelBuilding = true;

preConfigure = ''
export CUDA_PATH=${cudatoolkit}
'';
preConfigure = ''
export CUDA_PATH=${cudatoolkit}
'';

installPhase = ''
runHook preInstall
installPhase = ''
runHook preInstall

install -Dm755 -t $out/bin bin/${backendStdenv.hostPlatform.parsed.cpu.name}/${backendStdenv.hostPlatform.parsed.kernel.name}/release/*
install -Dm755 -t $out/bin bin/${backendStdenv.hostPlatform.parsed.cpu.name}/${backendStdenv.hostPlatform.parsed.kernel.name}/release/*

runHook postInstall
'';
runHook postInstall
'';

meta = {
description = "Samples for CUDA Developers which demonstrates features in CUDA Toolkit";
# CUDA itself is proprietary, but these sample apps are not.
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [obsidian-systems-maintenance] ++ lib.teams.cuda.members;
};
}
)
meta = {
description = "Samples for CUDA Developers which demonstrates features in CUDA Toolkit";
# CUDA itself is proprietary, but these sample apps are not.
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ obsidian-systems-maintenance ] ++ lib.teams.cuda.members;
};
})
34 changes: 16 additions & 18 deletions pkgs/development/cuda-modules/cuda/extension.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{cudaVersion, lib}:
{ cudaVersion, lib }:
let
inherit (lib) attrsets modules trivial;
redistName = "cuda";
Expand Down Expand Up @@ -63,23 +63,21 @@ let
featureRelease
;
}).overrideAttrs
(
prevAttrs: {
# Add the package-specific license.
meta = prevAttrs.meta // {
license =
let
licensePath =
if redistribRelease.license_path != null then
redistribRelease.license_path
else
"${pname}/LICENSE.txt";
url = "https://developer.download.nvidia.com/compute/cuda/redist/${licensePath}";
in
lib.licenses.nvidiaCudaRedist // {inherit url;};
};
}
);
(prevAttrs: {
# Add the package-specific license.
meta = prevAttrs.meta // {
license =
let
licensePath =
if redistribRelease.license_path != null then
redistribRelease.license_path
else
"${pname}/LICENSE.txt";
url = "https://developer.download.nvidia.com/compute/cuda/redist/${licensePath}";
in
lib.licenses.nvidiaCudaRedist // { inherit url; };
};
});
in
drv;

Expand Down
Loading