Skip to content

fix(cargo-oxide): take the scaffold's host crates from cuda-host's git source - #1488

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
alejandro-soto-franco:fix/scaffold-single-cuda-core
Oct 15, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
alejandro-soto-franco:fix/scaffold-single-cuda-core

Conversation

@alejandro-soto-franco

@alejandro-soto-franco alejandro-soto-franco commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What this adds

cargo oxide new wrote a manifest that took cuda-device and cuda-host from the repository's git URL but cuda-core (and cuda-async with --async) from crates.io 0.4.0. cuda-host depends on cuda-core by path inside that checkout, so every scaffolded project resolved two cuda-core packages and the code #[cuda_module] generates failed to type-check. The templates now name every CUDA crate from the same git source, so cargo resolves one copy of each.

Before:  cuda-host = { git = <repo> }   cuda-core = "0.4.0"
         Cargo.lock: cuda-core x2 (registry + git), cuda-bindings x2, cuda-core-derive x2
         error[E0308]: expected `cuda_core::simt::context::CudaContext`, found `CudaContext`
         7 errors sync, 13 errors async; nothing runs

After:   cuda-host = { git = <repo> }   cuda-core = { git = <repo> }   cuda-async = { git = <repo> }
         Cargo.lock: cuda-core x1, cuda-bindings x1, cuda-core-derive x1, all at one commit
         PASSED: all 1024 elements correct
#[cuda_module]
mod kernels {
    #[kernel]
    pub fn vecadd(a: &[f32], b: &[f32], mut c: DisjointSlice<f32>) { /* ... */ }
}
let module = unsafe { kernels::load(&ctx)? }; // generated code names cuda-host's CudaContext

What we fixed

  • Both templates take cuda-core and cuda-async from GIT_REPO, the source cuda-host comes from; SHARED_HOST_CRATES_VERSION is gone.
  • check-shared-crate-pin.sh section 3 requires git = "{GIT_REPO}" on every host-crate line in the templates and rejects a crates.io requirement there.
  • New test scaffold_takes_every_cuda_crate_from_one_git_source asserts every cuda-* line in both templates names the same git source as cuda-device.
  • The manifest comment and the status-guard step name that still described a crates.io scaffold now describe the git source.

Scaffold dependency contract

Every CUDA crate in a new project comes from one git source with no version requirement. The first build locks all of them to one commit of that repository, and cargo update moves them together. A crates.io cuda-core or cuda-async beside a git cuda-host is always a second crate and does not compile.

Implementation

Verification

Checked at 180770a9:

  • ✅ cargo test -p cargo-oxide --all-targets: 244 passed. With the old template lines restored and the new tests kept, 3 scaffold tests fail.
  • ✅ cargo clippy -p cargo-oxide --all-targets -- -D warnings, cargo fmt --check and rustdoc with -D warnings clean.
  • ✅ All 18 check-*.sh guards pass. check-shared-crate-pin.sh rejects four reintroduced forms (cuda-core = "0.4.0", { version = "0.4.0" }, a different git URL, cuda-async = "0.4.0") with exit 1.
  • ✅ Baseline: main's cargo oxide new for both templates fails to build, 7 and 13 errors, with two cuda-core, cuda-bindings and cuda-core-derive per lockfile (and two cuda-async).
  • ✅ Fix: cargo oxide new then cargo oxide run for both templates on an RTX 5090 (sm_120a, CUDA 13.4): PASSED: all 1024 elements correct, compute-sanitizer --tool memcheck 0 errors, one cuda-core per lockfile and zero registry cuda-* packages. Same result on the author's RTX 5060 Laptop (sm_120, CUDA 13.3).
  • ✅ Merges cleanly with fix(cargo-oxide): scaffold and clone from NVIDIA/cuda-rust #1489 in either order; after both, every template line names https://github.com/NVIDIA/cuda-rust.git.

