Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlx/compile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright © 2023-2024 Apple Inc.
#include <cstdlib>
#include <map>
#include <mutex>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -305,6 +306,7 @@ class CompilerCache {
const std::vector<array>& inputs,
bool shapeless,
const std::vector<uint64_t>& constants) {
std::lock_guard<std::mutex> guard(mtx_);
// Find the cache entries for |fun_id|.
std::vector<CacheEntry>& entries = cache_[fun_id];

Expand Down Expand Up @@ -353,10 +355,12 @@ class CompilerCache {
}

void erase(std::uintptr_t fun_id) {
std::lock_guard<std::mutex> guard(mtx_);
cache_.erase(fun_id);
}

void clear() {
std::lock_guard<std::mutex> guard(mtx_);
cache_.clear();
}

Expand All @@ -368,6 +372,7 @@ class CompilerCache {
}

friend CompilerCache& compiler_cache();
std::mutex mtx_;
std::unordered_map<std::uintptr_t, std::vector<CacheEntry>> cache_;
};

Expand Down