Skip to content

Commit 4a555b4

Browse files
committed
ggml : style / formatting
1 parent 875a1e1 commit 4a555b4

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

ggml.c

+21-7
Original file line numberDiff line numberDiff line change
@@ -16626,39 +16626,50 @@ typedef pthread_t ggml_thread_t;
1662616626
#endif
1662716627

1662816628
#ifdef __linux__
16629-
void set_numa_thread_affinity(int thread_n, int n_threads)
16630-
{
16631-
if (!ggml_is_numa()) { return; }
16629+
void set_numa_thread_affinity(int thread_n, int n_threads) {
16630+
if (!ggml_is_numa()) {
16631+
return;
16632+
}
16633+
1663216634
// run thread on node_num thread_n / (threads per node)
16633-
int node_num = thread_n / ((n_threads + g_state.numa.n_nodes - 1) / g_state.numa.n_nodes);
16635+
const int node_num = thread_n / ((n_threads + g_state.numa.n_nodes - 1) / g_state.numa.n_nodes);
1663416636
struct ggml_numa_node * node = &g_state.numa.nodes[node_num];
1663516637
size_t setsize = CPU_ALLOC_SIZE(g_state.numa.total_cpus);
16638+
1663616639
cpu_set_t * cpus = CPU_ALLOC(g_state.numa.total_cpus);
1663716640
CPU_ZERO_S(setsize, cpus);
1663816641
for (size_t i = 0; i < node->n_cpus; ++i) {
1663916642
CPU_SET_S(node->cpus[i], setsize, cpus);
1664016643
}
16644+
1664116645
int rv = pthread_setaffinity_np(pthread_self(), setsize, cpus);
1664216646
if (rv) {
1664316647
fprintf(stderr, "warning: pthread_setaffinity_np() failed: %s\n",
1664416648
strerror(rv));
1664516649
}
16650+
1664616651
CPU_FREE(cpus);
1664716652
}
16648-
void clear_numa_thread_affinity(void)
16649-
{
16650-
if (!ggml_is_numa()) { return; }
16653+
16654+
void clear_numa_thread_affinity(void) {
16655+
if (!ggml_is_numa()) {
16656+
return;
16657+
}
16658+
1665116659
size_t setsize = CPU_ALLOC_SIZE(g_state.numa.total_cpus);
16660+
1665216661
cpu_set_t * cpus = CPU_ALLOC(g_state.numa.total_cpus);
1665316662
CPU_ZERO_S(setsize, cpus);
1665416663
for (unsigned i = 0; i < g_state.numa.total_cpus; ++i) {
1665516664
CPU_SET_S(i, setsize, cpus);
1665616665
}
16666+
1665716667
int rv = pthread_setaffinity_np(pthread_self(), setsize, cpus);
1665816668
if (rv) {
1665916669
fprintf(stderr, "warning: pthread_setaffinity_np() failed: %s\n",
1666016670
strerror(rv));
1666116671
}
16672+
1666216673
CPU_FREE(cpus);
1666316674
}
1666416675
#else
@@ -16699,10 +16710,12 @@ static void ggml_graph_compute_perf_stats_node(struct ggml_tensor * node, const
1669916710
static thread_ret_t ggml_graph_compute_thread(void * data) {
1670016711
struct ggml_compute_state * state = (struct ggml_compute_state *) data;
1670116712
struct ggml_cgraph * cgraph = state->shared->cgraph;
16713+
1670216714
const int n_threads = state->shared->n_threads;
1670316715
set_numa_thread_affinity(state->ith, n_threads);
1670416716

1670516717
int node_n = -1;
16718+
1670616719
while (true) {
1670716720
if (atomic_fetch_sub(&state->shared->n_active, 1) == 1) {
1670816721
// all other threads are finished and spinning
@@ -17165,6 +17178,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
1716517178

1716617179
// this is a work thread too
1716717180
ggml_graph_compute_thread(&workers[0]);
17181+
1716817182
// don't leave affinity set on the main thread
1716917183
clear_numa_thread_affinity();
1717017184

0 commit comments

Comments
 (0)