Skip to content

Fix cuda-core allocation lease scaling - #1787

Open
SycamoreQ wants to merge 4 commits into
NVIDIA:mainfrom
SycamoreQ:fix/cuda-core-lease-scaling
Open

SycamoreQ wants to merge 4 commits into
NVIDIA:mainfrom
SycamoreQ:fix/cuda-core-lease-scaling

Conversation

@SycamoreQ

@SycamoreQ SycamoreQ commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

Avoid linear scans of outstanding allocation leases when repeatedly acquiring or releasing leases on one CUDA stream. The fast path now uses per-stream access counts and indexed lease lookup/removal. Closes #1786.

Changes

  • Replace the active-lease vector with an ID-indexed map and per-stream reader/writer sets and totals.
  • Preserve same-stream access and cross-stream conflict semantics, including completion-event retirement.
  • Add a focused access-exclusion unit test, a standalone Rust scaling repro, and a Modal GPU runner.

Testing

  • cargo fmt --all -- --check — passed.

  • rustfmt --edition 2021 --check cuda-core/src/allocation.rs — passed.

  • rustfmt --edition 2024 --check cuda-core/repro/lease_scaling/src/main.rs — passed.

  • Python syntax compilation of cuda-core/repro/lease_scaling/modal_runner.py — passed.

  • cargo test -p cuda-core --lib access_counts_preserve_same_stream_and_cross_stream_exclusion — blocked during cuda-bindings build because no CUDA 13.0+ toolkit is installed on the host.

  • GitHub reports the embedded SSH commit signature as unknown_key; it is valid locally but this key is not recognized as a GitHub signing key, so the commit is not Verified on GitHub.

  • The Modal runner and GPU repro were not executed.

  • just -f cuda-oxide/Justfile check passes (the local mirror of CI: fmt, clippy, tests, guards, docs)

  • cargo oxide run <example> passes, or cuda-oxide/scripts/smoketest.sh -o '^<example>$'

  • New example added (if applicable)

Checklist

  • All commits signed off (git commit -s)
  • All commits cryptographically signed and shown as Verified on GitHub (git commit -S)
  • SPDX headers on new source files

Questions about the review? Ping us in #contributors on Discord.

Use indexed active leases and per-stream access counts to avoid scanning every held lease on the same-stream hot path. Add a standalone CUDA repro and Modal GPU runner for issue NVIDIA#1786.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: SycamoreQ <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 12, 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.

@elibol elibol added the cutile-rs Tile programming model: cutile crates, compiler, macros, IR, kernels, and book label Nov 12, 2026
@physwkim

Copy link
Copy Markdown

This removes the same-stream quadratic cost but not its cause: a submission still takes one lease per access, so while another stream's work is pending, every conflicting register makes retire_completed_conflicts query one event per lease id, and the cross-stream case stays O(N) per attempt. Reusing the submission's existing lease for the same allocation and stream would make both paths O(1) without the extra maps; that is the rule replay_identity already applies to graph replay, with a write covering reads. The repro crate and Modal runner belong in the issue, not under cuda-core.

@SycamoreQ

SycamoreQ commented Nov 13, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review, @physwkim!

I've moved the Modal runner and the repro crate over to issue #1786 as requested, and removed them from the cuda-core tree in this PR.

Regarding the root cause: you're completely right. I'm updating the allocation submission path to reuse the existing AllocationLease for the same (allocation, stream) pair, mirroring the replay_identity rule so a write covers reads. This will eliminate the per-access lease creation and make both the same-stream and cross-stream paths O(1).

I will push the updated code shortly.

@SycamoreQ

Copy link
Copy Markdown
Author

All tests are now passing.

I've implemented the O(1) lease reuse logic you requested in cuda-core/src/allocation.rs:

  1. register() now checks for an existing lease on the same (allocation, stream) pair. If one exists, it reuses the ID. If the existing lease is a read and the new request is a write, it upgrades the lease in place (write covers reads).
  2. Added a ref_count to Access so that reused leases are only retired when the last reference is dropped.
  3. Fixed the release() cleanup for recording leases.

I removed the repro crate and Modal runner from cuda-core (they are attached to #1786 now).

I ran the full cuda-core test suite on an NVIDIA T4 GPU via Modal, single-threaded, and all 51 unit tests pass:
test result: ok. 51 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

The commits are now signed. Thanks for the detailed review and guidance on the root cause!

@SycamoreQ
SycamoreQ force-pushed the fix/cuda-core-lease-scaling branch from 6e90d74 to 4b175d0 Compare November 14, 2026 02:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cutile-rs Tile programming model: cutile crates, compiler, macros, IR, kernels, and book

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: cuda-core launch cost grows linearly with the leases an open ExecutionContext holds on a buffer

3 participants