Skip to content

Plan native library shared storage in prepared MIR - #1574

Draft
tpn wants to merge 81 commits into
NVIDIA:mainfrom
tpn:codex/coop-interop-native-storage
Draft

tpn wants to merge 81 commits into
NVIDIA:mainfrom
tpn:codex/coop-interop-native-storage

Conversation

@tpn

@tpn tpn commented Oct 20, 2026 •

Copy link
Copy Markdown

Native library calls need shared memory whose size and alignment depend on their specialization. This change moves storage identity, reuse and allocation analysis into rustc-free prepared MIR after mem2reg. The compiler carries the resulting layout into checked launches.

Full-block calls support managed reuse, shared or exclusive descriptors, synchronization policy and typed reservations. Borrowed wrapper fields preserve descriptor, allocation-witness and reservation identities across helpers. Scratch-free calls add no allocation or completion barrier. This update also supports Rust 1.99.1.

Owning host tests, strict Clippy/rustdoc, all 37 compiler cases and the original 96 storage plus 480 checked GPU cases pass. Both ordinary Git and fresh HTTPS installations use matching automatic backends and pass those GPU cases. The 24 storage entries match across routes; all five HTTPS checked entries differ in code and register counts while retaining ABI, launch facts and shared/stack/local allocations. The previous nightly comparison also retains three bounded minimum-instruction differences; whole images remain different. No compile-time speedup is claimed.

Builds on #1572 and its prerequisites. Review the 25-file storage change above #1572. GitHub's Files tab remains cumulative against main: narrow existing-number stacks require maintainer-created upstream parent branches or prerequisite landing. This PR remains draft.

