1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#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);
/* Bidirectional attention over one unpadded sequence with equal Q/K/V head counts.
* Missing scratch uses the online-softmax path instead of tiled BLAS. */
size_t attention_scratch_bytes(int seq);
void attention_with_scratch(float *out,
const float *Q,
const float *K,
const float *V,
int seq,
int n_heads,
int head_dim,
float scale,
float *scratch,
size_t scratch_bytes);
#endif /* KERNELS_H */
|