summaryrefslogtreecommitdiff
path: root/llama_util.h
diff options
context:
space:
mode:
authorcomex <comexk@gmail.com>2023-04-11 06:19:54 -0700
committerGitHub <noreply@github.com>2023-04-11 15:19:54 +0200
commit2663d2c6784ad7b77998c6874df25648d597f74b (patch)
tree1739feb4d2c189ddb5f04e14a4fb326ec61b0242 /llama_util.h
parenta0caa34b162449b5c13b8d604573053300ff54a1 (diff)
Windows fixes (#890)
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.
Diffstat (limited to 'llama_util.h')
-rwxr-xr-xllama_util.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/llama_util.h b/llama_util.h
index d68f49bd..653bf713 100755
--- a/llama_util.h
+++ b/llama_util.h
@@ -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());