Repository navigation
fix(codegen): pin library-crate device artifacts with a link-anchor symbol - #166
Merged
Merged
Conversation
…ymbol
A #[cuda_module] in a library crate compiles its PTX into an extra
object file holding only the .oxart data section. For binary crates
that object is passed straight to the linker and always survives, but
for library crates it becomes an rlib archive member, and linkers only
extract archive members that define a symbol someone references. The
artifact object defined no symbols, so the member was silently dropped
and kernels::load(&ctx) failed at runtime with
ModuleNotFound { name: "<lib package name>" }.
Fix it with a symbol handshake, the same mechanism nvcc uses to anchor
fatbin registration objects:
- oxide-artifacts: build_host_object_for_target can now define a
global hidden data symbol at the start of the .oxart section.
- rustc-codegen-cuda: derives the anchor name from CARGO_PKG_NAME and
CARGO_PKG_VERSION and defines it in every embedded artifact object.
- cuda-macros: the generated load_named() reads the anchor's address
through black_box, so any caller of load() carries an undefined
reference that forces the linker to extract the artifact member.
Modules with only generic kernels skip the reference (their PTX is
monomorphized and embedded in the consuming crate); modules whose
concrete kernels are all cfg-gated guard the reference with the
disjunction of those cfg conditions.
- reserved-oxide-symbols: owns the anchor naming contract
(artifact_anchor_symbol). The version is part of the name so two
versions of one package each keep their own bundle.
The new cuda_module_in_lib example puts the #[cuda_module] in a nested
library crate and verifies, before any CUDA call, that both the
library bundle and the binary's own bundle are embedded in the
executable, then loads and launches kernels from both modules.
Fixes #72
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
Signed-off-by: Melih Elibol <[email protected]>
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
A
#[cuda_module]defined in a library crate now survives into the final binary; previously it failed at runtime withModuleNotFound.Evidence
cuda_module_in_libputs the#[cuda_module]in a nested library crate and loads it from the binary; executes on sm_120 (this is the actual runtime repro, so the fix is proven on hardware, not just by object inspection)..oxart, and reproduces the missing-bundle failure. Retention proven bynm/objcopyinspection, under-Wl,--gc-sections(SHF_GNU_RETAIN), and for a partial-use rlib vialld --why-extractshowing the exact designed extraction chain.cross_crate_kernelstill passes.Fixes #72