Skip to content

Commit

Permalink
ggml: fix ggml_graph_cpy undefined behavior (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesGaessler authored Aug 31, 2024
1 parent 21d3a30 commit d3a58b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ extern "C" {

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

// computation graph
Expand Down
3 changes: 2 additions & 1 deletion src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -18764,7 +18764,8 @@ void ggml_graph_cpy(struct ggml_cgraph * src, struct ggml_cgraph * dst) {
}

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

0 comments on commit d3a58b0

Please sign in to comment.