aisop/tools/Install-GpuRuntime.ps1

35 lines
1.7 KiB
PowerShell

param(
[string]$Destination = (Join-Path $PSScriptRoot '..\libs\cuda')
)
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$runtimeDirectory = [IO.Path]::GetFullPath($Destination)
New-Item -ItemType Directory -Path $runtimeDirectory -Force | Out-Null
# NVIDIA 官方 cuDNN 9 / CUDA 12 发行包;仅解压运行所需 DLL 和许可证,不修改系统 PATH。
$manifest = Invoke-RestMethod -Uri 'https://developer.download.nvidia.com/compute/cudnn/redist/redistrib_9.5.1.json'
$package = $manifest.cudnn.'windows-x86_64'.cuda12
$archivePath = Join-Path $runtimeDirectory 'cudnn-runtime.zip'
if (!(Test-Path -LiteralPath $archivePath)) {
Write-Host 'Downloading NVIDIA cuDNN (about 532 MiB)...'
Invoke-WebRequest -Uri ('https://developer.download.nvidia.com/compute/cudnn/redist/' + $package.relative_path) -OutFile $archivePath
}
if ((Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash -ne $package.sha256) {
throw 'cuDNN SHA256 校验失败,请移除下载文件后重试。'
}
$archive = [IO.Compression.ZipFile]::OpenRead($archivePath)
try {
foreach ($entry in $archive.Entries) {
if ($entry.FullName -notmatch '/bin/[^/]+\.dll$' -and $entry.Name -notmatch '^LICENSE') { continue }
$target = Join-Path $runtimeDirectory $entry.Name
[IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target, $true)
Write-Host ('Extracted ' + $entry.Name)
}
}
finally { $archive.Dispose() }
if (!(Test-Path -LiteralPath (Join-Path $runtimeDirectory 'cudnn64_9.dll'))) { throw '发行包中未找到 cuDNN DLL' }
Remove-Item -LiteralPath $archivePath
Write-Host 'cuDNN ready. Rebuild the application to copy DLLs to its output directory.'