Skip to content
Draft
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@ void shutdown_early(bool CanJoinThreads = true) {
GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool.Inst.reset(nullptr);
}

// Reset in-memory cache before releasing default contexts.
{
// Keeping the default context for platforms in the global cache to avoid
// shared_ptr based circular dependency between platform and context classes
std::lock_guard<std::mutex> Lock{
GlobalHandler::RTGlobalObjHandler
->getPlatformToDefaultContextCacheMutex()};

auto &PlatformToDefaultContextCache =
GlobalHandler::RTGlobalObjHandler->getPlatformToDefaultContextCache();

for (auto &Pair : PlatformToDefaultContextCache) {
Pair.second->getKernelProgramCache().reset();
}
}

// This releases OUR reference to the default context, but
// other may yet have refs
GlobalHandler::RTGlobalObjHandler->releaseDefaultContexts();
Expand Down
11 changes: 5 additions & 6 deletions sycl/source/detail/kernel_program_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,8 @@ class KernelProgramCache {

traceProgram("Program evicted.", CacheKey);
} else
// This should never happen.
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"Program not found in the cache.");
// This can happen if we try to remove cache entries after early shutdown.
return 0;

return MCachedPrograms.ProgramCacheSizeInBytes;
}
Expand Down Expand Up @@ -684,9 +683,9 @@ class KernelProgramCache {
std::lock_guard<std::mutex> L1(MProgramCacheMutex);
std::lock_guard<std::mutex> L2(MKernelsPerProgramCacheMutex);
FastKernelCacheWriteLockT L3(MFastKernelCacheMutex);
MCachedPrograms = ProgramCache{};
MKernelsPerProgramCache = KernelCacheT{};
MFastKernelCache = FastKernelCacheT{};
MCachedPrograms.Cache.clear();
MKernelsPerProgramCache.clear();
MFastKernelCache.clear();
MProgramToFastKernelCacheKeyMap.clear();
// Clear the eviction lists and its mutexes.
MEvictionList.clear();
Expand Down
Loading