fxeqxmulfx and others added 30 commits October 12, 2026 02:14
With `lto = "fat"` or `lto = "thin"`, the build of a binary that uses a
library with kernels stopped with an error: "failed to get bitcode from
object file for LTO (Can't find section .llvmbc)". rustc keeps a list of
the Rust objects in each rlib. This list contains the objects of all
modules. With LTO, rustc reads bitcode from these objects and removes
them from the link. The artifact objects have no bitcode.

If a session writes an rlib, the backend now gives each artifact object
to rustc as the DWARF object of its module. This object is in the rlib,
but it is not in the list. LTO does not read this object, and the linker
gets it from the rlib.

The system linker does not get the DWARF objects. If the session also
writes a binary or a dynamic library, the backend gives the artifact
objects to this linker as link arguments. With
`-Zlink-native-libraries=no`, rustc does not give link arguments to the
linker. Then the artifact objects of this session are Rust objects, as
before.

The book said that `join_codegen()` and `link()` only call the LLVM
backend. Now it tells what they add to the outputs.

CI builds `cuda_module_in_lib` with fat LTO. The library is an rlib, and
then an rlib and a cdylib. After each build, CI makes sure that the
binary has the PTX bundles of the library and of the binary. It also
makes sure that the cdylib has the PTX bundle of the library.

Fixes NVIDIA#1495

Signed-off-by: Mikhail Borisov <mikhail.boriso2014@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use Cargo target names for standalone emit-ltoir artifacts. Bind the
compiler and reader to the same intermediate directory when invoked
from a Cargo workspace member.

Signed-off-by: Trent Nelson <trent@trent.me>
Accept ordered external LTO files when materializing embedded cubins.
Include their content in the codegen fingerprint and verify owned bytes
before linking through the existing finalizer. Preserve inputs that
overlap generated output paths and diagnose unresolved device symbols.

Add a standalone CUDA FFI example and a native regression script.

Signed-off-by: Trent Nelson <trent@trent.me>
Reuse existing example dependency pins and classify external LTO as
an FFI fixture. Run its linking regression in native sweeps and verify
relocatable debug output in the existing full-debug route.

Signed-off-by: Trent Nelson <trent@trent.me>
Preserve exact geometry and fixed dynamic shared-memory requirements
through artifact loading so preparation can select and validate the
compiled allocation. Keep artifact writers and readers on one in-tree
implementation while preserving legacy bundles without launch facts.

Signed-off-by: Trent Nelson <trent@trent.me>
Combine the reviewed compiler prerequisites for native library calls.
Keep the external LTO fixture on the shared in-tree artifact implementation.

Signed-off-by: Trent Nelson <trent@trent.me>
Use the reviewed Cargo target and output-directory correction in the
combined compiler prerequisite tree.

Signed-off-by: Trent Nelson <trent@trent.me>
Resolve concrete registration functions and scalar argument types during
device compilation, then invoke the native provider and link its owned
LTO output through the ordinary artifact finalizer.

Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Carry the convergence marker through private dependency metadata and
emit it on each marked LLVM declaration before native optimization.
Deduplicate repeated extern symbols while rejecting incompatible
signatures and convergence requirements.

Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>

# Conflicts:
#	cuda-oxide/crates/rustc-codegen-cuda/src/library.rs
Keep original MIR and static identities while emitting checked helper

bodies for each root. Route typed calls and native plans through those

bodies so shared helpers can use distinct block shapes.

Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Treat each block as one cluster when a known earlier target is selected.
Bind a device hint only after this fallback is used, so later feature
selection cannot silently change its semantics. Keep raw intrinsic and
cluster operation target requirements intact.

Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
tpn added 9 commits October 21, 2026 21:54
Instantiate a registration getter constant with its concrete function
arguments before reading the registration text. Exercise the existing
raw native calls through a generic associated-constant getter.

Signed-off-by: Trent Nelson <trent@trent.me>
Instantiate a registration getter constant with its concrete function
arguments before reading the registration text. Exercise the existing
raw native calls through a generic associated-constant getter.

Signed-off-by: Trent Nelson <trent@trent.me>
Carry native-call identities and source effects through the importer,
then validate collective participation and payload ownership in the
rustc-free MIR pipeline. Require the consumed proof before materializing
native calls and preserve destination checks during result forwarding.

Remove the raw rustc MIR collective checker.

Signed-off-by: Trent Nelson <trent@trent.me>
Carry the accepted generic registration owner into the block proof
chain. The merged source tree is unchanged.

Signed-off-by: Trent Nelson <trent@trent.me>
Carry the provider branch onto the upstream shared-host v0.5 source.
Refresh the launch-facts example lockfile for the four local packages
so the merged example workspace resolves with --locked.

Signed-off-by: Trent Nelson <trent@trent.me>
Keep both standalone native examples locked to the local v0.5 host
packages after the upstream integration. Third-party dependencies and
all dependency edges are unchanged.

Signed-off-by: Trent Nelson <trent@trent.me>
Retain the rustc-free collective analysis and typed provider changes
while joining the current upstream host and tooling updates.

Signed-off-by: Trent Nelson <trent@trent.me>
Return summaries already receive nonreturn effects through the settled
incoming states. Transfer return blocks to collect their results, and
keep the complete traversal when validating source obligations.

Signed-off-by: Trent Nelson <trent@trent.me>
Allocate native scratch and validate its reuse in rustc-free MIR passes.
Carry authenticated descriptor facts through import, then lower the
validated plan into shared views and launch requirements.

Signed-off-by: Trent Nelson <trent@trent.me>
@tpn
tpn force-pushed the codex/coop-interop-native-storage branch from 240366d to 82b16db Compare October 23, 2026 03:49
@tpn tpn changed the title Plan native library shared storage and checked reuse Plan native library shared storage in prepared MIR Oct 23, 2026
tpn added 19 commits October 22, 2026 22:18
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Preserve upstream backend selection and output ownership across the
prepared-module pause while retaining native proof and late lowering.

Signed-off-by: Trent Nelson <trent@trent.me>
Carry the storage ownership and planning changes onto the refreshed
checked compiler pipeline. Preserve the existing borrowed-wrapper
semantics and proof ordering.

Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>
Recognize genuine core integer methods at the import boundary and
retain their scalar effects on the original direct calls. Other
helper calls keep their conservative borrow handling.

Signed-off-by: Trent Nelson <trent@trent.me>
Check signed and unsigned imports and preserve ordinary call effects
when no direct target is selected. Clarify the source metadata comment.

Signed-off-by: Trent Nelson <trent@trent.me>
Signed-off-by: Trent Nelson <trent@trent.me>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book Depends Blocked on another PR/issue or an upstream dependency device-apis User-facing device-side and kernel-authoring APIs (cuda-device, cuda-macros) enhancement New feature or request interop Interop with external compilers / frontends safety Memory safety, soundness, or undefined behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants