aboutsummaryrefslogtreecommitdiff
path: root/src/kernels_act.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-20 20:10:56 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-21 05:57:19 +0200
commit6b969d25ce136eaf695222bd1a10bff1ecac0220 (patch)
treec23afb50c28b9deaddae5c6526a74ee11cf2d865 /src/kernels_act.c
parentd4bdb8dae753462f621507d5fc3582e0e53da35c (diff)
downloadffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.tar.gz
ffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.zip
all: split Makefile and reorg library/tools
Diffstat (limited to '')
-rw-r--r--libffwd/act.c (renamed from src/kernels_act.c)32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/kernels_act.c b/libffwd/act.c
index abbade4..688dd71 100644
--- a/src/kernels_act.c
+++ b/libffwd/act.c
@@ -1,28 +1,32 @@
-#include "kernels.h"
-#include "kernels_impl.h"
+/*
+ * act.c - activations
+ */
#include <math.h>
#include <stdlib.h>
#include <string.h>
+#include "impl.h"
+#include "kernels.h"
+
#if (defined(__AVX512F__) || defined(__AVX2__)) && \
(defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || defined(_M_IX86))
-#include <immintrin.h>
+# include <immintrin.h>
#endif
#if defined(__ARM_NEON) || defined(__ARM_NEON__)
-#include <arm_neon.h>
+# include <arm_neon.h>
#endif
#ifdef USE_BLAS
-#ifdef __APPLE__
-#include <Accelerate/Accelerate.h>
-#else
-#include <cblas.h>
-#endif
+# ifdef __APPLE__
+# include <Accelerate/Accelerate.h>
+# else
+# include <cblas.h>
+# endif
#endif
#ifndef M_PI
-#define M_PI 3.14159265358979323846
+# define M_PI 3.14159265358979323846
#endif
/* Activation kernels: softmax, SiLU-gated multiply, and the erf and tanh GeLU
@@ -32,7 +36,7 @@
* Activation Functions
* ======================================================================== */
-void embed_silu_mul_inplace(float *gate, const float *up, int n) {
+void silu_mul_inplace(float *gate, const float *up, int n) {
#if defined(__APPLE__) && defined(USE_BLAS)
enum { CHUNK = 4096 };
float exp_neg[CHUNK];
@@ -59,13 +63,13 @@ void embed_silu_mul_inplace(float *gate, const float *up, int n) {
#endif
}
-void embed_gelu_inplace(float *x, int n) {
+void gelu_inplace(float *x, int n) {
/* Exact erf GeLU; 0.70710678... = 1/sqrt(2). */
for (int i = 0; i < n; i++)
x[i] = 0.5f * x[i] * (1.0f + erff(x[i] * 0.70710678118654752f));
}
-void embed_gelu_tanh_inplace(float *x, int n) {
+void gelu_tanh_inplace(float *x, int n) {
/* Tanh-approximation GeLU; 0.79788456... = sqrt(2/pi). */
for (int i = 0; i < n; i++) {
float v = x[i];
@@ -74,7 +78,7 @@ void embed_gelu_tanh_inplace(float *x, int n) {
}
}
-void embed_softmax(float *x, int rows, int cols) {
+void softmax(float *x, int rows, int cols) {
for (int r = 0; r < rows; r++) {
float *row = x + r * cols;
float max_val = row[0];