Caveats

  • The test and guard compare the git URL only. A rev, branch or tag added to one line still resolves a second cuda-core, even at the same commit; a follow-up tightens the comparison to the full source.
  • No CI job compiles a scaffolded project, which is how the broken template survived from 2026-10-01; a scaffold compile gate is a separate follow-up.
  • The GPU runs used a cached backend; the standalone backend build from the scaffold's git checkout is unchanged by this PR and was not re-run here.
  • GIT_REPO still names NVlabs/cuda-oxide, which GitHub redirects; fix(cargo-oxide): scaffold and clone from NVIDIA/cuda-rust #1489 renames it.

Closes #1459.

…t source

`cargo oxide new` named cuda-core (and, with --async, cuda-async) from
crates.io at 0.4.0 next to a git cuda-host. cuda-host depends on those crates
by path at tip of tree. The lockfile therefore carried two cuda-core packages
and the expansion of #[cuda_module] failed to type-check: 7 errors in the
sync template, 13 in the async one, all CudaContext/CudaModule mismatches.

The templates now take cuda-core and cuda-async from GIT_REPO, the source
cuda-host already comes from, and SHARED_HOST_CRATES_VERSION goes away.
check-shared-crate-pin.sh section 3 now requires every host-crate line in
the templates to use GIT_REPO and rejects a crates.io requirement there. A
new test asserts the same invariant over both templates.

Signed-off-by: Alejandro Soto Franco <sotofranco.eng@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 11, 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
The scaffold now names every CUDA crate from the git source cuda-host
comes from, and the guard checks for that instead of a crates.io version
constant. Rewrite the root manifest comment that still named the removed
constant, and the status-guard job comment and step name that still
described a crates.io release copied into the templates.

Signed-off-by: nihalpasham <nihalp@nvidia.com>
@nihalpasham

Copy link
Copy Markdown
Collaborator

/ok to test a536122

@nihalpasham nihalpasham added bug Something isn't working cargo-oxide The `cargo oxide` subcommand and build automation build-related Build scripts, toolchain discovery, or compilation setup labels Oct 15, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

I verified the breakage and the fix at a5361224 on the 5090 box:

  • On main, a cargo oxide new project resolves two cuda_core crates (crates.io 0.4.0 and the git copy cuda-host pulls by path) and fails with the CudaContext type mismatches. With this change both templates compile and the lockfile has one cuda-core.
  • I added one commit on top: two comments that still described the removed version constant (root manifest and the status-guard job). Nothing else changed.
  • 244 cargo-oxide tests, clippy, fmt and all 18 guards pass. CI is green on this head.

Merges cleanly with #1489 in either order. Closes #1459: the scaffold no longer needs a version derived from the root manifests.

@nihalpasham
nihalpasham merged commit db977a4 into NVIDIA:main Oct 15, 2026
60 checks passed
nihalpasham added a commit that referenced this pull request Oct 15, 2026
## What this adds

`cargo oxide new` writes the repository address of `cuda-device` and
`cuda-host` into every new project's manifest, and the backend fallback
clone fetches the same address when no cuda-oxide dependency pins a
commit. Both still named the pre-move `NVlabs/cuda-oxide` repository,
which resolves only through GitHub's redirect and leaves every new
lockfile recording the old source. Both now name `NVIDIA/cuda-rust`.

```text
cargo oxide new demo

Before  cuda-device = { git = "https://github.com/NVlabs/cuda-oxide.git" }
        source = "git+https://github.com/NVlabs/cuda-oxide.git#bc46b1ff..."   (via redirect)
        checkout ~/.cargo/git/checkouts/cuda-oxide-<hash>/bc46b1f/

After   cuda-device = { git = "https://github.com/NVIDIA/cuda-rust.git" }
        source = "git+https://github.com/NVIDIA/cuda-rust.git#bc46b1ff..."    (direct)
        checkout ~/.cargo/git/checkouts/cuda-rust-<hash>/bc46b1f/
```

```bash
cargo oxide new demo && cd demo
cargo oxide build   # builds the backend from the checkout Cargo made for cuda-device
```

## What we fixed

