Repository navigation
fix(#222): load all PTX bundles merged for binaries with generic kernels - #247
Merged
Merged
Conversation
…ernels Generic kernels are monomorphized in the consuming crate, so their PTX ends up in that crate's artifact bundle rather than the defining crate's. Calling `load_embedded_module` with the defining crate's name failed with `named symbol not found` because the kernel symbol lived in a different bundle. Add `load_all_ptx_bundles_merged` to cuda-host: it iterates every PTX bundle in the current binary, strips duplicate header directives (`.version`, `.target`, `.address_size`) from all but the first bundle, and concatenates the bodies into one PTX string for the CUDA driver. The generated `load_named` function in cuda-macros uses this path automatically when any `#[kernel]` in the crate is generic.
Exercises the embedded bundle loading path that issue #222 fixed. The existing cross_crate_kernel example always passed because it loads PTX from a file on disk (load_module_from_file), which bypasses the embedded bundle machinery entirely. This example calls kernel_lib::kernels::load(&ctx) directly, which uses the macro-generated embedded loader. Because the module contains a generic kernel (scale<T>), the macro emits load_all_ptx_bundles_merged instead of load_embedded_module. Without the fix, calling load() would panic with "named symbol not found" because the monomorphized PTX for scale::<f32> lives in the binary crate's bundle, not the library's.
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
…VIDIA#247) The Sphinx author field listed only the first-draft author and is not rendered anywhere visible. List both authors there, add an About This Book page under Reference that credits the first draft explicitly, and extend the copyright year. Signed-off-by: Melih Elibol <[email protected]>
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
…NVIDIA#225, NVIDIA#185) (NVIDIA#256) Three squash merges landed from branches that had resolved a merge against main by keeping pre-merge copies of files, so each one quietly reverted an earlier, unrelated merge: - NVIDIA#239 (2482cb9) reverted NVIDIA#240 (1216aef): the const raw-pointer surface (as_ptr, program_id/num_programs, the cast_* and get_tensor_base helpers, unsafe on load_ptr_tko/store_ptr_tko), the compiler's const-pointer typing, the two GPU test files and the matching book and tutorial text. - NVIDIA#247 (5f5f4c5) reverted NVIDIA#225 (a2843e7): integer division and remainder serialization (rounding<zero> and inferred signedness on divi/remi) and its test. - NVIDIA#187 (35a9cc2) reverted NVIDIA#185 (cbf52c0): the flake.nix toolkit-assembly hardening and host-arch driver directory derivation. This re-applies all three verbatim as cherry-picks. The only overlapping file, cutile-book/guide/performance.md, merges cleanly with NVIDIA#239's own edits. A per-file scan of the last 60 merges finds no other reversal still missing at HEAD: NVIDIA#249's removal of the About page was deliberate, and the two setup-python flips in .github/workflows/pages.yml were re-applied by the later dependabot bump. Verified: cargo fmt, cargo build, and the restored GPU tests (const_pointers, program_id) plus integer_ops, memory_and_atomic_ops and optimization_hints pass on an RTX 5090 with CUDA 13.3. Signed-off-by: Melih Elibol <[email protected]> Co-authored-by: Gabriel Wu <[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
Closes #222.
Generic kernels (e.g.
fn add<T>(...)) are monomorphized in theconsuming crate, not the crate that defines them. Their PTX lands in
the consuming crate's artifact bundle. Calling
load_embedded_modulewith the defining crate's name failed at runtime with:
Fix
cuda-host: add
load_all_ptx_bundles_merged. It iterates everyPTX bundle embedded in the current binary, strips the per-file header
directives (
.version,.target,.address_size) from all but thefirst bundle, and concatenates the bodies into one PTX string for the
CUDA driver. All kernel symbols are then visible regardless of which
bundle they were compiled into.
cuda-macros: during
#[kernel]macro expansion, check whether anykernel in the crate is generic. If so, emit
load_all_ptx_bundles_mergedin the generated
load_namedfunction instead ofload_embedded_module.Non-generic crates continue to use the existing named-bundle path.
Test plan
DriverError(500)cargo test -p cuda-host