-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp MLX C API #38
base: main
Are you sure you want to change the base?
Revamp MLX C API #38
Conversation
|
||
.. code-block:: c | ||
|
||
mlx_stream stream = mlx_gpu_stream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be destroyed? Maybe not since it isn't new
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think it needs to be freed -- the implementation of this is:
extern "C" mlx_stream mlx_gpu_stream() {
try {
return mlx_stream_new_(
/** | ||
* Get stream description. | ||
*/ | ||
mlx_string mlx_stream_tostring(mlx_device stream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mlx_string mlx_stream_tostring(mlx_device stream); | |
mlx_string mlx_stream_tostring(mlx_stream stream); |
int mlx_fast_metal_kernel_set_input_names( | ||
mlx_fast_metal_kernel cls, | ||
int num, | ||
...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per offline discussion swift can't call variadic C functions
const mlx_array a, | ||
const mlx_stream s) { | ||
try { | ||
std::tie(mlx_array_get_(*res_0), mlx_array_get_(*res_1)) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get:
MLX error: expected a non-empty mlx_array at mlx-swift2/Source/Cmlx/include/mlx/c/linalg.cpp:161
from calling like this:
public func qr(_ array: MLXArray, stream: StreamOrDevice = .default) -> (MLXArray, MLXArray) {
var r0 = mlx_array_new()
var r1 = mlx_array_new()
mlx_linalg_qr(&r0, &r1, array.ctx, stream.ctx)
return (MLXArray(r0), MLXArray(r1))
}
The mlx_array_get()
doesn't seem like it is meant to be used on out params.
mlx_fast_metal_kernel cls, | ||
const mlx_vector_array inputs, | ||
const mlx_stream stream, | ||
mlx_vector_array* outputs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per offline discussion this function doesn't match the pattern of other functions -- the out parameter is last instead of first.
const mlx_array key, | ||
const mlx_stream s) { | ||
try { | ||
std::tie(mlx_array_get_(*res_0), mlx_array_get_(*res_1)) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case of:
MLX error: expected a non-empty mlx_array at mlx-swift2/Source/Cmlx/include/mlx/c/random.cpp:281
I think mlx_array_get()
is not meant to be used on out parameters.
This introduces the new API of MLX C