diff --git a/LLama/Native/NativeApi.Load.cs b/LLama/Native/NativeApi.Load.cs index 28f0564d..b5b3a530 100644 --- a/LLama/Native/NativeApi.Load.cs +++ b/LLama/Native/NativeApi.Load.cs @@ -135,6 +135,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 ///