Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e931888

Browse filesBrowse files
authored
ggml : fix calloc argument ordering. (#6820)
Latest gcc complains here: /home/airlied/devel/llama.cpp/ggml-alloc.c: In function ‘ggml_gallocr_new_n’: /home/airlied/devel/llama.cpp/ggml-alloc.c:374:59: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args] 374 | ggml_gallocr_t galloc = (ggml_gallocr_t)calloc(sizeof(struct ggml_gallocr), 1); | ^~~~~~ /home/airlied/devel/llama.cpp/ggml-alloc.c:374:59: note: earlier argument should specify number of elements, later size of each element and a bunch more. calloc is specified to take nmemb first then size, so realign the code. In a couple of places there was a * x, 1 so I fixed those to use calloc properly.
1 parent 8960fe8 commit e931888
Copy full SHA for e931888

File tree

Expand file treeCollapse file tree

2 files changed

+17
-17
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-17
lines changed

‎ggml-alloc.c

Copy file name to clipboardExpand all lines: ggml-alloc.c
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,16 @@ struct ggml_gallocr {
371371
};
372372

373373
ggml_gallocr_t ggml_gallocr_new_n(ggml_backend_buffer_type_t * bufts, int n_bufs) {
374-
ggml_gallocr_t galloc = (ggml_gallocr_t)calloc(sizeof(struct ggml_gallocr), 1);
374+
ggml_gallocr_t galloc = (ggml_gallocr_t)calloc(1, sizeof(struct ggml_gallocr));
375375
GGML_ASSERT(galloc != NULL);
376376

377-
galloc->bufts = calloc(sizeof(ggml_backend_buffer_type_t) * n_bufs, 1);
377+
galloc->bufts = calloc(n_bufs, sizeof(ggml_backend_buffer_type_t));
378378
GGML_ASSERT(galloc->bufts != NULL);
379379

380-
galloc->buffers = calloc(sizeof(ggml_backend_buffer_t) * n_bufs, 1);
380+
galloc->buffers = calloc(n_bufs, sizeof(ggml_backend_buffer_t) * n_bufs);
381381
GGML_ASSERT(galloc->buffers != NULL);
382382

383-
galloc->buf_tallocs = calloc(sizeof(struct ggml_dyn_tallocr *) * n_bufs, 1);
383+
galloc->buf_tallocs = calloc(n_bufs, sizeof(struct ggml_dyn_tallocr *));
384384
GGML_ASSERT(galloc->buf_tallocs != NULL);
385385

386386
for (int i = 0; i < n_bufs; i++) {
@@ -646,8 +646,8 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c
646646
free(galloc->hash_set.keys);
647647
free(galloc->hash_values);
648648
galloc->hash_set.size = hash_size;
649-
galloc->hash_set.keys = calloc(sizeof(struct ggml_tensor *), hash_size);
650-
galloc->hash_values = calloc(sizeof(struct hash_node), hash_size);
649+
galloc->hash_set.keys = calloc(hash_size, sizeof(struct ggml_tensor *));
650+
galloc->hash_values = calloc(hash_size, sizeof(struct hash_node));
651651
GGML_ASSERT(galloc->hash_set.keys != NULL);
652652
GGML_ASSERT(galloc->hash_values != NULL);
653653
} else {
@@ -667,7 +667,7 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c
667667
// set the node_allocs from the hash table
668668
if (galloc->n_nodes < graph->n_nodes) {
669669
free(galloc->node_allocs);
670-
galloc->node_allocs = calloc(sizeof(struct node_alloc), graph->n_nodes);
670+
galloc->node_allocs = calloc(graph->n_nodes, sizeof(struct node_alloc));
671671
GGML_ASSERT(galloc->node_allocs != NULL);
672672
}
673673
galloc->n_nodes = graph->n_nodes;
@@ -697,7 +697,7 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c
697697
}
698698
if (galloc->n_leafs < graph->n_leafs) {
699699
free(galloc->leaf_allocs);
700-
galloc->leaf_allocs = calloc(sizeof(galloc->leaf_allocs[0]), graph->n_leafs);
700+
galloc->leaf_allocs = calloc(graph->n_leafs, sizeof(galloc->leaf_allocs[0]));
701701
GGML_ASSERT(galloc->leaf_allocs != NULL);
702702
}
703703
galloc->n_leafs = graph->n_leafs;

‎ggml-backend.c

Copy file name to clipboardExpand all lines: ggml-backend.c
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,23 +1725,23 @@ ggml_backend_sched_t ggml_backend_sched_new(
17251725
GGML_ASSERT(n_backends <= GGML_SCHED_MAX_BACKENDS);
17261726
GGML_ASSERT(ggml_backend_is_cpu(backends[n_backends - 1])); // last backend must be CPU
17271727

1728-
struct ggml_backend_sched * sched = calloc(sizeof(struct ggml_backend_sched), 1);
1728+
struct ggml_backend_sched * sched = calloc(1, sizeof(struct ggml_backend_sched));
17291729

17301730
// initialize hash table
17311731
sched->hash_set = ggml_hash_set_new(graph_size);
1732-
sched->tensor_backend_id = calloc(sizeof(sched->tensor_backend_id[0]), sched->hash_set.size);
1733-
sched->tensor_copies = calloc(sizeof(sched->tensor_copies[0]), sched->hash_set.size);
1732+
sched->tensor_backend_id = calloc(sched->hash_set.size, sizeof(sched->tensor_backend_id[0]));
1733+
sched->tensor_copies = calloc(sched->hash_set.size, sizeof(sched->tensor_copies[0]));
17341734

17351735
const size_t nodes_size = graph_size + GGML_SCHED_MAX_SPLITS*GGML_SCHED_MAX_SPLIT_INPUTS*2;
1736-
sched->node_backend_ids = calloc(sizeof(sched->node_backend_ids[0]), nodes_size);
1737-
sched->leaf_backend_ids = calloc(sizeof(sched->leaf_backend_ids[0]), nodes_size);
1736+
sched->node_backend_ids = calloc(nodes_size, sizeof(sched->node_backend_ids[0]));
1737+
sched->leaf_backend_ids = calloc(nodes_size, sizeof(sched->leaf_backend_ids[0]));
17381738

17391739
sched->n_backends = n_backends;
17401740

17411741
sched->n_copies = parallel ? GGML_SCHED_MAX_COPIES : 1;
17421742

17431743
const int initial_splits_capacity = 16;
1744-
sched->splits = calloc(sizeof(sched->splits[0]), initial_splits_capacity);
1744+
sched->splits = calloc(initial_splits_capacity, sizeof(sched->splits[0]));
17451745
sched->splits_capacity = initial_splits_capacity;
17461746

17471747
for (int b = 0; b < n_backends; b++) {
@@ -1972,10 +1972,10 @@ static void graph_copy_init_tensor(struct ggml_hash_set hash_set, struct ggml_te
19721972
struct ggml_backend_graph_copy ggml_backend_graph_copy(ggml_backend_t backend, struct ggml_cgraph * graph) {
19731973
struct ggml_hash_set hash_set = {
19741974
/* .size = */ graph->visited_hash_table.size,
1975-
/* .keys = */ calloc(sizeof(hash_set.keys[0]), graph->visited_hash_table.size) // NOLINT
1975+
/* .keys = */ calloc(graph->visited_hash_table.size, sizeof(hash_set.keys[0])) // NOLINT
19761976
};
1977-
struct ggml_tensor ** node_copies = calloc(sizeof(node_copies[0]), hash_set.size); // NOLINT
1978-
bool * node_init = calloc(sizeof(node_init[0]), hash_set.size);
1977+
struct ggml_tensor ** node_copies = calloc(hash_set.size, sizeof(node_copies[0])); // NOLINT
1978+
bool * node_init = calloc(hash_set.size, sizeof(node_init[0]));
19791979

19801980
struct ggml_init_params params = {
19811981
/* .mem_size = */ ggml_tensor_overhead()*hash_set.size + ggml_graph_overhead_custom(graph->size, false),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.