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))
@@ -6326,8 +6328,10 @@ static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_ba
63266328 ctx->all_data = ggml_metal_host_malloc (size_aligned);
63276329 ctx->is_shared = true ;
63286330 } else {
6329- // dummy, non-NULL value - we'll populate this after creating the Metal buffer below
6330- ctx->all_data = (void *) 0x000000400ULL ;
6331+ // virtual address for GPU memory allocations
6332+ static atomic_uintptr_t addr_device = 0x000000400ULL ;
6333+
6334+ ctx->all_data = (void *) atomic_fetch_add_explicit (&addr_device, size_aligned, memory_order_relaxed);
63316335 ctx->is_shared = false ;
63326336 }
63336337 ctx->all_size = size_aligned;
@@ -6350,7 +6354,10 @@ static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_ba
63506354 } else {
63516355 ctx->buffers [0 ].metal = [device newBufferWithLength: size_aligned options: MTLResourceStorageModePrivate ];
63526356
6353- ctx->all_data = (void *) (ctx->buffers [0 ].metal .gpuAddress );
6357+ // MTLBuffer.gpuAddress is not available on early OSes, so we use a virtual address instead
6358+ // if (@available(macOS 10.13, iOS 16.0, *)) {
6359+ // ctx->all_data = (void *) (ctx->buffers[0].metal.gpuAddress);
6360+ // }
63546361 }
63556362 }
63566363
You can’t perform that action at this time.
0 commit comments