Skip to content

feat(cuda-oxide): carry inline intent through the device pipeline - #1511

Open
ssoj13 wants to merge 1 commit into
NVIDIA:mainfrom
ssoj13:nvidia/feat/inline-intent
Open

ssoj13 wants to merge 1 commit into
NVIDIA:mainfrom
ssoj13:nvidia/feat/inline-intent

Conversation

@ssoj13

@ssoj13 ssoj13 commented Oct 13, 2026

Copy link
Copy Markdown

Carry Rust's device-function inline intent through MIR into LLVM: #[inline] becomes inlinehint, #[inline(always)] becomes alwaysinline, and #[inline(never)] becomes noinline. Previously only alwaysinline survived. The verifier rejects malformed intent and intent on kernel entries.

Port of ansidium/cuda-rust-windows#11, independently adapted to NVIDIA main bc46b1ffb. It preserves the recently added kernel reference-validity attributes and uses rustc_attr_ir::InlineAttr, the type in the pinned nightly-2026-10-11. Related: #188 and #189.

The generic #[device] collector boundary remains a deliberate exception: its macro-injected noinline is a host collection requirement and must not block device const-generic folding. This does not resolve user inline attributes being shadowed by that macro on generic functions (#1471).

Verified on pinned nightly-2026-10-11, Linux/WSL2, CUDA 13.3 and RTX 3080 Ti:

  • Tests and clippy/all targets with -D warnings pass for dialect-mir, llvm-export, mir-importer, mir-lower, mir-transforms and reserved-oxide-symbols.
  • The rustc-codegen-cuda backend's library tests and clippy/all targets pass.
  • A backend built from this branch runs const_generic --arch sm_86 (distinct VALUE=4/8 results) and addressof_sharedarray --arch sm_86 (pointer/device-call round trips and raw receiver checks pass).
  • Formatting and SPDX checks pass.

The original change was authored by Alex Khal with Claude Code. This adaptation and current verification were prepared with Codex; original attribution and DCO are preserved.

…uded

Device code only reached LLVM with `alwaysinline`: `#[inline]` hints were
dropped and `#[inline(never)]` became an ordinary function that `opt` was
free to inline. Code that relies on a call boundary (to keep a helper's
floating-point contraction identical across call sites, or to bound code
size in a hot loop) could not express it.

`InlineIntent` (`MirFuncOp::inline_intent`) records the Rust attribute on the
imported function and the lowering maps it to LLVM function attributes:
`#[inline]` -> `inlinehint`, `#[inline(always)]` -> `alwaysinline`,
`#[inline(never)]` -> `noinline`, rendered through `llvm_func_attrs` like any
other function attribute. The MirFuncOp verifier rejects an unknown keyword
and any intent on a kernel entry (a `.entry` is never called, so an inline
keyword on it has no meaning); a new test covers both rules. No inliner pass
is added: `opt` honours the keywords.

One `#[inline(never)]` is not carried: the one `#[device]` puts on the
prefixed function of a device function with its own type or const
parameters, so each monomorphization stays a separate item for the
collector. It is a host-side boundary; as `noinline` it would keep every
call and stop const-generic arguments from folding into their callers (the
`const_generic` example checks that they fold). The macro's attribute comes
first, so rustc keeps it and reports an inline attribute the user adds there
as unused; on such functions a user's own inline attribute did not reach
device code before this change and does not now. The match uses
`opt_item_name`, so closures, which may carry `#[inline(never)]`, are
handled like any other function.

Signed-off-by: Alex Khal <joss13@gmail.com>
Signed-off-by: ssoj13 <96214515+ssoj13@users.noreply.github.com>
@ssoj13
ssoj13 requested a review from nihalpasham as a code owner October 13, 2026 19:29
@copy-pr-bot

copy-pr-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@nihalpasham nihalpasham added the cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book label Oct 15, 2026

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

cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants