char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
81b0d882a
char/aliceai-t5-moe
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 { 10SPINE_CACHE_ALIGN std ::atomic < int64_t > pending_ ; 11SPINE_CACHE_ALIGN std ::atomic < int64_t > rounds_ ; 12SPINE_CACHE_ALIGN int64_t total_ ; 13}; 14 15inline void spine_barrier_wait (spine_barrier_t * b ) { 16 autocur_round = b -> rounds_ . load (std::memory_order_acquire); 17auto cnt = -- b -> pending_ ; 18if (cnt == 0 ) { 19b -> pending_ . store (b -> total_ ); 20b -> rounds_ . store (cur_round + 1 ); 21} else { 22while (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) { 29for ( int i = 0 ; i < num_barriers; i ++ ) { 30b[i]. total_ = thread_count; 31b[i]. pending_ . store (thread_count); 32b[i]. rounds_ . store ( 0 ); 33 } 34}