Spaces:
Sleeping
Sleeping
Przemysław Pawełczyk
commited on
talk-llama : fix build on macOS (#1062)
Browse files* 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 +7 -0
- examples/talk-llama/llama-util.h +2 -2
Makefile
CHANGED
|
@@ -43,6 +43,13 @@ LDFLAGS =
|
|
| 43 |
CFLAGS += -D_XOPEN_SOURCE=600
|
| 44 |
CXXFLAGS += -D_XOPEN_SOURCE=600
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# OS specific
|
| 47 |
# TODO: support Windows
|
| 48 |
ifeq ($(UNAME_S),Linux)
|
|
|
|
| 43 |
CFLAGS += -D_XOPEN_SOURCE=600
|
| 44 |
CXXFLAGS += -D_XOPEN_SOURCE=600
|
| 45 |
|
| 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 |
+
|
| 53 |
# OS specific
|
| 54 |
# TODO: support Windows
|
| 55 |
ifeq ($(UNAME_S),Linux)
|
examples/talk-llama/llama-util.h
CHANGED
|
@@ -186,8 +186,8 @@ struct llama_mmap {
|
|
| 186 |
|
| 187 |
if (prefetch > 0) {
|
| 188 |
// Advise the kernel to preload the mapped memory
|
| 189 |
-
if (
|
| 190 |
-
fprintf(stderr, "warning:
|
| 191 |
strerror(errno));
|
| 192 |
}
|
| 193 |
}
|
|
|
|
| 186 |
|
| 187 |
if (prefetch > 0) {
|
| 188 |
// Advise the kernel to preload the mapped memory
|
| 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",
|
| 191 |
strerror(errno));
|
| 192 |
}
|
| 193 |
}
|