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

Function map_tensor

subprojects/llama.cpp/ggml/src/ggml-opt.cpp:262–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262static ggml_tensor * map_tensor(std::map<ggml_tensor *, ggml_tensor *> & tensor_map, ggml_context * ctx, ggml_tensor * tensor) {
263 if (!tensor) {
264 return nullptr;
265 }
266
267 if (tensor_map.find(tensor) != tensor_map.end()) {
268 return tensor_map[tensor];
269 }
270
271 ggml_tensor * new_tensor = ggml_dup_tensor(ctx, tensor);
272 tensor_map[tensor] = new_tensor;
273
274 new_tensor->op = tensor->op;
275 for (int i = 0; i < GGML_MAX_DIMS; i++) {
276 new_tensor->nb[i] = tensor->nb[i];
277 }
278 new_tensor->flags = tensor->flags;
279 memcpy(new_tensor->op_params, tensor->op_params, sizeof(tensor->op_params));
280 strcpy(new_tensor->name, tensor->name);
281 new_tensor->data = tensor->data;
282 new_tensor->buffer = tensor->buffer;
283 new_tensor->extra = tensor->extra;
284 new_tensor->view_offs = tensor->view_offs;
285 new_tensor->view_src = map_tensor(tensor_map, ctx, tensor->view_src);
286 for (int i = 0; i < GGML_MAX_SRC; i++) {
287 new_tensor->src[i] = map_tensor(tensor_map, ctx, tensor->src[i]);
288 }
289
290 return new_tensor;
291}
292
293static ggml_cgraph * dup_graph(ggml_context * ctx, ggml_cgraph * src) {
294 std::map<ggml_tensor *, ggml_tensor *> tensor_map;

Callers 1

dup_graphFunction · 0.85

Calls 3

ggml_dup_tensorFunction · 0.85
findMethod · 0.65
endMethod · 0.45

Tested by

no test coverage detected