-
Notifications
You must be signed in to change notification settings - Fork 1.5k
win: symbol exports and minor fixes #3024
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
base: main
Are you sure you want to change the base?
Conversation
zcbenz
left a comment
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.
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={})
mlx/random.cpp
Outdated
| T f = T(1.0); | ||
| uint16_t* m = (uint16_t*)&f; | ||
| *m -= 1; | ||
| f.bits_ -= 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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
tests/linalg_tests.cpp
Outdated
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| struct MLX_API TypeToDtype { | |
| struct TypeToDtype { |
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.
The template specializations are defined in dtype.cpp and called from Python bindings across the DLL boundary.
mlx/event.h
Outdated
| #include <memory> | ||
| #include <stdexcept> | ||
|
|
||
| #include "mlx/mlx_export.h" |
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.
| #include "mlx/mlx_export.h" |
mlx/event.h
Outdated
| namespace mlx::core { | ||
|
|
||
| class Event { | ||
| class MLX_API Event { |
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.
| class MLX_API Event { | |
| class Event { |
mlx/fence.h
Outdated
| * iOS 18+). | ||
| */ | ||
| class Fence { | ||
| class MLX_API Fence { |
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.
| class MLX_API Fence { | |
| class Fence { |
mlx/fence.h
Outdated
| #include <vector> | ||
|
|
||
| #include "mlx/array.h" | ||
| #include "mlx/mlx_export.h" |
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.
| #include "mlx/mlx_export.h" |
| }; | ||
|
|
||
| class ArgReduce : public UnaryPrimitive { | ||
| class MLX_API ArgReduce : public UnaryPrimitive { |
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.
| class MLX_API ArgReduce : public UnaryPrimitive { | |
| class ArgReduce : public UnaryPrimitive { |
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.
Used directly by the C++ test suite (arg_reduce_tests.cpp)
mlx/primitives.h
Outdated
|
|
||
| // Abstract base class | ||
| class Primitive { | ||
| class MLX_API Primitive { |
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.
| class MLX_API Primitive { | |
| class Primitive { |
mlx/primitives.h
Outdated
| #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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #include "mlx/mlx_export.h" |
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_API used elsewhere in the file.
| } | ||
|
|
||
| Scheduler& scheduler(); | ||
| MLX_API Scheduler& scheduler(); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used directly by the C++ test suite (scheduler_tests.cpp)
mlx/utils.h
Outdated
| namespace env { | ||
|
|
||
| int get_var(const char* name, int default_value); | ||
| MLX_API int get_var(const char* name, int default_value); |
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.
Probably shouldn't expose that one.
| MLX_API int | ||
| normalize_axis_index(int axis, int ndim, const std::string& msg_prefix = ""); |
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_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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used directly by the C++ test suite (utils_tests.cpp)
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.
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
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