From 57a8f146a069e5999d8735a6e885c0d46386c293 Mon Sep 17 00:00:00 2001 From: dane madsen Date: Sun, 15 Oct 2023 19:45:33 +1000 Subject: [PATCH] Address undeclared identifiers by adding conditional compilation --- llama.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/llama.cpp b/llama.cpp index 5329bd828..4c568b68d 100644 --- a/llama.cpp +++ b/llama.cpp @@ -735,19 +735,37 @@ struct llama_mmap { } if (prefetch > 0) { + #ifdef __USE_XOPEN2K // Advise the kernel to preload the mapped memory 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)); } + #else + // 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", + strerror(errno)); + } + #endif + } if (numa) { + #ifdef __USE_XOPEN2K // advise the kernel not to use readahead // (because the next page might not belong on the same node) if (posix_madvise(addr, file->size, POSIX_MADV_RANDOM)) { fprintf(stderr, "warning: posix_madvise(.., POSIX_MADV_RANDOM) failed: %s\n", strerror(errno)); } + #else + // advise the kernel not to use readahead + // (because the next page might not belong on the same node) + if (madvise(addr, file->size, MADV_RANDOM)) { + fprintf(stderr, "warning: madvise(.., MADV_RANDOM) failed: %s\n", + strerror(errno)); + } + #endif } }