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

Conversation

ConnorBaker
Copy link
Contributor

@ConnorBaker ConnorBaker commented Mar 27, 2024

Description of changes

Reformats the following paths with nixfmt-rfc-style:

  • pkgs/development/cuda-modules
  • pkgs/test/cuda
  • pkgs/top-level/cuda-packages.nix

Additionally, adds the commit in which the reformatting happens to .git-blame-ignore-revs.

Ideally this will not cause any rebuilds, but it may if whitespace in raw text blocks change.

This PR also introduces a workflow to ensure that the changed files continue to stay formatted.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ConnorBaker ConnorBaker added the 6.topic: cuda Parallel computing platform and API label Mar 27, 2024
@ConnorBaker ConnorBaker self-assigned this Mar 27, 2024
@ConnorBaker
Copy link
Contributor Author

PR="299578"; \
SYSTEM="x86_64-linux"; \
CUDA_SUPPORT="true"; \
CUDA_CAPABILITIES='[ "7.5" ]'; \
nixpkgs-review pr "$PR" \
  --system "$SYSTEM" \
  --no-shell \
  --checkout commit \
  --allow aliases \
  --build-args "--max-jobs 1" \
  --skip-package-regex 'python3(\d){1,2}Packages\.(pytorch-pfn-extras|ffcv)' \
  --skip-package-regex 'python3(\d){1,2}Packages\.(shap|mlflow|optuna)' \
  --extra-nixpkgs-config "{
    allowUnfree = true;
    allowBroken = false;
    cudaSupport = ${CUDA_SUPPORT:-false};
    cudaCapabilities = ${CUDA_CAPABILITIES:-[]};
  }"

Result of nixpkgs-review pr 299578 --extra-nixpkgs-config '{ allowUnfree = true; allowBroken = false; cudaSupport = true; cudaCapabilities = [ "7.5" ]; }' run on x86_64-linux 1

3 packages built:
  • cudaPackages.saxpy
  • cudaPackagesGoogle.saxpy
  • cudaPackages_10.saxpy

@ConnorBaker ConnorBaker marked this pull request as ready for review March 27, 2024 20:37
@ConnorBaker
Copy link
Contributor Author

PR="299578"; \
SYSTEM="aarch64-darwin"; \
CUDA_SUPPORT="false"; \
CUDA_CAPABILITIES='[ ]'; \
nixpkgs-review pr "$PR" \
  --system "$SYSTEM" \
  --no-shell \
  --checkout commit \
  --allow aliases \
  --build-args "--max-jobs 1" \
  --extra-nixpkgs-config "{
    allowUnfree = true;
    allowBroken = false;
    cudaSupport = ${CUDA_SUPPORT:-false};
    cudaCapabilities = ${CUDA_CAPABILITIES:-[]};
  }"

Result of nixpkgs-review pr 299578 --extra-nixpkgs-config '{ allowUnfree = true; allowBroken = false; cudaSupport = false; cudaCapabilities = [ ]; }' run on aarch64-darwin 1

@ConnorBaker
Copy link
Contributor Author

PR="299578"; \
SYSTEM="x86_64-darwin"; \
CUDA_SUPPORT="false"; \
CUDA_CAPABILITIES='[ ]'; \
nixpkgs-review pr "$PR" \
  --system "$SYSTEM" \
  --no-shell \
  --checkout commit \
  --allow aliases \
  --build-args "--max-jobs 1" \
  --extra-nixpkgs-config "{
    allowUnfree = true;
    allowBroken = false;
    cudaSupport = ${CUDA_SUPPORT:-false};
    cudaCapabilities = ${CUDA_CAPABILITIES:-[]};
  }"

Result of nixpkgs-review pr 299578 --extra-nixpkgs-config '{ allowUnfree = true; allowBroken = false; cudaSupport = false; cudaCapabilities = [ ]; }' run on x86_64-darwin 1

@ConnorBaker
Copy link
Contributor Author

PR="299578"; \
SYSTEM="aarch64-linux"; \
CUDA_SUPPORT="true"; \
CUDA_CAPABILITIES='[ "7.2" ]'; \
nixpkgs-review pr "$PR" \
  --system "$SYSTEM" \
  --no-shell \
  --checkout commit \
  --allow aliases \
  --build-args "--max-jobs 4" \
  --extra-nixpkgs-config "{
    allowUnfree = true;
    allowBroken = false;
    cudaSupport = ${CUDA_SUPPORT:-false};
    cudaCapabilities = ${CUDA_CAPABILITIES:-[]};
  }"

