Implementation:Ollama Ollama MLXRunner MLX Generated C
| Knowledge Sources | |
|---|---|
| Domains | MLX Runtime, Code Generation |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
Auto-generated C source file containing function pointer declarations and dynamic symbol loading for all MLX C API functions.
Description
This file declares function pointers (initialized to NULL) for every MLX C API function, then provides a mlx_dynamic_load_symbols function that resolves all symbols from a dynamically loaded library handle using CHECK_LOAD macros. The wrapper functions call through these function pointers, enabling runtime binding rather than link-time binding. This file is generated by the generator/main.go tool and should not be edited manually.
Usage
Included at compile time by the CGo layer to provide the dynamic loading implementation. Enables Ollama to optionally use MLX without requiring it at compile time.
Code Reference
Source Location
- Repository: Ollama
- File: x/mlxrunner/mlx/generated.c
- Lines: 1-2724
Signature
// Auto-generated function pointer declarations
size_t (*mlx_dtype_size_)(mlx_dtype dtype) = NULL;
int (*mlx_array_tostring_)(mlx_string* str, const mlx_array arr) = NULL;
mlx_array (*mlx_array_new_)(void) = NULL;
int (*mlx_array_free_)(mlx_array arr) = NULL;
mlx_array (*mlx_array_new_data_)(const void* data, const int* shape, int dim, mlx_dtype dtype) = NULL;
// Dynamic symbol loading
void mlx_dynamic_load_symbols(void* handle);
Import
#include "generated.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| handle | void* | Yes | Dynamically loaded library handle from dlopen |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | void | All function pointers are resolved and set to non-NULL |
Usage Examples
// Called during MLX initialization
void* handle = dlopen("libmlx.dylib", RTLD_LAZY);
mlx_dynamic_load_symbols(handle);
// Now all MLX functions can be called through the wrappers
mlx_array arr = mlx_array_new_float(1.0f);