]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
alloc : fix allocation data of pre-allocated leafs
authorslaren <redacted>
Sat, 16 Mar 2024 14:47:14 +0000 (15:47 +0100)
committerGeorgi Gerganov <redacted>
Mon, 18 Mar 2024 08:59:05 +0000 (10:59 +0200)
src/ggml-alloc.c

index 8ac1d3e51470c9cdcc3d4107a9e731c0dd8ea6d6..60b86c27581621b508ba468415d3aa82a117810e 100644 (file)
@@ -701,8 +701,13 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c
         struct ggml_tensor * leaf = graph->leafs[i];
         struct hash_node * hn = ggml_gallocr_hash_get(galloc, leaf);
         galloc->leaf_allocs[i].buffer_id = hn->buffer_id;
-        galloc->leaf_allocs[i].leaf.offset = hn->offset;
-        galloc->leaf_allocs[i].leaf.size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], leaf);
+        if (leaf->view_src || leaf->data) {
+            galloc->leaf_allocs[i].leaf.offset = SIZE_MAX;
+            galloc->leaf_allocs[i].leaf.size_max = 0;
+        } else {
+            galloc->leaf_allocs[i].leaf.offset = hn->offset;
+            galloc->leaf_allocs[i].leaf.size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], leaf);
+        }
     }
 
     // reallocate buffers if needed