Skip to content

Commit

Permalink
Shorter kernel name for Windows (#1701)
Browse files Browse the repository at this point in the history
* Shorter kernel name for Windows

* Only hash the clipped part
  • Loading branch information
zcbenz authored Dec 18, 2024
1 parent c8fb549 commit 070bd43
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mlx/backend/common/compiled_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ 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
<< std::string_view(kernel_name).substr(0, max_file_name_length - 16);
auto file_id = std::hash<std::string>{}(kernel_name);
auto file_id =
std::hash<std::string>{}(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 {
Expand Down

0 comments on commit 070bd43

Please sign in to comment.