-
Notifications
You must be signed in to change notification settings - Fork 55
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
[WIP] adopt new mlx-c api #150
Conversation
dcadeaf
to
b4b2572
Compare
let description = mlx_tostring(UnsafeMutableRawPointer(ptr))! | ||
defer { mlx_free(description) } | ||
return String(cString: mlx_string_data(description)) | ||
} |
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.
These no longer take opaque pointers -- the callers can use the mlx_
functions directly and don't need helpers.
} | ||
|
||
func mlx_vector_array_values(_ vector_array: mlx_vector_array) -> [MLXArray] { | ||
(0 ..< mlx_vector_array_size(vector_array)) | ||
.map { index in | ||
// ctx is a +1 object, the array takes ownership | ||
let ctx = mlx_vector_array_get(vector_array, index)! | ||
var ctx = mlx_array_new() | ||
mlx_vector_array_get(&ctx, vector_array, index) |
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.
99% of the changes in this PR are of this nature: adopt the new API
MLXArray(mlx_zeros(shape.map { Int32($0) }, shape.count, T.dtype.cmlxDtype, stream.ctx)) | ||
var result = mlx_array_new() | ||
mlx_zeros(&result, shape.map { Int32($0) }, shape.count, T.dtype.cmlxDtype, stream.ctx) | ||
return MLXArray(result) |
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.
This is a typical operation:
- create the result (
mlx_array_new()
) - call the function (
mlx_zeros
) - return the result, transfer ownership to it (
MLXArray(result)
)
@@ -14,7 +14,7 @@ This is https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz | |||
|
|||
This comes from https://developer.apple.com/metal/cpp/ specifically: | |||
|
|||
- https://developer.apple.com/metal/cpp/files/metal-cpp_macOS14.2_iOS17.2.zip | |||
- https://developer.apple.com/metal/cpp/files/metal-cpp_macOS15_iOS18-beta.zip |
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.
Picked up the current version of metal-cpp (per mlx requirements)
5d7cf03
to
dd0cc30
Compare
I'm a bit daunted by the size of the diff 😅 . I can peruse but (other than you inline comments) is there anything specific that would be good to have reviewed? |
It is mostly mechanical -- I was able to do a good chunk of the work with creative search and replace. The metal kernel code is the biggest change because the structure of the back end changed (and it is complicated anyway). It is big but mostly uninteresting. |
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.
Tests clear, LGTM. Thanks for getting this one done!!
Awesome, thanks for looking! I will merge and tag it in the morning. |
Adopt new API from ml-explore/mlx-c#38 and move to mlx v0.21.0 (just adopting API, not picking up new ops yet)
This is complete (now that mlx-c is tagged)