Skip to content
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

Fix shared library not exporting symbols on Windows #1684

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ if(MSVC)
target_compile_options(mlx PUBLIC /wd4068 /wd4244 /wd4267 /wd4804)
endif()

if(WIN32)
# Export symbols by default to behave like macOS/linux.
set_target_properties(mlx PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()

if(MLX_BUILD_CPU)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backend/common)
else()
Expand Down
9 changes: 6 additions & 3 deletions mlx/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ inline void PrintFormatter::print(std::ostream& os, complex64_t val) {
os << val;
}

PrintFormatter global_formatter;
PrintFormatter& get_global_formatter() {
static PrintFormatter formatter;
return formatter;
}

Dtype result_type(const std::vector<array>& arrays) {
Dtype t = bool_;
Expand Down Expand Up @@ -171,7 +174,7 @@ void print_subarray(std::ostream& os, const array& a, size_t index, int dim) {
i = n - num_print - 1;
index += s * (n - 2 * num_print - 1);
} else if (is_last) {
global_formatter.print(os, a.data<T>()[index]);
get_global_formatter().print(os, a.data<T>()[index]);
} else {
print_subarray<T>(os, a, index, dim + 1);
}
Expand All @@ -187,7 +190,7 @@ void print_array(std::ostream& os, const array& a) {
os << "array(";
if (a.ndim() == 0) {
auto data = a.data<T>();
global_formatter.print(os, data[0]);
get_global_formatter().print(os, data[0]);
} else {
print_subarray<T>(os, a, 0, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion mlx/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct PrintFormatter {
bool capitalize_bool{false};
};

extern PrintFormatter global_formatter;
PrintFormatter& get_global_formatter();

/** The type from promoting the arrays' types with one another. */
inline Dtype result_type(const array& a, const array& b) {
Expand Down
2 changes: 1 addition & 1 deletion python/src/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ArrayPythonIterator {

void init_array(nb::module_& m) {
// Set Python print formatting options
mlx::core::global_formatter.capitalize_bool = true;
get_global_formatter().capitalize_bool = true;

// Types
nb::class_<Dtype>(
Expand Down