From 82e50204d743b0e20da327d54cb89161401d0dac Mon Sep 17 00:00:00 2001 From: Emmanuel Adebiyi Date: Wed, 29 May 2024 19:45:29 +0100 Subject: [PATCH] add logic to auto load library --- LLama/LLamaSharp.Runtime.targets | 136 ++---------------- LLama/Native/NativeApi.Load.cs | 9 +- .../build/LLamaSharp.Backend.Android.nuspec | 32 +++++ .../build/LLamaSharp.Backend.Cpu.nuspec | 5 +- 4 files changed, 51 insertions(+), 131 deletions(-) create mode 100644 LLama/runtimes/build/LLamaSharp.Backend.Android.nuspec diff --git a/LLama/LLamaSharp.Runtime.targets b/LLama/LLamaSharp.Runtime.targets index fa7a018c1..764d772bc 100644 --- a/LLama/LLamaSharp.Runtime.targets +++ b/LLama/LLamaSharp.Runtime.targets @@ -2,133 +2,17 @@ true - - - PreserveNewest - runtimes/win-x64/native/noavx/llama.dll - - - PreserveNewest - runtimes/win-x64/native/avx/llama.dll - - - PreserveNewest - runtimes/win-x64/native/avx2/llama.dll - - - PreserveNewest - runtimes/win-x64/native/avx512/llama.dll - - - PreserveNewest - runtimes/win-x64/native/cuda11/llama.dll - - - PreserveNewest - runtimes/win-x64/native/cuda12/llama.dll - + + + libllama.so + arm64-v8a + - - PreserveNewest - runtimes/linux-x64/native/noavx/libllama.so - - - PreserveNewest - runtimes/linux-x64/native/avx/libllama.so - - - PreserveNewest - runtimes/linux-x64/native/avx2/libllama.so - - - PreserveNewest - runtimes/linux-x64/native/avx512/libllama.so - - - PreserveNewest - runtimes/linux-x64/native/cuda11/libllama.so - - - PreserveNewest - runtimes/linux-x64/native/cuda12/libllama.so - - - - PreserveNewest - runtimes/osx-arm64/native/libllama.dylib - - - PreserveNewest - runtimes/osx-arm64/native/ggml-metal.metal - - - - PreserveNewest - runtimes/osx-x64/native/libllama.dylib - - - - PreserveNewest - runtimes/win-x64/native/noavx/llava_shared.dll - - - PreserveNewest - runtimes/win-x64/native/avx/llava_shared.dll - - - PreserveNewest - runtimes/win-x64/native/avx2/llava_shared.dll - - - PreserveNewest - runtimes/win-x64/native/avx512/llava_shared.dll - - - PreserveNewest - runtimes/win-x64/native/cuda11/llava_shared.dll - - - PreserveNewest - runtimes/win-x64/native/cuda12/llava_shared.dll - - - - - PreserveNewest - runtimes/linux-x64/native/noavx/libllava_shared.so - - - PreserveNewest - runtimes/linux-x64/native/avx/libllava_shared.so - - - PreserveNewest - runtimes/linux-x64/native/avx2/libllava_shared.so - - - PreserveNewest - runtimes/linux-x64/native/avx512/libllava_shared.so - - - PreserveNewest - runtimes/linux-x64/native/cuda11/libllava_shared.so - - - PreserveNewest - runtimes/linux-x64/native/cuda12/libllava_shared.so - - - - PreserveNewest - runtimes/osx-arm64/native/libllava_shared.dylib - - - - PreserveNewest - runtimes/osx-x64/native/libllava_shared.dylib - - - + + libllava_shared.so + arm64-v8a + + \ No newline at end of file diff --git a/LLama/Native/NativeApi.Load.cs b/LLama/Native/NativeApi.Load.cs index 5275023e6..3b0dd70f7 100644 --- a/LLama/Native/NativeApi.Load.cs +++ b/LLama/Native/NativeApi.Load.cs @@ -1,4 +1,4 @@ -using LLama.Exceptions; +using LLama.Exceptions; using System; using System.IO; using System.Runtime.InteropServices; @@ -55,6 +55,11 @@ private static void SetDllImportResolver() // NativeLibrary is not available on older runtimes. We'll have to depend on // the normal runtime dll resolution there. #if NET5_0_OR_GREATER + + // We don't need special dll resolution on Android + if (OperatingSystem.IsAndroid()) + return; + NativeLibrary.SetDllImportResolver(typeof(NativeApi).Assembly, (name, _, _) => { if (name == "llama") @@ -316,7 +321,9 @@ private static void GetPlatformPathParts(out OSPlatform platform, out string os, ? "osx-arm64" : "osx-x64"; libPrefix = "lib"; + return; } + else { throw new RuntimeError("Your operating system is not supported, please open an issue in LLamaSharp."); diff --git a/LLama/runtimes/build/LLamaSharp.Backend.Android.nuspec b/LLama/runtimes/build/LLamaSharp.Backend.Android.nuspec new file mode 100644 index 000000000..1e77784f1 --- /dev/null +++ b/LLama/runtimes/build/LLamaSharp.Backend.Android.nuspec @@ -0,0 +1,32 @@ + + + + LLamaSharp.Backend.Android + $version$ + LLamaSharp.Backend.Android - Android Backend for LLamaSharp + llama.cpp Authors + false + MIT + icon512.png + https://github.com/SciSharp/LLamaSharp + LLamaSharp.Backend.Android is a backend for LLamaSharp to use with Android. + + Copyright 2023 The llama.cpp Authors. All rights reserved. + LLamaSharp LLama LLM GPT AI ChatBot SciSharp + + + + + + + + + + + + + + + + + diff --git a/LLama/runtimes/build/LLamaSharp.Backend.Cpu.nuspec b/LLama/runtimes/build/LLamaSharp.Backend.Cpu.nuspec index 531640a69..a120613fd 100644 --- a/LLama/runtimes/build/LLamaSharp.Backend.Cpu.nuspec +++ b/LLama/runtimes/build/LLamaSharp.Backend.Cpu.nuspec @@ -44,10 +44,7 @@ - - - - +