Repository navigation
fix(ptx): internalize non-root device helpers - #387
Merged
nihalpasham merged 5 commits intoJul 23, 2026
Merged
nihalpasham merged 5 commits into
nihalpasham merged 5 commits into
Conversation
Signed-off-by: nik <[email protected]>
…nalization emit_llvm_used and public_symbols each re-implemented the kernels-if-any-else-device-functions rule, so the @llvm.used set and the internalize public-API list could silently drift apart. Compute the root list once, as the union of kernel entries and #[device] definitions: a #[device] export now stays visible even in a module that also has kernels, while anonymous helpers carry neither marker and remain internalizable.
The NVIDIA#410 libdevice test predates public_symbols; pass the module's kernel as the internalization root so the test now also covers the llvm-link + internalize composition.
nihalpasham
force-pushed
the
codex/upstream-internalize-ptx-helpers
branch
from
July 23, 2026 10:30
295575a to
6d1d74d
Compare
Collaborator
|
Thanks for the PR What landed on top of your commit:
Validated: exporter and codegen suites including your spine regression (which fails on unfixed main: a fully inlined helper used to survive |
Threading public_symbols through generate_ptx alongside NVIDIA#410's libdevice parameter pushed both entry points past clippy's argument limit. The module-shaped inputs (IR path, PTX output path, symbol roots) already had a struct inside the impl; take PtxModule at the public boundary too instead of three loose parameters.
The compile-only gate required the two nested_identity monomorphizations to survive as .visible .func in the final PTX. Internalizing non-root helpers deliberately inlines and deletes them there, which is the optimization this branch adds. What the NVIDIA#358 regression actually needs pinned is canonical mangling and non-kernel classification, and both are decided before the middle-end runs: assert them in the pre-opt LLVM IR instead, and keep the PTX assertions for the single kernel entry and the absence of _TID_ helper symbols.
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.
Closes #386.
Summary
Make LLVM's optimized PTX pipeline internalize compiler-private device helpers so ordinary inlining and GlobalDCE can remove their unused definitions. Preserve the module's exporter-derived public ABI, including kernel entries, standalone device-function roots, and defined globals.
What changed
Semantic public roots
ExportedModule.PTX optimization
internalize,default<O2>with the explicit public API list when roots are available.-O2path for modules without roots and leave no-opt compilation unchanged.Correctness hardening
Known separate limitations
Testing
cargo oxide fmt --checkcargo test -p llvm-export— 26 unit tests, 46 export integration tests, and 3 operation tests passedcargo test -p cuda-oxide-codegen— 59 unit tests, 10compile_to_ptxtests, concurrent and spine integrations, and 1 doctest passedcargo clippy -p llvm-export -p cuda-oxide-codegen --all-targets -- -D warningsopt/llcartifact regression: optimized PTX retainsadd_kerneland removesunused_helper; no-opt PTX retains the helpersm_86): optimizedconstant_memorysuccessfully looked up, populated, and read its host-visible constant across two launchessm_86): optimized and no-optarray_for_loopruns passed during branch preparationChecklist
upstream/main