Skip to content

Commit d485c34

Browse files
committed
revert spin hint + sched_yield
1 parent a890922 commit d485c34

File tree

1 file changed

+2
-51
lines changed

1 file changed

+2
-51
lines changed

ggml.c

+2-51
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <stdlib.h>
1717
#include <string.h>
1818
#include <stdint.h>
19-
#include <sched.h>
2019
#include <inttypes.h>
2120
#include <stdio.h>
2221
#include <float.h>
@@ -9243,21 +9242,6 @@ typedef pthread_t ggml_thread_t;
92439242
// To rollback quickly, set `-DDISABLE_GGML_COMPUTE_SPIN_V2` to `CFLAGS` in Makefile.
92449243
// TODO(mqy): cleanup feature flag DISABLE_GGML_COMPUTE_SPIN_V2.
92459244

9246-
// Spin loop hint for some architectures.
9247-
#ifndef DISABLE_GGML_COMPUTE_SPIN_V2
9248-
9249-
#ifndef DISABLE_SPIN_HINT
9250-
static inline void spin_hint(void) {
9251-
#if defined(__x86_64__)
9252-
__asm__ __volatile__ ("pause");
9253-
#elif defined(__aarch64__)
9254-
__asm__ __volatile__ ("wfe");
9255-
#endif
9256-
}
9257-
#define NUM_SPIN_BEFOR_SCHED_YIELD 100
9258-
#endif
9259-
#endif
9260-
92619245
struct ggml_compute_state_shared {
92629246
#ifdef DISABLE_GGML_COMPUTE_SPIN_V2
92639247
ggml_lock_t spin;
@@ -9295,9 +9279,6 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
92959279
const int n_threads = state->shared->n_threads;
92969280
#endif
92979281

9298-
#ifndef DISABLE_SPIN_HINT
9299-
int spin_counter = 0;
9300-
#endif
93019282
while (true) {
93029283
#ifndef DISABLE_GGML_COMPUTE_SPIN_V2
93039284
int flag = atomic_load(&state->shared->flag);
@@ -9310,14 +9291,6 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
93109291
atomic_fetch_sub(&state->shared->flag, 1); // done
93119292
}
93129293
}
9313-
9314-
#ifndef DISABLE_SPIN_HINT
9315-
spin_hint();
9316-
if (++spin_counter > NUM_SPIN_BEFOR_SCHED_YIELD) {
9317-
spin_counter = 0;
9318-
sched_yield();
9319-
}
9320-
#endif
93219294
#else
93229295
if (atomic_fetch_add(&state->shared->n_ready, 1) == n_threads - 1) {
93239296
atomic_store(&state->shared->has_work, false);
@@ -9689,18 +9662,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
96899662
// wait for thread pool
96909663
if (node->n_tasks > 1) {
96919664
#ifndef DISABLE_GGML_COMPUTE_SPIN_V2
9692-
#ifndef DISABLE_SPIN_HINT
9693-
int spin_count = 0;
9694-
#endif
9695-
while (atomic_load(&state_shared.flag) != 0) {
9696-
#ifndef DISABLE_SPIN_HINT
9697-
spin_hint();
9698-
if (++spin_count > NUM_SPIN_BEFOR_SCHED_YIELD) {
9699-
spin_count = 0;
9700-
sched_yield();
9701-
}
9702-
#endif
9703-
}
9665+
while (atomic_load(&state_shared.flag) != 0) {}
97049666
#else
97059667
if (atomic_fetch_add(&state_shared.n_ready, 1) == n_threads - 1) {
97069668
atomic_store(&state_shared.has_work, false);
@@ -9767,18 +9729,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
97679729
// wait for thread pool
97689730
if (node->n_tasks > 1) {
97699731
#ifndef DISABLE_GGML_COMPUTE_SPIN_V2
9770-
#ifndef DISABLE_SPIN_HINT
9771-
int spin_count = 0;
9772-
#endif
9773-
while (atomic_load(&state_shared.flag) != 0) {
9774-
#ifndef DISABLE_SPIN_HINT
9775-
spin_hint();
9776-
if (++spin_count > NUM_SPIN_BEFOR_SCHED_YIELD) {
9777-
spin_count = 0;
9778-
sched_yield();
9779-
}
9780-
#endif
9781-
}
9732+
while (atomic_load(&state_shared.flag) != 0) {}
97829733
#else
97839734
if (atomic_fetch_add(&state_shared.n_ready, 1) == n_threads - 1) {
97849735
atomic_store(&state_shared.has_work, false);

0 commit comments

Comments
 (0)