Files
ollama/x/imagegen/mlx/mlx_error_handler.h
Daniel Hiltgen 87d21c7fc0 MLX: harden for init failures (#14777)
The CLI now links to the lazy-load MLX code, but that still happens in
init functions.  On internal MLX errors, the CLI exits before it has a
chance to start.  This change re-wires the MLX error handling so it
doesn't exit by default.  The MLX based runners currently expect exits
on failure, so they re-initialize the default error handling.  We can
refine error handling for better go stack traces in the future.
2026-03-10 22:52:23 -07:00

23 lines
816 B
C

// mlx_error_handler.h - Safe error handling for MLX initialization
// This replaces the default exit(-1) MLX error handler during init()
// so that GPU failures don't kill the process.
#ifndef MLX_ERROR_HANDLER_H
#define MLX_ERROR_HANDLER_H
// Enter safe mode before any MLX compute calls during init().
// Replaces the default exit(-1) handler with one that silently stores errors.
void mlx_set_safe_init_mode(void);
// Restore the default MLX error handler (exit on error).
// Call from runner entry points after confirming MLX is available.
void mlx_set_default_error_mode(void);
// Check whether an error occurred while in safe init mode.
int mlx_had_init_error(void);
// Get the error message from the last init error, or NULL if none.
const char* mlx_get_init_error(void);
#endif // MLX_ERROR_HANDLER_H