MLX, MLX-C: version bump (#18449)

Includes quantized matmul corruption fix, which impacts nvfp4 multimodal models (gemma4 vision towers). Deferring wiring up the new MLX-C thread-local stream/sync APIs for now.
This commit is contained in:
Daniel Hiltgen
2026-09-14 20:53:05 -07:00
committed by GitHub
parent 98acec40ae
commit 4ea3472496
9 changed files with 299 additions and 8 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ jobs:
superbuild_args: '-DOLLAMA_LLAMA_BACKENDS=vulkan' superbuild_args: '-DOLLAMA_LLAMA_BACKENDS=vulkan'
expected_payload: lib/ollama/vulkan/libggml-vulkan.so expected_payload: lib/ollama/vulkan/libggml-vulkan.so
- preset: 'MLX CUDA 13' - preset: 'MLX CUDA 13'
container: nvidia/cuda:13.0.0-devel-ubuntu22.04 container: nvidia/cuda:13.0.0-devel-ubuntu24.04
extra-packages: libcudnn9-dev-cuda-13 libopenblas-dev liblapack-dev liblapacke-dev git curl extra-packages: libcudnn9-dev-cuda-13 libopenblas-dev liblapack-dev liblapacke-dev git curl
superbuild_target: ollama-mlx-cuda_v13 superbuild_target: ollama-mlx-cuda_v13
superbuild_dir: build/local-superbuild-mlx-cuda_v13 superbuild_dir: build/local-superbuild-mlx-cuda_v13
+1 -1
View File
@@ -1 +1 @@
c74db5307cc8ce122f48d97ef951b30578674e7f ebc88f10caa1b625e6b581437a8dea6df8a70085
+1 -1
View File
@@ -1 +1 @@
cbb4059d8c6652d1c2cce98c348a8a689eb275b8 d9add9d11f3154111a4c85f267ec2fd307ecd18e
+53
View File
@@ -2404,6 +2404,15 @@ int (*mlx_random_uniform_)(
mlx_stream (*mlx_stream_new_)(void) = NULL; mlx_stream (*mlx_stream_new_)(void) = NULL;
mlx_stream (*mlx_stream_new_device_)(mlx_device dev) = NULL; mlx_stream (*mlx_stream_new_device_)(mlx_device dev) = NULL;
mlx_stream (*mlx_stream_new_thread_unsafe_)(mlx_device dev) = NULL; mlx_stream (*mlx_stream_new_thread_unsafe_)(mlx_device dev) = NULL;
mlx_stream_thread_local (*mlx_stream_thread_local_new_)(mlx_device dev) = NULL;
int (*mlx_stream_thread_local_set_)(
mlx_stream_thread_local* tls,
const mlx_stream_thread_local src) = NULL;
int (*mlx_stream_thread_local_free_)(mlx_stream_thread_local tls) = NULL;
int (*mlx_stream_from_thread_local_)(
mlx_stream* res,
const mlx_stream_thread_local tls) = NULL;
int (*mlx_get_streams_)(mlx_vector_stream* res) = NULL;
int (*mlx_stream_set_)(mlx_stream* stream, const mlx_stream src) = NULL; int (*mlx_stream_set_)(mlx_stream* stream, const mlx_stream src) = NULL;
int (*mlx_stream_free_)(mlx_stream stream) = NULL; int (*mlx_stream_free_)(mlx_stream stream) = NULL;
int (*mlx_stream_tostring_)(mlx_string* str, mlx_stream stream) = NULL; int (*mlx_stream_tostring_)(mlx_string* str, mlx_stream stream) = NULL;
@@ -2411,6 +2420,9 @@ bool (*mlx_stream_equal_)(mlx_stream lhs, mlx_stream rhs) = NULL;
int (*mlx_stream_get_device_)(mlx_device* dev, mlx_stream stream) = NULL; int (*mlx_stream_get_device_)(mlx_device* dev, mlx_stream stream) = NULL;
int (*mlx_stream_get_index_)(int* index, mlx_stream stream) = NULL; int (*mlx_stream_get_index_)(int* index, mlx_stream stream) = NULL;
int (*mlx_synchronize_)(mlx_stream stream) = NULL; int (*mlx_synchronize_)(mlx_stream stream) = NULL;
int (*mlx_synchronize_default_)(void) = NULL;
int (*mlx_synchronize_thread_local_)(mlx_stream_thread_local tls) = NULL;
int (*mlx_clear_streams_)(void) = NULL;
int (*mlx_get_default_stream_)(mlx_stream* stream, mlx_device dev) = NULL; int (*mlx_get_default_stream_)(mlx_stream* stream, mlx_device dev) = NULL;
int (*mlx_set_default_stream_)(mlx_stream stream) = NULL; int (*mlx_set_default_stream_)(mlx_stream stream) = NULL;
mlx_stream (*mlx_default_cpu_stream_new_)(void) = NULL; mlx_stream (*mlx_default_cpu_stream_new_)(void) = NULL;
@@ -2543,6 +2555,28 @@ int (*mlx_vector_string_append_data_)(
int (*mlx_vector_string_append_value_)(mlx_vector_string vec, const char* val) = NULL; int (*mlx_vector_string_append_value_)(mlx_vector_string vec, const char* val) = NULL;
size_t (*mlx_vector_string_size_)(mlx_vector_string vec) = NULL; size_t (*mlx_vector_string_size_)(mlx_vector_string vec) = NULL;
int (*mlx_vector_string_get_)(char** res, const mlx_vector_string vec, size_t idx) = NULL; int (*mlx_vector_string_get_)(char** res, const mlx_vector_string vec, size_t idx) = NULL;
mlx_vector_stream (*mlx_vector_stream_new_)(void) = NULL;
int (*mlx_vector_stream_set_)(mlx_vector_stream* vec, const mlx_vector_stream src) = NULL;
int (*mlx_vector_stream_free_)(mlx_vector_stream vec) = NULL;
mlx_vector_stream (*mlx_vector_stream_new_data_)(
const mlx_stream* data,
size_t size) = NULL;
mlx_vector_stream (*mlx_vector_stream_new_value_)(const mlx_stream val) = NULL;
int (*mlx_vector_stream_set_data_)(
mlx_vector_stream* vec,
const mlx_stream* data,
size_t size) = NULL;
int (*mlx_vector_stream_set_value_)(mlx_vector_stream* vec, const mlx_stream val) = NULL;
int (*mlx_vector_stream_append_data_)(
mlx_vector_stream vec,
const mlx_stream* data,
size_t size) = NULL;
int (*mlx_vector_stream_append_value_)(mlx_vector_stream vec, const mlx_stream val) = NULL;
size_t (*mlx_vector_stream_size_)(mlx_vector_stream vec) = NULL;
int (*mlx_vector_stream_get_)(
mlx_stream* res,
const mlx_vector_stream vec,
size_t idx) = NULL;
int (*mlx_version_)(mlx_string* str_) = NULL; int (*mlx_version_)(mlx_string* str_) = NULL;
int mlx_dynamic_load_symbols(mlx_dynamic_handle handle) { int mlx_dynamic_load_symbols(mlx_dynamic_handle handle) {
@@ -3130,6 +3164,11 @@ int mlx_dynamic_load_symbols(mlx_dynamic_handle handle) {
CHECK_LOAD(handle, mlx_stream_new); CHECK_LOAD(handle, mlx_stream_new);
CHECK_LOAD(handle, mlx_stream_new_device); CHECK_LOAD(handle, mlx_stream_new_device);
CHECK_LOAD(handle, mlx_stream_new_thread_unsafe); CHECK_LOAD(handle, mlx_stream_new_thread_unsafe);
CHECK_LOAD(handle, mlx_stream_thread_local_new);
CHECK_LOAD(handle, mlx_stream_thread_local_set);
CHECK_LOAD(handle, mlx_stream_thread_local_free);
CHECK_LOAD(handle, mlx_stream_from_thread_local);
CHECK_LOAD(handle, mlx_get_streams);
CHECK_LOAD(handle, mlx_stream_set); CHECK_LOAD(handle, mlx_stream_set);
CHECK_LOAD(handle, mlx_stream_free); CHECK_LOAD(handle, mlx_stream_free);
CHECK_LOAD(handle, mlx_stream_tostring); CHECK_LOAD(handle, mlx_stream_tostring);
@@ -3137,6 +3176,9 @@ int mlx_dynamic_load_symbols(mlx_dynamic_handle handle) {
CHECK_LOAD(handle, mlx_stream_get_device); CHECK_LOAD(handle, mlx_stream_get_device);
CHECK_LOAD(handle, mlx_stream_get_index); CHECK_LOAD(handle, mlx_stream_get_index);
CHECK_LOAD(handle, mlx_synchronize); CHECK_LOAD(handle, mlx_synchronize);
CHECK_LOAD(handle, mlx_synchronize_default);
CHECK_LOAD(handle, mlx_synchronize_thread_local);
CHECK_LOAD(handle, mlx_clear_streams);
CHECK_LOAD(handle, mlx_get_default_stream); CHECK_LOAD(handle, mlx_get_default_stream);
CHECK_LOAD(handle, mlx_set_default_stream); CHECK_LOAD(handle, mlx_set_default_stream);
CHECK_LOAD(handle, mlx_default_cpu_stream_new); CHECK_LOAD(handle, mlx_default_cpu_stream_new);
@@ -3200,6 +3242,17 @@ int mlx_dynamic_load_symbols(mlx_dynamic_handle handle) {
CHECK_LOAD(handle, mlx_vector_string_append_value); CHECK_LOAD(handle, mlx_vector_string_append_value);
CHECK_LOAD(handle, mlx_vector_string_size); CHECK_LOAD(handle, mlx_vector_string_size);
CHECK_LOAD(handle, mlx_vector_string_get); CHECK_LOAD(handle, mlx_vector_string_get);
CHECK_LOAD(handle, mlx_vector_stream_new);
CHECK_LOAD(handle, mlx_vector_stream_set);
CHECK_LOAD(handle, mlx_vector_stream_free);
CHECK_LOAD(handle, mlx_vector_stream_new_data);
CHECK_LOAD(handle, mlx_vector_stream_new_value);
CHECK_LOAD(handle, mlx_vector_stream_set_data);
CHECK_LOAD(handle, mlx_vector_stream_set_value);
CHECK_LOAD(handle, mlx_vector_stream_append_data);
CHECK_LOAD(handle, mlx_vector_stream_append_value);
CHECK_LOAD(handle, mlx_vector_stream_size);
CHECK_LOAD(handle, mlx_vector_stream_get);
CHECK_LOAD(handle, mlx_version); CHECK_LOAD(handle, mlx_version);
return 0; return 0;
} }
+144
View File
@@ -589,6 +589,11 @@
#define mlx_stream_new mlx_stream_new_mlx_gen_orig_ #define mlx_stream_new mlx_stream_new_mlx_gen_orig_
#define mlx_stream_new_device mlx_stream_new_device_mlx_gen_orig_ #define mlx_stream_new_device mlx_stream_new_device_mlx_gen_orig_
#define mlx_stream_new_thread_unsafe mlx_stream_new_thread_unsafe_mlx_gen_orig_ #define mlx_stream_new_thread_unsafe mlx_stream_new_thread_unsafe_mlx_gen_orig_
#define mlx_stream_thread_local_new mlx_stream_thread_local_new_mlx_gen_orig_
#define mlx_stream_thread_local_set mlx_stream_thread_local_set_mlx_gen_orig_
#define mlx_stream_thread_local_free mlx_stream_thread_local_free_mlx_gen_orig_
#define mlx_stream_from_thread_local mlx_stream_from_thread_local_mlx_gen_orig_
#define mlx_get_streams mlx_get_streams_mlx_gen_orig_
#define mlx_stream_set mlx_stream_set_mlx_gen_orig_ #define mlx_stream_set mlx_stream_set_mlx_gen_orig_
#define mlx_stream_free mlx_stream_free_mlx_gen_orig_ #define mlx_stream_free mlx_stream_free_mlx_gen_orig_
#define mlx_stream_tostring mlx_stream_tostring_mlx_gen_orig_ #define mlx_stream_tostring mlx_stream_tostring_mlx_gen_orig_
@@ -596,6 +601,9 @@
#define mlx_stream_get_device mlx_stream_get_device_mlx_gen_orig_ #define mlx_stream_get_device mlx_stream_get_device_mlx_gen_orig_
#define mlx_stream_get_index mlx_stream_get_index_mlx_gen_orig_ #define mlx_stream_get_index mlx_stream_get_index_mlx_gen_orig_
#define mlx_synchronize mlx_synchronize_mlx_gen_orig_ #define mlx_synchronize mlx_synchronize_mlx_gen_orig_
#define mlx_synchronize_default mlx_synchronize_default_mlx_gen_orig_
#define mlx_synchronize_thread_local mlx_synchronize_thread_local_mlx_gen_orig_
#define mlx_clear_streams mlx_clear_streams_mlx_gen_orig_
#define mlx_get_default_stream mlx_get_default_stream_mlx_gen_orig_ #define mlx_get_default_stream mlx_get_default_stream_mlx_gen_orig_
#define mlx_set_default_stream mlx_set_default_stream_mlx_gen_orig_ #define mlx_set_default_stream mlx_set_default_stream_mlx_gen_orig_
#define mlx_default_cpu_stream_new mlx_default_cpu_stream_new_mlx_gen_orig_ #define mlx_default_cpu_stream_new mlx_default_cpu_stream_new_mlx_gen_orig_
@@ -659,6 +667,17 @@
#define mlx_vector_string_append_value mlx_vector_string_append_value_mlx_gen_orig_ #define mlx_vector_string_append_value mlx_vector_string_append_value_mlx_gen_orig_
#define mlx_vector_string_size mlx_vector_string_size_mlx_gen_orig_ #define mlx_vector_string_size mlx_vector_string_size_mlx_gen_orig_
#define mlx_vector_string_get mlx_vector_string_get_mlx_gen_orig_ #define mlx_vector_string_get mlx_vector_string_get_mlx_gen_orig_
#define mlx_vector_stream_new mlx_vector_stream_new_mlx_gen_orig_
#define mlx_vector_stream_set mlx_vector_stream_set_mlx_gen_orig_
#define mlx_vector_stream_free mlx_vector_stream_free_mlx_gen_orig_
#define mlx_vector_stream_new_data mlx_vector_stream_new_data_mlx_gen_orig_
#define mlx_vector_stream_new_value mlx_vector_stream_new_value_mlx_gen_orig_
#define mlx_vector_stream_set_data mlx_vector_stream_set_data_mlx_gen_orig_
#define mlx_vector_stream_set_value mlx_vector_stream_set_value_mlx_gen_orig_
#define mlx_vector_stream_append_data mlx_vector_stream_append_data_mlx_gen_orig_
#define mlx_vector_stream_append_value mlx_vector_stream_append_value_mlx_gen_orig_
#define mlx_vector_stream_size mlx_vector_stream_size_mlx_gen_orig_
#define mlx_vector_stream_get mlx_vector_stream_get_mlx_gen_orig_
#define mlx_version mlx_version_mlx_gen_orig_ #define mlx_version mlx_version_mlx_gen_orig_
#include "mlx/c/mlx.h" #include "mlx/c/mlx.h"
@@ -1247,6 +1266,11 @@
#undef mlx_stream_new #undef mlx_stream_new
#undef mlx_stream_new_device #undef mlx_stream_new_device
#undef mlx_stream_new_thread_unsafe #undef mlx_stream_new_thread_unsafe
#undef mlx_stream_thread_local_new
#undef mlx_stream_thread_local_set
#undef mlx_stream_thread_local_free
#undef mlx_stream_from_thread_local
#undef mlx_get_streams
#undef mlx_stream_set #undef mlx_stream_set
#undef mlx_stream_free #undef mlx_stream_free
#undef mlx_stream_tostring #undef mlx_stream_tostring
@@ -1254,6 +1278,9 @@
#undef mlx_stream_get_device #undef mlx_stream_get_device
#undef mlx_stream_get_index #undef mlx_stream_get_index
#undef mlx_synchronize #undef mlx_synchronize
#undef mlx_synchronize_default
#undef mlx_synchronize_thread_local
#undef mlx_clear_streams
#undef mlx_get_default_stream #undef mlx_get_default_stream
#undef mlx_set_default_stream #undef mlx_set_default_stream
#undef mlx_default_cpu_stream_new #undef mlx_default_cpu_stream_new
@@ -1317,6 +1344,17 @@
#undef mlx_vector_string_append_value #undef mlx_vector_string_append_value
#undef mlx_vector_string_size #undef mlx_vector_string_size
#undef mlx_vector_string_get #undef mlx_vector_string_get
#undef mlx_vector_stream_new
#undef mlx_vector_stream_set
#undef mlx_vector_stream_free
#undef mlx_vector_stream_new_data
#undef mlx_vector_stream_new_value
#undef mlx_vector_stream_set_data
#undef mlx_vector_stream_set_value
#undef mlx_vector_stream_append_data
#undef mlx_vector_stream_append_value
#undef mlx_vector_stream_size
#undef mlx_vector_stream_get
#undef mlx_version #undef mlx_version
extern size_t (*mlx_dtype_size_)(mlx_dtype dtype); extern size_t (*mlx_dtype_size_)(mlx_dtype dtype);
@@ -3717,6 +3755,15 @@ extern int (*mlx_random_uniform_)(
extern mlx_stream (*mlx_stream_new_)(void); extern mlx_stream (*mlx_stream_new_)(void);
extern mlx_stream (*mlx_stream_new_device_)(mlx_device dev); extern mlx_stream (*mlx_stream_new_device_)(mlx_device dev);
extern mlx_stream (*mlx_stream_new_thread_unsafe_)(mlx_device dev); extern mlx_stream (*mlx_stream_new_thread_unsafe_)(mlx_device dev);
extern mlx_stream_thread_local (*mlx_stream_thread_local_new_)(mlx_device dev);
extern int (*mlx_stream_thread_local_set_)(
mlx_stream_thread_local* tls,
const mlx_stream_thread_local src);
extern int (*mlx_stream_thread_local_free_)(mlx_stream_thread_local tls);
extern int (*mlx_stream_from_thread_local_)(
mlx_stream* res,
const mlx_stream_thread_local tls);
extern int (*mlx_get_streams_)(mlx_vector_stream* res);
extern int (*mlx_stream_set_)(mlx_stream* stream, const mlx_stream src); extern int (*mlx_stream_set_)(mlx_stream* stream, const mlx_stream src);
extern int (*mlx_stream_free_)(mlx_stream stream); extern int (*mlx_stream_free_)(mlx_stream stream);
extern int (*mlx_stream_tostring_)(mlx_string* str, mlx_stream stream); extern int (*mlx_stream_tostring_)(mlx_string* str, mlx_stream stream);
@@ -3724,6 +3771,9 @@ extern bool (*mlx_stream_equal_)(mlx_stream lhs, mlx_stream rhs);
extern int (*mlx_stream_get_device_)(mlx_device* dev, mlx_stream stream); extern int (*mlx_stream_get_device_)(mlx_device* dev, mlx_stream stream);
extern int (*mlx_stream_get_index_)(int* index, mlx_stream stream); extern int (*mlx_stream_get_index_)(int* index, mlx_stream stream);
extern int (*mlx_synchronize_)(mlx_stream stream); extern int (*mlx_synchronize_)(mlx_stream stream);
extern int (*mlx_synchronize_default_)(void);
extern int (*mlx_synchronize_thread_local_)(mlx_stream_thread_local tls);
extern int (*mlx_clear_streams_)(void);
extern int (*mlx_get_default_stream_)(mlx_stream* stream, mlx_device dev); extern int (*mlx_get_default_stream_)(mlx_stream* stream, mlx_device dev);
extern int (*mlx_set_default_stream_)(mlx_stream stream); extern int (*mlx_set_default_stream_)(mlx_stream stream);
extern mlx_stream (*mlx_default_cpu_stream_new_)(void); extern mlx_stream (*mlx_default_cpu_stream_new_)(void);
@@ -3856,6 +3906,28 @@ extern int (*mlx_vector_string_append_data_)(
extern int (*mlx_vector_string_append_value_)(mlx_vector_string vec, const char* val); extern int (*mlx_vector_string_append_value_)(mlx_vector_string vec, const char* val);
extern size_t (*mlx_vector_string_size_)(mlx_vector_string vec); extern size_t (*mlx_vector_string_size_)(mlx_vector_string vec);
extern int (*mlx_vector_string_get_)(char** res, const mlx_vector_string vec, size_t idx); extern int (*mlx_vector_string_get_)(char** res, const mlx_vector_string vec, size_t idx);
extern mlx_vector_stream (*mlx_vector_stream_new_)(void);
extern int (*mlx_vector_stream_set_)(mlx_vector_stream* vec, const mlx_vector_stream src);
extern int (*mlx_vector_stream_free_)(mlx_vector_stream vec);
extern mlx_vector_stream (*mlx_vector_stream_new_data_)(
const mlx_stream* data,
size_t size);
extern mlx_vector_stream (*mlx_vector_stream_new_value_)(const mlx_stream val);
extern int (*mlx_vector_stream_set_data_)(
mlx_vector_stream* vec,
const mlx_stream* data,
size_t size);
extern int (*mlx_vector_stream_set_value_)(mlx_vector_stream* vec, const mlx_stream val);
extern int (*mlx_vector_stream_append_data_)(
mlx_vector_stream vec,
const mlx_stream* data,
size_t size);
extern int (*mlx_vector_stream_append_value_)(mlx_vector_stream vec, const mlx_stream val);
extern size_t (*mlx_vector_stream_size_)(mlx_vector_stream vec);
extern int (*mlx_vector_stream_get_)(
mlx_stream* res,
const mlx_vector_stream vec,
size_t idx);
extern int (*mlx_version_)(mlx_string* str_); extern int (*mlx_version_)(mlx_string* str_);
int mlx_dynamic_load_symbols(mlx_dynamic_handle handle); int mlx_dynamic_load_symbols(mlx_dynamic_handle handle);
@@ -7426,6 +7498,25 @@ static inline mlx_stream mlx_stream_new_device(mlx_device dev) {
static inline mlx_stream mlx_stream_new_thread_unsafe(mlx_device dev) { static inline mlx_stream mlx_stream_new_thread_unsafe(mlx_device dev) {
return mlx_stream_new_thread_unsafe_(dev); return mlx_stream_new_thread_unsafe_(dev);
} }
static inline mlx_stream_thread_local mlx_stream_thread_local_new(mlx_device dev) {
return mlx_stream_thread_local_new_(dev);
}
static inline int mlx_stream_thread_local_set(
mlx_stream_thread_local* tls,
const mlx_stream_thread_local src) {
return mlx_stream_thread_local_set_(tls, src);
}
static inline int mlx_stream_thread_local_free(mlx_stream_thread_local tls) {
return mlx_stream_thread_local_free_(tls);
}
static inline int mlx_stream_from_thread_local(
mlx_stream* res,
const mlx_stream_thread_local tls) {
return mlx_stream_from_thread_local_(res, tls);
}
static inline int mlx_get_streams(mlx_vector_stream* res) {
return mlx_get_streams_(res);
}
static inline int mlx_stream_set(mlx_stream* stream, const mlx_stream src) { static inline int mlx_stream_set(mlx_stream* stream, const mlx_stream src) {
return mlx_stream_set_(stream, src); return mlx_stream_set_(stream, src);
} }
@@ -7447,6 +7538,15 @@ static inline int mlx_stream_get_index(int* index, mlx_stream stream) {
static inline int mlx_synchronize(mlx_stream stream) { static inline int mlx_synchronize(mlx_stream stream) {
return mlx_synchronize_(stream); return mlx_synchronize_(stream);
} }
static inline int mlx_synchronize_default(void) {
return mlx_synchronize_default_();
}
static inline int mlx_synchronize_thread_local(mlx_stream_thread_local tls) {
return mlx_synchronize_thread_local_(tls);
}
static inline int mlx_clear_streams(void) {
return mlx_clear_streams_();
}
static inline int mlx_get_default_stream(mlx_stream* stream, mlx_device dev) { static inline int mlx_get_default_stream(mlx_stream* stream, mlx_device dev) {
return mlx_get_default_stream_(stream, dev); return mlx_get_default_stream_(stream, dev);
} }
@@ -7705,6 +7805,50 @@ static inline size_t mlx_vector_string_size(mlx_vector_string vec) {
static inline int mlx_vector_string_get(char** res, const mlx_vector_string vec, size_t idx) { static inline int mlx_vector_string_get(char** res, const mlx_vector_string vec, size_t idx) {
return mlx_vector_string_get_(res, vec, idx); return mlx_vector_string_get_(res, vec, idx);
} }
static inline mlx_vector_stream mlx_vector_stream_new(void) {
return mlx_vector_stream_new_();
}
static inline int mlx_vector_stream_set(mlx_vector_stream* vec, const mlx_vector_stream src) {
return mlx_vector_stream_set_(vec, src);
}
static inline int mlx_vector_stream_free(mlx_vector_stream vec) {
return mlx_vector_stream_free_(vec);
}
static inline mlx_vector_stream mlx_vector_stream_new_data(
const mlx_stream* data,
size_t size) {
return mlx_vector_stream_new_data_(data, size);
}
static inline mlx_vector_stream mlx_vector_stream_new_value(const mlx_stream val) {
return mlx_vector_stream_new_value_(val);
}
static inline int mlx_vector_stream_set_data(
mlx_vector_stream* vec,
const mlx_stream* data,
size_t size) {
return mlx_vector_stream_set_data_(vec, data, size);
}
static inline int mlx_vector_stream_set_value(mlx_vector_stream* vec, const mlx_stream val) {
return mlx_vector_stream_set_value_(vec, val);
}
static inline int mlx_vector_stream_append_data(
mlx_vector_stream vec,
const mlx_stream* data,
size_t size) {
return mlx_vector_stream_append_data_(vec, data, size);
}
static inline int mlx_vector_stream_append_value(mlx_vector_stream vec, const mlx_stream val) {
return mlx_vector_stream_append_value_(vec, val);
}
static inline size_t mlx_vector_stream_size(mlx_vector_stream vec) {
return mlx_vector_stream_size_(vec);
}
static inline int mlx_vector_stream_get(
mlx_stream* res,
const mlx_vector_stream vec,
size_t idx) {
return mlx_vector_stream_get_(res, vec, idx);
}
static inline int mlx_version(mlx_string* str_) { static inline int mlx_version(mlx_string* str_) {
return mlx_version_(str_); return mlx_version_(str_);
} }
+6 -1
View File
@@ -7,7 +7,6 @@
#include <stddef.h> #include <stddef.h>
#include "mlx/c/string.h" #include "mlx/c/string.h"
#include "mlx/c/vector.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -26,6 +25,12 @@ typedef struct mlx_device_ {
void* ctx; void* ctx;
} mlx_device; } mlx_device;
/**
* A MLX vector of strings.
* Forward declaration to avoid circular references.
*/
typedef struct mlx_vector_string_ mlx_vector_string;
/** /**
* Device type. * Device type.
*/ */
+4 -4
View File
@@ -37,10 +37,10 @@ typedef struct mlx_io_vtable_ {
bool (*is_open)(void*); bool (*is_open)(void*);
bool (*good)(void*); bool (*good)(void*);
size_t (*tell)(void*); size_t (*tell)(void*);
void (*seek)(void*, int64_t off, int whence); int (*seek)(void*, int64_t off, int whence);
void (*read)(void*, char* data, size_t n); size_t (*read)(void*, char* data, size_t n);
void (*read_at_offset)(void*, char* data, size_t n, size_t off); size_t (*read_at_offset)(void*, char* data, size_t n, size_t off);
void (*write)(void*, const char* data, size_t n); size_t (*write)(void*, const char* data, size_t n);
const char* (*label)(void*); const char* (*label)(void*);
void (*free)(void*); void (*free)(void*);
} mlx_io_vtable; } mlx_io_vtable;
+59
View File
@@ -4,6 +4,7 @@
#define MLX_STREAM_H #define MLX_STREAM_H
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include "mlx/c/device.h" #include "mlx/c/device.h"
@@ -24,6 +25,22 @@ typedef struct mlx_stream_ {
void* ctx; void* ctx;
} mlx_stream; } mlx_stream;
/**
* A per-thread stream object.
*
* The same thread-local stream can be used from any number of threads; the
* stream's GPU command encoder is registered once per thread.
*/
typedef struct mlx_stream_thread_local_ {
void* ctx;
} mlx_stream_thread_local;
/**
* A vector of mlx_stream.
* Forward declaration to avoid circular references.
*/
typedef struct mlx_vector_stream_ mlx_vector_stream;
/** /**
* Returns a new empty stream. * Returns a new empty stream.
*/ */
@@ -45,6 +62,36 @@ mlx_stream mlx_stream_new_device(mlx_device dev);
* responsibility to ensure there are no data races on them. * responsibility to ensure there are no data races on them.
*/ */
mlx_stream mlx_stream_new_thread_unsafe(mlx_device dev); mlx_stream mlx_stream_new_thread_unsafe(mlx_device dev);
/**
* Returns a new per-thread stream on a device.
*
* Streams created this way are unique per thread: evaluating the same
* `mlx_stream_thread_local` from different threads yields distinct streams.
*/
mlx_stream_thread_local mlx_stream_thread_local_new(mlx_device dev);
/**
* Set a per-thread stream to the provided src stream.
*/
int mlx_stream_thread_local_set(
mlx_stream_thread_local* tls,
const mlx_stream_thread_local src);
/**
* Free a per-thread stream.
*/
int mlx_stream_thread_local_free(mlx_stream_thread_local tls);
/**
* Returns the concrete stream backing a per-thread stream on the current
* thread.
*/
int mlx_stream_from_thread_local(
mlx_stream* res,
const mlx_stream_thread_local tls);
/**
* Get the vector of available streams.
*/
int mlx_get_streams(mlx_vector_stream* res);
/** /**
* Set stream to provided src stream. * Set stream to provided src stream.
*/ */
@@ -73,6 +120,18 @@ int mlx_stream_get_index(int* index, mlx_stream stream);
* Synchronize with the provided stream. * Synchronize with the provided stream.
*/ */
int mlx_synchronize(mlx_stream stream); int mlx_synchronize(mlx_stream stream);
/**
* Synchronize with the default stream.
*/
int mlx_synchronize_default(void);
/**
* Synchronize with the stream corresponding to the current thread.
*/
int mlx_synchronize_thread_local(mlx_stream_thread_local tls);
/**
* Destroy all streams created in the current thread.
*/
int mlx_clear_streams(void);
/** /**
* Returns the default stream on the given device. * Returns the default stream on the given device.
*/ */
+30
View File
@@ -7,6 +7,7 @@
#define MLX_VECTOR_H #define MLX_VECTOR_H
#include "mlx/c/array.h" #include "mlx/c/array.h"
#include "mlx/c/stream.h"
#include "mlx/c/string.h" #include "mlx/c/string.h"
#ifdef __cplusplus #ifdef __cplusplus
@@ -124,6 +125,35 @@ int mlx_vector_string_append_value(mlx_vector_string vec, const char* val);
size_t mlx_vector_string_size(mlx_vector_string vec); size_t mlx_vector_string_size(mlx_vector_string vec);
int mlx_vector_string_get(char** res, const mlx_vector_string vec, size_t idx); int mlx_vector_string_get(char** res, const mlx_vector_string vec, size_t idx);
/**
* A vector of stream.
*/
typedef struct mlx_vector_stream_ {
void* ctx;
} mlx_vector_stream;
mlx_vector_stream mlx_vector_stream_new(void);
int mlx_vector_stream_set(mlx_vector_stream* vec, const mlx_vector_stream src);
int mlx_vector_stream_free(mlx_vector_stream vec);
mlx_vector_stream mlx_vector_stream_new_data(
const mlx_stream* data,
size_t size);
mlx_vector_stream mlx_vector_stream_new_value(const mlx_stream val);
int mlx_vector_stream_set_data(
mlx_vector_stream* vec,
const mlx_stream* data,
size_t size);
int mlx_vector_stream_set_value(mlx_vector_stream* vec, const mlx_stream val);
int mlx_vector_stream_append_data(
mlx_vector_stream vec,
const mlx_stream* data,
size_t size);
int mlx_vector_stream_append_value(mlx_vector_stream vec, const mlx_stream val);
size_t mlx_vector_stream_size(mlx_vector_stream vec);
int mlx_vector_stream_get(
mlx_stream* res,
const mlx_vector_stream vec,
size_t idx);
/**@}*/ /**@}*/
#ifdef __cplusplus #ifdef __cplusplus