]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
talk-llama : fix build on macOS (#1062)
authorPrzemysław Pawełczyk <redacted>
Wed, 28 Jun 2023 19:34:50 +0000 (21:34 +0200)
committerGitHub <redacted>
Wed, 28 Jun 2023 19:34:50 +0000 (22:34 +0300)
* talk-llama : use posix_madvise() instead of madvise() derived from BSD

sed -i 's,\<madvise\>,posix_&,g;s,\<MADV_,POSIX_&,g' examples/talk-llama/llama-util.h

* make : enable Darwin extensions for macOS builds

This is an attempt at fixing macOS build error coming from the fact that
RLIMIT_MEMLOCK define is not available there without Darwin extensions.

Makefile
examples/talk-llama/llama-util.h

index c7b05a9a6d9903db4f051ce8185fd1fadf38fb41..a9ae2e7ab96d368712b39b8ed9d75b640b904aea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,13 @@ LDFLAGS  =
 CFLAGS   += -D_XOPEN_SOURCE=600
 CXXFLAGS += -D_XOPEN_SOURCE=600
 
+# RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,
+# and on macOS its availability depends on enabling Darwin extensions
+ifeq ($(UNAME_S),Darwin)
+       CFLAGS   += -D_DARWIN_C_SOURCE
+       CXXFLAGS += -D_DARWIN_C_SOURCE
+endif
+
 # OS specific
 # TODO: support Windows
 ifeq ($(UNAME_S),Linux)
index 3cac9f681800bcd83962a603ca04bf79f69f4b9f..4d5100638f6289a79527e23962e660ff4409ce97 100644 (file)
@@ -186,8 +186,8 @@ struct llama_mmap {
 
         if (prefetch > 0) {
             // Advise the kernel to preload the mapped memory
-            if (madvise(addr, std::min(file->size, prefetch), MADV_WILLNEED)) {
-                fprintf(stderr, "warning: madvise(.., MADV_WILLNEED) failed: %s\n",
+            if (posix_madvise(addr, std::min(file->size, prefetch), POSIX_MADV_WILLNEED)) {
+                fprintf(stderr, "warning: posix_madvise(.., POSIX_MADV_WILLNEED) failed: %s\n",
                         strerror(errno));
             }
         }