mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2024-10-01 01:06:10 -04:00
797891c995
* Initial Library Loader * Load library as part of Model factory * Dynamically search and find the dlls * Update tests to use locally built runtimes * Fix dylib loading, add macos runtime support for sample/tests * Bypass automatic loading by default. * Only set CMAKE_OSX_ARCHITECTURES if not already set, allow cross-compile * Switch Loading again * Update build scripts for mac/linux * Update bindings to support newest breaking changes * Fix build * Use llmodel for Windows * Actually, it does need to be libllmodel * Name * Remove TFMs, bypass loading by default * Fix script * Delete mac script --------- Co-authored-by: Tim Miller <innerlogic4321@ghmail.com>
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace Gpt4All.LibraryLoader;
|
|
|
|
internal class LinuxLibraryLoader : ILibraryLoader
|
|
{
|
|
#pragma warning disable CA2101
|
|
[DllImport("libdl.so", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlopen")]
|
|
#pragma warning restore CA2101
|
|
public static extern IntPtr NativeOpenLibraryLibdl(string? filename, int flags);
|
|
|
|
#pragma warning disable CA2101
|
|
[DllImport("libdl.so.2", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlopen")]
|
|
#pragma warning restore CA2101
|
|
public static extern IntPtr NativeOpenLibraryLibdl2(string? filename, int flags);
|
|
|
|
[DllImport("libdl.so", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlerror")]
|
|
public static extern IntPtr GetLoadError();
|
|
|
|
[DllImport("libdl.so.2", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlerror")]
|
|
public static extern IntPtr GetLoadError2();
|
|
|
|
public LoadResult OpenLibrary(string? fileName)
|
|
{
|
|
IntPtr loadedLib;
|
|
try
|
|
{
|
|
// open with rtls lazy flag
|
|
loadedLib = NativeOpenLibraryLibdl2(fileName, 0x00001);
|
|
}
|
|
catch (DllNotFoundException)
|
|
{
|
|
loadedLib = NativeOpenLibraryLibdl(fileName, 0x00001);
|
|
}
|
|
|
|
if (loadedLib == IntPtr.Zero)
|
|
{
|
|
string errorMessage;
|
|
try
|
|
{
|
|
errorMessage = Marshal.PtrToStringAnsi(GetLoadError2()) ?? "Unknown error";
|
|
}
|
|
catch (DllNotFoundException)
|
|
{
|
|
errorMessage = Marshal.PtrToStringAnsi(GetLoadError()) ?? "Unknown error";
|
|
}
|
|
|
|
return LoadResult.Failure(errorMessage);
|
|
}
|
|
|
|
return LoadResult.Success;
|
|
}
|
|
}
|