Skip to content

Commit a461ac4

Browse files
authored
talk-llama : fix build on macOS (ggml-org#1062)
* 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.
1 parent 15aa3da commit a461ac4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ LDFLAGS =
4343
CFLAGS += -D_XOPEN_SOURCE=600
4444
CXXFLAGS += -D_XOPEN_SOURCE=600
4545

46+
# RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,
47+
# and on macOS its availability depends on enabling Darwin extensions
48+
ifeq ($(UNAME_S),Darwin)
49+
CFLAGS += -D_DARWIN_C_SOURCE
50+
CXXFLAGS += -D_DARWIN_C_SOURCE
51+
endif
52+
4653
# OS specific
4754
# TODO: support Windows
4855
ifeq ($(UNAME_S),Linux)

examples/talk-llama/llama-util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ struct llama_mmap {
186186

187187
if (prefetch > 0) {
188188
// Advise the kernel to preload the mapped memory
189-
if (madvise(addr, std::min(file->size, prefetch), MADV_WILLNEED)) {
190-
fprintf(stderr, "warning: madvise(.., MADV_WILLNEED) failed: %s\n",
189+
if (posix_madvise(addr, std::min(file->size, prefetch), POSIX_MADV_WILLNEED)) {
190+
fprintf(stderr, "warning: posix_madvise(.., POSIX_MADV_WILLNEED) failed: %s\n",
191191
strerror(errno));
192192
}
193193
}

0 commit comments

Comments
 (0)