From 9d091c0316cf51168ad578f4a164e15762025dd2 Mon Sep 17 00:00:00 2001 From: evolcano Date: Sat, 30 Mar 2024 10:54:44 +0800 Subject: [PATCH] Add path to find llama.dll for MAUI This commit is originally made by lcarrere in https://github.com/SciSharp/LLamaSharp/issues/180 . I have confirmed this modification is OK in my windows 11 laptop, add make this commit according require of AsakusaRinne. --- LLama/Native/NativeApi.Load.cs | 9 +++++++++ LLama/Native/NativeApi.cs | 3 +++ 2 files changed, 12 insertions(+) diff --git a/LLama/Native/NativeApi.Load.cs b/LLama/Native/NativeApi.Load.cs index 1b186816..459b29ba 100644 --- a/LLama/Native/NativeApi.Load.cs +++ b/LLama/Native/NativeApi.Load.cs @@ -74,6 +74,15 @@ namespace LLama.Native { return -1; } + + //Ensuring cuda bin path is reachable. Especially for MAUI environment. + string cudaBinPath = Path.Combine(cudaPath, "bin"); + + if (Directory.Exists(cudaBinPath)) + { + AddDllDirectory(cudaBinPath); + } + version = GetCudaVersionFromPath(cudaPath); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) diff --git a/LLama/Native/NativeApi.cs b/LLama/Native/NativeApi.cs index b53f47ee..d46d48a2 100644 --- a/LLama/Native/NativeApi.cs +++ b/LLama/Native/NativeApi.cs @@ -26,6 +26,9 @@ namespace LLama.Native llama_max_devices(); } + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + private static extern int AddDllDirectory(string NewDirectory); + /// /// Get the maximum number of devices supported by llama.cpp ///