Skip to content

patchpkg: patch python to use devbox CUDA libs #2296

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

Merged
merged 3 commits into from
Sep 27, 2024
Merged

patchpkg: patch python to use devbox CUDA libs #2296

merged 3 commits into from
Sep 27, 2024

Conversation

gcurtis
Copy link
Collaborator

@gcurtis gcurtis commented Sep 24, 2024

Automatically patch python to use any cudaPackages.* packages that are in devbox.json. This will only work if the CUDA drivers are already installed on the host system.

The patching process is:

  1. When generating the patch flake, look for the system’s libcuda.so library (installed by the driver) and copy it into the flake’s directory.
  2. Nix copies the flake’s source directory (and therefore libcuda.so) into the nix store when building it.
  3. The flake calls devbox patch which adds a DT_NEEDED entry to the python binary for libcuda.so. It also adds the lib directories of any other cudaPackages.* packages that it finds in the environment.

@gcurtis gcurtis force-pushed the gcurtis/cuda branch 5 times, most recently from 7507bdf to 04f319e Compare September 24, 2024 22:06
Automatically patch python to use any `cudaPackages.*` packages that are
in devbox.json. This will only work if the CUDA drivers are already
installed on the host system.

The patching process is:

1. When generating the patch flake, look for the system's `libcuda.so`
   library (installed by the driver) and copy it into the flake's
   directory.
2. Nix copies the flake's source directory (and therefore libcuda.so)
   into the nix store when building it.
3. The flake calls `devbox patch` which adds a `DT_NEEDED` entry to the
   python binary for `libcuda.so`. It also adds the lib directories of
   any other `cudaPackages.*` packages that it finds in the
   environment.
Copy link
Collaborator

@savil savil left a comment

Choose a reason for hiding this comment

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

LGTM, modulo one question below

@@ -302,6 +322,65 @@ func (d *DerivationBuilder) findRemovedRefs(ctx context.Context, pkg *packageFS)
return refs, nil
}

func (d *DerivationBuilder) findCUDA(ctx context.Context, out *packageFS) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Food for future thought: Is there a way to do this in a more plugin-like way? Maybe we allow built in plugins to use go code (or in the future compile plugins as needed).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like the idea of aligning plugins and patching. This code runs as part of the flake builder (in the nix build sandbox), so plugins would just need something similar.

@gcurtis gcurtis merged commit 57312c0 into main Sep 27, 2024
28 checks passed
@gcurtis gcurtis deleted the gcurtis/cuda branch September 27, 2024 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants