Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

perf(simd): add OpenMP SIMD reductions to hot-path matrix multiplication loops (#442)

Egon Ruiter961e81ff93d3
diff --git a/c/olmoe.c b/c/olmoe.c
index e770efe0..0673df18 100644
--- a/c/olmoe.c
+++ b/c/olmoe.c
@@ -134,6 +134,7 @@ static void matmul(float *y, const float *x, const float *W, int S, int I, int O
for (int s = 0; s < S; s++) {
const float *xs = x + (int64_t)s * I;
float acc = 0.f;
+ #pragma omp simd reduction(+:acc)
for (int i = 0; i < I; i++) acc += xs[i] * w[i];
y[(int64_t)s * O + o] = acc;
}
@@ -207,6 +208,7 @@ static void matmul_q(float *y, const float *x, const int8_t *q, const float *sca
for (int o = 0; o < O; o++) {
const int8_t *w = q + (int64_t)o * I;
float acc = 0.f;
+ #pragma omp simd reduction(+:acc)
for (int i = 0; i < I; i++) acc += x[i] * (float)w[i];
y[o] = acc * scale[o];
}