win: symbol exports and minor fixes - #3024
Conversation
zcbenz
left a comment
There was a problem hiding this comment.
The documentation generator does not seem to recognize the macro:
/home/runner/work/mlx/mlx/docs/src/cpp/ops.rst:6: WARNING: Error when parsing function declaration.
If the function has no return type:
Error in declarator or parameters-and-qualifiers
Invalid C++ declaration: Expecting "(" in parameters-and-qualifiers. [error at 8]
MLX_API array roll (const array &a, const Shape &shift, const std::vector< int > &axes, StreamOrDevice s={})
| T f = T(1.0); | ||
| uint16_t* m = (uint16_t*)&f; | ||
| *m -= 1; | ||
| f.bits_ -= 1; |
There was a problem hiding this comment.
This does not work on mac:
/Users/runner/actions-runner/_work/mlx/mlx/mlx/random.cpp:92:4: error: member reference base type '__fp16' is not a structure or union
92 | f.bits_ -= 1;
| ~^~~~~~
/Users/runner/actions-runner/_work/mlx/mlx/mlx/random.cpp:128:22: note: in instantiation of function template specialization 'mlx::core::random::below_one<__fp16>' requested here
128 | return array(below_one<float16_t>(), float32);
| ^
There was a problem hiding this comment.
I couldn't find a good pattern for this one, so I backed it out. As a result, there's one known test failure:
C:\Users\danie\code\mlx\tests\random_tests.cpp(244):
TEST CASE: test random uniform
C:\Users\danie\code\mlx\tests\random_tests.cpp(368): ERROR: CHECK( abs(float(mean(out).item<bfloat16_t>()) - 0.5f) < 0.02 ) is NOT correct!
values: CHECK( 0.244141 < 0.02 )
There was a problem hiding this comment.
I can reproduce this failure on Mac running CPP tests with CPU, and it is also failing on Windows. /cc @awni
|
Properly exporting public APIs on Windows requires adding a |
01ce4ed to
395591d
Compare
zcbenz
left a comment
There was a problem hiding this comment.
Looks good to me, thanks for putting this together!
We still need a few more reviews before merging though.
| @@ -0,0 +1,31 @@ | |||
| // Copyright © 2024 Apple Inc. | |||
There was a problem hiding this comment.
Can we change the name of this file to api.h or mlx_api.h if you prefer? mlx_export.h is conflated a bit with export.h which is for function exports.
| // Note: When TF32 is enabled (default on CUDA/Metal for performance), | ||
| // matmul has ~1e-3 precision instead of ~1e-7. Use 1e-3 tolerance to | ||
| // accommodate this. The test verifies SVD correctness, not matmul precision. |
There was a problem hiding this comment.
We usually run the tests with TF32 disabled. It's basically the main reason we have environment flags for that. Where did you notice this failing?
|
I think I'm ok with the MLX_API macro. One thing I observed is that it is infront of most functions in the top-level headers. Is that necessary even for functions which we don't really intend to be part of the API? |
No, we only need to export functions that we expect users to explicitly use. |
|
|
||
| template <typename T> | ||
| struct TypeToDtype { | ||
| struct MLX_API TypeToDtype { |
There was a problem hiding this comment.
| struct MLX_API TypeToDtype { | |
| struct TypeToDtype { |
There was a problem hiding this comment.
The template specializations are defined in dtype.cpp and called from Python bindings across the DLL boundary.
| #include <memory> | ||
| #include <stdexcept> | ||
|
|
||
| #include "mlx/mlx_export.h" |
There was a problem hiding this comment.
| #include "mlx/mlx_export.h" |
| namespace mlx::core { | ||
|
|
||
| class Event { | ||
| class MLX_API Event { |
There was a problem hiding this comment.
| class MLX_API Event { | |
| class Event { |
| * iOS 18+). | ||
| */ | ||
| class Fence { | ||
| class MLX_API Fence { |
There was a problem hiding this comment.
| class MLX_API Fence { | |
| class Fence { |
| #include <vector> | ||
|
|
||
| #include "mlx/array.h" | ||
| #include "mlx/mlx_export.h" |
There was a problem hiding this comment.
| #include "mlx/mlx_export.h" |
| }; | ||
|
|
||
| class ArgReduce : public UnaryPrimitive { | ||
| class MLX_API ArgReduce : public UnaryPrimitive { |
There was a problem hiding this comment.
| class MLX_API ArgReduce : public UnaryPrimitive { | |
| class ArgReduce : public UnaryPrimitive { |
There was a problem hiding this comment.
Used directly by the C++ test suite (arg_reduce_tests.cpp)
|
|
||
| // Abstract base class | ||
| class Primitive { | ||
| class MLX_API Primitive { |
There was a problem hiding this comment.
| class MLX_API Primitive { | |
| class Primitive { |
| #include "mlx/array.h" | ||
| #include "mlx/device.h" | ||
| #include "mlx/io/load.h" | ||
| #include "mlx/mlx_export.h" |
There was a problem hiding this comment.
| #include "mlx/mlx_export.h" |
There was a problem hiding this comment.
MLX_API used elsewhere in the file.
| } | ||
|
|
||
| Scheduler& scheduler(); | ||
| MLX_API Scheduler& scheduler(); |
There was a problem hiding this comment.
Did you add that one for a specific reason? Like would some test fail if we remove it?
There was a problem hiding this comment.
Used directly by the C++ test suite (scheduler_tests.cpp)
| MLX_API int | ||
| normalize_axis_index(int axis, int ndim, const std::string& msg_prefix = ""); |
There was a problem hiding this comment.
| MLX_API int | |
| normalize_axis_index(int axis, int ndim, const std::string& msg_prefix = ""); | |
| int | |
| normalize_axis_index(int axis, int ndim, const std::string& msg_prefix = ""); |
There was a problem hiding this comment.
Used directly by the C++ test suite (utils_tests.cpp)
There was a problem hiding this comment.
Gotcha - ok for those ones I might do a follow up PR to make the tests a little less intrusive. But it's also not a big deal so let's 🚢
|
I went through and suggested we remove a few of the MLX_API. If they were needed for a test failure or something then feel free to disregard the suggestion. So basically two comments:
|
|
Otherwise LGTM! Thanks for the change! |
Also fixes DLL dependencies for test tools
395591d to
00409dd
Compare
|
@awni Would you need another review or are we good to merge? |
|
Good to go on my end. Thanks for making the changes @dhiltgen. We can merge as soon as the tests clear. |
Co-authored-by: Cheng <zcbenz@gmail.com>
Proposed changes
This PR extracts the non-CUDA portions of #2972 for Windows support.
Test results (known GGUF library incompatibility on Windows)
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes