MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / can_reuse_memory

Function can_reuse_memory

subprojects/llama.cpp/tests/test-alloc.cpp:205–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205static 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
227static bool memory_overlap(ggml_tensor * a, ggml_tensor * b) {
228 if (a->buffer != b->buffer) {

Callers 1

check_no_overlapFunction · 0.85

Calls 3

ggml_graph_n_nodesFunction · 0.85
ggml_graph_nodeFunction · 0.85
ggml_op_can_inplaceFunction · 0.85

Tested by

no test coverage detected