Repository navigation
feat(cuda-module): #[cooperative_launch] for grid-wide sync on the typed path - #169
Merged
Merged
Conversation
cuLaunchKernelEx takes an array of launch attributes, so one call can carry both CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION and CU_LAUNCH_ATTRIBUTE_COOPERATIVE. Add launch_kernel_ex_cooperative and its context-binding launch_kernel_ex_cooperative_on_stream wrapper, mirroring the existing launch_kernel_ex / launch_kernel_cooperative pair. This is the driver path used when a #[cuda_module] kernel combines #[cluster_launch(...)] with #[cooperative_launch].
Mirror the cluster_dim knob: a cooperative flag stored on the builder (set_cooperative, next to set_cluster_dim) and applied at launch time. The launch dispatch now picks the driver entry point from the (cluster_dim, cooperative) pair: plain cuLaunchKernel when neither is set, and cuLaunchKernelEx with the matching attribute(s) otherwise. Cooperative launches are the precondition for grid-wide barriers (cuda_device::grid::sync()); until now only the legacy cuda_launch\! macro could request one.
Doc-hidden helper next to set_async_kernel_cluster_dim, so code generated by #[cuda_module] can flip the cooperative knob on an AsyncKernelLaunch without naming cuda-async types directly. Exported from the crate root under the async feature, exactly like the cluster-dim shim.
…rnels A bare #[cooperative_launch] marker on a #[kernel] inside a #[cuda_module] module routes every generated launch shape through the cooperative driver path, mirroring how #[cluster_launch] is wired: - the sync method calls launch_kernel_cooperative_on_stream instead of launch_kernel_on_stream; - the borrowed-async and owned-async builders call set_async_kernel_cooperative right where set_async_kernel_cluster_dim is set for cluster kernels; - combining #[cooperative_launch] with #[cluster_launch] is allowed (cuLaunchKernelEx accepts both attributes in one call) and routes through launch_kernel_ex_cooperative_on_stream. The attribute itself is a validating pass-through: unlike #[cluster_launch] it changes nothing in the PTX, because cooperative-ness is purely a launch-time property. It is re-exported from cuda-device next to the other kernel attributes. Tests: - cuda-macros unit tests pin the generated tokens for the cooperative, plain, combined, and async shapes, and the no-arguments rule; - cuda-host's cuda_module_api compile test grows a #[cooperative_launch] kernel so the generated sync/async/owned-async methods keep typechecking against the real helpers.
…yped path Move test_grid_sync and test_typed_grid_sync into a #[cuda_module] module and mark them #[cooperative_launch]; their two 'cooperative: true' cuda_launch\! call sites become typed module.<kernel>(...) calls. Kernel bodies and every other cuda_launch\! call in the example are unchanged, so the device-verified grid-sync checks remain the live regression for the new attribute on GPU runs. Also add a compile-only kernel combining #[cluster_launch(2, 1, 1)] with #[cooperative_launch]. It is never launched; it pins that the combination compiles end to end (macro expansion, generated host methods against the combined cuda-core helper, and device PTX).
Add a 'Cooperative launch' section to the launching-kernels chapter, list the attribute in the API quick reference, and point the supported-features entry at the typed #[cuda_module] path alongside the legacy cuda_launch\! flag.
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 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
Kernels using
grid::sync()can now launch through the typed#[cuda_module]path; previously cooperative launch existed only in the legacycuda_launch\!macro.Mirrors the
#[cluster_launch]precedent at every layer: cuda-core gainslaunch_kernel_ex_cooperative[_on_stream](onecuLaunchKernelExcarrying both the cluster and cooperative attributes when combined),AsyncKernelLaunchgainsset_cooperativenext toset_cluster_dimwith a 4-way dispatch, cuda-host gains the doc-hidden shim, and the macro stores the flag and routes all three generated launch shapes (sync, async, owned-async). Combining with#[cluster_launch]is allowed becausecuLaunchKernelExexpresses both attributes in one array; a never-launched kernel pins that the combination compiles.Evidence
coop_groups_demo's two grid-sync tests now launch through the typed path and PASS on sm_120 (they deadlock or mis-sum if the attribute is not genuinely applied), with kernel bodies byte-identical to before.-Zunpretty=expanded) to verify the sync path reacheslaunch_kernel_cooperative_on_streamand both async builders set the flag; non-cooperative kernels are unchanged (several untouched examples rebuilt and verified).