interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

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 <atomic>
4#include <cstdint>
5
6#define SPINE_CACHE_LINE 64
7#define SPINE_CACHE_ALIGN __attribute__((aligned(SPINE_CACHE_LINE)))
8
9struct spine_barrier_t {
10 SPINE_CACHE_ALIGN std::atomic<int64_t> pending_;
11 SPINE_CACHE_ALIGN std::atomic<int64_t> rounds_;
12 SPINE_CACHE_ALIGN int64_t total_;
13};
14
15inline 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
28inline 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}