You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e2a2269
Browse filesBrowse the repository at this point in the historyBrowse files
CUDA backend: one current stream on Windows, shim copies during another thread's graph capture, and low-memory mode moves weights off the GPU while autotuning (#24597)
### What is wrong today
**Windows stream state.** The CUDA delegate and its shims share a
per-thread "current stream" map. In the default Windows build
(`EXECUTORCH_BUILD_SHARED` off) it exists twice, in
`aoti_cuda_shims.dll` (not exported) and in the program. The shims read
the empty copy and make their own stream, so they race with generated
kernels. On every platform, a thread with no stream selected also leaked
a stream.
**Copies during another thread's graph capture.** With no caller stream,
a shim copy used `cudaMemcpy` on the legacy stream. CUDA rejects that
during a capture on a blocking stream like the delegate's, so the
process aborted. Reading back a strided output also failed.
**Export memory.** AOTInductor's final autotuning pass keeps the real
weights on the GPU, unused. A video policy needing about 60 GiB ran out
of memory on an 80 GB GPU.
### What this change does
- Move the current-stream map into the shared library `extension_cuda`,
in an internal namespace. With no stream selected, use
`cudaStreamPerThread`, the stream the delegate runs on.
- Copy with `cudaMemcpyAsync` on the current stream, and read strided
outputs back on the delegate's stream.
- Still on the legacy stream, among others: the allocator's copy and
`synchronize()`, mutable-state and load-time copies, and the capture
step's seed copies.
- In the existing `low_memory_mode`, move the weights to a file in
PyTorch's cache directory during that pass. It needs PyTorch 2.15 or a
nightly from 2026-09-24 or later; with older PyTorch the mode works as
before. It needs free space there, and PyTorch skips the move when the
last generated kernel runs on the CPU.
### Tested
- A100: the CUDA runtime and shim tests, and most CUDA Python tests
(PyTorch 2.14), pass. The new per-thread, strided read-back and
cross-thread copy tests fail without their fix.
- With the Windows layout emulated on Linux, `test_cuda_current_stream`
fails before the change and passes after. CI's Windows CUDA runtime job
runs it in that layout, but does not build the shim tests, so
`RefusedInsideGraphCapture` and `CopiesWhileAnotherThreadCaptures` run
only on Linux. Windows was not built locally.
- A100 with PyTorch 2.15: the low-memory tests pass and fail without the
change. In low-memory mode, a model with 512 MiB of weights peaks at
about 0.66 GiB of GPU memory instead of 1.16 GiB and matches eager. With
PyTorch 2.14, nothing changes.
- Pending: exporting the video policy in low-memory mode.
0 commit comments