Skip to content

Further fixes to closure launch ABI - #60

Merged
nihalpasham merged 4 commits into
NVIDIA:mainfrom
josephglanville:jpg/typed-launch-closures
May 27, 2026
Merged

nihalpasham merged 4 commits into
NVIDIA:mainfrom
josephglanville:jpg/typed-launch-closures

Conversation

@josephglanville

@josephglanville josephglanville commented May 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Recently landed fixes to pass aggregate types byval did a lot to unify and fix underlying issues in the closure problem but were not the complete fix, some types of closures aren't getting closure specific handling they need, some problems with ZST and also the pre-existing problem of layout issues.

This PR addresses these problems and extends the test coverage to cover all APIs across a broader range of closure shapes.

Test Coverage

host_closure now runs the same closure cases across all four launch surfaces. The matrix covers:

  • zero-capture closures
  • single scalar capture
  • multiple scalar captures
  • polynomial/four-capture closures
  • where-clause Fn bounds
  • mixed-size captures
  • struct captures with internal padding and mixed field types
  • non-move stack-reference captures

@josephglanville
josephglanville force-pushed the jpg/typed-launch-closures branch 2 times, most recently from e70ae99 to 5aae79c Compare May 15, 2026 02:35
@josephglanville josephglanville changed the title Fix and unify launch closure ABI Further fixes to closure launch ABI May 15, 2026
@josephglanville
josephglanville force-pushed the jpg/typed-launch-closures branch from 5aae79c to 33bc50c Compare May 15, 2026 03:45
@nihalpasham nihalpasham added bug Something isn't working enhancement New feature or request QoL-improvement Quality-of-life improvement; not a correctness fix codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels May 27, 2026
No conflicts. Brings in 51 commits since the PR's merge-base
(b6a06ff), including PR NVIDIA#44 (embedded IR + binary artifacts) and
PR NVIDIA#52 (globaltimer named intrinsic). Re-runs CI against the
merged state.
…dency note

Three follow-up additions on top of the closure ABI fixes:

* Tests 10/11: kernels `map_mut` (`FnMut`) and `map_once` (`FnOnce` + Copy)
  drive the closure-shape sweep through the two remaining trait bounds the
  macro already recognises. The captures are same-size f32s on purpose, so
  these tests don't re-prove the layout fix from tests 7/8 — they exercise
  the device-side dispatch path (`call_mut` / `call_once`) instead of `Fn::call`.

* Test 12: a `#[repr(C)]` counterpart to test 8's reordered struct capture.
  Same fields (u8 / f64 / f32) and same closure body, but `#[repr(C)]` pins
  the layout to declaration order with explicit alignment padding. The layout
  fix in mir-importer has to handle both reordered (default repr) and identity
  -order (repr(C)) cases. Confirmed by reverting the types.rs change locally:
  tests 7, 8, AND 12 all fail with 1024 errors per sub-test; tests 10/11 pass
  (different code path).

* Test 9 (non-move ref captures) now documents that it silently depends on
  Heterogeneous Memory Management — the closure environment carries `&f32`
  pointers into the host stack, and the GPU dereferences them at kernel entry.
  On systems without HMM this surfaces as `CUDA_ERROR_ILLEGAL_ADDRESS`, which
  the smoketest's `verdict_standard` correctly flags as FAIL via the failure-
  marker regex — but the test should at least name the dependency so the next
  debugger isn't surprised.

Verified: 48/48 sub-tests pass on RTX 5090 (sm_120) via both `cargo oxide run`
and `scripts/smoketest.sh --only host_closure`. fmt-check, `clippy --workspace`,
and the full per-package cargo test matrix all clean.

@nihalpasham nihalpasham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is excellent 🚀 and LGTM.

Pushed 2 commits on top to layer some extra defensive coverage and bring the branch up to date:

  • ba047a5 Merge origin/main — no conflicts, picks up PR #44 and PR #52 since fork.
  • fecec55 Three additions to host_closure:
    • Tests 10/11: FnMut and FnOnce kernels exercising the device-side dispatch paths the macro already recognized via find_closure_generic. They pass with or without the layout fix (same-size captures) — pure defensive coverage of the dispatch trait.
    • Test 12: #[repr(C)] counterpart to test 8. Locks down that the layout fix handles identity-order layouts with alignment padding too. Adversarial check confirms it ALSO fails 1024/1024 when types.rs is reverted.
    • Test 9: one-line note that non-move ref captures depend on HMM (sm_75+ on Linux); GPUs without HMM surface this as CUDA_ERROR_ILLEGAL_ADDRESS, which verdict_standard flags as FAIL.

@nihalpasham
nihalpasham merged commit 54252d0 into NVIDIA:main May 27, 2026
20 checks passed
nihalpasham added a commit to ur4t/cuda-oxide that referenced this pull request May 27, 2026
Brings in the 20 commits that have landed since the PR's merge-base
(c8b3103), including PR NVIDIA#44, PR NVIDIA#52, and PR NVIDIA#60. Auto-merges cleanly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) enhancement New feature or request QoL-improvement Quality-of-life improvement; not a correctness fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants