ggml : minor style changes
This commit is contained in:
parent
90a0e65c67
commit
d0e3596350
1 changed files with 16 additions and 10 deletions
24
ggml.c
24
ggml.c
|
@ -16342,6 +16342,7 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
|
||||||
/*.wsize =*/ cgraph->work ? ggml_nbytes(cgraph->work) : 0,
|
/*.wsize =*/ cgraph->work ? ggml_nbytes(cgraph->work) : 0,
|
||||||
/*.wdata =*/ cgraph->work ? cgraph->work->data : NULL,
|
/*.wdata =*/ cgraph->work ? cgraph->work->data : NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (node_n != -1) {
|
if (node_n != -1) {
|
||||||
/* FINALIZE */
|
/* FINALIZE */
|
||||||
struct ggml_tensor * node = state->shared->cgraph->nodes[node_n];
|
struct ggml_tensor * node = state->shared->cgraph->nodes[node_n];
|
||||||
|
@ -16349,18 +16350,19 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
|
||||||
ggml_compute_forward(¶ms, node);
|
ggml_compute_forward(¶ms, node);
|
||||||
ggml_graph_compute_perf_stats_node(node, state->shared);
|
ggml_graph_compute_perf_stats_node(node, state->shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
// distribute new work or execute it direct if 1T
|
// distribute new work or execute it direct if 1T
|
||||||
while (++node_n < cgraph->n_nodes) {
|
while (++node_n < cgraph->n_nodes) {
|
||||||
GGML_PRINT_DEBUG_5("%s: %d/%d\n", __func__, node_n, cgraph->n_nodes);
|
GGML_PRINT_DEBUG_5("%s: %d/%d\n", __func__, node_n, cgraph->n_nodes);
|
||||||
|
|
||||||
struct ggml_tensor * node = cgraph->nodes[node_n];
|
struct ggml_tensor * node = cgraph->nodes[node_n];
|
||||||
|
|
||||||
state->shared->perf_node_start_cycles = ggml_perf_cycles();
|
state->shared->perf_node_start_cycles = ggml_perf_cycles();
|
||||||
state->shared->perf_node_start_time_us = ggml_perf_time_us();
|
state->shared->perf_node_start_time_us = ggml_perf_time_us();
|
||||||
|
|
||||||
/* INIT */
|
/* INIT */
|
||||||
params.type = GGML_TASK_INIT;
|
params.type = GGML_TASK_INIT;
|
||||||
params.nth = node->n_tasks;
|
params.nth = node->n_tasks;
|
||||||
ggml_compute_forward(¶ms, node);
|
ggml_compute_forward(¶ms, node);
|
||||||
|
|
||||||
if (node->n_tasks == 1) {
|
if (node->n_tasks == 1) {
|
||||||
|
@ -16368,6 +16370,7 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
|
||||||
// they do something more efficient than spinning (?)
|
// they do something more efficient than spinning (?)
|
||||||
params.type = GGML_TASK_COMPUTE;
|
params.type = GGML_TASK_COMPUTE;
|
||||||
ggml_compute_forward(¶ms, node);
|
ggml_compute_forward(¶ms, node);
|
||||||
|
|
||||||
params.type = GGML_TASK_FINALIZE;
|
params.type = GGML_TASK_FINALIZE;
|
||||||
ggml_compute_forward(¶ms, node);
|
ggml_compute_forward(¶ms, node);
|
||||||
ggml_graph_compute_perf_stats_node(node, state->shared);
|
ggml_graph_compute_perf_stats_node(node, state->shared);
|
||||||
|
@ -16375,6 +16378,7 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_store(&state->shared->n_active, n_threads);
|
atomic_store(&state->shared->n_active, n_threads);
|
||||||
atomic_store(&state->shared->node_n, node_n);
|
atomic_store(&state->shared->node_n, node_n);
|
||||||
} else {
|
} else {
|
||||||
|
@ -16387,8 +16391,9 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
|
||||||
}
|
}
|
||||||
// check if we should stop
|
// check if we should stop
|
||||||
if (node_n >= cgraph->n_nodes) break;
|
if (node_n >= cgraph->n_nodes) break;
|
||||||
struct ggml_tensor * node = cgraph->nodes[node_n];
|
|
||||||
/* COMPUTE */
|
/* COMPUTE */
|
||||||
|
struct ggml_tensor * node = cgraph->nodes[node_n];
|
||||||
struct ggml_compute_params params = {
|
struct ggml_compute_params params = {
|
||||||
/*.type =*/ GGML_TASK_COMPUTE,
|
/*.type =*/ GGML_TASK_COMPUTE,
|
||||||
/*.ith =*/ state->ith,
|
/*.ith =*/ state->ith,
|
||||||
|
@ -16396,12 +16401,14 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
|
||||||
/*.wsize =*/ cgraph->work ? ggml_nbytes(cgraph->work) : 0,
|
/*.wsize =*/ cgraph->work ? ggml_nbytes(cgraph->work) : 0,
|
||||||
/*.wdata =*/ cgraph->work ? cgraph->work->data : NULL,
|
/*.wdata =*/ cgraph->work ? cgraph->work->data : NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
if(state->ith < node->n_tasks) {
|
if(state->ith < node->n_tasks) {
|
||||||
ggml_compute_forward(¶ms, node);
|
ggml_compute_forward(¶ms, node);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16409,12 +16416,12 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
|
||||||
const int n_threads = cgraph->n_threads;
|
const int n_threads = cgraph->n_threads;
|
||||||
|
|
||||||
struct ggml_compute_state_shared state_shared = {
|
struct ggml_compute_state_shared state_shared = {
|
||||||
/*.cgraph =*/ cgraph,
|
/*.cgraph =*/ cgraph,
|
||||||
/*.perf_node_start_cycles =*/ 0,
|
/*.perf_node_start_cycles =*/ 0,
|
||||||
/*.perf_node_start_time_us =*/ 0,
|
/*.perf_node_start_time_us =*/ 0,
|
||||||
/*.n_threads =*/ n_threads,
|
/*.n_threads =*/ n_threads,
|
||||||
/*.n_active =*/ n_threads,
|
/*.n_active =*/ n_threads,
|
||||||
/*.node_n =*/ -1,
|
/*.node_n =*/ -1,
|
||||||
};
|
};
|
||||||
struct ggml_compute_state * workers = alloca(sizeof(struct ggml_compute_state)*n_threads);
|
struct ggml_compute_state * workers = alloca(sizeof(struct ggml_compute_state)*n_threads);
|
||||||
|
|
||||||
|
@ -16778,7 +16785,6 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
|
||||||
workers[0].ith = 0;
|
workers[0].ith = 0;
|
||||||
workers[0].shared = &state_shared;
|
workers[0].shared = &state_shared;
|
||||||
|
|
||||||
|
|
||||||
const int64_t perf_start_cycles = ggml_perf_cycles();
|
const int64_t perf_start_cycles = ggml_perf_cycles();
|
||||||
const int64_t perf_start_time_us = ggml_perf_time_us();
|
const int64_t perf_start_time_us = ggml_perf_time_us();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue