Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
FreeBSD compatibility: platform guards in glm.c/olmoe.c (#206)
yuri@FreeBSD4a936c8af373
diff --git a/c/glm.c b/c/glm.cindex ed9cbea6..297b9645 100644--- a/c/glm.c+++ b/c/glm.c@@ -27,10 +27,10 @@#include <stdatomic.h> /* PIPE ready-flags/job queue + PILOT_REAL cross-layer handshake */#include <sched.h> /* sched_yield: PIPE spin / PILOT barrier */#include <unistd.h>-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)#include <sys/select.h> /* select() serve-loop polling (#68); not on native MinGW */#endif-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)#include <sys/resource.h>#include <sys/mman.h> /* mlock: inchioda le pagine in RAM / wire pages into RAM */#include <sys/stat.h> /* fstat per mmap degli shard (COLI_MMAP) */@@ -1286,7 +1286,7 @@ static void *map_of_fd(int fd){pthread_mutex_lock(&g_map_mtx);for(int i=0;i<g_nmaps;i++) if(g_maps[i].fd==fd){ void *b=g_maps[i].base; pthread_mutex_unlock(&g_map_mtx); return b; }void *base=NULL;-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)struct stat st;if(g_nmaps<512 && fstat(fd,&st)==0){size_t len=((size_t)st.st_size+16383)&~(size_t)16383;@@ -1358,7 +1358,7 @@ static int expert_load(Model *m, int layer, int eid, ESlot *s, int fatal){* residency. This is pread's I/O without the copy and without the slab. */for(int k=0;k<3;k++){char *p=(char*)bw[k]+tw[k]->off; size_t n=(size_t)tw[k]->nbytes;-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)madvise((void*)((uintptr_t)p & ~16383UL), n+16384, MADV_WILLNEED);#endifvolatile char acc=0;@@ -1562,7 +1562,7 @@ static inline void pipe_wait(int q){#ifdef COLI_CUDAstatic void expert_host_release(Model *m, ESlot *s){if(!s->slab&&!s->fslab) return;-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)if(s->slab) munlock(s->slab,(size_t)s->slab_cap);if(s->fslab) munlock(s->fslab,(size_t)s->fslab_cap*sizeof(float));#elif defined(_WIN32)@@ -3900,7 +3900,7 @@ static void run_serve_mux(Model *m, const char *snap){* the Windows equivalent: it reports bytes available without reading. */int ready=0;if(!eof){-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)fd_set rfds; FD_ZERO(&rfds); FD_SET(STDIN_FILENO,&rfds);struct timeval tv={0,0}, *ptv=active?&tv:NULL;ready=select(STDIN_FILENO+1,&rfds,NULL,NULL,ptv);@@ -4309,7 +4309,7 @@ static int mem_should_wire(void){/* Inchioda [addr,addr+len) in RAM fisica. No-op fuori da POSIX (Windows ecc.).* EN: wire [addr,addr+len) into physical RAM. No-op off POSIX (Windows, etc.). */static int mem_wire(void *addr, size_t len){-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)return mlock(addr, len);#elif defined(_WIN32)return compat_mlock(addr, len); /* VirtualLock + working-set growth */@@ -4583,6 +4583,11 @@ int main(int argc, char **argv){fprintf(stderr,"[OMP] hot-thread tuning: re-exec once (COLI_NO_OMP_TUNE=1 to skip)\n");execv("/proc/self/exe", argv); /* returns only on failure -> fall through and run untuned */perror("[OMP] execv self-reexec failed, running untuned");+#endif+#ifdef __FreeBSD__+ fprintf(stderr,"[OMP] hot-thread tuning: re-exec once (COLI_NO_OMP_TUNE=1 to skip)\n");+ execv("/proc/curproc/file", argv); /* returns only on failure -> fall through and run untuned */+ perror("[OMP] execv self-reexec failed, running untuned");#endif}#if defined(__AVX512F__) && defined(__AVX512BW__)diff --git a/c/olmoe.c b/c/olmoe.cindex 1c5ffaa8..5923bdee 100644--- a/c/olmoe.c+++ b/c/olmoe.c@@ -12,7 +12,7 @@#include <string.h>#include <math.h>#include <time.h>-#if defined(__APPLE__) || defined(__linux__)+#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)#include <sys/resource.h>#endif#include "st.h"