- `GIT_REPO` in `scaffold.rs`, interpolated into both scaffold
templates, now reads `https://github.com/NVIDIA/cuda-rust.git`.
- The fallback `git clone --depth 1` in `backend.rs`, used only for
projects with no cuda-oxide dependency, clones the same address.
- The `backend_source.rs` module diagram, its test constant and the
matching README diagram follow: the checkout is `cuda-rust-<hash>`, and
the backend crate and the toolchain pin sit under `cuda-oxide/` in it.
- A scaffold test asserts the emitted `git =
"https://github.com/NVIDIA/cuda-rust.git"` lines in both templates and
rejects the old address.

<details><summary>Implementation</summary>

- Backend discovery never reads the URL:
`dependency_source_from_metadata` keys on the package name and
`manifest_path`, `git_source_rev` keeps only the `#<sha>` fragment, and
`checkout_root` walks up to the first directory holding `Cargo.toml`
plus the codegen crate, bounded by `.git` or `.cargo-ok`.
- `codegen_crate_in_checkout` prefers
`cuda-oxide/crates/rustc-codegen-cuda` and falls back to the historical
flat `crates/rustc-codegen-cuda`; `pinned_channel` walks from the
codegen crate upward, so the component nightly wins over the stable pin
at the git root. The same two functions serve the fallback clone.
- The backend cache is keyed by commit (`source-rev.txt`), not by URL,
so cached backends and existing projects are unaffected.
- The historical issue permalink to `/issues/96` in the
README stays, per the repository guide.

</details>

## Verification

Checked at `746d60eb`:

- ✅ `cargo test -p cargo-oxide --all-targets`: 243 passed; 244 with the
new URL test.
- ✅ `cargo clippy -p cargo-oxide --all-targets -- -D warnings`, `cargo
fmt --check`, rustdoc with `-D warnings`, and all 18
`scripts/check-*.sh` guards pass.
- ✅ `grep -rn NVlabs crates/cargo-oxide/src` returns nothing; the
remaining hits are the README install line (#1491) and the #96
permalink.
- ✅ In an isolated `CARGO_HOME`: `cargo oxide new` writes the new
address in both templates; `cargo generate-lockfile` records
`git+https://github.com/NVIDIA/cuda-rust.git#bc46b1ff` for
`cuda-device`, `cuda-host` and `cuda-macros` in a `cuda-rust-*`
checkout; `cargo oxide build` builds the backend from that checkout's
`cuda-oxide/crates/rustc-codegen-cuda` under nightly-2026-10-11 and
caches it with `source-rev.txt = bc46b1f`.
- ✅ The old-address baseline binary scaffolds `NVlabs/cuda-oxide.git`
and resolves the same commit through the redirect; `git ls-remote` on
both URLs returns the same HEAD.
- ✅ A shallow clone of `NVIDIA/cuda-rust` builds the backend offline
from its nested codegen crate under the component nightly, which is the
fallback route.
- ✅ Auto-merges with #1488, #1490 and #1491 in either order.

## Caveats

- A scaffolded project still fails to compile at this head with two
`cuda-core` crates in its graph; that is #1488's fix and is independent
of the address.
- A graph that mixes the old and new address for the same crate resolves
two checkouts and `cargo oxide` refuses it;
`[patch."https://github.com/NVlabs/cuda-oxide.git"]` pointing the crate
at the new address collapses the graph to one source.
- Machines that already hold the old-address git database fetch the
repository once more under the new name; the backend cache is reused
because it is keyed by commit.
- The remaining old-address mentions are the install lines (#1491) and
the manifest `repository` fields and license CSV (#1490).

---------

Signed-off-by: Alejandro Soto Franco <sotofranco.eng@gmail.com>
Signed-off-by: nihalpasham <nihalp@nvidia.com>
Co-authored-by: nihalpasham <nihalp@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup cargo-oxide The `cargo oxide` subcommand and build automation 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.

Build cuda-oxide against tip-of-tree host crates and drop the version from their license-inventory rows

3 participants