File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 99
1010#import < Metal/Metal.h>
1111
12+ #include < stdatomic.h>
13+
1214#undef MIN
1315#undef MAX
1416#define MIN (a, b ) ((a) < (b) ? (a) : (b))
@@ -6327,8 +6329,10 @@ static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_ba
63276329 ctx->all_data = ggml_metal_host_malloc (size_aligned);
63286330 ctx->is_shared = true ;
63296331 } else {
6330- // dummy, non-NULL value - we'll populate this after creating the Metal buffer below
6331- ctx->all_data = (void *) 0x000000400ULL ;
6332+ // virtual address for GPU memory allocations
6333+ static atomic_uintptr_t addr_device = 0x000000400ULL ;
6334+
6335+ ctx->all_data = (void *) atomic_fetch_add_explicit (&addr_device, size_aligned, memory_order_relaxed);
63326336 ctx->is_shared = false ;
63336337 }
63346338 ctx->all_size = size_aligned;
@@ -6351,7 +6355,10 @@ static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_ba
63516355 } else {
63526356 ctx->buffers [0 ].metal = [device newBufferWithLength: size_aligned options: MTLResourceStorageModePrivate ];
63536357
6354- ctx->all_data = (void *) (ctx->buffers [0 ].metal .gpuAddress );
6358+ // MTLBuffer.gpuAddress is not available on early OSes, so we use a virtual address instead
6359+ // if (@available(macOS 10.13, iOS 16.0, *)) {
6360+ // ctx->all_data = (void *) (ctx->buffers[0].metal.gpuAddress);
6361+ // }
63556362 }
63566363 }
63576364
You can’t perform that action at this time.
0 commit comments