From f55222bc38cdccb2b83767ada331f86640bf051f Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Tue, 30 Apr 2024 16:10:08 +0100 Subject: [PATCH] Fixed `bool` marshalling --- LLama/LLamaStatelessExecutor.cs | 1 + LLama/Native/NativeApi.LLava.cs | 5 +++-- LLama/Native/NativeApi.cs | 6 ++++++ LLama/Native/SafeLlamaModelHandle.cs | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/LLama/LLamaStatelessExecutor.cs b/LLama/LLamaStatelessExecutor.cs index a16995ba..087d2819 100644 --- a/LLama/LLamaStatelessExecutor.cs +++ b/LLama/LLamaStatelessExecutor.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; +using System.Text; using System.Threading; using LLama.Exceptions; using LLama.Native; diff --git a/LLama/Native/NativeApi.LLava.cs b/LLama/Native/NativeApi.LLava.cs index e3aeef4b..183f183a 100644 --- a/LLama/Native/NativeApi.LLava.cs +++ b/LLama/Native/NativeApi.LLava.cs @@ -13,6 +13,7 @@ public static unsafe partial class NativeApi /// Llava Model /// True if validate successfully [DllImport(llavaLibraryName, EntryPoint = "llava_validate_embed_size", CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] public static extern bool llava_validate_embed_size( SafeLLamaContextHandle ctxLlama, SafeLlavaModelHandle ctxClip); /// @@ -56,7 +57,7 @@ public static unsafe partial class NativeApi /// Embedding handle /// True on success [DllImport(llavaLibraryName, EntryPoint = "llava_eval_image_embed", CallingConvention = CallingConvention.Cdecl)] - public static extern bool llava_eval_image_embed(SafeLLamaContextHandle ctx_llama, SafeLlavaImageEmbedHandle embed, - int n_batch, ref int n_past); + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool llava_eval_image_embed(SafeLLamaContextHandle ctx_llama, SafeLlavaImageEmbedHandle embed, int n_batch, ref int n_past); } \ No newline at end of file diff --git a/LLama/Native/NativeApi.cs b/LLama/Native/NativeApi.cs index 309e12d5..11a8690f 100644 --- a/LLama/Native/NativeApi.cs +++ b/LLama/Native/NativeApi.cs @@ -34,6 +34,7 @@ namespace LLama.Native /// /// [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] public static extern bool llama_supports_mmap(); /// @@ -41,6 +42,7 @@ namespace LLama.Native /// /// [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] public static extern bool llama_supports_mlock(); /// @@ -48,6 +50,7 @@ namespace LLama.Native /// /// [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] public static extern bool llama_supports_gpu_offload(); /// @@ -77,6 +80,7 @@ namespace LLama.Native /// /// [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] public static extern bool llama_state_load_file(SafeLLamaContextHandle ctx, string path_session, LLamaToken[] tokens_out, ulong n_token_capacity, out ulong n_token_count_out); /// @@ -88,6 +92,7 @@ namespace LLama.Native /// /// [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] public static extern bool llama_state_save_file(SafeLLamaContextHandle ctx, string path_session, LLamaToken[] tokens, ulong n_token_count); [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] @@ -284,6 +289,7 @@ namespace LLama.Native /// /// Returns false if a partial sequence cannot be removed. Removing a whole sequence never fails [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] public static extern bool llama_kv_cache_seq_rm(SafeLLamaContextHandle ctx, LLamaSeqId seq, LLamaPos p0, LLamaPos p1); /// diff --git a/LLama/Native/SafeLlamaModelHandle.cs b/LLama/Native/SafeLlamaModelHandle.cs index e55902bc..f24cfe5f 100644 --- a/LLama/Native/SafeLlamaModelHandle.cs +++ b/LLama/Native/SafeLlamaModelHandle.cs @@ -369,6 +369,7 @@ namespace LLama.Native /// /// [DllImport(NativeApi.libraryName, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.U1)] private static extern bool llama_token_is_eog(SafeLlamaModelHandle model, LLamaToken token); #endregion