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

Function ggml_graph_export

ggml.c:17542–17727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17540}
17541
17542void ggml_graph_export(const struct ggml_cgraph * cgraph, const char * fname) {
17543 uint64_t size_eval = 0;
17544
17545 // compute size of intermediate results
17546 // TODO: does not take into account scratch buffers !!!!
17547 for (int i = 0; i < cgraph->n_nodes; ++i) {
17548 size_eval += ggml_nbytes_pad(cgraph->nodes[i]);
17549 }
17550
17551 // print
17552 {
17553 FILE * fout = stdout;
17554
17555 fprintf(fout, "\n");
17556 fprintf(fout, "%-16s %8x\n", "magic", GGML_FILE_MAGIC);
17557 fprintf(fout, "%-16s %8d\n", "version", GGML_FILE_VERSION);
17558 fprintf(fout, "%-16s %8d\n", "leafs", cgraph->n_leafs);
17559 fprintf(fout, "%-16s %8d\n", "nodes", cgraph->n_nodes);
17560 fprintf(fout, "%-16s %" PRIu64 "\n", "eval", size_eval);
17561
17562 // header
17563 fprintf(fout, "\n");
17564 fprintf(fout, "%-6s %-12s %8s %8s %8s %8s %8s %16s %16s %16s %16s %16s %16s\n",
17565 "TYPE", "OP", "NDIMS", "NE0", "NE1", "NE2", "NE3", "NB0", "NB1", "NB2", "NB3", "DATA", "NAME");
17566
17567 for (int i = 0; i < cgraph->n_leafs; ++i) {
17568 ggml_graph_export_leaf(cgraph->leafs[i], fout);
17569
17570 GGML_ASSERT(cgraph->leafs[i]->op == GGML_OP_NONE);
17571 GGML_ASSERT(cgraph->leafs[i]->src[0] == NULL);
17572 GGML_ASSERT(cgraph->leafs[i]->src[1] == NULL);
17573 }
17574
17575 // header
17576 fprintf(fout, "\n");
17577 fprintf(fout, "%-6s %-6s %-12s %8s %8s %8s %8s %8s %16s %16s %16s %16s %8s %16s %16s\n",
17578 "ARG", "TYPE", "OP", "NDIMS", "NE0", "NE1", "NE2", "NE3", "NB0", "NB1", "NB2", "NB3", "NTASKS", "DATA", "NAME");
17579
17580 for (int i = 0; i < cgraph->n_nodes; ++i) {
17581 ggml_graph_export_node(cgraph->nodes[i], "DST", fout);
17582
17583 for (int j = 0; j < GGML_MAX_SRC; ++j) {
17584 if (cgraph->nodes[i]->src[j]) {
17585 ggml_graph_export_node(cgraph->nodes[i]->src[j], "SRC", fout);
17586 }
17587 }
17588
17589 fprintf(fout, "\n");
17590 }
17591
17592 fprintf(fout, "\n");
17593 }
17594
17595 // write binary data
17596 {
17597 FILE * fout = fopen(fname, "wb");
17598
17599 if (!fout) {

Callers

nothing calls this directly

Calls 5

fprintfFunction · 0.85
ggml_graph_export_leafFunction · 0.85
ggml_graph_export_nodeFunction · 0.85
ggml_nbytes_padFunction · 0.70
ggml_nbytesFunction · 0.70

Tested by

no test coverage detected