16
16
#include <stdlib.h>
17
17
#include <string.h>
18
18
#include <stdint.h>
19
- #include <sched.h>
20
19
#include <inttypes.h>
21
20
#include <stdio.h>
22
21
#include <float.h>
@@ -9243,21 +9242,6 @@ typedef pthread_t ggml_thread_t;
9243
9242
// To rollback quickly, set `-DDISABLE_GGML_COMPUTE_SPIN_V2` to `CFLAGS` in Makefile.
9244
9243
// TODO(mqy): cleanup feature flag DISABLE_GGML_COMPUTE_SPIN_V2.
9245
9244
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
-
9261
9245
struct ggml_compute_state_shared {
9262
9246
#ifdef DISABLE_GGML_COMPUTE_SPIN_V2
9263
9247
ggml_lock_t spin ;
@@ -9295,9 +9279,6 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
9295
9279
const int n_threads = state -> shared -> n_threads ;
9296
9280
#endif
9297
9281
9298
- #ifndef DISABLE_SPIN_HINT
9299
- int spin_counter = 0 ;
9300
- #endif
9301
9282
while (true) {
9302
9283
#ifndef DISABLE_GGML_COMPUTE_SPIN_V2
9303
9284
int flag = atomic_load (& state -> shared -> flag );
@@ -9310,14 +9291,6 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
9310
9291
atomic_fetch_sub (& state -> shared -> flag , 1 ); // done
9311
9292
}
9312
9293
}
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
9321
9294
#else
9322
9295
if (atomic_fetch_add (& state -> shared -> n_ready , 1 ) == n_threads - 1 ) {
9323
9296
atomic_store (& state -> shared -> has_work , false);
@@ -9689,18 +9662,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
9689
9662
// wait for thread pool
9690
9663
if (node -> n_tasks > 1 ) {
9691
9664
#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 ) {}
9704
9666
#else
9705
9667
if (atomic_fetch_add (& state_shared .n_ready , 1 ) == n_threads - 1 ) {
9706
9668
atomic_store (& state_shared .has_work , false);
@@ -9767,18 +9729,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
9767
9729
// wait for thread pool
9768
9730
if (node -> n_tasks > 1 ) {
9769
9731
#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 ) {}
9782
9733
#else
9783
9734
if (atomic_fetch_add (& state_shared .n_ready , 1 ) == n_threads - 1 ) {
9784
9735
atomic_store (& state_shared .has_work , false);
0 commit comments