aboutsummaryrefslogtreecommitdiff
path: root/liblangdet/kernels.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-09-29 13:11:00 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-09-29 13:11:00 +0200
commit37cbaef9ceb828c667da8f398027ba5415ee7475 (patch)
tree6103e92a9030766e78a35df00f7a1155d0d0ecf5 /liblangdet/kernels.h
parentcf7d8169ec12cb3adf90d4ff78b3257e74985302 (diff)
downloadlangdet-37cbaef9ceb828c667da8f398027ba5415ee7475.tar.gz
langdet-37cbaef9ceb828c667da8f398027ba5415ee7475.zip
Rename CPU library API and sources to langdet
Diffstat (limited to 'liblangdet/kernels.h')
-rw-r--r--liblangdet/kernels.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/liblangdet/kernels.h b/liblangdet/kernels.h
new file mode 100644
index 0000000..1025602
--- /dev/null
+++ b/liblangdet/kernels.h
@@ -0,0 +1,42 @@
+#ifndef KERNELS_H
+#define KERNELS_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+void add_inplace(float *a, const float *b, int n);
+
+/* y = x @ W^T + b: x[seq,in], W[out,in], b[out], y[seq,out]. */
+void linear(
+ float *y, const float *x, const float *W, const float *b, int seq_len, int in_dim, int out_dim);
+void linear_nobias(float *y, const float *x, const float *W, int seq_len, int in_dim, int out_dim);
+
+/* Mean and population variance are reduced over the hidden axis per row. */
+void layer_norm(float *out,
+ const float *x,
+ const float *gamma,
+ const float *beta,
+ int seq_len,
+ int hidden,
+ float eps);
+
+void softmax(float *x, int rows, int cols);
+void gelu_inplace(float *x, int n);
+
+/* Attention is block-diagonal: each token attends only within its offsets span.
+ * Missing scratch uses the online-softmax path instead of tiled BLAS. */
+size_t bidirectional_gqa_attention_packed_scratch_bytes(const int *offsets, int batch);
+void bidirectional_gqa_attention_packed_with_scratch(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ float *scratch,
+ size_t scratch_bytes);
+
+#endif /* KERNELS_H */