@@ -568,7 +568,7 @@ static bool ggml_metal_heap_resize(struct ggml_metal_heap * heap, size_t size) {
568
568
569
569
heap->need += size_aligned;
570
570
571
- if (!heap->fail && heap-> need > [heap->obj maxAvailableSizeWithAlignment: alignment]) {
571
+ if (!heap->fail && size_aligned > [heap->obj maxAvailableSizeWithAlignment: alignment]) {
572
572
heap->fail = 1 ;
573
573
}
574
574
@@ -2277,11 +2277,13 @@ static bool ggml_metal_encode_node(
2277
2277
/* .nb3 =*/ nb03,
2278
2278
};
2279
2279
2280
- id <MTLBuffer > id_src0h = ggml_metal_heap_alloc (heap, ggml_nbytes (src0), 32 );
2280
+ id <MTLBuffer > id_src0h = ggml_metal_heap_alloc (heap, ggml_nbytes (src0), 64 * 1024 );
2281
2281
if (!id_src0h) {
2282
- // GGML_LOG_ERROR("%s: failed to allocate buffer for cpy, size = %zu, need = %zu, max available = %zu\n",
2283
- // __func__, ggml_nbytes(src0), heap->need, [heap->obj maxAvailableSizeWithAlignment:32]);
2284
- return false ;
2282
+ // GGML_LOG_ERROR("%s: failed to allocate buffer, idx = %4d, size = %8zu, need = %8zu, max available = %9zu, heap size = %9zu, heap used = %zu\n",
2283
+ // __func__, idx, ggml_nbytes(src0), heap->need, [heap->obj maxAvailableSizeWithAlignment:0], [heap->obj size], [heap->obj usedSize]);
2284
+ return true ;
2285
+ } else {
2286
+ // GGML_LOG_ERROR("%s: allocated %zu\n", __func__, ggml_nbytes(src0));
2285
2287
}
2286
2288
2287
2289
if (src0->type == GGML_TYPE_F16) {
@@ -4688,7 +4690,7 @@ static enum ggml_status ggml_metal_graph_compute(
4688
4690
// number of threads in addition to the main thread
4689
4691
const int n_cb = ctx->n_cb ;
4690
4692
4691
- int n_try = 64 ;
4693
+ int n_try = 2 ;
4692
4694
4693
4695
// submit the ggml compute graph to the GPU by creating command buffers and encoding the ops in them
4694
4696
// the first n_nodes_0 are encoded and submitted for processing directly by the calling thread
@@ -4815,7 +4817,7 @@ static enum ggml_status ggml_metal_graph_compute(
4815
4817
for (int i = 0 ; i <= n_cb; ++i) {
4816
4818
struct ggml_metal_heap * heap = ctx->cmd_bufs [i].heap ;
4817
4819
4818
- const size_t need = 4 * heap->need ;
4820
+ const size_t need = heap->need ;
4819
4821
4820
4822
// printf("\nXXXXXXXXXXXXXXXXX cb %d, need = %zu, fail = %d, size = %zu\n", i, need, heap->fail, [heap->obj currentAllocatedSize]);
4821
4823
0 commit comments