Spaces:
Sleeping
Sleeping
Commit
·
9202e70
1
Parent(s):
406ac07
ggml: fix ggml_graph_cpy undefined behavior (ggml/943)
Browse files- ggml/include/ggml.h +2 -2
- ggml/src/ggml.c +2 -1
ggml/include/ggml.h
CHANGED
|
@@ -651,8 +651,8 @@ extern "C" {
|
|
| 651 |
|
| 652 |
struct ggml_hash_set {
|
| 653 |
size_t size;
|
| 654 |
-
ggml_bitset_t * used;
|
| 655 |
-
struct ggml_tensor ** keys;
|
| 656 |
};
|
| 657 |
|
| 658 |
// computation graph
|
|
|
|
| 651 |
|
| 652 |
struct ggml_hash_set {
|
| 653 |
size_t size;
|
| 654 |
+
ggml_bitset_t * used; // whether or not the keys are in use i.e. set
|
| 655 |
+
struct ggml_tensor ** keys; // actual tensors in the set, keys[i] is only defined if ggml_bitset_get(used, i)
|
| 656 |
};
|
| 657 |
|
| 658 |
// computation graph
|
ggml/src/ggml.c
CHANGED
|
@@ -18764,7 +18764,8 @@ void ggml_graph_cpy(struct ggml_cgraph * src, struct ggml_cgraph * dst) {
|
|
| 18764 |
}
|
| 18765 |
|
| 18766 |
for (size_t i = 0; i < src->visited_hash_set.size; ++i) {
|
| 18767 |
-
|
|
|
|
| 18768 |
ggml_hash_insert(&dst->visited_hash_set, src->visited_hash_set.keys[i]);
|
| 18769 |
}
|
| 18770 |
}
|
|
|
|
| 18764 |
}
|
| 18765 |
|
| 18766 |
for (size_t i = 0; i < src->visited_hash_set.size; ++i) {
|
| 18767 |
+
// copy all hashset keys (tensors) that are in use
|
| 18768 |
+
if (ggml_bitset_get(src->visited_hash_set.used, i)) {
|
| 18769 |
ggml_hash_insert(&dst->visited_hash_set, src->visited_hash_set.keys[i]);
|
| 18770 |
}
|
| 18771 |
}
|