MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / build_graph

Function build_graph

external/ggml/examples/simple/simple-backend.cpp:68–96  ·  view source on GitHub ↗

build the compute graph to perform a matrix multiplication

Source from the content-addressed store, hash-verified

66
67// build the compute graph to perform a matrix multiplication
68struct ggml_cgraph * build_graph(simple_model& model) {
69 size_t buf_size = ggml_tensor_overhead()*GGML_DEFAULT_GRAPH_SIZE + ggml_graph_overhead();
70 model.buf.resize(buf_size);
71
72 struct ggml_init_params params0 = {
73 /*.mem_size =*/ buf_size,
74 /*.mem_buffer =*/ model.buf.data(),
75 /*.no_alloc =*/ true, // the tensors will be allocated later
76 };
77
78 // create a context to build the graph
79 struct ggml_context * ctx = ggml_init(params0);
80
81 struct ggml_cgraph * gf = ggml_new_graph(ctx);
82
83 // create tensors
84 model.a = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, cols_A, rows_A);
85 model.b = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, cols_B, rows_B);
86
87 // result = a*b^T
88 struct ggml_tensor * result = ggml_mul_mat(ctx, model.a, model.b);
89
90 // build operations nodes
91 ggml_build_forward_expand(gf, result);
92
93 ggml_free(ctx);
94
95 return gf;
96}
97
98// compute with backend
99struct ggml_tensor * compute(simple_model & model, struct ggml_cgraph * gf) {

Callers 1

mainFunction · 0.70

Calls 10

ggml_tensor_overheadFunction · 0.85
ggml_graph_overheadFunction · 0.85
ggml_initFunction · 0.85
ggml_new_graphFunction · 0.85
ggml_new_tensor_2dFunction · 0.85
ggml_mul_matFunction · 0.85
ggml_freeFunction · 0.85
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected