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

Function ggml_backend_sched_split_graph

external/ggml/src/ggml-backend.cpp:1014–1487  ·  view source on GitHub ↗

assigns backends to ops and splits the graph into subgraphs that can be computed on the same backend

Source from the content-addressed store, hash-verified

1012
1013// assigns backends to ops and splits the graph into subgraphs that can be computed on the same backend
1014void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct ggml_cgraph * graph) {
1015 // reset splits
1016 sched->n_splits = 0;
1017 sched->n_graph_inputs = 0;
1018 sched->is_reset = false;
1019
1020 struct ggml_init_params params = {
1021 /* .mem_size = */ sched->context_buffer_size,
1022 /* .mem_buffer = */ sched->context_buffer,
1023 /* .no_alloc = */ true
1024 };
1025
1026 ggml_free(sched->ctx);
1027
1028 sched->ctx = ggml_init(params);
1029 if (sched->ctx == NULL) {
1030 GGML_ABORT("%s: failed to initialize context\n", __func__);
1031 }
1032
1033 graph->uid = ggml_graph_next_uid();
1034
1035 // pass 1: assign backends to ops with pre-allocated inputs
1036 for (int i = 0; i < graph->n_leafs; i++) {
1037 struct ggml_tensor * leaf = graph->leafs[i];
1038 int * leaf_backend_id = &tensor_backend_id(leaf);
1039 // do not overwrite user assignments
1040 if (*leaf_backend_id == -1) {
1041 *leaf_backend_id = ggml_backend_sched_backend_id_from_cur(sched, leaf);
1042 }
1043 }
1044
1045 for (int i = 0; i < graph->n_nodes; i++) {
1046 struct ggml_tensor * node = graph->nodes[i];
1047 int * node_backend_id = &tensor_backend_id(node);
1048 // do not overwrite user assignments
1049 if (*node_backend_id == -1) {
1050 *node_backend_id = ggml_backend_sched_backend_id_from_cur(sched, node);
1051
1052#if 0
1053 // src
1054 if (node->op == GGML_OP_NONE) {
1055 continue;
1056 }
1057
1058 for (int j = 0; j < GGML_MAX_SRC; j++) {
1059 struct ggml_tensor * src = node->src[j];
1060 if (src == NULL) {
1061 continue;
1062 }
1063 int * src_backend_id = &tensor_backend_id(src);
1064 if (*src_backend_id == -1) {
1065 *src_backend_id = ggml_backend_sched_backend_id_from_cur(sched, src);
1066 }
1067 }
1068#endif
1069 }
1070 }
1071

Calls 15

ggml_freeFunction · 0.85
ggml_initFunction · 0.85
ggml_graph_next_uidFunction · 0.85
ggml_backend_supports_opFunction · 0.85
ggml_dup_tensor_layoutFunction · 0.85
ggml_format_nameFunction · 0.85
ggml_backend_nameFunction · 0.85
ggml_set_inputFunction · 0.85
ggml_set_outputFunction · 0.85

Tested by

no test coverage detected