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

Function ggml_graph_plan

ggml.c:17185–17378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17183}
17184
17185struct ggml_cplan ggml_graph_plan(struct ggml_cgraph * cgraph, int n_threads) {
17186 if (n_threads <= 0) {
17187 n_threads = GGML_DEFAULT_N_THREADS;
17188 }
17189
17190 size_t work_size = 0;
17191
17192 struct ggml_cplan cplan;
17193 memset(&cplan, 0, sizeof(struct ggml_cplan));
17194
17195 // thread scheduling for the different operations + work buffer size estimation
17196 for (int i = 0; i < cgraph->n_nodes; i++) {
17197 int n_tasks = 1;
17198
17199 struct ggml_tensor * node = cgraph->nodes[i];
17200
17201 size_t cur = 0;
17202
17203 switch (node->op) {
17204 case GGML_OP_CPY:
17205 case GGML_OP_DUP:
17206 {
17207 n_tasks = n_threads;
17208
17209 if (ggml_is_quantized(node->type)) {
17210 cur = ggml_type_size(GGML_TYPE_F32) * node->ne[0] * n_tasks;
17211 }
17212 } break;
17213 case GGML_OP_ADD:
17214 case GGML_OP_ADD1:
17215 {
17216 n_tasks = n_threads;
17217
17218 if (ggml_is_quantized(node->src[0]->type)) {
17219 cur = ggml_type_size(GGML_TYPE_F32) * node->src[0]->ne[0] * n_tasks;
17220 }
17221 } break;
17222 case GGML_OP_ACC:
17223 {
17224 n_tasks = n_threads;
17225
17226 if (ggml_is_quantized(node->src[0]->type)) {
17227 cur = ggml_type_size(GGML_TYPE_F32) * node->src[1]->ne[0] * n_tasks;
17228 }
17229 } break;
17230 case GGML_OP_MUL_MAT:
17231 case GGML_OP_MUL_MAT_SPARSE:
17232 {
17233 const enum ggml_type vec_dot_type = type_traits[node->src[0]->type].vec_dot_type;
17234
17235#if defined(GGML_USE_CLBLAST)
17236 if (ggml_cl_can_mul_mat(node->src[0], node->src[1], node)) {
17237 cur = ggml_cl_mul_mat_get_wsize(node->src[0], node->src[1], node);
17238 } else
17239#endif
17240#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS)
17241 if (ggml_compute_forward_mul_mat_use_blas(node->src[0], node->src[1], node)) {
17242 if (node->src[0]->type != GGML_TYPE_F32) {

Callers 13

ggml_opt_adamFunction · 0.70
ggml_opt_lbfgsFunction · 0.70
apply_loraFunction · 0.50
clip_image_batch_encodeFunction · 0.50
mainFunction · 0.50

Calls 8

ggml_is_quantizedFunction · 0.70
ggml_type_sizeFunction · 0.70
ggml_cl_can_mul_matFunction · 0.70
ggml_nelementsFunction · 0.70
ggml_blck_sizeFunction · 0.70
ggml_upFunction · 0.70

Tested by 1