diff --git a/mlx/distributed/ibv/CMakeLists.txt b/mlx/distributed/ibv/CMakeLists.txt index 2ed69c075..7db9d3337 100644 --- a/mlx/distributed/ibv/CMakeLists.txt +++ b/mlx/distributed/ibv/CMakeLists.txt @@ -1,2 +1,8 @@ -target_sources(mlx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ibv.cpp) -target_link_libraries(mlx PRIVATE rdma) +if(MLX_BUILD_CPU + AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" + AND MACOS_SDK_VERSION GREATER_EQUAL 26.2) + target_sources(mlx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ibv.cpp) + target_link_libraries(mlx PRIVATE rdma) +else() + target_sources(mlx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/no_ibv.cpp) +endif() diff --git a/mlx/distributed/ibv/ibv.cpp b/mlx/distributed/ibv/ibv.cpp index 84671c694..447ba7d2e 100644 --- a/mlx/distributed/ibv/ibv.cpp +++ b/mlx/distributed/ibv/ibv.cpp @@ -1077,7 +1077,9 @@ class IBVGroup : public GroupImpl { }; bool is_available() { - return true; + if (__builtin_available(macOS 26.2, *)) { + return true; + } } std::shared_ptr init(bool strict /* = false */) { diff --git a/mlx/distributed/ibv/no_ibv.cpp b/mlx/distributed/ibv/no_ibv.cpp new file mode 100644 index 000000000..2d2c00f95 --- /dev/null +++ b/mlx/distributed/ibv/no_ibv.cpp @@ -0,0 +1,20 @@ +// Copyright © 2025 Apple Inc. + +#include "mlx/distributed/ibv/ibv.h" + +namespace mlx::core::distributed::ibv { + +using GroupImpl = mlx::core::distributed::detail::GroupImpl; + +bool is_available() { + return false; +} + +std::shared_ptr init(bool strict /* = false */) { + if (strict) { + throw std::runtime_error("Cannot initialize ibv distributed backend."); + } + return nullptr; +} + +} // namespace mlx::core::distributed::ibv