Result of nixpkgs-review pr 299578 --extra-nixpkgs-config '{ allowUnfree = true; allowBroken = false; cudaSupport = true; cudaCapabilities = [ "7.2" ]; }' run on aarch64-linux 1

@ConnorBaker
Copy link
Contributor Author

PR="299578"; \
SYSTEM="aarch64-linux"; \
CUDA_SUPPORT="true"; \
CUDA_CAPABILITIES='[ "7.5" ]'; \
nixpkgs-review pr "$PR" \
  --system "$SYSTEM" \
  --no-shell \
  --checkout commit \
  --allow aliases \
  --build-args "--max-jobs 4" \
  --extra-nixpkgs-config "{
    allowUnfree = true;
    allowBroken = false;
    cudaSupport = ${CUDA_SUPPORT:-false};
    cudaCapabilities = ${CUDA_CAPABILITIES:-[]};
  }"

Result of nixpkgs-review pr 299578 --extra-nixpkgs-config '{ allowUnfree = true; allowBroken = false; cudaSupport = true; cudaCapabilities = [ "7.5" ]; }' run on aarch64-linux 1

2 packages built:
  • cudaPackages.saxpy
  • cudaPackagesGoogle.saxpy

@ofborg ofborg bot requested review from samuela and SomeoneSerge March 27, 2024 21:39
@ofborg ofborg bot added 11.by: package-maintainer This PR was created by the maintainer of the package it changes 10.rebuild-darwin: 11-100 10.rebuild-linux: 11-100 labels Mar 27, 2024
@samuela
Copy link
Member

samuela commented Mar 27, 2024

Thanks for doing this @ConnorBaker ! I'm a fan of all things automated formatting.

How will we enforce this formatting standard in future PRs? Once things are all pretty and pristine after this PR, what's to stop someone from unknowingly breaking formatting in a subsequent PR?

@ConnorBaker
Copy link
Contributor Author

How will we enforce this formatting standard in future PRs? Once things are all pretty and pristine after this PR, what's to stop someone from unknowingly breaking formatting in a subsequent PR?

I don't know :(

As far as I can tell, we don't have any sort of pre-commit hook setup with Nixpkgs. I suppose I could add a new workflow which checks to make sure that the paths formatted by this PR are unchanged when the formatter is run again, but I'm not sure if that's something which is allowed.

Any ideas?

@samuela
Copy link
Member

samuela commented Mar 27, 2024

I suppose I could add a new workflow which checks to make sure that the paths formatted by this PR are unchanged when the formatter is run again, but I'm not sure if that's something which is allowed.

A GitHub Actions workflow? Yeah I think that makes sense. IIUC there's a --verify option that we can make use of.

Perhaps the NixOS/rfcs#166 authors (cc @piegamesde @infinisil) might have input on how to enforce the new formatting standard in CI?

@ConnorBaker
Copy link
Contributor Author

@samuela see b6024fa48c4240837f276ca603f8176052c7de75 -- I use the --check argument so the command should fail with an error if a file isn't formatted.

@samuela
Copy link
Member

samuela commented Mar 27, 2024

@samuela see b6024fa -- I use the --check argument so the command should fail with an error if a file isn't formatted.

Woohoo! Looks great!

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

This is a bit early, because nixfmt-rfc-style is not yet stable! We still need to release the first official version, and we planned it to only apply to Nixpkgs after that, see NixOS/nixfmt#153.

That said, I don't see any major problems with code owners manually starting to enforce even the unstable format.

.github/workflows/check-cuda-formatted.yml Outdated Show resolved Hide resolved
.github/workflows/check-cuda-formatted.yml Outdated Show resolved Hide resolved
@piegamesde
Copy link
Member

Am I seeing correctly that the reformat is causing a rebuild? If so, would you please investigate this and open a bug report? Nixfmt should never change the code's semantics, and thus never cause any rebuilds.

@infinisil
Copy link
Member

Oh and with a more generic check, the @NixOS/nix-formatting team should be added as the workflows code owner

@gabyx
Copy link
Contributor

gabyx commented Mar 28, 2024

I suppose I could add a new workflow which checks to make sure that the paths formatted by this PR are unchanged when the formatter is run again, but I'm not sure if that's something which is allowed.

A GitHub Actions workflow? Yeah I think that makes sense. IIUC there's a --verify option that we can make use of.

Perhaps the NixOS/rfcs#166 authors (cc @piegamesde @infinisil) might have input on how to enforce the new formatting standard in CI?

I would make a GIthub action workflow to just run the changed files in the PR through the formatter and if any diff arises after the run -> report to the PR and block it from merging (basically happens directly because this workflow would be unsuccessful).

@samuela
Copy link
Member

samuela commented Mar 28, 2024

