Repository navigation
Ship the CUDA runtime in the Windows CUDA wheel #23123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| # Installs the NVIDIA display driver on a Windows GPU runner. The runner images carry the | ||
| # GPU but no driver, so without this nvcuda.dll is missing and every CUDA call fails with | ||
| # cudaErrorInsufficientDriver. The same driver, from the same place, that PyTorch's Windows | ||
| # CUDA smoke tests install first (.ci/pytorch/windows/internal/driver_update.bat in | ||
| # pytorch/pytorch), so both projects test against one driver. | ||
| $ErrorActionPreference = "Stop" | ||
| $version = "580.88" | ||
| $installer = Join-Path $env:RUNNER_TEMP "$version-data-center-tesla-desktop-win10-win11-64bit-dch-international.exe" | ||
| $url = "https://ossci-windows.s3.amazonaws.com/$(Split-Path $installer -Leaf)" | ||
|
|
||
| $nvcuda = Join-Path $env:SystemRoot "System32\nvcuda.dll" | ||
| if (Test-Path $nvcuda) { | ||
| Write-Host "NVIDIA driver already present: $((Get-Item $nvcuda).VersionInfo.FileVersion)" | ||
| exit 0 | ||
| } | ||
| curl.exe --retry 3 -fsSL $url --output $installer | ||
| if ($LASTEXITCODE -ne 0) { throw "downloading the NVIDIA driver from $url failed" } | ||
| $process = Start-Process -FilePath $installer -ArgumentList "-s", "-noreboot" -Wait -PassThru | ||
| Remove-Item $installer -ErrorAction SilentlyContinue | ||
| if ($process.ExitCode -ne 0) { throw "the NVIDIA driver installer exited with $($process.ExitCode)" } | ||
| if (-not (Test-Path $nvcuda)) { throw "the NVIDIA driver installed but $nvcuda is missing" } | ||
| Write-Host "NVIDIA driver $version installed: $((Get-Item $nvcuda).VersionInfo.FileVersion)" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| # Builds and runs the CUDA backend's runtime C++ tests on a Windows GPU runner, the | ||
| # counterpart of the unittest-cuda-runtime job in cuda.yml. The Windows runners carry | ||
| # data-center GPUs in TCC mode, which have no memory pools, so this is also what covers the | ||
| # allocator's synchronous fallback; the Linux job covers the pool path. | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| # Windows PowerShell 5.1 does not stop on a failing native command. | ||
| function Invoke-Native { | ||
| param([Parameter(Mandatory = $true)][scriptblock]$Command) | ||
| & $Command | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "exit code ${LASTEXITCODE}: $Command" | ||
| } | ||
| } | ||
|
|
||
| & "$PSScriptRoot\install_nvidia_driver_windows.ps1" | ||
|
|
||
| $cudaNvcc = Join-Path $env:CUDA_HOME "bin\nvcc.exe" | ||
| if (-not (Test-Path $cudaNvcc)) { throw "CUDA compiler not found at '$cudaNvcc'" } | ||
| $env:CUDACXX = $cudaNvcc | ||
| $env:PATH = "$env:CUDA_HOME\bin\x64;$env:CUDA_HOME\bin;$env:PATH" | ||
| # The runner's GPU has no memory pools, which is what makes this job cover the | ||
| # allocator's fallback; fail rather than skip those tests if it ever has them. | ||
| $env:EXECUTORCH_CUDA_TEST_REQUIRE_NO_MEMORY_POOLS = "1" | ||
|
|
||
| $tests = @( | ||
| "test_cuda_allocator", | ||
| "test_cuda_mutable_state", | ||
| "test_cuda_weight_cache", | ||
| "test_cuda_sort_rand", | ||
| "test_cuda_guard", | ||
| "test_cuda_stream_guard" | ||
| ) | ||
| $numCores = [Math]::Max([Environment]::ProcessorCount - 1, 1) | ||
| Invoke-Native { | ||
| cmake --preset llm-release-cuda -DEXECUTORCH_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=20 ` | ||
| -T "cuda=$env:CUDA_HOME" "-DCMAKE_CUDA_COMPILER=$cudaNvcc" "-DCUDAToolkit_ROOT=$env:CUDA_HOME" | ||
| } | ||
| Invoke-Native { cmake --build cmake-out --config Release -j $numCores --target $tests } | ||
| foreach ($test in $tests) { | ||
| Invoke-Native { ctest --test-dir cmake-out -C Release -R "^$test`$" --output-on-failure -V } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #!/usr/bin/env python | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| """Assemble part of a CUDA toolkit from NVIDIA's redistributable component archives. | ||
|
|
||
| The Windows CUDA wheel end-to-end jobs cover several CUDA trains while the CI images carry | ||
| one toolkit, and NVIDIA publishes no full Windows installer for every release. The redist | ||
| archives exist for every release on both platforms, need no installer or admin rights, and | ||
| are checksummed in a JSON index. Merging the components a job needs into one directory | ||
| gives the layout nvcc, CMake's FindCUDAToolkit and torch's cross-compile step expect. | ||
|
|
||
| install_cuda_redist.py --train 13.4 --platform linux-x86_64 --dest /opt/cuda-13.4 | ||
| install_cuda_redist.py --train 13.4 --platform windows-x86_64 --dest DIR --components cuda_cudart | ||
| """ | ||
|
|
||
| import argparse | ||
| import hashlib | ||
| import json | ||
| import shutil | ||
| import sys | ||
| import tarfile | ||
| import tempfile | ||
| import urllib.request | ||
| import zipfile | ||
| from pathlib import Path | ||
|
|
||
| _REDIST = "https://developer.download.nvidia.com/compute/cuda/redist" | ||
|
|
||
| # The patch release each train resolves to: one entry per train in filter_cuda_matrix.py's | ||
| # SUPPORTED_CUDA_VERSIONS, which the end-to-end jobs take their matrix from, and 13.0, which | ||
| # is no longer published but still builds from source and is what local tests of it use. A | ||
| # train missing here fails the job at argument parsing rather than testing a different | ||
| # release. | ||
| _RELEASES = {"13.0": "13.0.2", "13.2": "13.2.2", "13.4": "13.4.1"} | ||
|
|
||
| # What a build of the CUDA backend needs. "a|b" names one component a release publishes | ||
| # under either name (CCCL was renamed between releases). | ||
| _BUILD_COMPONENTS = [ | ||
| "cuda_nvcc", | ||
| "cuda_cudart", | ||
| "cuda_crt", | ||
| "cccl|cuda_cccl", | ||
| "libnvvm", | ||
| "cuda_cuobjdump", | ||
| "cuda_nvrtc", | ||
| "cuda_profiler_api", | ||
| "cuda_nvtx", | ||
| # rand.cu includes curand_kernel.h. | ||
| "libcurand", | ||
| ] | ||
|
|
||
|
|
||
| def _fetch(url: str, destination: Path) -> None: | ||
| with urllib.request.urlopen(url, timeout=300) as response, open( | ||
| destination, "wb" | ||
| ) as handle: | ||
| shutil.copyfileobj(response, handle) | ||
|
|
||
|
|
||
| def _extract(archive: Path, into: Path) -> Path: | ||
| if archive.suffix == ".zip": | ||
| with zipfile.ZipFile(archive) as bundle: | ||
| bundle.extractall(into) | ||
| else: | ||
| with tarfile.open(archive) as bundle: | ||
| if hasattr(tarfile, "fully_trusted_filter"): | ||
| bundle.extractall(into, filter="fully_trusted") | ||
| else: | ||
| bundle.extractall(into) | ||
| # Each archive holds one top-level directory named after itself. | ||
| (top,) = [entry for entry in into.iterdir() if entry.is_dir()] | ||
| return top | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) | ||
| parser.add_argument("--train", required=True, choices=sorted(_RELEASES)) | ||
| parser.add_argument( | ||
| "--platform", required=True, choices=["linux-x86_64", "windows-x86_64"] | ||
| ) | ||
| parser.add_argument("--dest", required=True, type=Path) | ||
| parser.add_argument("--components", nargs="+", default=_BUILD_COMPONENTS) | ||
| arguments = parser.parse_args() | ||
|
|
||
| release = _RELEASES[arguments.train] | ||
| with urllib.request.urlopen( | ||
| f"{_REDIST}/redistrib_{release}.json", timeout=120 | ||
| ) as response: | ||
| index = json.load(response) | ||
| arguments.dest.mkdir(parents=True, exist_ok=True) | ||
| with tempfile.TemporaryDirectory() as work: | ||
| work = Path(work) | ||
| for choice in arguments.components: | ||
| names = [ | ||
| name | ||
| for name in choice.split("|") | ||
| if arguments.platform in index.get(name, {}) | ||
| ] | ||
| if not names: | ||
| sys.exit( | ||
| f"CUDA {release} publishes none of {choice} for {arguments.platform}" | ||
| ) | ||
| entry = index[names[0]][arguments.platform] | ||
| archive = work / Path(entry["relative_path"]).name | ||
| _fetch(f"{_REDIST}/{entry['relative_path']}", archive) | ||
| digest = hashlib.sha256(archive.read_bytes()).hexdigest() | ||
| if digest != entry["sha256"]: | ||
| sys.exit(f"checksum mismatch for {archive.name}") | ||
| staging = work / "staging" | ||
| top = _extract(archive, staging) | ||
| shutil.copytree(top, arguments.dest, symlinks=True, dirs_exist_ok=True) | ||
| shutil.rmtree(staging) | ||
| archive.unlink() | ||
| print( | ||
| f"merged {names[0]} {index[names[0]]['version']} into {arguments.dest}" | ||
| ) | ||
| # The Linux archives keep libraries in lib/, while nvcc's link step and CMake's | ||
| # FindCUDAToolkit look in lib64/, which is where an installed toolkit has them. | ||
| lib, lib64 = arguments.dest / "lib", arguments.dest / "lib64" | ||
| if arguments.platform == "linux-x86_64" and lib.is_dir() and not lib64.exists(): | ||
| lib64.symlink_to("lib", target_is_directory=True) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.