From 8c92bcb69380a25b2f167052637c6fafe89da18a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 14 Dec 2024 04:34:36 +0000 Subject: [PATCH 1/2] Shorter kernel name for Windows --- mlx/backend/common/compiled_cpu.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mlx/backend/common/compiled_cpu.cpp b/mlx/backend/common/compiled_cpu.cpp index 853617f5a..5c31f620e 100644 --- a/mlx/backend/common/compiled_cpu.cpp +++ b/mlx/backend/common/compiled_cpu.cpp @@ -68,10 +68,14 @@ void* compile( std::string source_code = source_builder(); std::string kernel_file_name; - // Deal with long kernel names. Maximum length for files on macOS is 255 - // characters. Clip file name with a little extra room and append a 16 - // character hash. + // Deal with long kernel names. Maximum length for filename on macOS is 255 + // characters, and on Windows the maximum length for whole path is 260. Clip + // file name with a little extra room and append a 16 character hash. +#ifdef _WIN32 + constexpr int max_file_name_length = 140; +#else constexpr int max_file_name_length = 245; +#endif if (kernel_name.size() > max_file_name_length) { std::ostringstream file_name; file_name From 0fc68f583b3a371f90fe7263da1c69b7f5319f8a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 18 Dec 2024 01:08:45 +0000 Subject: [PATCH 2/2] Only hash the clipped part --- mlx/backend/common/compiled_cpu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mlx/backend/common/compiled_cpu.cpp b/mlx/backend/common/compiled_cpu.cpp index 5c31f620e..eb08d070d 100644 --- a/mlx/backend/common/compiled_cpu.cpp +++ b/mlx/backend/common/compiled_cpu.cpp @@ -80,7 +80,8 @@ void* compile( std::ostringstream file_name; file_name << std::string_view(kernel_name).substr(0, max_file_name_length - 16); - auto file_id = std::hash{}(kernel_name); + auto file_id = + std::hash{}(kernel_name.substr(max_file_name_length - 16)); file_name << "_" << std::hex << std::setw(16) << file_id << std::dec; kernel_file_name = file_name.str(); } else {