aboutsummaryrefslogtreecommitdiff
path: root/embed_mlx.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-10 15:49:59 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:27:03 +0200
commit7fe02715aac68b958250b43f9d48d641af0a045c (patch)
tree7bc866f87999991ef0a3ffa0dd36ce91444e5172 /embed_mlx.h
parente8259865f41ceb50dd28b267186d11c62a465135 (diff)
downloadffwd-7fe02715aac68b958250b43f9d48d641af0a045c.tar.gz
ffwd-7fe02715aac68b958250b43f9d48d641af0a045c.zip
build: export only the public API from the shared library
Diffstat (limited to 'embed_mlx.h')
-rw-r--r--embed_mlx.h63
1 files changed, 37 insertions, 26 deletions
diff --git a/embed_mlx.h b/embed_mlx.h
index 25376e9..52a8801 100644
--- a/embed_mlx.h
+++ b/embed_mlx.h
@@ -7,6 +7,17 @@
#ifndef PPLX_EMBED_MLX_H
#define PPLX_EMBED_MLX_H
+/* Public-API export annotation. The libraries are built with
+ * -fvisibility=hidden, so only declarations carrying PPLX_API are exported
+ * from the shared library; everything else stays internal. */
+#ifndef PPLX_API
+#if defined(__GNUC__)
+#define PPLX_API __attribute__((visibility("default")))
+#else
+#define PPLX_API
+#endif
+#endif
+
#include <stddef.h>
#include <stdint.h>
#include "embed.h"
@@ -25,8 +36,8 @@ typedef struct {
* Load model into MLX arrays from safetensors + config.json.
* Returns NULL on error.
*/
-pplx_mlx_ctx_t *pplx_mlx_load(const char *model_dir);
-pplx_mlx_ctx_t *pplx_mlx_load_with_options(const char *model_dir,
+PPLX_API pplx_mlx_ctx_t *pplx_mlx_load(const char *model_dir);
+PPLX_API pplx_mlx_ctx_t *pplx_mlx_load_with_options(const char *model_dir,
const pplx_mlx_options_t *opts);
/*
@@ -34,26 +45,26 @@ pplx_mlx_ctx_t *pplx_mlx_load_with_options(const char *model_dir,
* Uses the same half-open range and endpoint ownership rules as
* pplx_model_load_slice().
*/
-pplx_mlx_ctx_t *pplx_mlx_load_slice(const char *model_dir,
+PPLX_API pplx_mlx_ctx_t *pplx_mlx_load_slice(const char *model_dir,
int layer_start, int layer_end);
-pplx_mlx_ctx_t *pplx_mlx_load_slice_with_options(
+PPLX_API pplx_mlx_ctx_t *pplx_mlx_load_slice_with_options(
const char *model_dir, int layer_start, int layer_end,
const pplx_mlx_options_t *opts);
-void pplx_mlx_free(pplx_mlx_ctx_t *ctx);
+PPLX_API void pplx_mlx_free(pplx_mlx_ctx_t *ctx);
/*
* Late-interaction MLX path. This is separate from pooled embeddings because
* late snapshots produce one projected token vector per input token for MaxSim
* scoring, not one pooled document vector.
*/
-pplx_mlx_late_ctx_t *pplx_mlx_late_load(const char *model_dir);
-pplx_mlx_late_ctx_t *pplx_mlx_late_load_with_options(
+PPLX_API pplx_mlx_late_ctx_t *pplx_mlx_late_load(const char *model_dir);
+PPLX_API pplx_mlx_late_ctx_t *pplx_mlx_late_load_with_options(
const char *model_dir, const pplx_mlx_options_t *opts);
-void pplx_mlx_late_free(pplx_mlx_late_ctx_t *ctx);
+PPLX_API void pplx_mlx_late_free(pplx_mlx_late_ctx_t *ctx);
-const pplx_config_t *pplx_mlx_late_config(const pplx_mlx_late_ctx_t *ctx);
-int pplx_mlx_late_token_dim(const pplx_mlx_late_ctx_t *ctx);
+PPLX_API const pplx_config_t *pplx_mlx_late_config(const pplx_mlx_late_ctx_t *ctx);
+PPLX_API int pplx_mlx_late_token_dim(const pplx_mlx_late_ctx_t *ctx);
/*
* Encode token_ids into out_vectors[n_tokens, token_dim].
@@ -61,7 +72,7 @@ int pplx_mlx_late_token_dim(const pplx_mlx_late_ctx_t *ctx);
* If normalize is non-zero, every token vector is L2-normalized on device
* before copying back to CPU memory.
*/
-int pplx_mlx_late_encode_tokens(pplx_mlx_late_ctx_t *ctx,
+PPLX_API int pplx_mlx_late_encode_tokens(pplx_mlx_late_ctx_t *ctx,
const int *token_ids, int n_tokens,
int normalize, float *out_vectors);
@@ -72,21 +83,21 @@ int pplx_mlx_late_encode_tokens(pplx_mlx_late_ctx_t *ctx,
* outlive ctx. Copying is optional: MaxSim can consume these handles directly
* and copy back only final candidate scores.
*/
-pplx_mlx_late_vectors_t *pplx_mlx_late_encode_tokens_device(
+PPLX_API pplx_mlx_late_vectors_t *pplx_mlx_late_encode_tokens_device(
pplx_mlx_late_ctx_t *ctx, const int *token_ids, int n_tokens,
int normalize);
-void pplx_mlx_late_vectors_free(pplx_mlx_late_vectors_t *vecs);
-int pplx_mlx_late_vectors_token_count(const pplx_mlx_late_vectors_t *vecs);
-int pplx_mlx_late_vectors_dim(const pplx_mlx_late_vectors_t *vecs);
-int pplx_mlx_late_vectors_copy(const pplx_mlx_late_vectors_t *vecs,
+PPLX_API void pplx_mlx_late_vectors_free(pplx_mlx_late_vectors_t *vecs);
+PPLX_API int pplx_mlx_late_vectors_token_count(const pplx_mlx_late_vectors_t *vecs);
+PPLX_API int pplx_mlx_late_vectors_dim(const pplx_mlx_late_vectors_t *vecs);
+PPLX_API int pplx_mlx_late_vectors_copy(const pplx_mlx_late_vectors_t *vecs,
float *out_vectors);
-pplx_mlx_late_vectors_t *pplx_mlx_late_vectors_concat(
+PPLX_API pplx_mlx_late_vectors_t *pplx_mlx_late_vectors_concat(
pplx_mlx_late_ctx_t *ctx,
const pplx_mlx_late_vectors_t *const *items, int count);
-pplx_mlx_late_vectors_t *pplx_mlx_late_vectors_select(
+PPLX_API pplx_mlx_late_vectors_t *pplx_mlx_late_vectors_select(
pplx_mlx_late_ctx_t *ctx, const pplx_mlx_late_vectors_t *vecs,
const int *token_indices, int count);
-int pplx_mlx_late_maxsim_batch_device(
+PPLX_API int pplx_mlx_late_maxsim_batch_device(
pplx_mlx_late_ctx_t *ctx, const pplx_mlx_late_vectors_t *query,
const pplx_mlx_late_vectors_t *docs, const int *doc_offsets,
int docs_count, float *scores);
@@ -95,13 +106,13 @@ int pplx_mlx_late_maxsim_batch_device(
* Compute embedding for token_ids[0..n_tokens-1].
* Returns malloc'd float[hidden_size] (caller frees). NULL on error.
*/
-float *pplx_mlx_embed(pplx_mlx_ctx_t *ctx, const int *token_ids, int n_tokens);
+PPLX_API float *pplx_mlx_embed(pplx_mlx_ctx_t *ctx, const int *token_ids, int n_tokens);
/*
* Compute one embedding into caller-provided out[hidden_size].
* Returns 0 on success, -1 on error.
*/
-int pplx_mlx_embed_into(pplx_mlx_ctx_t *ctx, const int *token_ids,
+PPLX_API int pplx_mlx_embed_into(pplx_mlx_ctx_t *ctx, const int *token_ids,
int n_tokens, float *out_embedding);
/*
@@ -111,7 +122,7 @@ int pplx_mlx_embed_into(pplx_mlx_ctx_t *ctx, const int *token_ids,
* Padded tokens are masked out of attention keys and mean pooling.
* Returns 0 on success, -1 on error.
*/
-int pplx_mlx_embed_batch(pplx_mlx_ctx_t *ctx, const pplx_input_t *inputs,
+PPLX_API int pplx_mlx_embed_batch(pplx_mlx_ctx_t *ctx, const pplx_input_t *inputs,
int batch, float *out_embeddings);
/*
@@ -120,7 +131,7 @@ int pplx_mlx_embed_batch(pplx_mlx_ctx_t *ctx, const pplx_input_t *inputs,
* Hidden states cross the API boundary as packed float32 rows even though MLX
* executes a padded dense batch internally.
*/
-int pplx_mlx_forward_slice_batch(pplx_mlx_ctx_t *ctx,
+PPLX_API int pplx_mlx_forward_slice_batch(pplx_mlx_ctx_t *ctx,
const pplx_input_t *inputs, int batch,
const float *input_states,
int layer_start, int layer_end,
@@ -131,7 +142,7 @@ int pplx_mlx_forward_slice_batch(pplx_mlx_ctx_t *ctx,
* Run one contextual sequence and pool selected token spans.
* Returns 0 on success, -1 on error.
*/
-int pplx_mlx_embed_spans(pplx_mlx_ctx_t *ctx, const int *token_ids,
+PPLX_API int pplx_mlx_embed_spans(pplx_mlx_ctx_t *ctx, const int *token_ids,
int n_tokens, const pplx_span_t *spans,
int n_spans, float *out_embeddings);
@@ -139,11 +150,11 @@ int pplx_mlx_embed_spans(pplx_mlx_ctx_t *ctx, const int *token_ids,
* Run a padded dense contextual document batch and pool every selected span.
* out_embeddings contains spans in document order.
*/
-int pplx_mlx_embed_spans_batch(pplx_mlx_ctx_t *ctx,
+PPLX_API int pplx_mlx_embed_spans_batch(pplx_mlx_ctx_t *ctx,
const pplx_context_input_t *inputs, int batch,
float *out_embeddings);
/* Get the config (so embed_cli.c can read hidden_size etc.) */
-const pplx_config_t *pplx_mlx_config(const pplx_mlx_ctx_t *ctx);
+PPLX_API const pplx_config_t *pplx_mlx_config(const pplx_mlx_ctx_t *ctx);
#endif /* PPLX_EMBED_MLX_H */