From df6e22d3393d858ba78daff5eef08ac8f7237e37 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Tue, 3 Feb 2026 13:55:07 -0800 Subject: [PATCH 1/2] Disable managed memory on WSL when concurrentManagedAccess is not supported Extend the Windows managed memory check from #3075 to also apply to WSL, as the underlying behavior is the same. --- mlx/backend/cuda/allocator.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/mlx/backend/cuda/allocator.cpp b/mlx/backend/cuda/allocator.cpp index b4ea473e9a..653183d846 100644 --- a/mlx/backend/cuda/allocator.cpp +++ b/mlx/backend/cuda/allocator.cpp @@ -12,6 +12,8 @@ #include #include +#include +#include namespace mlx::core { @@ -26,6 +28,29 @@ constexpr int small_block_size = 8; // size and small_block_size. constexpr int small_pool_size = 4 * page_size; +// Check if running on Windows or Windows Subsystem for Linux +bool is_windows() { +#if defined(_WIN32) + return true; +#elif defined(__linux__) + // WSL kernels contain "microsoft" or "WSL" in /proc/version + static bool is_wsl = []() { + std::ifstream version("/proc/version"); + if (version.is_open()) { + std::string line; + std::getline(version, line); + return line.find("microsoft") != std::string::npos || + line.find("Microsoft") != std::string::npos || + line.find("WSL") != std::string::npos; + } + return false; + }(); + return is_wsl; +#else + return false; +#endif +} + bool supports_managed_memory() { static bool managed_memory = []() { int device_count = gpu::device_count(); @@ -34,13 +59,11 @@ bool supports_managed_memory() { if (!d.managed_memory()) { return false; } -#if defined(_WIN32) - // Empirically on Windows if there is no concurrentManagedAccess the - // managed memory also does not work. - if (!d.concurrent_managed_access()) { + // Empirically on Windows (and WSL) if there is no concurrentManagedAccess + // the managed memory also does not work. + if (is_windows() && !d.concurrent_managed_access()) { return false; } -#endif } return true; }(); From 7f18bc4d667fa3fc56df66135f51a62d436bb739 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Tue, 3 Feb 2026 15:04:02 -0800 Subject: [PATCH 2/2] lint --- mlx/backend/cuda/allocator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlx/backend/cuda/allocator.cpp b/mlx/backend/cuda/allocator.cpp index 653183d846..5dcca43cde 100644 --- a/mlx/backend/cuda/allocator.cpp +++ b/mlx/backend/cuda/allocator.cpp @@ -40,8 +40,8 @@ bool is_windows() { std::string line; std::getline(version, line); return line.find("microsoft") != std::string::npos || - line.find("Microsoft") != std::string::npos || - line.find("WSL") != std::string::npos; + line.find("Microsoft") != std::string::npos || + line.find("WSL") != std::string::npos; } return false; }();