MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_tallocr_alloc_graph_impl

Function ggml_tallocr_alloc_graph_impl

ggml-alloc.c:528–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526}
527
528static void ggml_tallocr_alloc_graph_impl(ggml_gallocr_t galloc, struct ggml_cgraph * gf) {
529 const int * parse_seq = galloc->parse_seq;
530 int parse_seq_len = galloc->parse_seq_len;
531
532 // count number of children and views
533 for (int i = 0; i < gf->n_nodes; i++) {
534 struct ggml_tensor * node = gf->nodes[i];
535
536 if (ggml_is_view(node)) {
537 struct ggml_tensor * view_src = node->view_src;
538 hash_get(galloc, view_src)->n_views += 1;
539 if (node->buffer == NULL && node->data != NULL) {
540 // view of a pre-allocated tensor, didn't call init_view() yet
541 init_view(galloc, node, true);
542 }
543 }
544
545 for (int j = 0; j < GGML_MAX_SRC; j++) {
546 struct ggml_tensor * parent = node->src[j];
547 if (parent == NULL) {
548 break;
549 }
550 hash_get(galloc, parent)->n_children += 1;
551 if (ggml_is_view(parent) && parent->buffer == NULL && parent->data != NULL) {
552 init_view(galloc, parent, true);
553 }
554 }
555 }
556
557 // allocate tensors
558 // if we have parse_seq then we allocate nodes following the list, and we only free nodes at barriers
559 int last_barrier_pos = 0;
560 int n_nodes = parse_seq_len ? parse_seq_len : gf->n_nodes;
561
562 for (int ind = 0; ind < n_nodes; ind++) {
563 // allocate a node if there is no parse_seq or this is not a barrier
564 if (parse_seq_len == 0 || parse_seq[ind] != -1) {
565 int i = parse_seq_len ? parse_seq[ind] : ind;
566 struct ggml_tensor * node = gf->nodes[i];
567
568 // allocate parents (leafs)
569 for (int j = 0; j < GGML_MAX_SRC; j++) {
570 struct ggml_tensor * parent = node->src[j];
571 if (parent == NULL) {
572 break;
573 }
574 allocate_node(galloc, parent);
575 }
576
577 // allocate node
578 allocate_node(galloc, node);
579
580 AT_PRINTF("exec: %s (%s) <= ", ggml_op_name(node->op), node->name);
581 for (int j = 0; j < GGML_MAX_SRC; j++) {
582 struct ggml_tensor * parent = node->src[j];
583 if (parent == NULL) {
584 break;
585 }

Callers 2

ggml_gallocr_alloc_graphFunction · 0.85

Calls 6

hash_getFunction · 0.85
init_viewFunction · 0.85
allocate_nodeFunction · 0.85
free_nodeFunction · 0.85
ggml_is_viewFunction · 0.70
ggml_op_nameFunction · 0.70

Tested by

no test coverage detected