summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrzemysław Pawełczyk <przemoc@gmail.com>2023-09-07 10:15:06 +0200
committerGitHub <noreply@github.com>2023-09-07 11:15:06 +0300
commitfec2fb19e4229aac58c98171c46e77144b99f8a3 (patch)
treeef3ae68596bed6c4e9ef8c089566bed57efd7bbd
parent178b1850ebd21b349cebbee887950e435c5aa2d3 (diff)
ggml : posixify madvise and pagesize (#3037)
* llama : use posix_madvise() instead of madvise() derived from BSD sed -i 's,\<madvise\>,posix_&,g;s,\<MADV_,POSIX_&,g' llama.cpp * ggml : use sysconf(_SC_PAGESIZE) instead of getpagesize() derived from BSD sed -i 's,getpagesize(),sysconf(_SC_PAGESIZE),g' ggml.c * metal : use sysconf(_SC_PAGESIZE) instead of getpagesize() derived from BSD sed -i 's,getpagesize(),sysconf(_SC_PAGESIZE),g' ggml-metal.m
-rw-r--r--ggml-metal.m4
-rw-r--r--ggml.c2
-rw-r--r--llama.cpp8
3 files changed, 7 insertions, 7 deletions
diff --git a/ggml-metal.m b/ggml-metal.m
index d0d23442..521ca180 100644
--- a/ggml-metal.m
+++ b/ggml-metal.m
@@ -327,7 +327,7 @@ void ggml_metal_free(struct ggml_metal_context * ctx) {
void * ggml_metal_host_malloc(size_t n) {
void * data = NULL;
- const int result = posix_memalign((void **) &data, getpagesize(), n);
+ const int result = posix_memalign((void **) &data, sysconf(_SC_PAGESIZE), n);
if (result != 0) {
metal_printf("%s: error: posix_memalign failed\n", __func__);
return NULL;
@@ -401,7 +401,7 @@ bool ggml_metal_add_buffer(
}
}
- const size_t size_page = getpagesize();
+ const size_t size_page = sysconf(_SC_PAGESIZE);
size_t size_aligned = size;
if ((size_aligned % size_page) != 0) {
diff --git a/ggml.c b/ggml.c
index 38b1155c..50adf18e 100644
--- a/ggml.c
+++ b/ggml.c
@@ -194,7 +194,7 @@ typedef void * thread_ret_t;
inline static void * ggml_aligned_malloc(size_t size) {
void * aligned_memory = NULL;
#ifdef GGML_USE_METAL
- int result = posix_memalign(&aligned_memory, getpagesize(), size);
+ int result = posix_memalign(&aligned_memory, sysconf(_SC_PAGESIZE), size);
#else
int result = posix_memalign(&aligned_memory, GGML_MEM_ALIGN, size);
#endif
diff --git a/llama.cpp b/llama.cpp
index 3413288f..2c9071a8 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -606,16 +606,16 @@ 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));
}
}
if (numa) {
// 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",
+ if (posix_madvise(addr, file->size, POSIX_MADV_RANDOM)) {
+ fprintf(stderr, "warning: posix_madvise(.., POSIX_MADV_RANDOM) failed: %s\n",
strerror(errno));
}
}