Skip to content

Commit 9361803

Browse files
committed
ggml : add ggml_tensor_overhead()
1 parent 83c54e6 commit 9361803

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

ggml.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,6 +3808,10 @@ enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype) {
38083808
return wtype;
38093809
}
38103810

3811+
size_t ggml_tensor_overhead(void) {
3812+
return GGML_OBJECT_SIZE + GGML_TENSOR_SIZE + 16;
3813+
}
3814+
38113815
static inline bool ggml_is_transposed(const struct ggml_tensor * tensor) {
38123816
return tensor->nb[0] > tensor->nb[1];
38133817
}
@@ -14527,6 +14531,14 @@ void ggml_graph_reset(struct ggml_cgraph * cgraph) {
1452714531
}
1452814532

1452914533
struct ggml_tensor * ggml_get_tensor_by_name(struct ggml_cgraph * cgraph, const char * name) {
14534+
for (int i = 0; i < cgraph->n_leafs; i++) {
14535+
struct ggml_tensor * leaf = cgraph->leafs[i];
14536+
14537+
if (strcmp(leaf->name, name) == 0) {
14538+
return leaf;
14539+
}
14540+
}
14541+
1453014542
for (int i = 0; i < cgraph->n_nodes; i++) {
1453114543
struct ggml_tensor * node = cgraph->nodes[i];
1453214544

ggml.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,6 @@ extern "C" {
380380

381381
static const size_t GGML_TENSOR_SIZE = sizeof(struct ggml_tensor);
382382

383-
// use this to compute the memory overhead of a tensor
384-
static const size_t GGML_TENSOR_OVERHEAD = (GGML_OBJECT_SIZE + GGML_TENSOR_SIZE + 16);
385-
386383
// computation graph
387384
struct ggml_cgraph {
388385
int n_nodes;
@@ -444,6 +441,9 @@ extern "C" {
444441
// TODO: temporary until model loading of ggml examples is refactored
445442
GGML_API enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype);
446443

444+
// use this to compute the memory overhead of a tensor
445+
GGML_API size_t ggml_tensor_overhead(void);
446+
447447
// main
448448

449449
GGML_API struct ggml_context * ggml_init(struct ggml_init_params params);

0 commit comments

Comments
 (0)