20 template <
typename CompilationContext>
23 std::lock_guard<std::mutex> lock(code_cache_mutex_);
25 auto it = code_cache_.find(key);
26 if (it != code_cache_.cend()) {
28 VLOG(1) << name_ <<
": Reuse cached compiled kernel";
34 template <
typename CompilationContext>
39 std::lock_guard<std::mutex> lock(code_cache_mutex_);
41 auto it = code_cache_.find(key);
43 if (it == code_cache_.cend()) {
44 VLOG(1) << name_ <<
": Add compiled kernel to code cache";
45 evict_count_ += code_cache_.put(key, value);
52 LOG(
WARNING) << *
this <<
": code already in cache, ignoring.\n";
58 template <
typename CompilationContext>
61 std::unique_lock<std::mutex> lk(code_cache_mutex_);
63 if (
auto* cached_code = code_cache_.get(key)) {
64 if (!cached_code->get()) {
73 compilation_cv_.wait(lk, [=] {
return cached_code->get(); });
76 CHECK(cached_code->get());
79 VLOG(1) << name_ <<
": Reuse a cached compiled code";
87 evict_count_ += code_cache_.put(key, std::move(not_a_code));
93 template <
typename CompilationContext>
97 std::lock_guard<std::mutex> lock(code_cache_mutex_);
98 auto result = code_cache_.get(key);
101 *
result = std::move(value);
102 compilation_cv_.notify_all();
105 template <
typename CompilationContext>
107 std::lock_guard<std::mutex> lock(code_cache_mutex_);
108 code_cache_.erase(key);
109 compilation_cv_.notify_all();
112 template <
typename CompilationContext>
114 std::lock_guard<std::mutex> lock(code_cache_mutex_);
std::shared_ptr< CC > CodeCacheVal
CodeCacheVal< CompilationContext > get_value(const CodeCacheKey &key)
std::vector< std::string > CodeCacheKey
bool put(const CodeCacheKey &key, CodeCacheVal< CompilationContext > &value)
void reset(const CodeCacheKey &key, CodeCacheVal< CompilationContext > value)
CodeCacheVal< CompilationContext > * get_or_wait(const CodeCacheKey &key)
void erase(const CodeCacheKey &key)