Skip to content

Commit cec2d4e

Browse files
committed
fix: switch to posix_memalign to keep existing free() usages work
1 parent 06b119a commit cec2d4e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ggml/src/ggml-backend.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#ifdef __APPLE__
2525
#include <sys/types.h>
2626
#include <sys/sysctl.h>
27-
#include <mach/mach.h>
27+
#include <unistd.h>
2828
#include <TargetConditionals.h>
2929
#endif
3030

@@ -772,11 +772,11 @@ static const char * ggml_backend_cpu_buffer_type_get_name(ggml_backend_buffer_ty
772772
}
773773

774774
static ggml_backend_buffer_t ggml_backend_cpu_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
775-
#ifdef TARGET_OS_OSX
775+
#if defined(GGML_USE_METAL) || defined(TARGET_OS_OSX)
776776
void * data = NULL;
777-
kern_return_t alloc_status = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t *) &data, size, VM_FLAGS_ANYWHERE);
778-
if (alloc_status != KERN_SUCCESS) {
779-
GGML_LOG_ERROR("%s: failed to allocate buffer using vm_allocate with size %zu\n", __func__, size);
777+
int result = posix_memalign(&data, sysconf(_SC_PAGESIZE), size);
778+
if (result != 0) {
779+
GGML_LOG_ERROR("%s: failed to allocate buffer using posix_memalign with size %zu\n", __func__, size);
780780
return NULL;
781781
}
782782
#else

0 commit comments

Comments
 (0)