aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-08 05:14:12 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:27:03 +0200
commit96e5dc95397cd9038212dc69cbe0384b24640dc3 (patch)
treee1eda6b5b3f6b4656a7a667edb98931ef797e163 /pplx_embed.c
parent6554530a57a6d73ff58cdf7e601ec3cab824a4c1 (diff)
downloadffwd-96e5dc95397cd9038212dc69cbe0384b24640dc3.tar.gz
ffwd-96e5dc95397cd9038212dc69cbe0384b24640dc3.zip
cuda: add initial CUDA embedding backend
Diffstat (limited to 'pplx_embed.c')
-rw-r--r--pplx_embed.c58
1 files changed, 1 insertions, 57 deletions
diff --git a/pplx_embed.c b/pplx_embed.c
index 2c0ade6..4dc358e 100644
--- a/pplx_embed.c
+++ b/pplx_embed.c
@@ -1,4 +1,5 @@
#include "pplx_embed.h"
+#include "pplx_embed_internal.h"
#include "qwen_asr_kernels.h"
#include "qwen_asr_safetensors.h"
@@ -9,63 +10,6 @@
#include <limits.h>
#include <float.h>
-typedef struct {
- safetensor_dtype_t dtype;
- const void *data;
-} pplx_weight_ref_t;
-
-typedef struct {
- pplx_weight_ref_t wq; /* [q_dim, hidden] */
- pplx_weight_ref_t wk; /* [kv_dim, hidden] */
- pplx_weight_ref_t wv; /* [kv_dim, hidden] */
- pplx_weight_ref_t wo; /* [hidden, q_dim] */
- const float *q_norm; /* [head_dim] */
- const float *k_norm; /* [head_dim] */
- const float *input_norm; /* [hidden] */
- const float *post_attn_norm;/* [hidden] */
- pplx_weight_ref_t gate_proj;/* [intermediate, hidden] */
- pplx_weight_ref_t up_proj; /* [intermediate, hidden] */
- pplx_weight_ref_t down_proj;/* [hidden, intermediate] */
-} pplx_layer_t;
-
-typedef struct {
- pplx_weight_ref_t embed_tokens; /* [vocab_size, hidden] */
- pplx_layer_t *layers; /* [n_layers] heap-allocated */
- const float *norm; /* [hidden] */
-} pplx_weights_t;
-
-struct pplx_model {
- pplx_config_t config;
- pplx_weights_t weights;
- void *safetensors; /* multi_safetensors_t*, keeps mmap alive */
- int layer_start; /* loaded transformer range, inclusive */
- int layer_end; /* loaded transformer range, exclusive */
-};
-
-struct pplx_workspace {
- const pplx_model_t *model; /* immutable model this workspace belongs to */
- int buf_seq_cap;
- float *x; /* [seq, hidden] */
- float *x_norm; /* [seq, hidden] */
- float *q; /* [seq, q_dim] */
- float *k; /* [seq, kv_dim] */
- float *v; /* [seq, kv_dim] */
- float *attn_out; /* [seq, q_dim] */
- float *proj_out; /* [seq, hidden] */
- float *ffn_gate; /* [seq, intermediate] */
- float *ffn_up; /* [seq, intermediate] */
- float *attn_scores; /* reusable BLAS attention score tiles */
- size_t attn_scores_bytes;
-
- int *offsets; /* [batch + 1] packed sequence offsets */
- int offsets_cap;
-
- /* RoPE cosine/sine cache [n_pos, head_dim], grown lazily. */
- float *rope_cos;
- float *rope_sin;
- int rope_cache_cap;
-};
-
struct pplx_late_model {
pplx_model_t *base;
safetensors_file_t *dense_sf;