Repository navigation
feat(codegen): opt-in build-time cubin materialization for embedded artifacts - #340
Merged
Merged
Conversation
…rtifacts Setting CUDA_OXIDE_MATERIALIZE_CUBIN (presence-based, mirroring CUDA_OXIDE_EMIT_NVVM_IR) makes the backend compile NVVM IR and LTOIR device artifacts to a final cubin before embedding them, so consuming binaries load device code directly through the CUDA driver: no libNVVM or nvJitLink on the deployment host, and no first-load compile hit. PTX and cubin artifacts pass through untouched. Off by default: the embedded IR keeps compiling at first load, where cuda-host's execution routing can still take the forward-compatible PTX bridge when the running GPU is newer than the emitted architecture. A materialized cubin is pinned to the emitted architecture, so the opt-in trades multi-arch flexibility for zero runtime JIT dependencies — appropriate when build and deployment targets are known and fixed. The backend talks to libnvvm-sys / nvjitlink-sys directly (both dlopen their libraries at call time), deliberately not through cuda-host: that would link the backend dylib against the CUDA driver (libcuda.so.1) and break building or loading the backend on machines without a GPU driver. The compile sequence (frontend validation, libdevice, -gen-lto, -lto link) mirrors cuda-host's ltoir module and cargo-oxide's emit-ltoir. Signed-off-by: Chris Allen <[email protected]> Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
feat/materialize-cubin
branch
from
July 21, 2026 07:19
8d8828f to
05552e7
Compare
Move build-time and runtime CUDA artifact finalization onto one driverless implementation with exact toolkit-input provenance, explicit architecture and policy handling, and fail-closed collection contracts. Expose the opt-in through cargo oxide, preserve the default PTX path, add artifact and backend regressions, and exercise both public paths in CI. Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
feat/materialize-cubin
branch
from
July 21, 2026 07:34
05552e7 to
3f04c20
Compare
Compile sha2 with optimization in the workspace dev profile so cargo oxide can retain exact content-based backend fingerprints without spending several seconds hashing the same large debug library on every example invocation. Signed-off-by: nihalp <[email protected]>
Signed-off-by: nihalp <[email protected]>
Collaborator
|
Thanks for the PR. I pushed a maintainer follow-up to fix the Cargo cache regression introduced while completing the cubin materialization path.
For example: Reviewer note: All 145 compile-only examples passed locally in 181s; the three previously regressed examples completed in 2s, 2s, and 3s. Package and backend tests, strict clippy, formatting, compatibility checks, and independent post-repair review passed. No CUDA device was available, so this is compile and artifact validation only. Hosted CI is pending and remains the final merge gate. #378, #388, and #390 are related; this PR does not close them. |
This was referenced Jul 22, 2026
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Some cuda-oxide deployments finish compiling embedded NVVM IR or LTOIR when
the program first loads. That adds startup work and can require libNVVM and
nvJitLink on the deployment machine.
This PR adds an explicit opt-in that finishes that compilation during the host
build and embeds native GPU code instead:
Default artifact behavior is preserved: without
--materialize-cubin, buildscontinue to embed PTX.
Why this is useful
For a deployment with a known GPU architecture, the program can load the cubin
directly through the CUDA driver. It does not need to run libNVVM or nvJitLink
at startup.
The trade-off is intentional: a cubin targets one real GPU architecture. It
does not provide the forward compatibility or multiple architectures of PTX
or a CUDA fatbinary.
How it works
implementation.
--no-fmad), and debugpolicy are preserved through libNVVM and nvJitLink.
linker identities, toolkit inputs, and
libdevice.toolkit libraries.
and unresolved late-link inputs fail with clear errors instead of producing
an incomplete cubin.
Cargo cache correctness and CI performance
The previous head was not a performance repair. It made target, output, and
materializer fingerprints global
CARGO_ENCODED_RUSTFLAGS, so every mode orarchitecture change invalidated Cargo's shared dependency cache.
Hosted comparison before this repair:
main(52accfa4): compile-examples step 10m25s.7616282c): 22m52s.generated_intrinsics: 3s -> 127s.generated_intrinsics_blackwell: 2s -> 122s.tcgen05: 4s -> 124s.This repair splits the cache boundary according to ownership:
.soSHA-256 remains global because that backend compilesevery crate.
materializer provenance are a full SHA-256 environment dependency recorded
by CUDA procedural macros only in crates that can own or instantiate device
artifacts.
and byte-checked by the backend before cubin generation.
The workflow now checks Cargo compilation events rather than imposing a timing
threshold. PTX -> cubin -> PTX may rebuild
vecadd, and ansm_86->sm_90cross-crate switch may rebuild
kernel-libplus its consumer, but eithertransition fails CI if an unrelated shared dependency recompiles.
Local validation of the repaired candidate compiled all 145 examples in 181s.
The formerly regressed examples completed in 2s, 2s, and 3s respectively. A
focused retained-log run confirmed that each compiled only its owning example
crate. These local timings are supporting evidence; the authoritative hosted
comparison will be recorded after the repaired head runs in CI.
Validation
cargo-oxidetests, including cold/warm/architecture/output/provenanceCargo JSON
freshassertions for an owner, downstream consumer, and plainshared dependency.
sm_86->sm_90cross-crate cache transitions.sm=86with exportedvecaddentry.which recognized
vecaddand embedded a non-empty PTX artifact.No CUDA device was available, so this validation does not make a GPU-execution
claim.
Issue relationship
Issues #378, #388, and #390 are related, but this PR does not close them.
History
The contributor-authored, DCO-compliant commit is preserved. Separate signed
maintainer commits rebuild the feature around the shared finalizer and repair
the Cargo cache boundary.