]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
ggml : add ggml_tensor_overhead()
authorGeorgi Gerganov <redacted>
Sat, 27 May 2023 13:19:56 +0000 (16:19 +0300)
committerGeorgi Gerganov <redacted>
Sat, 27 May 2023 13:19:56 +0000 (16:19 +0300)
ggml.c
ggml.h

diff --git a/ggml.c b/ggml.c
index c2499226051aa96c76d8b4852ee4d05b4030f858..14972464b55e78a2e93349fa761c8c49eca1821d 100644 (file)
--- a/ggml.c
+++ b/ggml.c
@@ -3808,6 +3808,10 @@ enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype) {
     return wtype;
 }
 
+size_t ggml_tensor_overhead(void) {
+    return GGML_OBJECT_SIZE + GGML_TENSOR_SIZE + 16;
+}
+
 static inline bool ggml_is_transposed(const struct ggml_tensor * tensor) {
     return tensor->nb[0] > tensor->nb[1];
 }
@@ -14527,6 +14531,14 @@ void ggml_graph_reset(struct ggml_cgraph * cgraph) {
 }
 
 struct ggml_tensor * ggml_get_tensor_by_name(struct ggml_cgraph * cgraph, const char * name) {
+    for (int i = 0; i < cgraph->n_leafs; i++) {
+        struct ggml_tensor * leaf = cgraph->leafs[i];
+
+        if (strcmp(leaf->name, name) == 0) {
+            return leaf;
+        }
+    }
+
     for (int i = 0; i < cgraph->n_nodes; i++) {
         struct ggml_tensor * node = cgraph->nodes[i];
 
diff --git a/ggml.h b/ggml.h
index 0c90f506410dd020bf49994da1a7ea17e09d52cc..55813828012a63c862bb3539984bee589c3ddf36 100644 (file)
--- a/ggml.h
+++ b/ggml.h
@@ -380,9 +380,6 @@ extern "C" {
 
     static const size_t GGML_TENSOR_SIZE = sizeof(struct ggml_tensor);
 
-    // use this to compute the memory overhead of a tensor
-    static const size_t GGML_TENSOR_OVERHEAD = (GGML_OBJECT_SIZE + GGML_TENSOR_SIZE + 16);
-
     // computation graph
     struct ggml_cgraph {
         int n_nodes;
@@ -444,6 +441,9 @@ extern "C" {
     // TODO: temporary until model loading of ggml examples is refactored
     GGML_API enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype);
 
+    // use this to compute the memory overhead of a tensor
+    GGML_API size_t ggml_tensor_overhead(void);
+
     // main
 
     GGML_API struct ggml_context * ggml_init(struct ggml_init_params params);