From 3cd0cbb1b5db24899fcf4fa7dd2feeeb28e77723 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Wed, 10 Jan 2024 11:50:10 +0200 Subject: [PATCH] metal : page align the data ptr (#4854) --- ggml-metal.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ggml-metal.m b/ggml-metal.m index 1e7ed6bb8b756..547b618b49f62 100644 --- a/ggml-metal.m +++ b/ggml-metal.m @@ -2656,6 +2656,14 @@ ggml_backend_buffer_t ggml_backend_metal_buffer_from_ptr(void * data, size_t siz ctx->n_buffers = 0; const size_t size_page = sysconf(_SC_PAGESIZE); + + // page-align the data ptr + { + const uintptr_t offs = (uintptr_t) data % size_page; + data = (void *) ((char *) data - offs); + size += offs; + } + size_t size_aligned = size; if ((size_aligned % size_page) != 0) { size_aligned += (size_page - (size_aligned % size_page));