Repository navigation
cuda-core: add safe DeviceCopy parity impls - #202
Merged
nihalpasham merged 2 commits intoJun 16, 2026
Merged
Conversation
Signed-off-by: nik <[email protected]>
bool and char have validity holes (only 0/1 for bool, only valid Unicode scalars for char). DeviceCopy promises that ANY value copied back from the device has a valid bit pattern for Self, and to_host_vec does set_len over the raw device bytes with no validation, so a kernel that writes a non-0/1 byte into a DeviceBuffer<bool> (or a surrogate/out-of- range u32 into DeviceBuffer<char>) is UB on readback. The trait's own # Safety docs name bool and char as the canonical reason DeviceCopy must be stronger than Copy, and the merged derive(DeviceCopy) macro (NVIDIA#193) documents the same. Admitting them would contradict both. Keep the representation-preserving parity additions, which are sound: PhantomData<T> (zero-sized), MaybeUninit<T> (any bit pattern valid by design), Wrapping<T> (repr(transparent) over T). Restore the # Safety doc and the type-level test to reject bool/char.
Collaborator
|
Split this one:
Restored the safety doc + the type-level test. If we do want bool/char later, it's worth a deliberate contract change rather than a doc tweak. Everything else looks great. |
elibol
added a commit
to elibol/cuda-rust
that referenced
this pull request
Aug 28, 2026
…head The NVIDIA#233 branch was rewritten while resolving its conflicts with cutile main; 9620a6f is no longer in its history. Repin all 222 example locks at 5cf5a55, regenerate the five that predated the shared-crate switch, and move nvls_all_reduce to simt::vmm now that cutile main's NVIDIA#202 vmm module owns the root name.
nihalpasham
pushed a commit
to elibol/cuda-rust
that referenced
this pull request
Sep 3, 2026
…head The NVIDIA#233 branch was rewritten while resolving its conflicts with cutile main; 9620a6f is no longer in its history. Repin all 222 example locks at 5cf5a55, regenerate the five that predated the shared-crate switch, and move nvls_all_reduce to simt::vmm now that cutile main's NVIDIA#202 vmm module owns the root name.
nihalpasham
added a commit
that referenced
this pull request
Sep 4, 2026
* feat: build the host-side crates from cutile-rs Switches the workspace's cuda-bindings, cuda-core, and cuda-async to the shared host-side crates from cutile-rs, pinned as git dependencies on its feat/cuda-oxide-host-support branch, which carries this workspace's surface under simt modules. The local copies leave the workspace members but stay on disk as standalone packages (the rustc-codegen-cuda pattern, manifests de-inherited), so the example workspaces keep building unchanged. Source changes are mechanical path edits: cuda_async module paths gain the simt level (55 sites in cuda-host and cuda-macros, including emitted code), and bare LaunchConfig becomes cuda_core::simt's, since the root export belongs to the Tile-side type. The cuda_launch_async! trybuild fixtures deepen their local cuda_async stub to match, and the recorded stderr baselines regenerate with the new paths. CI installs CUDA 13.2.0, the shared bindings' minimum. cuda-host and cuda-macros test suites pass against the shared crates, 194 tests plus the trybuild guards, on an RTX 5090. * ci: retire the departed host crates from the lanes; fmt; trybuild baselines cuda-core and cuda-async left the workspace for the shared crates, so the unit-test matrix drops their lanes and the exclusion comment stops naming cuda-bindings; their tests run in cutile-rs CI. The Justfile mirrors the matrix, as its guard requires. deny.toml allows the cutile-rs git source the workspace now pins. rustfmt over the files the path edits touched, and the remaining trybuild stderr baselines regenerate with the simt paths, under both the plain and all-features invocations. * examples: build against the shared host-side crates With cuda-host on the shared crates, every example graph carried two same-named cuda-cores, its own path dependency on the retired local copy and the shared one underneath cuda-host, which cannot type-check together. The example manifests move to the same git dependencies the workspace uses, their sources take the simt::LaunchConfig path the rest of the tree took, and all 218 lockfiles refresh against the new graph. The tile+simt interop example points its cutile dependencies at the same branch, collapsing its graph to a single cuda-core. * examples: rustfmt over the import rewrites * examples: sweep the nested workspaces too Four examples carry a nested device or kernel-lib workspace one level deeper than the sweep reached; they kept path dependencies on the retired local crates, recreating the two-cuda-core graph the sweep exists to remove. Their manifests and lockfiles follow the rest. * examples: catch the aligned-assignment manifests the sweep missed Nine manifests write their dependencies with aligned equals signs, which the exact-string sweep did not match, leaving them on the retired path dependencies. A whitespace-tolerant pass converts them; no path dependency on the retired crates remains anywhere under the examples. * examples: finish the shared-crate switch for all ten failing lanes The async examples take the simt-level module paths, matching cuda-host. The two primitive-f16 examples enable the shared crate's f16 feature, which carries the nightly-gated DeviceCopy impl. nvls_all_reduce builds against simt::vmm, with the multicast surface enabled by the shared crate's new build script, and error-module paths move to the root re-exports since the module is private there. Every lockfile pins the branch rev carrying those additions. * fix: keep tile interop on the tile async surface Signed-off-by: nihalp <[email protected]> * ci: back to CUDA 13.1.1, the shared bindings floor is 12.0 now The shared host-side crates keep cuda-oxide's 12.x support: the bindings floor dropped to 12.0 with the 13.x-only symbols behind header probes, so the toolkit bump this branch carried is no longer needed and the lanes return to their original 13.1.1. * build: pin the shared crates at the 12.8-floor revision Every red lane died in the pinned cuda-bindings build script, which still enforced the old 13.2 floor against the 13.1.1 CI toolkit. All 219 lockfiles move to the branch revision carrying the 12.8 floor, the probed host-function helper, peer, the published oxide-artifacts dependency, and the DeviceCopy derive crate. * build: repin the shared crates at the #233 conflict-resolution head The #233 branch was rewritten while resolving its conflicts with cutile main; 9620a6f is no longer in its history. Repin all 222 example locks at 5cf5a55, regenerate the five that predated the shared-crate switch, and move nvls_all_reduce to simt::vmm now that cutile main's #202 vmm module owns the root name. * build: align example locks to one version per crate Main's #1198 gates CI on sync-example-locks.sh --check; align the git-pinned workspaces the way its own docs prescribe (--align never touches the git pins). 1920 pins moved, 221 locks agree. * ci: detach the retired host crates and name them in the license guard cuda-bindings was never given the standalone [workspace] table its two siblings got at retirement, and main's stricter license guard now walks every tracked manifest. Detach it the same way, commit the three standalone locks the guard's --locked metadata needs, and name all three retired roots first-party so their declared dependencies stay in the inventory. * build: repin the shared crates at aaf1364 The #233 branch gained the extern "C" wrapper ABI and the cuInit coercion regression nihalpasham asked for; manifests are unchanged, so this is a pure pin substitution across all 222 locks. * examples: convert the three examples added on main to the shared crates reborrow, sparse_mma_ordered_float, and shared_stage_select arrived on main with local path deps and root LaunchConfig imports; convert them the established way and seed their locks from vecadd's per the sync script's doc, which lands them aligned on the first try (224 locks agree). This also clears the clippy and cargo-deny lanes, which were failing on the unconverted expansion and the stale --locked resolve. * deps: track cutile-rs main for the shared host crates cutile-rs#233 was squash-merged into cutile-rs main as a2c1ea4 and its feature branch deleted, so the git dependencies on feat/cuda-oxide-host-support no longer resolve. Point the 222 manifests that declare cuda-bindings, cuda-core, and cuda-async at branch main and repin the 225 lockfiles that carry the four shared packages (cuda-bindings, cuda-core, cuda-core-derive, cuda-async, all 0.3.0) at a2c1ea4bb4ae804f573a879785c96f870a4e1b84. The shared crates' manifests are unchanged since the previous pin, so the lock rewrite is a pure source substitution; every one of the 225 workspaces resolves with --locked. The only change in the four crates between aaf1364 and main is the host-side toolkit floor moving from CUDA 12.8 to 13.0 (MIN_CUDA_VERSION 13000 in cuda-bindings/build.rs); CI installs 13.1.1 and already clears it. From here cuda-oxide tracks cutile-rs main; advancing the pin is a deliberate cargo update, reviewed like any dependency bump. Signed-off-by: Melih Elibol <[email protected]> * deps: pin the shared host crates to cutile-rs v0.3.1 Point the 222 manifests that declare cuda-bindings, cuda-core, and cuda-async at the v0.3.1 tag instead of branch main, and re-resolve the 225 lockfiles that carry the four shared packages with cargo update, so they now record cuda-bindings, cuda-core, cuda-core-derive, and cuda-async 0.3.1 at the tag's current target, 9f68be2d0aff0882ec329a453ddc756ad6e4f9e7. Every workspace resolves with --locked and the example locks still agree on one version per crate. Referencing the tag rather than a commit means a re-tag before the final release costs one cargo update pass and no manifest edits. Between a2c1ea4 and the tag the shared crates gained toolkit-discovery parity (CUDA_HOME fallback, targets/<arch>/include lookup, CUDA_TOOLKIT_TARGET_DIR), executed host-crate tests, and the host runtime audit follow-ups; DType became an unsafe trait and several driver wrappers now return Result. None of those surfaces are used by cuda-oxide's own code, and the simt:: modules are unchanged, so nothing here needed adapting. Signed-off-by: Melih Elibol <[email protected]> * docs, scaffold: name the shared crates' simt surface everywhere users copy from The host runtime now comes from the cutile-rs crates, whose cuda-oxide API lives under cuda_core::simt and cuda_async::simt. Every snippet a user copies has to say so: the README, the cuda-host README, the book pages, two example READMEs, and the two cargo oxide new templates. The scaffold also pointed cuda-core, cuda-async, and cuda-bindings at this repository's git URL. With the local copies retired that either resolves to nothing or to a stale copy on an old revision, so the templates now take the crates.io release (SHARED_HOST_CRATES_VERSION) and a test checks no git pin comes back. cuda-bindings leaves the async template: nothing in it names cuda_bindings. Book links that pointed at crates/cuda-core/{src,tests} now point at the simt files in cutile-rs. Signed-off-by: Nihal Pasham <[email protected]> * retire the local host crates for real; CI, licensing, and docs follow the shared crates The switch to the cutile-rs crates left the old crates/cuda-bindings, crates/cuda-core, and crates/cuda-async on disk as standalone packages "so the example workspaces keep building unchanged". Nothing built them: every example already took the git pin, no CI lane tested them, and their only effect was to make `cargo oxide new` resolve `cuda-core` from this repository's git URL to a stale 0.2.1 copy. They are gone, together with the dead `#[derive(DeviceCopy)]` in cuda-macros (cuda-core now re-exports cuda-core-derive's), the three retired roots in the license inventory guard, the CODEOWNERS rule for the moved crate, and the comments that pointed at the old paths (root Cargo.toml, doctor.rs, spine_kernel_ptx.rs, docs.yml). The shared cuda-bindings loads libcuda at run time through libloading instead of linking it, so the libcuda.so.1 stub shadowing in unit-tests.yml, docs.yml, the Justfile, and CONTRIBUTING was dead plumbing; it is removed and the `--exclude cuda-bindings` doctest exclusions with it. bindgen now also reads curand.h, which the flake provides and the docs name. cutile_inter_kernel leaves the license-policy exemption (#953): its git source is allowed and every cutile-rs crate is Apache-2.0, so it is judged like every other example. dependency-licenses.csv describes the crates as resolved (0.3.1 from cutile-rs) and gains cuda-core-derive and dashmap rows. Docs: the CUDA floor is 13.0 with an R580+ driver (README, installation, building-from-source, example READMEs), the remaining root-path snippets move to the simt paths, the `f16` feature is explained where it is enabled, the cuda-host re-export of cuda_async says which surface is which, and the docs.rs links for LaunchConfig point at the simt page. Seven trybuild fixtures get the line-neutral formatting fixes the path rewrite skipped. Signed-off-by: Nihal Pasham <[email protected]> * guards: host-API paths in docs and templates; shared host-crate pin parity Two things the crate switch showed nothing was checking: - Some forty book, README, and scaffold lines kept spelling the old root paths (cuda_core::LaunchConfig, cuda_async::device_operation::...), which on the shared crates either do not resolve or bind cutile's Tile-side types. No lane compiles those snippets. check-host-api-paths.sh greps them for the root spellings that are wrong on the shared crates; it fails on the pre-fix tree at 50 sites and passes now. - The shared-crate release is named once in the root workspace and copied into 221 example manifests and the `cargo oxide new` templates. check-shared-crate-pin.sh requires every copy to agree with the root on version and form (git tag or crates.io), so the crates.io repin cannot leave a straggler and the scaffold cannot drift. Both run in the status-guard workflow and in `just check-guards`. Signed-off-by: Nihal Pasham <[email protected]> * oxide-artifacts: consume the crates.io release everywhere; the in-tree crate is the publish source The backend wrote artifact bundles with the in-tree crates/oxide-artifacts (a path dependency) while the shared cuda-core from cutile-rs reads them through crates.io oxide-artifacts 0.2.1. Same version, same code, but two crates to rustc: the root lock carried both, and nothing tied the two versions together. It worked only because just bytes cross the boundary. The root workspace and the backend workspace now take oxide-artifacts from crates.io like every other consumer, so writer and reader are one crate. crates/oxide-artifacts stays a workspace member as the source the release is published from; format changes go bump, publish, then move the requirement and relock. check-oxide-artifacts-parity.sh keeps the in-tree version, both manifest requirements, and the version resolved in every lock equal, and fails if any lock stops consuming the registry copy. It fails on a drifted in-tree bump and passes on this tree. Runs in status-guard and just check-guards. Validated on an RTX 5090: cargo-oxide, mir-importer, ptx-schedule and backend lib tests, workspace clippy and fmt, all guards, and the full smoketest (222/222) with the backend writing through the registry crate. Signed-off-by: Nihal Pasham <[email protected]> * deps: take the shared host crates from the crates.io 0.3.1 release cutile-rs 0.3.1 is on crates.io (cuda-bindings, cuda-core-derive, cuda-core, cuda-async, and the cutile stack), so the git-tag pin that bridged the gap goes away: - root workspace and all 224 example workspaces (nested ones included) name `"0.3.1"` from the registry; `features = ["f16"]` and the `package = "cuda-core"` rename in cutile_inter_kernel are kept, and cutile_inter_kernel's cutile / cutile-compiler pins move with them - every Cargo.lock re-resolved with `cargo update -w`: 684 source lines flip from `git+...cutile-rs?tag=v0.3.1` to the registry plus a checksum each; no other package moves - deny.toml drops the cutile-rs `allow-git` entry (pliron is the only git source left) - dependency-licenses.csv: the four rows become "1st Party (crates.io)" - async_mlp and async_vecadd drop their direct cuda-bindings dependency; neither names `cuda_bindings` anywhere - comments in the two license guards and the cutile_inter_kernel README stop describing a git dependency Provenance, checked before this commit: the published .crate archives match the v0.3.1 tag tree (cdc69c1) file for file, and their sha256 matches both the crates.io index and the new lock checksums. The tag moved from 9f68be2 (the previous pin) to cdc69c1 for the release; the shared-crate delta is confined to the Tile-side `AsyncKernelLaunch` argument storage in cuda-async plus workspace lint config. The `cuda_async::simt` launch path cuda-oxide uses is unchanged. Signed-off-by: nihalpasham <[email protected]> --------- Signed-off-by: nihalp <[email protected]> Signed-off-by: Melih Elibol <[email protected]> Signed-off-by: Nihal Pasham <[email protected]> Signed-off-by: nihalpasham <[email protected]> Co-authored-by: nihalp <[email protected]>
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
…A#202) * feat(cuda-core): port the CUDA VMM wrappers from cuda-oxide RAII wrappers for the virtual memory management driver API: PhysicalAllocation (cuMemCreate/cuMemRelease), VirtualReservation (cuMemAddressReserve/cuMemAddressFree), Mapping (cuMemMap/cuMemUnmap), plus set_access and granularity helpers. VMM separates physical allocation, VA reservation, and mapping so physical memory from one device can be mapped into another device address space, the foundation for P2P symmetric heaps. Ported from cuda-oxide cuda-core, which is migrating onto this crate. The integration test exercises the full single-GPU lifecycle, alignment edge cases, a data roundtrip through the mapping, and leak-free teardown. The GPU runner executes the target, and the implementation uses the bindings layout helper for CUmemLocation. Signed-off-by: nihalp <[email protected]> * feat(cuda-core): NVLink switch multicast wrappers Safe RAII wrappers for the cuMulticast driver API within this crate CUDA 13.2+ toolkit floor: MulticastObject builds an NVLink SHARP team, add_device registers each GPU, bind_mem attaches per-GPU physical memory, and Mapping::new_multicast maps the team into a device address space so multimem instructions operate on all bound copies. Support and granularity queries allow probe-and-skip on systems without an NVLink switch. Ported from cuda-oxide PR NVIDIA#606, validated end to end on an 8x B200 HGX system there. The two-GPU integration test establishes and tears down the full team plumbing and skips gracefully off NVLS hardware. The shared GPU runner now executes the test. Signed-off-by: David Holtz <[email protected]> Co-authored-by: nihalp <[email protected]> Signed-off-by: nihalp <[email protected]> --------- Signed-off-by: nihalp <[email protected]> Co-authored-by: David Holtz <[email protected]> Co-authored-by: Melih Elibol <[email protected]>
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.
Closes #201.
Problem
cuda_core::DeviceCopydid not cover several standard types whose byte-copy and zero-initialization behavior is safe for device transfer. That left users unable to putbool,char,PhantomData<T>,MaybeUninit<T>, orWrapping<T>in otherwise transfer-safe payloads without writing local unsafe impls.Related context: #192 and #193 added
#[derive(DeviceCopy)]. This PR fills in conservative standard-library parity impls so derived application types can use these fields without downstream unsafe boilerplate.Fix
Add
DeviceCopyimpls at the marker-trait boundary for the safe subset:boolandchar, whose all-zero representations are valid values;PhantomData<T>, which stores no bytes;MaybeUninit<T>whenT: DeviceCopy, becauseMaybeUninitaccepts any initializedness for its payload storage;Wrapping<T>whenT: DeviceCopy, because it is a transparent arithmetic wrapper overT.The documentation examples are adjusted so they no longer describe
boolandcharas rejected types.NonZeroU32remains the example of a type whose all-zero representation is invalid.Diligence
This branch deliberately keeps the trait rule narrow. I did not add bare
NonZero*impls becauseDeviceBuffer::zeroedandPinnedHostBuffer::zeroedmake the all-zero representation part of the public safety contract. I also did not add blanketOption<T>orResult<T, E>impls because their zero validity depends on variant layout and niche choices, not simply onT: DeviceCopy.The tests cover both the type-level marker impls and the runtime zero-initialization path for the newly accepted scalar values.
Tests
Added
crates/cuda-core/tests/device_copy_impls.rs, which checks that the safe standard-library parity types implementDeviceCopy.Extended
DeviceBufferandPinnedHostBuffertests to zero-initializeboolandcharbuffers and read back[false, false, false]and['\0', '\0'].The regression fails on
upstream/mainwithout the impls and passes on this branch.Validation