From 343ddf0d738a716f8563fe93e0ff371b55c181cf Mon Sep 17 00:00:00 2001 From: Cheng Date: Tue, 27 Jan 2026 08:53:26 +0900 Subject: [PATCH] Fix long cache file path on Windows (#3065) --- .gitignore | 21 +++++++-------------- mlx/backend/cuda/jit_module.cpp | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 43629548..1daaa46d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,16 +3,12 @@ __pycache__/ *.py[cod] *$py.class -# C extensions -*.so - # tensor files *.safe *.safetensors # Metal libraries *.metallib -venv/ # Distribution / packaging python/mlx/core @@ -30,6 +26,7 @@ lib64/ parts/ sdist/ var/ +venv/ wheels/ share/python-wheels/ *.egg-info/ @@ -37,12 +34,7 @@ share/python-wheels/ *.egg MANIFEST uv.lock - -# vim -*.swp - -# Ignore build dir -build/ +.DS_Store # Prerequisites *.d @@ -52,6 +44,7 @@ build/ *.lo *.o *.obj +*.ilk # Precompiled Headers *.gch @@ -80,9 +73,9 @@ build/ # Debug symbols *.pdb -# VSCode +# VSCode .vscode/ -.DS_Store - # Jetbrains -.cache +.cache/ +# vim +*.swp diff --git a/mlx/backend/cuda/jit_module.cpp b/mlx/backend/cuda/jit_module.cpp index 39d5e878..6cd8231c 100644 --- a/mlx/backend/cuda/jit_module.cpp +++ b/mlx/backend/cuda/jit_module.cpp @@ -79,6 +79,18 @@ const std::filesystem::path& ptx_cache_dir() { cache = std::filesystem::temp_directory_path() / "mlx" / version() / "ptx"; } + +#if defined(_WIN32) + // Add "\\?\" prefix to support long file path. + const wchar_t* long_path_prefix = L"\\\\?\\"; + if (cache.is_relative()) { + cache = std::filesystem::absolute(cache); + } + if (!cache.native().starts_with(long_path_prefix)) { + cache = long_path_prefix + cache.native(); + } +#endif + if (!std::filesystem::exists(cache)) { std::error_code error; if (!std::filesystem::create_directories(cache, error)) { @@ -93,12 +105,7 @@ const std::filesystem::path& ptx_cache_dir() { std::filesystem::path get_ptx_path( const std::filesystem::path& cache_dir, const std::string& module_name) { -#ifdef _WIN32 - constexpr int max_file_name_length = 140; -#else constexpr int max_file_name_length = 245; -#endif - if (module_name.size() <= max_file_name_length) { return cache_dir / (module_name + ".ptx"); }