// if false, the Metal buffer data is allocated in private GPU memory and is not shared with the host
bool is_shared;
+ bool owned;
// multiple buffers are used only to avoid the maximum buffer size limitation when using mmap
int n_buffers;
if (shared) {
res->all_data = ggml_metal_host_malloc(size_aligned);
res->is_shared = true;
+ res->owned = true;
} else {
// dummy, non-NULL value - we'll populate this after creating the Metal buffer below
res->all_data = (void *) 0x000000400ULL;
res->all_size = size;
res->is_shared = true;
+ res->owned = false;
res->n_buffers = 0;
ggml_metal_buffer_rset_free(buf);
- if (buf->is_shared) {
+ if (buf->is_shared && buf->owned) {
#if TARGET_OS_OSX
vm_deallocate((vm_map_t)mach_task_self(), (vm_address_t)buf->all_data, buf->all_size);
#else