if any diff arises after the run -> report to the PR and block it from merging

Is this not the behavior of nixfmt --check?

@ConnorBaker ConnorBaker force-pushed the fix/treewide-cuda-reformat-nixfmt-rfc-style-2024-03-01 branch from b6024fa to c93591b Compare March 30, 2024 00:46
@ConnorBaker
Copy link
Contributor Author

The only thing is that I wouldn't want people to add additional GitHub workflows for each part that starts using the unstable format, so instead I'd say let's not imply that the GitHub action is specific to CUDA, and instead name it something generic like check-nix-formatting.yml

Also please add an explanatory comment in this file to say that it's not stable yet with a link to NixOS/rfcs#166

@infinisil I've renamed the file and added a comment to make it clear its opt-in.

Do we want to run the check for all PRs at this point? Maybe we maintain (in the workflow definition) a list of subsystems that explicitly opt-in into enforcing the experimental style

@SomeoneSerge @piegamesde I've relaxed the run condition so it will trigger on all PRs, but have restricted it to just the relevant CUDA files.

I would make a GIthub action workflow to just run the changed files in the PR through the formatter and if any diff arises after the run -> report to the PR and block it from merging (basically happens directly because this workflow would be unsuccessful).

@gabyx @samuela yes, that is what the --check flag is for. Though, it won't print the diff itself.

Am I seeing correctly that the reformat is causing a rebuild? If so, would you please investigate this and open a bug report? Nixfmt should never change the code's semantics, and thus never cause any rebuilds.

@piegamesde @infinisil I've often wondered about those counts, especially for unfree redistributables. If they're calculated naively (e.g., does Hydra have a copy of the package cached?) then it would make sense there are always "rebuilds"; Hydra doesn't build unfree packages (like anything involving CUDA). That the Darwin count is non-zero makes me chuckle, because that's definitely one platform NVIDIA doesn't support, and one which should never be impacted by our changes (unless we, you know, break evaluation).

Is there an easy way for me to check exactly what would need to be rebuilt, or to further investigate this?


I see the current PR as the minimal amount of work necessary to format the portion of the code the @NixOS/cuda-maintainers team works on, and to keep it formatted.

I think it would be a good idea to open an issue on the nixfmt repo to create a list of requirements for a GitHub Action which runs nixfmt on a repository. I think that's a good way to gain further adoption; I know if there were a GitHub action specifically for nixfmt that I'd use it -- especially if it provided additional functionality like producing a diff of the changed files, like @gabyx suggested.

What are y'all's thoughts on something like that? I think the changes I've made to the PR (finding paths from environment variables) make it flexible enough for a small group of maintainers to opt-in prior to tree-wide formatting, but I wouldn't want to extend it further.

Connor Baker added 3 commits April 1, 2024 01:14
…kages.nix}: reformat all CUDA files with nixfmt-rfc-style 2023-03-01

```bash
nix run github:NixOS/nixpkgs/ab6071eb54cc9b66dda436111d4f569e4e56cbf4#nixfmt-rfc-style -L --allow-import-from-derivation -- pkgs/development/cuda-modules pkgs/test/cuda pkgs/top-level/cuda-packages.nix
```
@ConnorBaker ConnorBaker force-pushed the fix/treewide-cuda-reformat-nixfmt-rfc-style-2024-03-01 branch from c93591b to d94495d Compare April 1, 2024 01:15
@ConnorBaker ConnorBaker dismissed infinisil’s stale review April 2, 2024 02:59

Concerns have been addressed; pending another review

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

Looking good to me! I opened NixOS/nixfmt#180 to track a generic GitHub workflow file.

We'll discuss this PR in today's formatting team meeting and will most likely merge it then :)

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Apr 2, 2024
This was referenced Apr 2, 2024
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

(discussed in the formatting team meeting)

Can confirm that the workflow works (tweag#88), let's merge!

@infinisil infinisil merged commit 073542a into NixOS:master Apr 2, 2024
20 checks passed
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2024-04-02/42658/1

@ConnorBaker ConnorBaker deleted the fix/treewide-cuda-reformat-nixfmt-rfc-style-2024-03-01 branch April 2, 2024 20:27
@samuela
Copy link
Member

samuela commented Apr 2, 2024

Woohoo!! thanks everyone -- excited to finally get some auto-formatting CI in nixpkgs!

@philiptaron
Copy link
Contributor

Thank you all for being the first-out-of-the-gate team to opt in to RFC 166!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cuda Parallel computing platform and API 6.topic: policy discussion 10.rebuild-darwin: 11-100 10.rebuild-linux: 11-100 11.by: package-maintainer This PR was created by the maintainer of the package it changes 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

10 participants