Skip to content

Commit dbbebca

Browse files
JohannesGaesslerggerganov
authored andcommitted
ggml: fix ggml_graph_cpy undefined behavior (ggml/943)
1 parent ba1cf84 commit dbbebca

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

ggml/include/ggml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ extern "C" {
681681

682682
struct ggml_hash_set {
683683
size_t size;
684-
ggml_bitset_t * used;
685-
struct ggml_tensor ** keys;
684+
ggml_bitset_t * used; // whether or not the keys are in use i.e. set
685+
struct ggml_tensor ** keys; // actual tensors in the set, keys[i] is only defined if ggml_bitset_get(used, i)
686686
};
687687

688688
// computation graph

ggml/src/ggml.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19130,7 +19130,8 @@ void ggml_graph_cpy(struct ggml_cgraph * src, struct ggml_cgraph * dst) {
1913019130
}
1913119131

1913219132
for (size_t i = 0; i < src->visited_hash_set.size; ++i) {
19133-
if (src->visited_hash_set.keys[i]) {
19133+
// copy all hashset keys (tensors) that are in use
19134+
if (ggml_bitset_get(src->visited_hash_set.used, i)) {
1913419135
ggml_hash_insert(&dst->visited_hash_set, src->visited_hash_set.keys[i]);
1913519136
}
1913619137
}

0 commit comments

Comments
 (0)