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

Function ggml_graph_compute_thread_hybrid

ggml.c:16980–17183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16978
16979
16980static thread_ret_t ggml_graph_compute_thread_hybrid(void * data) {
16981 struct ggml_compute_state * state = (struct ggml_compute_state *) data;
16982
16983 const struct ggml_cgraph * cgraph = state->shared->cgraph;
16984 const struct ggml_cplan * cplan = state->shared->cplan;
16985
16986 const int n_threads = state->shared->n_threads;
16987
16988 set_numa_thread_affinity(state->ith, n_threads);
16989
16990 // cpu_set_t mask;
16991 // CPU_ZERO(&mask);
16992 // CPU_SET(state->ith * 2, &mask);
16993 // if (sched_setaffinity(0, sizeof(mask), &mask) == -1) {
16994 // perror("sched_setaffinity");
16995 // }
16996
16997 int node_n = -1;
16998
16999 while (true) {
17000 if (cplan->abort_callback && cplan->abort_callback(cplan->abort_callback_data)) {
17001 state->shared->node_n += 1;
17002 return (thread_ret_t) GGML_EXIT_ABORTED;
17003 }
17004 if (state->ith == 0)
17005 {
17006 // atomic_fetch_sub(&state->shared->n_active, 1);
17007 node_n = -1;
17008 // return 0;
17009
17010 while (1)
17011 {
17012 state->shared->perf_node_start_cycles = ggml_perf_cycles();
17013 state->shared->perf_node_start_time_us = ggml_perf_time_us();
17014 node_n = node_n + 1;
17015 if (node_n >= cgraph->n_nodes)
17016 return 0;
17017 struct ggml_tensor *node = cgraph->nodes[node_n];
17018 if (node->backend == GGML_BACKEND_CPU)
17019 continue;
17020 // uint64_t dbug = 0;
17021 while (1)
17022 {
17023 // dbug++;
17024 int status0 = atomic_load(&node->src[0]->is_finish);
17025 int status1 = 1;
17026 int status2 = 1;
17027 if (node->src[1] != NULL)
17028 status1 = atomic_load(&node->src[1]->is_finish);
17029 if (node->src[2] != NULL)
17030 status2 = atomic_load(&node->src[2]->is_finish);
17031 // if (dbug > 10000000) {
17032 // printf("stuck %s thread %d\n", ggml_get_name(node), n_threads);
17033 // int k;
17034 // scanf("%d", &k);
17035 // }
17036 if (status0 == 1 && status1 == 1 && status2 == 1)
17037 {

Callers 1

ggml_graph_computeFunction · 0.85

Calls 8

atomic_loadFunction · 0.85
atomic_storeFunction · 0.85
set_numa_thread_affinityFunction · 0.70
ggml_compute_forwardFunction · 0.70
ggml_get_n_tasksFunction · 0.70
sched_yieldFunction · 0.70

Tested by

no test coverage detected