Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-cpu/spacemit/spine_barrier.h # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-cpu / spacemit / spine_barrier.h` 34 lines ยท 1007 bytes Raw Blame History 1 #pragma once 2 3 #include 4 #include 5 6 #define SPINE_CACHE_LINE 64 7 #define SPINE_CACHE_ALIGN __attribute__((aligned(SPINE_CACHE_LINE))) 8 9 struct spine_barrier_t { 10 SPINE_CACHE_ALIGN std::atomic pending_; 11 SPINE_CACHE_ALIGN std::atomic rounds_; 12 SPINE_CACHE_ALIGN int64_t total_; 13 }; 14 15 inline void spine_barrier_wait(spine_barrier_t * b) { 16 auto cur_round = b->rounds_.load(std::memory_order_acquire); 17 auto cnt = --b->pending_; 18 if (cnt == 0) { 19 b->pending_.store(b->total_); 20 b->rounds_.store(cur_round + 1); 21 } else { 22 while (cur_round == b->rounds_.load(std::memory_order_relaxed)) { 23 __asm__ volatile("pause " ::: "memory"); 24 } 25 } 26 } 27 28 inline void spine_barrier_init(spine_barrier_t * b, int num_barriers, uint64_t thread_count) { 29 for (int i = 0; i < num_barriers; i++) { 30 b[i].total_ = thread_count; 31 b[i].pending_.store(thread_count); 32 b[i].rounds_.store(0); 33 } 34 }