Repository navigation
feat(cuda-macros): make cuda_launch\! a caller-unsafe API - #171
Merged
Merged
Conversation
The legacy launch macro checks neither argument count nor types (issue #29): a forgotten argument makes the driver read past the end of the args array, and a `&struct` argument marshals a host stack address the device then dereferences. For kernels embedded at compile time the checked #[cuda_module] path is the replacement (cooperative launch and the example ports landed earlier). The macro's remaining legitimate niche is kernels loaded at runtime by name, where no compile-time signature exists to check against, so safety cannot be built there, only labeled. This is the labeling: the expansion no longer wraps its calls to the unsafe cuda_core launch functions, so every use must sit inside the caller's own `unsafe { }` block, with the contract documented on the macro (argument count, order, and types must match the named kernel's real signature; pointer arguments must be device-accessible). A trybuild compile-fail test pins that a bare cuda_launch\! is rejected with the missing-unsafe error. All remaining in-tree call sites (the two deliberate low-level API examples, the fuzzer harness, host_closure's secondary variant, and coop_groups_demo's non-cooperative calls) are wrapped with one-line SAFETY comments. README and book sections now present #[cuda_module] first and the macro as the unsafe escape hatch for runtime-loaded modules. The macro is not deprecated or removed; that is a separate decision. References #29 (the typed-path half landed as the cooperative-launch and example-port PRs).
The launch_requires_unsafe trybuild fixture dev-depends on cuda-host and cuda-core so the real cuda_launch\! expansion type-checks, which pulls cuda-bindings into the test build; its build script needs cuda.h. Install the toolkit for the cuda-macros matrix row, the same pattern as cuda-host/cargo-oxide/cuda-async.
nihalpasham
added a commit
to goog00/cuda-oxide
that referenced
this pull request
Jun 12, 2026
…odule] Main made bare cuda_launch! a caller-unsafe API (NVIDIA#171) after this example was written, so its host side no longer compiles (E0133). The typed #[cuda_module] launch path is the safe replacement the other math examples already use; the 16-value x 2-width host comparison and the SUCCESS marker are unchanged.
This was referenced Jun 12, 2026
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
cuda_launch\!now requires the caller's ownunsafe { }block; a bare invocation no longer compiles.Why unsafe rather than checked
Issue #29: the macro validates neither argument count nor types — a forgotten argument sends the driver past the end of the args array (host UB), and
&structmarshals a host stack address the device dereferences. For embedded kernels, the checked answer already exists:#[cuda_module]'s generated methods make these mistakes compile errors, and the prerequisites landed earlier (#169 cooperative launch, #170 example ports). What remains for the macro is launching kernels loaded at runtime by name — external PTX, LTOIR-linked artifacts, fuzzer output — where no compile-time signature exists to check against. For that niche, safety cannot be built, only labeled honestly.How
unsafeblocks are removed, surfacing the obligation to the caller (E0133 otherwise); the safety contract is documented on the macro in plain language.launch_requires_unsafe) pins the rejection with expected stderr.manual_launch_generic,manual_launch_libdevice(the deliberate low-level API coverage),rustlantis-smoke,host_closure's secondary variant,coop_groups_demo's non-cooperative calls.#[cuda_module]and present the macro as the unsafe escape hatch. Not deprecated/removed — separate decision.Evidence
References #29