Skip to content

Commit 158526e

Browse files
committed
metal : remove ggml_metal_heap
ggml-ci
1 parent fcc113f commit 158526e

File tree

1 file changed

+0
-90
lines changed

1 file changed

+0
-90
lines changed

ggml/src/ggml-metal/ggml-metal.m

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -532,96 +532,6 @@ - (void) dealloc {
532532
GGML_METAL_KERNEL_TYPE_COUNT
533533
};
534534

535-
//
536-
// ggml_metal_heap
537-
//
538-
539-
struct ggml_metal_heap {
540-
// number of times the heap was unused
541-
int n_unused;
542-
543-
// total number of buffer allocations in this heap across all computes
544-
int64_t n_alloc;
545-
546-
// current offset in the heap - we reset this after each node in order to reuse the memory
547-
size_t offs;
548-
549-
// the currently allocated MTLBuffer objects in this heap
550-
id<MTLHeap> obj;
551-
552-
NSMutableArray * bufs;
553-
};
554-
555-
static struct ggml_metal_heap * ggml_metal_heap_init(id<MTLDevice> device, size_t size) {
556-
struct ggml_metal_heap * heap = calloc(1, sizeof(struct ggml_metal_heap));
557-
558-
MTLHeapDescriptor * desc = [[MTLHeapDescriptor alloc] init];
559-
desc.storageMode = MTLStorageModePrivate;
560-
desc.cpuCacheMode = MTLCPUCacheModeDefaultCache;
561-
desc.type = MTLHeapTypePlacement;
562-
desc.size = size;
563-
564-
heap->n_unused = 0;
565-
heap->n_alloc = 0;
566-
567-
heap->obj = [device newHeapWithDescriptor:desc];
568-
if (!heap->obj) {
569-
GGML_LOG_ERROR("%s: error: failed to create MTLHeap with size %zu\n", __func__, size);
570-
571-
free(heap);
572-
573-
return false;
574-
}
575-
576-
[desc release];
577-
578-
heap->bufs = [[NSMutableArray alloc] init];
579-
580-
return heap;
581-
}
582-
583-
static void ggml_metal_heap_reset(struct ggml_metal_heap * heap) {
584-
heap->offs = 0;
585-
586-
// count how many graph computes the heap ended up being unused
587-
if ([heap->bufs count] > 0) {
588-
heap->n_unused = 0;
589-
} else {
590-
heap->n_unused++;
591-
}
592-
593-
for (id<MTLBuffer> buf in heap->bufs) {
594-
[buf release];
595-
}
596-
[heap->bufs removeAllObjects];
597-
598-
// tell the OS that it can reuse this memory if needed
599-
// ref: https://developer.apple.com/documentation/metal/mtlpurgeablestate?language=objc
600-
[heap->obj setPurgeableState:MTLPurgeableStateVolatile];
601-
}
602-
603-
static void ggml_metal_heap_free(struct ggml_metal_heap * heap) {
604-
if (heap == nil) {
605-
return;
606-
}
607-
608-
ggml_metal_heap_reset(heap);
609-
610-
[heap->obj release];
611-
[heap->bufs release];
612-
613-
free(heap);
614-
}
615-
616-
@interface ggml_metal_heap_ptr : NSObject
617-
618-
@property (nonatomic, assign) struct ggml_metal_heap * data;
619-
620-
@end
621-
622-
@implementation ggml_metal_heap_ptr
623-
@end
624-
625535
struct ggml_metal_command_buffer {
626536
id<MTLCommandBuffer> obj;
627537

0 commit comments

Comments
 (0)