From ca0a5c72b2696be25672475b57df2adc0901c29a Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Mon, 9 Nov 2026 20:43:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=20CUDA=2013=20=E7=9A=84=20cuDNN=20=E4=B8=8E=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E7=BC=96=E8=AF=91=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Inference/CudaRuntime.cs | 8 +++++++- tools/Install-GpuRuntime.ps1 | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/SopHelper.CrossPlatform.Engine/Inference/CudaRuntime.cs b/src/SopHelper.CrossPlatform.Engine/Inference/CudaRuntime.cs index 6b0b231..c6ad1c7 100644 --- a/src/SopHelper.CrossPlatform.Engine/Inference/CudaRuntime.cs +++ b/src/SopHelper.CrossPlatform.Engine/Inference/CudaRuntime.cs @@ -10,7 +10,13 @@ internal static class CudaRuntime { if (!OperatingSystem.IsWindows()) return []; var handles = new List(); - foreach (var name in new[] { "cublasLt64_13.dll", "cublas64_13.dll", "cudart64_13.dll", "cudnn64_9.dll" }) + foreach (var name in new[] + { + "cublasLt64_13.dll", "cublas64_13.dll", "cudart64_13.dll", + "nvrtc-builtins64_130.dll", "nvrtc64_130_0.dll", + "cudnn_graph64_9.dll", "cudnn_ops64_9.dll", "cudnn_cnn64_9.dll", "cudnn_adv64_9.dll", + "cudnn_engines_precompiled64_9.dll", "cudnn_engines_runtime_compiled64_9.dll", "cudnn_heuristic64_9.dll", "cudnn64_9.dll", + }) { var path = Path.Combine(AppContext.BaseDirectory, name); try { handles.Add(NativeLibrary.Load(File.Exists(path) ? path : name)); } diff --git a/tools/Install-GpuRuntime.ps1 b/tools/Install-GpuRuntime.ps1 index 74f2412..27c790a 100644 --- a/tools/Install-GpuRuntime.ps1 +++ b/tools/Install-GpuRuntime.ps1 @@ -54,11 +54,23 @@ if ($CudaRuntimeSource) { Install-NvidiaArchive $name 'https://developer.download.nvidia.com/compute/cuda/redist/' $cuda.$name.'windows-x86_64' } } -if (!(Test-Path -LiteralPath (Join-Path $runtimeDirectory 'cudnn64_9.dll'))) { +$nvrtcDlls = @('nvrtc-builtins64_130.dll','nvrtc64_130_0.dll') +if (@($nvrtcDlls | Where-Object { !(Test-Path -LiteralPath (Join-Path $runtimeDirectory $_)) }).Count) { + $cuda = Invoke-RestMethod 'https://developer.download.nvidia.com/compute/cuda/redist/redistrib_13.0.2.json' + Install-NvidiaArchive 'cuda_nvrtc' 'https://developer.download.nvidia.com/compute/cuda/redist/' $cuda.cuda_nvrtc.'windows-x86_64' +} +$cudnnDlls = @('cudnn_graph64_9.dll','cudnn_ops64_9.dll','cudnn_cnn64_9.dll','cudnn_adv64_9.dll', + 'cudnn_engines_precompiled64_9.dll','cudnn_engines_runtime_compiled64_9.dll','cudnn_heuristic64_9.dll','cudnn64_9.dll') +# CUDA 12 与 CUDA 13 的 cuDNN 文件名相同,必须记录已安装的发行包,不能只判断 DLL 是否存在。 +$cudnnStamp = Join-Path $runtimeDirectory '.cudnn-cuda13-version' +if (!(Test-Path -LiteralPath $cudnnStamp) -or + (Get-Content -LiteralPath $cudnnStamp -Raw).Trim() -ne '9.13.0' -or + @($cudnnDlls | Where-Object { !(Test-Path -LiteralPath (Join-Path $runtimeDirectory $_)) }).Count) { $cudnn = Invoke-RestMethod 'https://developer.download.nvidia.com/compute/cudnn/redist/redistrib_9.13.0.json' Install-NvidiaArchive 'cudnn' 'https://developer.download.nvidia.com/compute/cudnn/redist/' $cudnn.cudnn.'windows-x86_64'.cuda13 + Set-Content -LiteralPath $cudnnStamp -Value '9.13.0' } -foreach ($name in $cudaDlls + 'cudnn64_9.dll') { +foreach ($name in $cudaDlls + $nvrtcDlls + $cudnnDlls) { if (!(Test-Path -LiteralPath (Join-Path $runtimeDirectory $name))) { throw "GPU 运行库不完整:$name" } } Write-Host 'CUDA 13 / cuDNN 9 ready. Rebuild and restart the application to use GPU inference.'