Skip to content

cuda-modules: surface capability-category helpers into _cuda.db and _cuda.lib#532065

Open
jfroche wants to merge 2 commits into
NixOS:masterfrom
jfroche:cuda-jetson-lib-helpers
Open

cuda-modules: surface capability-category helpers into _cuda.db and _cuda.lib#532065
jfroche wants to merge 2 commits into
NixOS:masterfrom
jfroche:cuda-jetson-lib-helpers

Conversation

@jfroche

@jfroche jfroche commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Three capability-category filters (architectureSpecificCudaCapabilities, familySpecificCudaCapabilities, jetsonCudaCapabilities) were computed as inline let-bindings in backendStdenv/default.nix.

The logic was not reusable outside backendStdenv: downstream consumers that need "is this a Jetson build?" cannot read cudaPackages.backendStdenv.hasJetsonCudaCapability from the lib fixpoint without infinite recursion — it pulls the whole cudaPackages scope. They were forced to re-derive the logic from _cuda.db themselves.

Commit 1: moves the three category lists into _cuda.db alongside allSortedCudaCapabilities and cudaArchNameToCapabilities, adds _-prefixed predicates to _cuda.lib, and updates backendStdenv to inherit from _cuda.db. No behaviour change.

Commit 2: adds stable public API to _cuda.lib for out-of-tree consumers, alongside _cuda.db.jetsonArchNames

jfroche added 2 commits June 15, 2026 21:15
We want to categorize CUDA capabilities according to various criteria (e.g. whether they are architecture-specific, family-specific, or Jetson-specific) in order to enable more fine-grained filtering of capabilities in the backend and elsewhere.

Currently, the logic for determining these categories is implemented as inline let-bindings in backendStdenv/default.nix, which makes it difficult to reuse this categorization logic elsewhere (e.g. in out-of-tree consumers).

This change moves the the three inline filter computations that were local let-bindings in backendStdenv/default.nix into _cuda.db, alongside allSortedCudaCapabilities and cudaArchNameToCapabilities.

Also add the corresponding _- prefixed functions to _cuda.lib for internal use within cuda-modules.
…uda.db

Enable the previously added functions to be used in the public API of _cuda, so they can be safely called from lib or from any code that receives _cuda as an argument, without risking infinite recursion or relying on unstable, internal predicates.

Add stable, supported names for the two predicates consumers are most likely to need, plus the list primitive they are built on:

- cudaCapabilitiesJetsonSubset :: [CudaCapability] -> [CudaCapability]
- cudaCapabilitiesAreJetson    :: [CudaCapability] -> Bool
- cudaCapabilitiesAreJetsonArch :: String -> [CudaCapability] -> Bool

Also add db.jetsonArchNames :: [String] so callers can enumerate or validate arch names (e.g. "Ampere", "Blackwell") without hard-coding strings.
@jfroche jfroche requested a review from ConnorBaker June 15, 2026 19:38
@nixpkgs-ci nixpkgs-ci Bot requested a review from a team June 15, 2026 19:44
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: cuda Parallel computing platform and API labels Jun 15, 2026
@GaetanLepage GaetanLepage moved this from New to 👀 Awaits reviews in CUDA Team Jun 21, 2026
@ConnorBaker ConnorBaker self-assigned this Jun 22, 2026
@SomeoneSerge

Copy link
Copy Markdown
Contributor

cudaPackages.backendStdenv.hasJetsonCudaCapability

All of the custom has* and is* attributes under backendStdenv are private, sorry the naming hadn't communicated that properly. Cf... maybe #456908, I don't remember if there's any commentary.

I think the de-facto public bit for "is jetson" is:

]$ nix eval -f "<nixpkgs>" --argstr system aarch64-linux --arg config '{cudaCapabilities = [ "8.7"]; }' cudaPackages.flags.isJetsonBuild
true

That said...

downstream consumers that need "is this a Jetson build?" cannot read ... from the lib fixpoint without infinite recursion

...still sounds like a regression

Commit 2: adds stable public API to _cuda.lib for out-of-tree consumers, alongside _cuda.db.jetsonArchNames

Heads-up: none of _cuda is public, quite all of it subject to change including in backports!

@ConnorBaker

Copy link
Copy Markdown
Contributor

Sorry for the delay, I'm hoping to get around to this today.

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jun 24, 2026

@ConnorBaker ConnorBaker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry it took so long for me to get a chance to review this!

Comment on lines +2 to +8
let
jetsonSubset =
cudaCapabilities: lib.intersectLists _cuda.db.jetsonCudaCapabilities cudaCapabilities;
jetsonArchSubset =
archName: cudaCapabilities:
lib.intersectLists (_cuda.db.cudaArchNameToJetsonCapabilities.${archName} or [ ]) cudaCapabilities;
in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inline and indirect through _cuda.lib so overrides/extensions function as expected.


: The list of CUDA capabilities to check
*/
_cudaCapabilitiesAreArchitectureSpecific =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Name needs work -- does not reflect the fact that the function is the join (any satisfies), not the meet (all satisfy), which is implied from Are in the function name. This holds for all the other functions introduced here.


: The list of CUDA capabilities to filter
*/
cudaCapabilitiesJetsonSubset = jetsonSubset;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be called something like getJetsonCudaCapabilities or filterJetsonCudaCapabilities.

@github-project-automation github-project-automation Bot moved this from 👀 Awaits reviews to 📋 The forgotten in CUDA Team Jun 28, 2026
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 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

Status: 📋 The forgotten

Development

Successfully merging this pull request may close these issues.

5 participants