# Download the CUDA 12 cuBLAS DLLs that the native Leleka engine needs (cublas64_12.dll, cublasLt64_12.dll) from NVIDIA's # redistributable archive, check it against the pinned SHA-256, and put the DLLs where `leleka` looks for them. # # powershell -ExecutionPolicy Bypass -File scripts\windows\fetch-cublas.ps1 [-OutDir DIR] [-ZipPath FILE] [-Force] # # The pin comes from NVIDIA's own manifest https://developer.download.nvidia.com/compute/cuda/redist/redistrib_12.9.1.json # (libcublas 12.9.1.4, windows-x86_64). The script REFUSES an archive whose length or SHA-256 differs and deletes it. # -ZipPath checks and unpacks an archive you downloaded yourself (no network access). The licence terms of the NVIDIA # redistributable (the LICENSE file inside the archive) apply to the DLLs; the script copies that file next to them. # # Result: \bin\cublas64_12.dll and cublasLt64_12.dll. The default OutDir, %LOCALAPPDATA%\leleka\cublas, is searched by # `leleka` automatically (no --cublas-dir needed). param( [string]$OutDir = (Join-Path $env:LOCALAPPDATA "leleka\cublas"), [string]$ZipPath = "", [switch]$Force ) $ErrorActionPreference = "Stop" $Url = "https://developer.download.nvidia.com/compute/cuda/redist/libcublas/windows-x86_64/libcublas-windows-x86_64-12.9.1.4-archive.zip" $Sha256 = "d534d98b0b453a98914dbf3adf47d7e84b55037abf02f87466439e1dcef581ed" $Bytes = 549755186 $Dlls = @("cublas64_12.dll", "cublasLt64_12.dll") $bin = Join-Path $OutDir "bin" if (-not $Force -and -not $ZipPath -and ($Dlls | ForEach-Object { Test-Path (Join-Path $bin $_) }) -notcontains $false) { Write-Host "already present in $bin (use -Force to download again)" exit 0 } New-Item -ItemType Directory -Force -Path $OutDir | Out-Null $zip = $ZipPath $downloaded = $false if (-not $zip) { $zip = Join-Path $OutDir "libcublas-12.9.1.4.zip" $part = "$zip.part" Write-Host "downloading $Url" Write-Host " to $part ($([math]::Round($Bytes / 1MB)) MiB; curl resumes an interrupted download when you rerun this script)" & curl.exe --location --fail --retry 5 --retry-delay 3 --continue-at - --output $part $Url if ($LASTEXITCODE -ne 0) { throw "download failed (curl exit code $LASTEXITCODE)" } Move-Item -Force $part $zip $downloaded = $true } function Refuse([string]$why) { if ($downloaded) { Remove-Item -Force $zip -ErrorAction SilentlyContinue } throw "REFUSED: $why. The archive was not unpacked$(if ($downloaded) { ' and was deleted' })." } $length = (Get-Item $zip).Length if ($length -ne $Bytes) { Refuse "$zip has $length bytes, the pin says $Bytes" } Write-Host "hashing $zip ..." $hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLower() if ($hash -ne $Sha256) { Refuse "SHA-256 of $zip is $hash, the pin says $Sha256" } Write-Host "SHA-256 matches the pin" $staging = Join-Path $OutDir ".unpack" if (Test-Path $staging) { Remove-Item -Recurse -Force $staging } Expand-Archive -Path $zip -DestinationPath $staging $found = @{} Get-ChildItem -Recurse -Path $staging -Include $Dlls | ForEach-Object { $found[$_.Name] = $_.FullName } foreach ($dll in $Dlls) { if (-not $found.ContainsKey($dll)) { throw "$dll is not inside the archive" } } New-Item -ItemType Directory -Force -Path $bin | Out-Null foreach ($dll in $Dlls) { Copy-Item -Force $found[$dll] (Join-Path $bin $dll) } $license = Get-ChildItem -Recurse -Path $staging -Filter "LICENSE*" | Select-Object -First 1 if ($license) { Copy-Item -Force $license.FullName (Join-Path $OutDir "LICENSE-cublas.txt") } Remove-Item -Recurse -Force $staging if ($downloaded) { Remove-Item -Force $zip } foreach ($dll in $Dlls) { $path = Join-Path $bin $dll "{0} {1} {2:N1} MiB" -f (Get-FileHash -Algorithm SHA256 $path).Hash.ToLower(), $dll, ((Get-Item $path).Length / 1MB) } Write-Host "cuBLAS DLLs are in $bin" Write-Host "next: leleka doctor"