From 23bf941a6ecd6d25d8ebe9001bd1cbee0335e82d Mon Sep 17 00:00:00 2001 From: m0nsky Date: Fri, 12 Jul 2024 14:50:40 +0200 Subject: [PATCH] Fix CUDA detection on WSL (#847) Improve CUDA detection on WSL --- LLama/Native/Load/SystemInfo.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/LLama/Native/Load/SystemInfo.cs b/LLama/Native/Load/SystemInfo.cs index 0ffc67e91..7a075064e 100644 --- a/LLama/Native/Load/SystemInfo.cs +++ b/LLama/Native/Load/SystemInfo.cs @@ -65,9 +65,24 @@ private static int GetCudaMajorVersion() } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - // Try the default first - cudaPath = "/usr/local/bin/cuda"; - version = GetCudaVersionFromPath(cudaPath); + // List of default cuda paths + string[] defaultCudaPaths = + { + "/usr/local/bin/cuda", + "/usr/local/cuda", + }; + + // Loop through every default path to find the version + foreach (var path in defaultCudaPaths) + { + // Attempt to get the version from the path + version = GetCudaVersionFromPath(path); + + // If a CUDA version is found, break the loop + if (!string.IsNullOrEmpty(version)) + break; + } + if (string.IsNullOrEmpty(version)) { cudaPath = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");