From 5cf984ca87bc65eeb1852b16a17129856214d6d9 Mon Sep 17 00:00:00 2001 From: Cheng Date: Wed, 27 Aug 2025 11:25:15 +0900 Subject: [PATCH] Separate cpu compilation cache by versions (#2548) --- mlx/backend/cpu/compiled.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mlx/backend/cpu/compiled.cpp b/mlx/backend/cpu/compiled.cpp index a21819ac0..53d6c47e3 100644 --- a/mlx/backend/cpu/compiled.cpp +++ b/mlx/backend/cpu/compiled.cpp @@ -15,6 +15,7 @@ #include "mlx/backend/cpu/jit_compiler.h" #include "mlx/device.h" #include "mlx/graph_utils.h" +#include "mlx/version.h" namespace mlx::core { @@ -94,7 +95,11 @@ void* compile( kernel_file_name = kernel_name; } - auto output_dir = std::filesystem::temp_directory_path(); + auto output_dir = + std::filesystem::temp_directory_path() / "mlx" / version() / "cpu"; + if (!std::filesystem::exists(output_dir)) { + std::filesystem::create_directories(output_dir); + } std::string shared_lib_name = "lib" + kernel_file_name + ".so"; auto shared_lib_path = (output_dir / shared_lib_name).string();