| 203 | } |
| 204 | |
| 205 | static bool can_reuse_memory(ggml_cgraph * graph, int current_i, ggml_tensor * current, ggml_tensor * other) { |
| 206 | if (other->flags & GGML_TENSOR_FLAG_OUTPUT) { |
| 207 | return false; |
| 208 | } |
| 209 | // Check if `other` is still "alive", ie. an input to any node after the `current` op |
| 210 | for (int i = current_i; i < ggml_graph_n_nodes(graph); ++i) { |
| 211 | ggml_tensor * t = ggml_graph_node(graph, i); |
| 212 | for (int s = 0; s < GGML_MAX_SRC; s++) { |
| 213 | if (t == current && ggml_op_can_inplace(t->op)) { |
| 214 | continue; |
| 215 | } |
| 216 | if (t->src[s] == other) { |
| 217 | return false; |
| 218 | } |
| 219 | if (t->src[s] && t->src[s]->view_src == other) { |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | return true; |
| 225 | } |
| 226 | |
| 227 | static bool memory_overlap(ggml_tensor * a, ggml_tensor * b) { |
| 228 | if (a->buffer != b->buffer) { |
no test coverage detected