Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama MLXRunner MLX Generated H

From Leeroopedia
Knowledge Sources
Domains MLX Runtime, Code Generation
Last Updated 2025-02-15 00:00 GMT

Overview

Auto-generated C header file that renames original MLX C symbols and declares function pointer wrappers used by the Go CGo layer for dynamic binding.

Description

Uses #define macros to rename every MLX C function to a _mlx_gen_orig_ suffixed version, preventing direct linking. Then declares extern function pointer variables for each function, and inline wrapper functions that call through these pointers. Includes the original MLX C headers to get type definitions, then undefs the renames. This file is generated by the generator/main.go tool.

Usage

Included by all Go CGo files (#include "generated.h") to access MLX functions through the dynamic loading mechanism rather than direct linking. This is the glue between Go and the MLX C library.

Code Reference

Source Location

  • Repository: Ollama
  • File: x/mlxrunner/mlx/generated.h
  • Lines: 1-7135

Signature

#ifndef MLX_GENERATED_H
#define MLX_GENERATED_H

#include "dynamic.h"

// Rename macros to prevent direct linking
#define mlx_dtype_size mlx_dtype_size_mlx_gen_orig_
#define mlx_array_new mlx_array_new_mlx_gen_orig_
#define mlx_array_free mlx_array_free_mlx_gen_orig_
// ... hundreds more

// Extern function pointer declarations
extern size_t (*mlx_dtype_size_)(mlx_dtype dtype);
extern mlx_array (*mlx_array_new_)(void);
// ... hundreds more

#endif // MLX_GENERATED_H

Import

#include "generated.h"

I/O Contract

Inputs

Name Type Required Description
(compile-time) N/A Yes Included via #include directive in CGo source files

Outputs

Name Type Description
(declarations) N/A Function pointer types and inline wrapper functions for all MLX C APIs

Usage Examples

// In a Go CGo file:
// #include "generated.h"
import "C"

// Now C.mlx_array_new(), C.mlx_add(), etc. are available
arr := C.mlx_array_new_float32(C.float(1.0))

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment