From: Johannes Gäßler Date: Sat, 31 Aug 2024 12:35:42 +0000 (+0200) Subject: ggml: fix ggml_graph_cpy undefined behavior (#943) X-Git-Tag: upstream/0.0.1642~405 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=d3a58b079f50b43e3fed852ccffa6b3fb6baac78;p=pkg%2Fggml%2Fsources%2Fggml ggml: fix ggml_graph_cpy undefined behavior (#943) --- diff --git a/include/ggml.h b/include/ggml.h index b11d047a..2d381f91 100644 --- a/include/ggml.h +++ b/include/ggml.h @@ -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 diff --git a/src/ggml.c b/src/ggml.c index 3b059ab6..1e0dde6e 100644 --- a/src/ggml.c +++ b/src/ggml.c @@ -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]); } }