Repository navigation
Move the CUDA allocator into extension/cuda so other delegates can share it - #23447
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23447
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 8 PendingAs of commit 4fb40e3 with merge base 91b2e90 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
3739f7f to
4e311a5
Compare
4e311a5 to
b78a3f4
Compare
digantdesai
left a comment
There was a problem hiding this comment.
The move looks right on Linux, and it also fixes a real problem on MSVC. The allocator used to be compiled into both aoti_cuda_shims.dll and the static aoti_cuda_backend, so MSVC builds had two singletons. A few things before this lands:
1. Rebase onto the current #23446. This branch still carries the earlier version of that commit (no 512 limit, old tests). Landing the stack as is would reapply that version over the reworked one.
2. ROCm and Windows CUDA haven't run. Because this comes from a fork, rocm.yml and cuda-windows.yml skip their jobs. Those are the two builds whose linking changes here:
- The MSVC case that compiled
cuda_allocator.cppintoaoti_cuda_backendis gone, so the class now crosses theextension_cudaDLL boundary throughEXECUTORCH_EXTENSION_CUDA_API. - Under ROCm,
extension_cudanow compiles the allocator withEXECUTORCH_USE_HIP.
Could you add ciflow/rocm and ciflow/cuda and get those green?
3. Registration doesn't allow sharing yet (fine as a follow-up). The allocator is still registered only from the static initializer in cuda_backend.cpp, and DeviceAllocatorRegistry::register_allocator ET_CHECKs that the slot is empty. So a second delegate (e.g. TensorRT) can't register it when the CUDA backend is also linked, because the process aborts. And a process with only that delegate has no CUDA allocator in the registry, so device-planned buffers fail. Registering once from extension_cuda, or making re-registration of the same pointer a no-op, would close the gap. This should be settled before the TensorRT delegate depends on it. The class doc comment ("automatically registered ... when the CUDA backend library is linked") should also say who registers it now that it lives in the shared extension.
4. Buck linkage. :caller_stream sets force_static = False, because the OSS wrapper otherwise forces static linkage and copies the library into every dependent shared object. :cuda_allocator exists to give one CudaAllocator::instance() and one pool per process, so it needs the same setting. The old target had the same gap, so this isn't a regression. Also, link_whole = True isn't needed anymore: cuda_allocator.cpp has no static registrar.
5. Wheel header check. The probe only looks for <cuda_runtime.h> on the compiler's default include path. On the usual CUDA builders it lives in /usr/local/cuda/include, so I think cuda_allocator.h and runtime_api.h get skipped in every CI run. Adding the toolkit include dir for just these two would keep them syntax-checked.
Nits:
- The class stays in
executorch::backends::cuda, while its neighbors inextension/cudauseexecutorch::extension::cuda. Consider moving it and leaving an alias in the forwarding header. - The
release_cached_memorydoc still says the pool belongs to "this backend" and that trimming never affects other users. Once other delegates share it, the CUDA backend's teardown trims (and device-syncs) memory they may rely on.
|
stamped to unblock the usage, but personally im not a huge fan of moving more and more gpu stuff into We should have a |
b78a3f4 to
27c70d9
Compare
|
Thanks for stamping! I think extension/cuda still fits that rule: the core runtime never needs it, only CUDA delegates do. It's the shared surface for them, in tree and out. The Torch-TensorRT delegate builds against it from the installed wheel, the same way it uses the caller-stream and device guards there today. Keeping the allocator next to them gives one shared library and one instance per process, without an out-of-tree delegate reaching into backends/cuda internals. |
|
Thanks for the explanation! I see where you're coming from, but I'm not sure I fully agree on a few points. Happy to discuss further.
I think the CUDA allocator is essential to the CUDA backend, so it would fit better inside the backend than under executorch/extension. If being optional for the core runtime were enough to put something in extension, then the whole CUDA backend would arguably belong there too, which doesn't seem like what we want.
Agreed, that's how it works today. That said, I'm not sure the current setup is ideal, and it might be worth revisiting.
Yes, that's exactly the concern I'm trying to address. My proposal is a shared directory like backends/gpu for the common logic. That way other delegates can reuse it without depending on backends/cuda internals, and the allocator still lives next to the backend code. Let me know what you think! |
|
That makes sense, and backends/gpu reads better than extension/ for things every GPU delegate needs. The allocator, caller stream and device guard all fit that description. How about I land this one as is, since it unblocks the TensorRT delegate, and then move all three into backends/gpu in one follow-up, with the old headers forwarding so out-of-tree delegates keep building? |
27c70d9 to
a955d45
Compare
a955d45 to
481e258
Compare
…are it Other CUDA delegates need ExecuTorch's allocator without compiling a second copy of its singleton. Move it into the shared CUDA extension and ship its public headers in the wheel. Declare the class in executorch::extension::cuda. Keep the old namespace, header and Buck target as compatibility aliases. The public CMake target exports its required C10 definition and discovers CUDA toolkit headers. Buck allows shared linkage and exports only the header dependencies. It drops link_whole: the library has no static registrar, and its one static initializer comes in with the allocator code that needs it. Initialize this library's platform state before allocator errors can log. Allocation and registration behavior are unchanged by the move: the CUDA backend still registers the allocator, and linking only the extension does not. Preserve checked padding and pointer rounding above 256 bytes, original pointer deallocation, and the lock free path when no rounded pointers are live. Document that delegates share the async pool: trimming may release another user's cached blocks but leaves live allocations intact. The wheel checks require both allocator headers, compile them with the CUDA toolkit, and build and run a consumer of the allocator target. Tested on Linux x86_64 with H100 and CUDA 12.8: five CUDA C++ suites passed 76 cases without skips. The allocator suite passed 21 cases, including alignment, overflow, concurrency and legacy alias checks. Compute Sanitizer reported zero memory errors and leaks, excluding intentional invalid device API error reports. Pinned formatting checks passed. Windows CUDA/MSVC, ROCm and actual Buck builds were not run.
481e258 to
4fb40e3
Compare
The CUDA backend's stream-ordered allocations fail on any device that does not support
memory pools, which includes data-center GPUs in TCC mode on Windows (A10G, A100, H100 and
the like). There cudaMemPoolCreate and cudaMallocAsync return cudaErrorNotSupported, and
nothing falls back:
E cuda_allocator.cpp:99] cudaMemPoolCreate failed for device 0: operation not supported. Using the default pool.
E cuda_allocator.cpp:448] cudaMallocAsync failed: operation not supported (requested 512 bytes on device 0)
F storage.h:126] In function allocate(), assert failed (result.ok()): CudaAllocator::allocate_async failed for 512 bytes on device 0
That is from a CUDA program running on the Windows GPU CI runner (an A10G) in #23123, the
first CI job to run the delegate on Windows with a driver installed. A GeForce card in WDDM
mode supports memory pools, which is why a local run passes.
## Change
- CudaAllocator (extension/cuda/cuda_allocator, where #23447 moved it) asks each device once
whether it supports memory pools
(cudaDevAttrMemoryPoolsSupported) and caches the answer in per-device atomics. On a device
that does not, allocate_async allocates with cudaMalloc and deallocate_async frees with
cudaFree, deciding by the device the pointer lives on. A failed attribute query keeps the
stream-ordered path.
- On a device with memory pools the paths are the ones they were: allocate_async adds one
atomic load, and deallocate_async looks up the pointer's device only once some device
without pools has been seen, so a process whose devices all have them frees exactly as
before.
- The fallback refuses while the stream is capturing a CUDA graph. In relaxed capture mode
cudaMalloc and cudaFree succeed, so a block freed during capture would be handed out
again while every replay still writes to it; refusing keeps the loud failure the
stream-ordered call gave, and a free kept during a capture is reported to the caller
(deallocate_stream_ordered returns NotSupported; a failed cudaFree returns Internal). On
such a device the backend also does not turn CUDA graphs on for a method that asks for
them (enable_cuda_graph_for_method), and says so in the log.
- sort.cu and rand.cu called cudaMallocAsync/cudaFreeAsync directly. They now call
CudaAllocator::allocate_stream_ordered / deallocate_stream_ordered with their real device,
which is cudaMallocAsync/cudaFreeAsync on the stream as before (the device default pool,
not the allocator's retaining pool) and the cudaMalloc fallback without pools. rand passes
the current device, the one its stream was created on.
- rand's one-time RNG state allocation now reports a failure: the shims return an error
instead of launching their kernels with a null state, and a later call tries again.
## Tests and CI
- test_cuda_allocator: AllocateAsyncRoundtrip and StreamOrderedScratchRoundtrip run on every
device. Four tests run on a device without pools: FallsBackWithoutMemoryPools checks that
the fallback allocation is actually released by deallocate_async,
FallbackRefusesWhileCapturing that neither allocator falls back inside a capture,
FallbackKeepsBlocksFreedWhileCapturing that blocks freed during a capture, through both
free paths, stay allocated and intact through a replay and that the kept block is
reported, and CudaGraphStaysOffWithoutMemoryPools that the CUDA graph state the backend
starts from (CudaGraphState::start_warmup) stays disabled. They skip on a device with pools,
except where EXECUTORCH_CUDA_TEST_REQUIRE_NO_MEMORY_POOLS is set, as the Windows job does,
where they fail instead so the fallback cannot go untested; with it set, no visible CUDA
device fails the tests too rather than skipping them. The pool tests move to a
fixture that skips on a device without pools, alongside CudaGraphStartsWithMemoryPools.
- test_cuda_sort_rand (new): runs the sort shim along both dims of a 2-D tensor (the
transpose path that allocates two scratch buffers, and thrust's scratch) on input with
repeated values in every slice, against a host stable sort, checking values and indices,
and the rand shim. Built only where sort.cu and
rand.cu are (a CUDA build that found a CUDA compiler).
- cuda-windows.yml gains unittest-cuda-runtime-windows, the Windows counterpart of
cuda.yml's unittest-cuda-runtime: it builds llm-release-cuda with tests and runs the same
runtime tests plus test_cuda_sort_rand. The Windows runner's A10G has no memory pools, so
this covers the fallback; the Linux job, which now runs test_cuda_sort_rand too, covers
the pool path. Its pull_request paths include the scripts and tools/cmake/Test.cmake it
depends on.
- The Windows GPU runners come without an NVIDIA driver (nvcuda.dll is missing and
cudaGetDeviceCount returns cudaErrorInsufficientDriver), so the job first installs the
data-center driver that pytorch/pytorch's Windows CUDA smoke tests install
(driver_update.bat, 580.88, from the same bucket); install_nvidia_driver_windows.ps1.
- et_cxx_test copies a test's runtime DLLs ($<TARGET_RUNTIME_DLLS>) beside it on Windows,
which records no search path: the CUDA tests link extension_cuda.dll from another
directory and could not start otherwise.
- extension/cuda/test/cuda_allocator_exit.cpp (Linux only) fakes every CUDA call on its
path; it now also fakes cudaDeviceGetAttribute to report pools, since the pool query is new
on that path and would otherwise make the test depend on the machine's GPU.
## Test plan
- Windows 11, RTX 5080 (WDDM, memory pools supported), CUDA 13.0, llm-release-cuda with
tests, rebased on main with the allocator in extension/cuda: all six runtime tests pass
(test_cuda_allocator 22 passed with the four no-pool tests skipped; mutable_state 15,
weight_cache 11, sort_rand 2, guard 7, stream_guard 21). With
EXECUTORCH_CUDA_TEST_REQUIRE_NO_MEMORY_POOLS set, the four no-pool tests fail there, as
intended. test_cuda_allocator_exit is Linux only and runs in the Linux job.
- The no-pool path runs in the Windows CI job on the A10G; on the previous revision of this
PR that job passed the fallback tests there.
- Linux: the pool path is covered by the existing unittest-cuda-runtime job.
Found while adding the Windows CUDA wheel (#23123), which needs this to run on the Windows
GPU runner; this PR does not depend on it.
Builds on #23121 (merged), which ships linkable libraries in the Windows wheel. Stacked on #23405, which makes the CUDA backend fall back to cudaMalloc on devices without memory pools: the Windows GPU CI runner's A10G is one, so this PR's end-to-end runs need it. A Windows user can run a CUDA program but cannot lower one: lowering compiles the model with a toolchain only the Linux side has, and the CUDA Windows CI job already exports on Linux and runs on Windows for exactly this reason. What was missing is a wheel that gives that Windows user the runtime. This adds a Windows CUDA wheel carrying the CUDA delegate as C++ libraries, the same components the Linux CUDA wheel ships (#21645, #21668), and nothing CUDA in the Python module, which on Windows has no CUDA program to lower. The export (AOT) side is unchanged and identical to the CPU wheel's; only the runtime links CUDA. lib/executorch_backend_cuda.dll + .lib the delegate executorch::backend_cuda lib/executorch_extension_cuda.dll + .lib allocator + streams executorch::extension_cuda backends/cuda/aoti_cuda_shims.dll the AOTI shim layer (runtime DLL of the delegate) data/lib/aoti_cuda_shims.lib already shipped as the lowering stub; also the shim layer's import library here extension/pybindings/_C.pyd unchanged: no CUDA dependency, no CudaBackend A C++ application links it exactly as on Linux: find_package(executorch REQUIRED COMPONENTS kernels_optimized backend_cuda) target_link_libraries(app PRIVATE executorch::runtime executorch::kernels_optimized executorch::backend_cuda) # plus the $<TARGET_RUNTIME_DLLS:app> copy from the CPU PR, which now also brings the # CUDA extension and the shim layer The wheel's DLLs import no CUDA runtime DLL: CMake links cudart.lib into them on Windows, and that reaches the driver (nvcuda.dll). The compiled model is different: the library AOTInductor builds into model.pte imports cudart64_13.dll, which comes from the CUDA Toolkit's bin directory on PATH, as the guide says. PyPI's nvidia-cuda-runtime has win_amd64 builds that carry that DLL, but a C++ program does not search site-packages, so declaring it would not make it loadable; the wheel declares no NVIDIA package for Windows. ## How - Generator. The CUDA toolkit's Visual Studio integration fails compiler identification under the ClangCL toolset on some toolkit and Visual Studio pairs (MSB4023 in its targets file), and the MSVC toolset cannot compile the Python extension's sources. A Windows CUDA build therefore uses Ninja Multi-Config with clang-cl, the compiler the CPU wheel uses, and nvcc with cl.exe as its host compiler, in a Visual Studio developer environment that has ninja (ninja, clang-cl and cl all on PATH, which is how the wheel build runs). Elsewhere, such as a plain shell, the build keeps the Visual Studio generator it always used. CMAKE_CUDA_COMPILER is passed only when CUDACXX is unset, so options a user put in CUDACXX (such as -allow-unsupported-compiler) still apply. The toolkit is the one install_utils already reports, so what compiles is the train packaging declares. - CUDA 13.2 and newer. Their CCCL stops with an #error under cl.exe's traditional preprocessor, so the CUDA sources pass -Xcompiler=/Zc:preprocessor on Windows (13.0 accepts it too). - flatc / flatcc byproducts and imported locations share one host executable suffix chosen by CMAKE_HOST_WIN32. CMAKE_EXECUTABLE_SUFFIX is the target's: a Zephyr toolchain sets .elf, and naming the byproduct after it left Ninja with no rule for the host tool. - The shims resolve the runtime from executorch.dll rather than a static core. (The PAL's strong symbols are in #23121; C++20 for the delegate and shims comes from #23135.) - The shims keep WINDOWS_EXPORT_ALL_SYMBOLS OFF in a static build, as upstream sets it, and turn it ON in the shared layout: the delegate DLL imports the stream guard functions (get/set/peek/clearCurrentCUDAStream) from the shim DLL, and those carry no AOTI_SHIM_EXPORT, so the annotations alone would not export them. The allocator is not in either DLL: main moved it into extension_cuda (#23447), a shared library the delegate and the shims both import it from, so the process has one. - #23121 keeps a Windows CUDA build static; this drops that guard, so the pybind preset now builds the shared layout with CUDA too, and adds the CUDA import libraries to the Windows packaging list. - The root CMake file no longer links the CUDA delegate into the Python extension on Windows; extension/cuda finds the CUDA toolkit itself, as on main. - The package config adds the CUDA extension (allocator and stream helpers) and the shim layer to the delegate's runtime DLL set, and reports EXECUTORCH_RUNTIME_DLLS_EXTRA for the pre-3.28 route, since the shim layer ships outside lib/. ## CI - build-wheels-cuda-windows.yml mirrors the Linux CUDA workflow on the Windows wheel builder and reuses filter_cuda_matrix.py. pre_build_script.sh drops the blanket Windows CUDA=OFF (a CPU row is still forced off by the generic row classification), resolves TORCH_CUDA_ARCH_LIST from cuda_arch_list.sh, and writes it to BUILD_ENV_FILE as well as GITHUB_ENV: the reusable workflow sources that file after the hook, and its own list had replaced the row's (sm_75 in, sm_89 out). It also installs ninja for the generator. - End-to-end, per published CUDA train, the route a Windows user has, modeled on cuda-windows.yml. The trains are read from filter_cuda_matrix.py's SUPPORTED_CUDA_VERSIONS (today cu132 and cu134; main stopped publishing cu130 in #23380), the same list the release rows are built from, so adding or dropping a train there changes what is tested. The end-to-end jobs take their trains from the build job's own filtered matrix, so a pull request without the ciflow/binaries/all label tests the one train it builds, and a train the generator dropped is not tested against a wheel that does not exist. (install_utils.py's list also has 12.6 for source builds, but 12.6 is no longer a published wheel train.) A Linux GPU job exports a Windows-target program with that train's torch (`test_cuda_windows.py --export`); a small job bundles it with the wheel the build job published for that train (windows_job.yml downloads one artifact and gives its script no token for a second); and a Windows GPU job installs that published wheel and runs test_cuda_windows.py with the program (test_cuda_windows_e2e.ps1), so CI runs a CUDA program through the artifact users install rather than a wheel rebuilt on the GPU runner. The export and end-to-end jobs check out the commit the build job builds (on a pull request, its merge commit), so the wheel, the program and the scripts that test them match. Each train's CUDA (on Linux for the export, and on Windows for the smoke test's cuobjdump and the model's CUDA runtime) is assembled from NVIDIA's checksummed redistributable archives by install_cuda_redist.py, which needs no installer or admin rights and fails on a train it has no release for. Each train's Windows job waits only for its own bundle, so one train failing does not skip the others, and like the export it does not run for a pull request from a fork. The Windows GPU runners come without an NVIDIA driver (nvcuda.dll is missing and cudaGetDeviceCount returns cudaErrorInsufficientDriver), so the job first installs the same data-center driver, from the same place, that pytorch/pytorch's Windows CUDA smoke tests install (driver_update.bat, 580.88); cu132 and cu134 run on it through CUDA's minor-version compatibility, as PyTorch's own wheels do. The wheel build's own smoke test has no GPU program and says so. ## Tests test_cuda_windows.py, the Windows counterpart of test_cuda_linux.py: - the CUDA DLLs and import libraries ship; - _C depends on no CUDA DLL and registers no CUDA backend; - no shipped CUDA DLL imports cudart64_*.dll (only the driver), and no Windows NVIDIA requirement is declared; - every DLL with device code carries exactly the row's GPUs, both directions, and the newest also as PTX; the expected list comes from executorch_cuda_arch_list in cuda_arch_list.sh, called the way the pre-build hook calls it and keyed by the wheel's +cuXYZ tag, not from the TORCH_CUDA_ARCH_LIST the build consumed; - a C++ application linking executorch::backend_cuda gets the three DLLs copied beside it and sees CudaBackend registered; - a program lowered on Linux for Windows runs through the C++ SDK and matches eager, after checking it was exported with the same CUDA train as the wheel (every CUDA 13 train loads cudart64_13.dll, so a mismatch would not fail on its own); - then what a CPU Windows row checks: test_shared_libraries.py (with the three CUDA ownership rows), test_cpp_sdk.py and the MobileNetV3/XNNPACK model run, including the Arm Cortex-M Python module, which builds under Ninja too: CMSIS-NN's test-only shared library took the static library's name, so its import library collided with it on Windows, and backends/cortex_m now gives the import library its own name. ## Test plan On Windows 11 x64 with an RTX 5080 (sm_120, driver 595.95), VS 2022 BuildTools, CPython 3.12, and WSL Ubuntu for the export, once per CUDA train. 13.2 and 13.4 are the published trains and the ones CI covers; 13.0 is no longer published (#23380) but still builds from source, so it was run too: | train | Windows nvcc | WSL export torch | wheel | test_cuda_windows.py | Linux-exported program | |---|---|---|---|---|---| | 13.0 | 13.0.88 (installer) | 2.14.1+cu130 | executorch-1.6.0+cu130 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | | 13.2 | 13.2.86 (redist) | 2.14.1+cu132 | executorch-1.6.0+cu132 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | | 13.4 | 13.4.59 (redist) | 2.14.0.dev20260810+cu134 | executorch-1.6.0+cu134 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | - Each wheel built with TORCH_CUDA_ARCH_LIST from cuda_arch_list.sh: device code for exactly sm_80/86/89/90/100/120, plus sm_120 PTX. 13.4 runs on a driver that reports 13.2, through CUDA's minor-version compatibility. - Before the /Zc:preprocessor change, 13.2 and 13.4 failed to compile the .cu shims with CCCL's "traditional preprocessor" #error; 13.0 was unaffected. - Negative: the cu134 wheel pointed at the 13.0-exported program fails the train check. - The export used `test_cuda_windows.py --export` from this branch in WSL, with mingw-w64 and the Windows CUDA runtime of the same train (13.0 from install_cuda_windows_cross_compile.sh, 13.2/13.4 from the redist archives, the steps the guide now gives). - CI, before the rebase onto main: the end-to-end jobs passed for both published trains on the Windows A10G runner, with a Linux-exported program matching eager (maxdiff 1.3e-7 for 13.2, 2.4e-7 for 13.4). - After rebasing onto main with the allocator moved into extension_cuda (#23447), the cu132 wheel was rebuilt and passes all 55 checks, including the new ownership row: a single CUDA allocator and stream helpers owned by executorch_extension_cuda.dll across the 15 shipped libraries. The rows above were measured before that rebase. - Linux: the CMake changes are behind WIN32 / MSVC, or pick the same suffix there (empty on a Linux host); setup.py's new path runs only on Windows.
Builds on #23121 (merged), which ships linkable libraries in the Windows wheel. Stacked on #23405, which makes the CUDA backend fall back to cudaMalloc on devices without memory pools: the Windows GPU CI runner's A10G is one, so this PR's end-to-end runs need it. A Windows user can run a CUDA program but cannot lower one: lowering compiles the model with a toolchain only the Linux side has, and the CUDA Windows CI job already exports on Linux and runs on Windows for exactly this reason. What was missing is a wheel that gives that Windows user the runtime. This adds a Windows CUDA wheel carrying the CUDA delegate as C++ libraries, the same components the Linux CUDA wheel ships (#21645, #21668), and nothing CUDA in the Python module, which on Windows has no CUDA program to lower. The export (AOT) side is unchanged and identical to the CPU wheel's; only the runtime links CUDA. lib/executorch_backend_cuda.dll + .lib the delegate executorch::backend_cuda lib/executorch_extension_cuda.dll + .lib allocator + streams executorch::extension_cuda backends/cuda/aoti_cuda_shims.dll the AOTI shim layer (runtime DLL of the delegate) data/lib/aoti_cuda_shims.lib already shipped as the lowering stub; also the shim layer's import library here extension/pybindings/_C.pyd unchanged: no CUDA dependency, no CudaBackend A C++ application links it exactly as on Linux: find_package(executorch REQUIRED COMPONENTS kernels_optimized backend_cuda) target_link_libraries(app PRIVATE executorch::runtime executorch::kernels_optimized executorch::backend_cuda) # plus the $<TARGET_RUNTIME_DLLS:app> copy from the CPU PR, which now also brings the # CUDA extension and the shim layer The wheel's DLLs import no CUDA runtime DLL: CMake links cudart.lib into them on Windows, and that reaches the driver (nvcuda.dll). The compiled model is different: the library AOTInductor builds into model.pte imports cudart64_13.dll, which comes from the CUDA Toolkit's bin directory on PATH, as the guide says. PyPI's nvidia-cuda-runtime has win_amd64 builds that carry that DLL, but a C++ program does not search site-packages, so declaring it would not make it loadable; the wheel declares no NVIDIA package for Windows. ## How - Generator. The CUDA toolkit's Visual Studio integration fails compiler identification under the ClangCL toolset on some toolkit and Visual Studio pairs (MSB4023 in its targets file), and the MSVC toolset cannot compile the Python extension's sources. A Windows CUDA build therefore uses Ninja Multi-Config with clang-cl, the compiler the CPU wheel uses, and nvcc with cl.exe as its host compiler, in a Visual Studio developer environment that has ninja (ninja, clang-cl and cl all on PATH, which is how the wheel build runs). Elsewhere, such as a plain shell, the build keeps the Visual Studio generator it always used. CMAKE_CUDA_COMPILER is passed only when CUDACXX is unset, so options a user put in CUDACXX (such as -allow-unsupported-compiler) still apply. The toolkit is the one install_utils already reports, so what compiles is the train packaging declares. - CUDA 13.2 and newer. Their CCCL stops with an #error under cl.exe's traditional preprocessor, so the CUDA sources pass -Xcompiler=/Zc:preprocessor on Windows (13.0 accepts it too). - flatc / flatcc byproducts and imported locations share one host executable suffix chosen by CMAKE_HOST_WIN32. CMAKE_EXECUTABLE_SUFFIX is the target's: a Zephyr toolchain sets .elf, and naming the byproduct after it left Ninja with no rule for the host tool. - The shims resolve the runtime from executorch.dll rather than a static core. (The PAL's strong symbols are in #23121; C++20 for the delegate and shims comes from #23135.) - The shims keep WINDOWS_EXPORT_ALL_SYMBOLS OFF in a static build, as upstream sets it, and turn it ON in the shared layout: the delegate DLL imports the stream guard functions (get/set/peek/clearCurrentCUDAStream) from the shim DLL, and those carry no AOTI_SHIM_EXPORT, so the annotations alone would not export them. The allocator is not in either DLL: main moved it into extension_cuda (#23447), a shared library the delegate and the shims both import it from, so the process has one. - #23121 keeps a Windows CUDA build static; this drops that guard, so the pybind preset now builds the shared layout with CUDA too, and adds the CUDA import libraries to the Windows packaging list. - The root CMake file no longer links the CUDA delegate into the Python extension on Windows; extension/cuda finds the CUDA toolkit itself, as on main. - The package config adds the CUDA extension (allocator and stream helpers) and the shim layer to the delegate's runtime DLL set, and reports EXECUTORCH_RUNTIME_DLLS_EXTRA for the pre-3.28 route, since the shim layer ships outside lib/. ## CI - build-wheels-cuda-windows.yml mirrors the Linux CUDA workflow on the Windows wheel builder and reuses filter_cuda_matrix.py. pre_build_script.sh drops the blanket Windows CUDA=OFF (a CPU row is still forced off by the generic row classification), resolves TORCH_CUDA_ARCH_LIST from cuda_arch_list.sh, and writes it to BUILD_ENV_FILE as well as GITHUB_ENV: the reusable workflow sources that file after the hook, and its own list had replaced the row's (sm_75 in, sm_89 out). It also installs ninja for the generator. - End-to-end, per published CUDA train, the route a Windows user has, modeled on cuda-windows.yml. The trains are read from filter_cuda_matrix.py's SUPPORTED_CUDA_VERSIONS (today cu132 and cu134; main stopped publishing cu130 in #23380), the same list the release rows are built from, so adding or dropping a train there changes what is tested. The end-to-end jobs take their trains from the build job's own filtered matrix, so a pull request without the ciflow/binaries/all label tests the one train it builds, and a train the generator dropped is not tested against a wheel that does not exist. (install_utils.py's list also has 12.6 for source builds, but 12.6 is no longer a published wheel train.) A Linux GPU job exports a Windows-target program with that train's torch (`test_cuda_windows.py --export`); a small job bundles it with the wheel the build job published for that train (windows_job.yml downloads one artifact and gives its script no token for a second); and a Windows GPU job installs that published wheel and runs test_cuda_windows.py with the program (test_cuda_windows_e2e.ps1), so CI runs a CUDA program through the artifact users install rather than a wheel rebuilt on the GPU runner. The export and end-to-end jobs check out the commit the build job builds (on a pull request, its merge commit), so the wheel, the program and the scripts that test them match. Each train's CUDA (on Linux for the export, and on Windows for the smoke test's cuobjdump and the model's CUDA runtime) is assembled from NVIDIA's checksummed redistributable archives by install_cuda_redist.py, which needs no installer or admin rights and fails on a train it has no release for. Each train's Windows job waits only for its own bundle, so one train failing does not skip the others, and like the export it does not run for a pull request from a fork. The Windows GPU runners come without an NVIDIA driver (nvcuda.dll is missing and cudaGetDeviceCount returns cudaErrorInsufficientDriver), so the job first installs the same data-center driver, from the same place, that pytorch/pytorch's Windows CUDA smoke tests install (driver_update.bat, 580.88); cu132 and cu134 run on it through CUDA's minor-version compatibility, as PyTorch's own wheels do. The wheel build's own smoke test has no GPU program and says so. ## Tests test_cuda_windows.py, the Windows counterpart of test_cuda_linux.py: - the CUDA DLLs and import libraries ship; - _C depends on no CUDA DLL and registers no CUDA backend; - no shipped CUDA DLL imports cudart64_*.dll (only the driver), and no Windows NVIDIA requirement is declared; - every DLL with device code carries exactly the row's GPUs, both directions, and the newest also as PTX; the expected list comes from executorch_cuda_arch_list in cuda_arch_list.sh, called the way the pre-build hook calls it and keyed by the wheel's +cuXYZ tag, not from the TORCH_CUDA_ARCH_LIST the build consumed; - a C++ application linking executorch::backend_cuda gets the three DLLs copied beside it and sees CudaBackend registered; - a program lowered on Linux for Windows runs through the C++ SDK and matches eager, after checking it was exported with the same CUDA train as the wheel (every CUDA 13 train loads cudart64_13.dll, so a mismatch would not fail on its own); - then what a CPU Windows row checks: test_shared_libraries.py (with the three CUDA ownership rows), test_cpp_sdk.py and the MobileNetV3/XNNPACK model run, including the Arm Cortex-M Python module, which builds under Ninja too: CMSIS-NN's test-only shared library took the static library's name, so its import library collided with it on Windows, and backends/cortex_m now gives the import library its own name. ## Test plan On Windows 11 x64 with an RTX 5080 (sm_120, driver 595.95), VS 2022 BuildTools, CPython 3.12, and WSL Ubuntu for the export, once per CUDA train. 13.2 and 13.4 are the published trains and the ones CI covers; 13.0 is no longer published (#23380) but still builds from source, so it was run too: | train | Windows nvcc | WSL export torch | wheel | test_cuda_windows.py | Linux-exported program | |---|---|---|---|---|---| | 13.0 | 13.0.88 (installer) | 2.14.1+cu130 | executorch-1.6.0+cu130 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | | 13.2 | 13.2.86 (redist) | 2.14.1+cu132 | executorch-1.6.0+cu132 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | | 13.4 | 13.4.59 (redist) | 2.14.0.dev20260810+cu134 | executorch-1.6.0+cu134 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | - Each wheel built with TORCH_CUDA_ARCH_LIST from cuda_arch_list.sh: device code for exactly sm_80/86/89/90/100/120, plus sm_120 PTX. 13.4 runs on a driver that reports 13.2, through CUDA's minor-version compatibility. - Before the /Zc:preprocessor change, 13.2 and 13.4 failed to compile the .cu shims with CCCL's "traditional preprocessor" #error; 13.0 was unaffected. - Negative: the cu134 wheel pointed at the 13.0-exported program fails the train check. - The export used `test_cuda_windows.py --export` from this branch in WSL, with mingw-w64 and the Windows CUDA runtime of the same train (13.0 from install_cuda_windows_cross_compile.sh, 13.2/13.4 from the redist archives, the steps the guide now gives). - CI, before the rebase onto main: the end-to-end jobs passed for both published trains on the Windows A10G runner, with a Linux-exported program matching eager (maxdiff 1.3e-7 for 13.2, 2.4e-7 for 13.4). - After rebasing onto main with the allocator moved into extension_cuda (#23447), the cu132 wheel was rebuilt and passes all 55 checks, including the new ownership row: a single CUDA allocator and stream helpers owned by executorch_extension_cuda.dll across the 15 shipped libraries. The rows above were measured before that rebase. - Linux: the CMake changes are behind WIN32 / MSVC, or pick the same suffix there (empty on a Linux host); setup.py's new path runs only on Windows.
The CUDA backend's stream-ordered allocations fail on any device that does not support memory pools, which includes data-center GPUs in TCC mode on Windows (A10G, A100, H100 and the like). There cudaMemPoolCreate and cudaMallocAsync return cudaErrorNotSupported, and nothing falls back: E cuda_allocator.cpp:99] cudaMemPoolCreate failed for device 0: operation not supported. Using the default pool. E cuda_allocator.cpp:448] cudaMallocAsync failed: operation not supported (requested 512 bytes on device 0) F storage.h:126] In function allocate(), assert failed (result.ok()): CudaAllocator::allocate_async failed for 512 bytes on device 0 That is from a CUDA program running on the Windows GPU CI runner (an A10G) in #23123, the first CI job to run the delegate on Windows with a driver installed. A GeForce card in WDDM mode supports memory pools, which is why a local run passes. ## Change - CudaAllocator (extension/cuda/cuda_allocator, where #23447 moved it) asks each device once whether it supports memory pools (cudaDevAttrMemoryPoolsSupported) and caches the answer in per-device atomics. On a device that does not, allocate_async allocates with cudaMalloc and deallocate_async frees with cudaFree, deciding by the device the pointer lives on. A failed attribute query keeps the stream-ordered path. - On a device with memory pools the paths are the ones they were: allocate_async adds one atomic load, and deallocate_async looks up the pointer's device only once some device without pools has been seen, so a process whose devices all have them frees exactly as before. - The fallback refuses while the stream is capturing a CUDA graph. In relaxed capture mode cudaMalloc and cudaFree succeed, so a block freed during capture would be handed out again while every replay still writes to it; refusing keeps the loud failure the stream-ordered call gave, and a free kept during a capture is reported to the caller (deallocate_stream_ordered returns NotSupported; a failed cudaFree returns Internal). On such a device the backend also does not turn CUDA graphs on for a method that asks for them (enable_cuda_graph_for_method), and says so in the log. - sort.cu and rand.cu called cudaMallocAsync/cudaFreeAsync directly. They now call CudaAllocator::allocate_stream_ordered / deallocate_stream_ordered with their real device, which is cudaMallocAsync/cudaFreeAsync on the stream as before (the device default pool, not the allocator's retaining pool) and the cudaMalloc fallback without pools. rand passes the current device, the one its stream was created on. - rand's one-time RNG state allocation now reports a failure: the shims return an error instead of launching their kernels with a null state, and a later call tries again. ## Tests and CI - test_cuda_allocator: AllocateAsyncRoundtrip and StreamOrderedScratchRoundtrip run on every device. Four tests run on a device without pools: FallsBackWithoutMemoryPools checks that the fallback allocation is actually released by deallocate_async, FallbackRefusesWhileCapturing that neither allocator falls back inside a capture, FallbackKeepsBlocksFreedWhileCapturing that blocks freed during a capture, through both free paths, stay allocated and intact through a replay and that the kept block is reported, and CudaGraphStaysOffWithoutMemoryPools that the CUDA graph state the backend starts from (CudaGraphState::start_warmup) stays disabled. They skip on a device with pools, except where EXECUTORCH_CUDA_TEST_REQUIRE_NO_MEMORY_POOLS is set, as the Windows job does, where they fail instead so the fallback cannot go untested; with it set, no visible CUDA device fails the tests too rather than skipping them. The pool tests move to a fixture that skips on a device without pools, alongside CudaGraphStartsWithMemoryPools. - test_cuda_sort_rand (new): runs the sort shim along both dims of a 2-D tensor (the transpose path that allocates two scratch buffers, and thrust's scratch) on input with repeated values in every slice, against a host stable sort, checking values and indices, and the rand shim. Built only where sort.cu and rand.cu are (a CUDA build that found a CUDA compiler). - cuda-windows.yml gains unittest-cuda-runtime-windows, the Windows counterpart of cuda.yml's unittest-cuda-runtime: it builds llm-release-cuda with tests and runs the same runtime tests plus test_cuda_sort_rand. The Windows runner's A10G has no memory pools, so this covers the fallback; the Linux job, which now runs test_cuda_sort_rand too, covers the pool path. Its pull_request paths include the scripts and tools/cmake/Test.cmake it depends on. - The Windows GPU runners come without an NVIDIA driver (nvcuda.dll is missing and cudaGetDeviceCount returns cudaErrorInsufficientDriver), so the job first installs the data-center driver that pytorch/pytorch's Windows CUDA smoke tests install (driver_update.bat, 580.88, from the same bucket); install_nvidia_driver_windows.ps1. - et_cxx_test copies a test's runtime DLLs ($<TARGET_RUNTIME_DLLS>) beside it on Windows, which records no search path: the CUDA tests link extension_cuda.dll from another directory and could not start otherwise. - extension/cuda/test/cuda_allocator_exit.cpp (Linux only) fakes every CUDA call on its path; it now also fakes cudaDeviceGetAttribute to report pools, since the pool query is new on that path and would otherwise make the test depend on the machine's GPU. ## Test plan - Windows 11, RTX 5080 (WDDM, memory pools supported), CUDA 13.0, llm-release-cuda with tests, rebased on main with the allocator in extension/cuda: all six runtime tests pass (test_cuda_allocator 22 passed with the four no-pool tests skipped; mutable_state 15, weight_cache 11, sort_rand 2, guard 7, stream_guard 21). With EXECUTORCH_CUDA_TEST_REQUIRE_NO_MEMORY_POOLS set, the four no-pool tests fail there, as intended. test_cuda_allocator_exit is Linux only and runs in the Linux job. - The no-pool path runs in the Windows CI job on the A10G; on the previous revision of this PR that job passed the fallback tests there. - Linux: the pool path is covered by the existing unittest-cuda-runtime job. Found while adding the Windows CUDA wheel (#23123), which needs this to run on the Windows GPU runner; this PR does not depend on it.
Builds on #23121 (merged), which ships linkable libraries in the Windows wheel. Stacked on #23405, which makes the CUDA backend fall back to cudaMalloc on devices without memory pools: the Windows GPU CI runner's A10G is one, so this PR's end-to-end runs need it. A Windows user can run a CUDA program but cannot lower one: lowering compiles the model with a toolchain only the Linux side has, and the CUDA Windows CI job already exports on Linux and runs on Windows for exactly this reason. What was missing is a wheel that gives that Windows user the runtime. This adds a Windows CUDA wheel carrying the CUDA delegate as C++ libraries, the same components the Linux CUDA wheel ships (#21645, #21668), and nothing CUDA in the Python module, which on Windows has no CUDA program to lower. The export (AOT) side is unchanged and identical to the CPU wheel's; only the runtime links CUDA. lib/executorch_backend_cuda.dll + .lib the delegate executorch::backend_cuda lib/executorch_extension_cuda.dll + .lib allocator + streams executorch::extension_cuda backends/cuda/aoti_cuda_shims.dll the AOTI shim layer (runtime DLL of the delegate) data/lib/aoti_cuda_shims.lib already shipped as the lowering stub; also the shim layer's import library here extension/pybindings/_C.pyd unchanged: no CUDA dependency, no CudaBackend A C++ application links it exactly as on Linux: find_package(executorch REQUIRED COMPONENTS kernels_optimized backend_cuda) target_link_libraries(app PRIVATE executorch::runtime executorch::kernels_optimized executorch::backend_cuda) # plus the $<TARGET_RUNTIME_DLLS:app> copy from the CPU PR, which now also brings the # CUDA extension and the shim layer The wheel's DLLs import no CUDA runtime DLL: CMake links cudart.lib into them on Windows, and that reaches the driver (nvcuda.dll). The compiled model is different: the library AOTInductor builds into model.pte imports cudart64_13.dll, which comes from the CUDA Toolkit's bin directory on PATH, as the guide says. PyPI's nvidia-cuda-runtime has win_amd64 builds that carry that DLL, but a C++ program does not search site-packages, so declaring it would not make it loadable; the wheel declares no NVIDIA package for Windows. ## How - Generator. The CUDA toolkit's Visual Studio integration fails compiler identification under the ClangCL toolset on some toolkit and Visual Studio pairs (MSB4023 in its targets file), and the MSVC toolset cannot compile the Python extension's sources. A Windows CUDA build therefore uses Ninja Multi-Config with clang-cl, the compiler the CPU wheel uses, and nvcc with cl.exe as its host compiler, in a Visual Studio developer environment that has ninja (ninja, clang-cl and cl all on PATH, which is how the wheel build runs). Elsewhere, such as a plain shell, the build keeps the Visual Studio generator it always used. CMAKE_CUDA_COMPILER is passed only when CUDACXX is unset, so options a user put in CUDACXX (such as -allow-unsupported-compiler) still apply. The toolkit is the one install_utils already reports, so what compiles is the train packaging declares. - CUDA 13.2 and newer. Their CCCL stops with an #error under cl.exe's traditional preprocessor, so the CUDA sources pass -Xcompiler=/Zc:preprocessor on Windows (13.0 accepts it too). - flatc / flatcc byproducts and imported locations share one host executable suffix chosen by CMAKE_HOST_WIN32. CMAKE_EXECUTABLE_SUFFIX is the target's: a Zephyr toolchain sets .elf, and naming the byproduct after it left Ninja with no rule for the host tool. - The shims resolve the runtime from executorch.dll rather than a static core. (The PAL's strong symbols are in #23121; C++20 for the delegate and shims comes from #23135.) - The shims keep WINDOWS_EXPORT_ALL_SYMBOLS OFF in a static build, as upstream sets it, and turn it ON in the shared layout: the delegate DLL imports the stream guard functions (get/set/peek/clearCurrentCUDAStream) from the shim DLL, and those carry no AOTI_SHIM_EXPORT, so the annotations alone would not export them. The allocator is not in either DLL: main moved it into extension_cuda (#23447), a shared library the delegate and the shims both import it from, so the process has one. - #23121 keeps a Windows CUDA build static; this drops that guard, so the pybind preset now builds the shared layout with CUDA too, and adds the CUDA import libraries to the Windows packaging list. - The root CMake file no longer links the CUDA delegate into the Python extension on Windows; extension/cuda finds the CUDA toolkit itself, as on main. - The package config adds the CUDA extension (allocator and stream helpers) and the shim layer to the delegate's runtime DLL set, and reports EXECUTORCH_RUNTIME_DLLS_EXTRA for the pre-3.28 route, since the shim layer ships outside lib/. ## CI - build-wheels-cuda-windows.yml mirrors the Linux CUDA workflow on the Windows wheel builder and reuses filter_cuda_matrix.py. pre_build_script.sh drops the blanket Windows CUDA=OFF (a CPU row is still forced off by the generic row classification), resolves TORCH_CUDA_ARCH_LIST from cuda_arch_list.sh, and writes it to BUILD_ENV_FILE as well as GITHUB_ENV: the reusable workflow sources that file after the hook, and its own list had replaced the row's (sm_75 in, sm_89 out). It also installs ninja for the generator. - End-to-end, per published CUDA train, the route a Windows user has, modeled on cuda-windows.yml. The trains are read from filter_cuda_matrix.py's SUPPORTED_CUDA_VERSIONS (today cu132 and cu134; main stopped publishing cu130 in #23380), the same list the release rows are built from, so adding or dropping a train there changes what is tested. The end-to-end jobs take their trains from the build job's own filtered matrix, so a pull request without the ciflow/binaries/all label tests the one train it builds, and a train the generator dropped is not tested against a wheel that does not exist. (install_utils.py's list also has 12.6 for source builds, but 12.6 is no longer a published wheel train.) A Linux GPU job exports a Windows-target program with that train's torch (`test_cuda_windows.py --export`); a small job bundles it with the wheel the build job published for that train (windows_job.yml downloads one artifact and gives its script no token for a second); and a Windows GPU job installs that published wheel and runs test_cuda_windows.py with the program (test_cuda_windows_e2e.ps1), so CI runs a CUDA program through the artifact users install rather than a wheel rebuilt on the GPU runner. The export and end-to-end jobs check out the commit the build job builds (on a pull request, its merge commit), so the wheel, the program and the scripts that test them match. Each train's CUDA (on Linux for the export, and on Windows for the smoke test's cuobjdump and the model's CUDA runtime) is assembled from NVIDIA's checksummed redistributable archives by install_cuda_redist.py, which needs no installer or admin rights and fails on a train it has no release for. Each train's Windows job waits only for its own bundle, so one train failing does not skip the others, and like the export it does not run for a pull request from a fork. The Windows GPU runners come without an NVIDIA driver (nvcuda.dll is missing and cudaGetDeviceCount returns cudaErrorInsufficientDriver), so the job first installs the same data-center driver, from the same place, that pytorch/pytorch's Windows CUDA smoke tests install (driver_update.bat, 580.88); cu132 and cu134 run on it through CUDA's minor-version compatibility, as PyTorch's own wheels do. The wheel build's own smoke test has no GPU program and says so. ## Tests test_cuda_windows.py, the Windows counterpart of test_cuda_linux.py: - the CUDA DLLs and import libraries ship; - _C depends on no CUDA DLL and registers no CUDA backend; - no shipped CUDA DLL imports cudart64_*.dll (only the driver), and no Windows NVIDIA requirement is declared; - every DLL with device code carries exactly the row's GPUs, both directions, and the newest also as PTX; the expected list comes from executorch_cuda_arch_list in cuda_arch_list.sh, called the way the pre-build hook calls it and keyed by the wheel's +cuXYZ tag, not from the TORCH_CUDA_ARCH_LIST the build consumed; - a C++ application linking executorch::backend_cuda gets the three DLLs copied beside it and sees CudaBackend registered; - a program lowered on Linux for Windows runs through the C++ SDK and matches eager, after checking it was exported with the same CUDA train as the wheel (every CUDA 13 train loads cudart64_13.dll, so a mismatch would not fail on its own); - then what a CPU Windows row checks: test_shared_libraries.py (with the three CUDA ownership rows), test_cpp_sdk.py and the MobileNetV3/XNNPACK model run, including the Arm Cortex-M Python module, which builds under Ninja too: CMSIS-NN's test-only shared library took the static library's name, so its import library collided with it on Windows, and backends/cortex_m now gives the import library its own name. ## Test plan On Windows 11 x64 with an RTX 5080 (sm_120, driver 595.95), VS 2022 BuildTools, CPython 3.12, and WSL Ubuntu for the export, once per CUDA train. 13.2 and 13.4 are the published trains and the ones CI covers; 13.0 is no longer published (#23380) but still builds from source, so it was run too: | train | Windows nvcc | WSL export torch | wheel | test_cuda_windows.py | Linux-exported program | |---|---|---|---|---|---| | 13.0 | 13.0.88 (installer) | 2.14.1+cu130 | executorch-1.6.0+cu130 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | | 13.2 | 13.2.86 (redist) | 2.14.1+cu132 | executorch-1.6.0+cu132 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | | 13.4 | 13.4.59 (redist) | 2.14.0.dev20260810+cu134 | executorch-1.6.0+cu134 | 52 checks pass | runs on the GPU, maxdiff 2.4e-7 | - Each wheel built with TORCH_CUDA_ARCH_LIST from cuda_arch_list.sh: device code for exactly sm_80/86/89/90/100/120, plus sm_120 PTX. 13.4 runs on a driver that reports 13.2, through CUDA's minor-version compatibility. - Before the /Zc:preprocessor change, 13.2 and 13.4 failed to compile the .cu shims with CCCL's "traditional preprocessor" #error; 13.0 was unaffected. - Negative: the cu134 wheel pointed at the 13.0-exported program fails the train check. - The export used `test_cuda_windows.py --export` from this branch in WSL, with mingw-w64 and the Windows CUDA runtime of the same train (13.0 from install_cuda_windows_cross_compile.sh, 13.2/13.4 from the redist archives, the steps the guide now gives). - CI, before the rebase onto main: the end-to-end jobs passed for both published trains on the Windows A10G runner, with a Linux-exported program matching eager (maxdiff 1.3e-7 for 13.2, 2.4e-7 for 13.4). - After rebasing onto main with the allocator moved into extension_cuda (#23447), the cu132 wheel was rebuilt and passes all 55 checks, including the new ownership row: a single CUDA allocator and stream helpers owned by executorch_extension_cuda.dll across the 15 shipped libraries. The rows above were measured before that rebase. - Linux: the CMake changes are behind WIN32 / MSVC, or pick the same suffix there (empty on a Linux host); setup.py's new path runs only on Windows.
Other CUDA delegates need ExecuTorch's allocator without compiling a second copy of its singleton. This moves the allocator into the shared CUDA extension and ships its public headers in the wheel.
The class lives in
executorch::extension::cuda. The old namespace, header and Buck target remain as compatibility aliases. CMake exports the required C10 definition and supplies CUDA toolkit headers when a toolkit is installed. The allocator header requires a CUDA development toolkit;CUDAToolkit_ROOTcan select it. The stream and device guard headers remain usable without one.Allocation and registration behavior are unchanged by the move: the CUDA backend still registers the allocator, and linking only the extension does not. Delegates share the async pool and its retention policy. A cache trim can release unused blocks cached by another delegate, but does not invalidate live allocations. The library initializes its platform state before logging allocator errors. Buck no longer forces the whole library into every binary: it has no static registrar, and its one static initializer comes in with the allocator code that uses it.
The allocator accepts any power of two alignment. Requests above 256 bytes use checked padding and pointer rounding. Deallocation frees the original pointer, and the move preserves this behavior.
Validation: built and ran five CUDA C++ suites on Linux x86_64 with H100 and CUDA 12.8. All 76 cases passed without skips, including 21 allocator cases covering alignment, overflow, concurrency and the legacy alias. Allocator memory checking reported no errors or leaks, with reporting disabled for intentional invalid device API errors. Pinned formatting checks passed. Added checks for required wheel headers and a CMake allocator consumer.
Windows CUDA with MSVC and ROCm were not built or run. Those jobs skip on fork pull requests. Buck linkage was not built; an executable target-contract check is not a Buck build.