Skip to content

Commit 3f8325a

Browse files
threadpool: better naming for thread/cpumask releated functions
1 parent c083ca3 commit 3f8325a

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

ggml/src/ggml.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,15 +3053,15 @@ static_assert(sizeof(struct ggml_tensor)%GGML_MEM_ALIGN == 0, "ggml_tensor size
30533053

30543054
// Helpers for polling loops
30553055
#if defined(__aarch64__) && ( defined(__clang__) || defined(__GNUC__) )
3056-
static inline void __cpu_relax(void) {
3056+
static inline void ggml_thread_cpu_relax(void) {
30573057
__asm__ volatile("yield" ::: "memory");
30583058
}
30593059
#elif defined(__x86_64__)
3060-
static inline void __cpu_relax(void) {
3060+
static inline void ggml_thread_cpu_relax(void) {
30613061
_mm_pause();
30623062
}
30633063
#else
3064-
static inline void __cpu_relax(void) {;}
3064+
static inline void ggml_thread_cpu_relax(void) {;}
30653065
#endif
30663066

30673067
//
@@ -3140,7 +3140,7 @@ static void ggml_barrier(struct ggml_compute_threadpool * threadpool) {
31403140
if (atomic_load_explicit(n_barrier_passed, memory_order_relaxed) != passed_old) {
31413141
return;
31423142
}
3143-
__cpu_relax();
3143+
ggml_thread_cpu_relax();
31443144
}
31453145
}
31463146
}
@@ -18654,7 +18654,7 @@ enum {
1865418654
#include "windows.h"
1865518655

1865618656
// TODO: support > 64 CPUs
18657-
static bool __thread_affinity(bool * mask) {
18657+
static bool ggml_thread_apply_affinity(bool * mask) {
1865818658
HANDLE h = GetCurrentThread();
1865918659
uint64_t bitmask = 0ULL;
1866018660

@@ -18688,7 +18688,7 @@ static bool __thread_affinity(bool * mask) {
1868818688
return m != 0;
1868918689
}
1869018690

18691-
static bool __process_priority(int32_t prio) {
18691+
static bool ggml_thread_apply_process_priority(int32_t prio) {
1869218692
DWORD p = NORMAL_PRIORITY_CLASS;
1869318693

1869418694
switch (prio) {
@@ -18701,7 +18701,7 @@ static bool __process_priority(int32_t prio) {
1870118701
return SetPriorityClass(GetCurrentProcess(), p);
1870218702
}
1870318703

18704-
static bool __thread_priority(int32_t prio) {
18704+
static bool ggml_thread_apply_thread_priority(int32_t prio) {
1870518705
DWORD p = NORMAL_PRIORITY_CLASS;
1870618706

1870718707
switch (prio) {
@@ -18719,12 +18719,12 @@ static bool __thread_priority(int32_t prio) {
1871918719
#include <sys/types.h>
1872018720
#include <sys/resource.h>
1872118721

18722-
static bool __thread_affinity(const bool * mask) {
18722+
static bool ggml_thread_apply_affinity(const bool * mask) {
1872318723
UNUSED(mask);
1872418724
return true;
1872518725
}
1872618726

18727-
static bool __process_priority(int32_t prio) {
18727+
static bool ggml_thread_apply_process_prio(int32_t prio) {
1872818728
int32_t p = 0;
1872918729

1873018730
switch (prio) {
@@ -18738,14 +18738,14 @@ static bool __process_priority(int32_t prio) {
1873818738
return r != -1;
1873918739
}
1874018740

18741-
static bool __thread_priority(int32_t prio) {
18741+
static bool ggml_thread_apply_thread_priority(int32_t prio) {
1874218742
UNUSED(prio);
1874318743
return true;
1874418744
}
1874518745

1874618746
#else // posix?
1874718747

18748-
static bool __thread_affinity(const bool * mask) {
18748+
static bool ggml_thread_apply_affinity(const bool * mask) {
1874918749
cpu_set_t cpuset;
1875018750
int32_t err;
1875118751

@@ -18774,7 +18774,7 @@ static bool __thread_affinity(const bool * mask) {
1877418774
return true;
1877518775
}
1877618776

18777-
static bool __process_priority(int32_t prio) {
18777+
static bool ggml_thread_apply_process_prio(int32_t prio) {
1877818778
struct sched_param p;
1877918779
int32_t policy = SCHED_OTHER;
1878018780

@@ -18794,7 +18794,7 @@ static bool __process_priority(int32_t prio) {
1879418794
return true;
1879518795
}
1879618796

18797-
static bool __thread_priority(int32_t prio) {
18797+
static bool ggml_thread_apply_thread_priority(int32_t prio) {
1879818798
struct sched_param p;
1879918799
int32_t policy = SCHED_OTHER;
1880018800
switch (prio) {
@@ -18815,7 +18815,7 @@ static bool __thread_priority(int32_t prio) {
1881518815

1881618816
#endif
1881718817

18818-
static void __cpumask_next(const bool * global_mask, bool * local_mask, bool strict, int32_t* iter) {
18818+
static void ggml_thread_cpumask_next(const bool * global_mask, bool * local_mask, bool strict, int32_t* iter) {
1881918819
if (!global_mask) {
1882018820
memset(local_mask, 1, GGML_MAX_N_THREADS);
1882118821
return;
@@ -19147,7 +19147,7 @@ static inline bool ggml_graph_compute_poll_for_work(struct ggml_compute_state *
1914719147

1914819148
for (uint64_t i=0; !ggml_graph_compute_ready(state) && i<n_rounds; i++) {
1914919149
// No new work. Keep polling.
19150-
__cpu_relax();
19150+
ggml_thread_cpu_relax();
1915119151
}
1915219152

1915319153
return state->pending;
@@ -19175,9 +19175,9 @@ static thread_ret_t ggml_graph_compute_secondary_thread(void* data) {
1917519175
struct ggml_compute_state * state = (struct ggml_compute_state *) data;
1917619176
struct ggml_compute_threadpool * threadpool = state->threadpool;
1917719177

19178-
__thread_priority(threadpool->prio);
19178+
ggml_thread_apply_thread_priority(threadpool->prio);
1917919179
if (state->mask_specified)
19180-
__thread_affinity(state->cpumask);
19180+
ggml_thread_apply_affinity(state->cpumask);
1918119181

1918219182
while (true) {
1918319183
// Check if we need to sleep
@@ -19293,8 +19293,8 @@ static struct ggml_compute_threadpool * ggml_create_threadpool_impl(
1929319293
#else // Not using OPENMP
1929419294
int32_t cpumask_iter = 0;
1929519295

19296-
__process_priority(tpp->prio);
19297-
__thread_priority(tpp->prio);
19296+
ggml_thread_apply_process_prio(tpp->prio);
19297+
ggml_thread_apply_thread_priority(tpp->prio);
1929819298

1929919299
for (int j = 0; j < tpp->n_threads; j++) {
1930019300
workers[j] = (struct ggml_compute_state) {
@@ -19307,7 +19307,7 @@ static struct ggml_compute_threadpool * ggml_create_threadpool_impl(
1930719307
};
1930819308

1930919309
if (tpp->mask_specified) {
19310-
__cpumask_next(tpp->cpumask, workers[j].cpumask, tpp->strict_cpu, &cpumask_iter);
19310+
ggml_thread_cpumask_next(tpp->cpumask, workers[j].cpumask, tpp->strict_cpu, &cpumask_iter);
1931119311
}
1931219312

1931319313
// Spin threads for all secondary workers
@@ -19395,7 +19395,7 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
1939519395
#else
1939619396
// Update main thread affinity to match the current threadpool
1939719397
if (threadpool->workers[0].mask_specified) {
19398-
__thread_affinity(threadpool->workers[0].cpumask);
19398+
ggml_thread_apply_affinity(threadpool->workers[0].cpumask);
1939919399
}
1940019400

1940119401
// Kick all threads to start the new graph

0 commit comments

Comments
 (0)