From cec2d4e2659ff652877ef5f53983f9da5d57869c Mon Sep 17 00:00:00 2001 From: Gilad S Date: Mon, 14 Oct 2024 03:40:25 +0300 Subject: [PATCH] fix: switch to `posix_memalign` to keep existing `free()` usages work --- ggml/src/ggml-backend.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ggml/src/ggml-backend.cpp b/ggml/src/ggml-backend.cpp index ef701e61d..263b3e75d 100644 --- a/ggml/src/ggml-backend.cpp +++ b/ggml/src/ggml-backend.cpp @@ -24,7 +24,7 @@ #ifdef __APPLE__ #include #include -#include +#include #include #endif @@ -772,11 +772,11 @@ static const char * ggml_backend_cpu_buffer_type_get_name(ggml_backend_buffer_ty } static ggml_backend_buffer_t ggml_backend_cpu_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) { -#ifdef TARGET_OS_OSX +#if defined(GGML_USE_METAL) || defined(TARGET_OS_OSX) void * data = NULL; - kern_return_t alloc_status = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t *) &data, size, VM_FLAGS_ANYWHERE); - if (alloc_status != KERN_SUCCESS) { - GGML_LOG_ERROR("%s: failed to allocate buffer using vm_allocate with size %zu\n", __func__, size); + int result = posix_memalign(&data, sysconf(_SC_PAGESIZE), size); + if (result != 0) { + GGML_LOG_ERROR("%s: failed to allocate buffer using posix_memalign with size %zu\n", __func__, size); return NULL; } #else