]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
Windows fixes (#890)
authorcomex <redacted>
Tue, 11 Apr 2023 13:19:54 +0000 (06:19 -0700)
committerGitHub <redacted>
Tue, 11 Apr 2023 13:19:54 +0000 (15:19 +0200)
Mostly for msys2 and mingw64 builds, which are different from each other
and different from standard Visual Studio builds.  Isn't Windows fun?

- Define _GNU_SOURCE in more files (it's already used in ggml.c for
  Linux's sake).

- Don't use PrefetchVirtualMemory if not building for Windows 8 or later
  (mingw64 doesn't by default).  But warn the user about this situation
  since it's probably not intended.

- Check for NOMINMAX already being defined, which it is on mingw64.

- Actually use the `increment` variable (bug in my `pizza` PR).

- Suppress unused variable warnings in the fake pthread_create and
  pthread_join implementations for Windows.

- (not Windows-related) Remove mention of `asprintf` from comment;
  `asprintf` is no longer used.

Fixes #871.

examples/main/main.cpp
ggml.c
llama.cpp
llama_util.h

index d333d0dbacd20531e9a909aec383c3586dc08bec..bf756c16de19d13a3f995332fc958253c780f56e 100644 (file)
@@ -1,3 +1,8 @@
+// Defines sigaction on msys:
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #include "common.h"
 #include "llama.h"
 
diff --git a/ggml.c b/ggml.c
index ada3bbbdcda80105a41c8358f14a0353cdd580ea..897b67d930614986e7593e7c73cb505ae9d82816 100644 (file)
--- a/ggml.c
+++ b/ggml.c
@@ -1,4 +1,4 @@
-// Defines CLOCK_MONOTONIC and asprintf on Linux
+// Defines CLOCK_MONOTONIC on Linux
 #define _GNU_SOURCE
 
 #include "ggml.h"
@@ -50,6 +50,7 @@ typedef HANDLE pthread_t;
 
 typedef DWORD thread_ret_t;
 static int pthread_create(pthread_t* out, void* unused, thread_ret_t(*func)(void*), void* arg) {
+    (void) unused;
     HANDLE handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, arg, 0, NULL);
     if (handle == NULL)
     {
@@ -61,6 +62,7 @@ static int pthread_create(pthread_t* out, void* unused, thread_ret_t(*func)(void
 }
 
 static int pthread_join(pthread_t thread, void* unused) {
+    (void) unused;
     return (int) WaitForSingleObject(thread, INFINITE);
 }
 
index 203a1adc0928a015eb6a3b7ae05af7e875598e7a..54ba01eefbade0633c8e3be493e9837737cd3a4d 100644 (file)
--- a/llama.cpp
+++ b/llama.cpp
@@ -1,3 +1,8 @@
+// Defines fileno on msys:
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #include "llama_util.h"
 #include "llama.h"
 #include "llama_internal.h"
index d68f49bd239a4847a5ccc18118da325cc0859b79..653bf71388bff2da970889eb378d3e3fbb774dd5 100755 (executable)
@@ -26,7 +26,9 @@
 
 #if defined(_WIN32)
     #define WIN32_LEAN_AND_MEAN
-    #define NOMINMAX
+    #ifndef NOMINMAX
+        #define NOMINMAX
+    #endif
     #include <windows.h>
     #include <io.h>
     #include <stdio.h> // for _fseeki64
@@ -209,6 +211,7 @@ struct llama_mmap {
             throw format("MapViewOfFile failed: %s", llama_format_win_err(error).c_str());
         }
 
+        #if _WIN32_WINNT >= _WIN32_WINNT_WIN8
         // Advise the kernel to preload the mapped memory
         WIN32_MEMORY_RANGE_ENTRY range;
         range.VirtualAddress = addr;
@@ -217,6 +220,9 @@ struct llama_mmap {
             fprintf(stderr, "warning: PrefetchVirtualMemory failed: %s\n",
                     llama_format_win_err(GetLastError()).c_str());
         }
+        #else
+        #pragma message("warning: You are building for pre-Windows 8; prefetch not supported")
+        #endif // _WIN32_WINNT >= _WIN32_WINNT_WIN8
     }
 
     ~llama_mmap() {
@@ -338,8 +344,8 @@ struct llama_mlock {
             // Hopefully a megabyte is enough overhead:
             size_t increment = size + 1048576;
             // The minimum must be <= the maximum, so we need to increase both:
-            min_ws_size += size;
-            max_ws_size += size;
+            min_ws_size += increment;
+            max_ws_size += increment;
             if (!SetProcessWorkingSetSize(GetCurrentProcess(), min_ws_size, max_ws_size)) {
                 fprintf(stderr, "warning: SetProcessWorkingSetSize failed: %s\n",
                         llama_format_win_err(GetLastError()).c_str());