1515#include < sycl/detail/common.hpp>
1616#include < sycl/detail/locked.hpp>
1717#include < sycl/detail/os_util.hpp>
18+ #include < sycl/detail/spinlock.hpp>
1819#include < sycl/detail/ur.hpp>
1920#include < sycl/detail/util.hpp>
2021
@@ -421,7 +422,7 @@ class KernelProgramCache {
421422
422423 template <typename KeyT>
423424 KernelFastCacheValT tryToGetKernelFast (KeyT &&CacheKey) {
424- std::unique_lock<std::mutex> Lock (MKernelFastCacheMutex);
425+ KernelFastCacheReadLockT Lock (MKernelFastCacheMutex);
425426 auto It = MKernelFastCache.find (CacheKey);
426427 if (It != MKernelFastCache.end ()) {
427428 traceKernel (" Kernel fetched." , CacheKey.second , true );
@@ -445,7 +446,7 @@ class KernelProgramCache {
445446 return ;
446447 }
447448 // Save reference between the program and the fast cache key.
448- std::unique_lock<std::mutex> Lock (MKernelFastCacheMutex);
449+ KernelFastCacheWriteLockT Lock (MKernelFastCacheMutex);
449450 MProgramToKernelFastCacheKeyMap[Program].emplace_back (CacheKey);
450451
451452 // if no insertion took place, thus some other thread has already inserted
@@ -483,7 +484,7 @@ class KernelProgramCache {
483484
484485 {
485486 // Remove corresponding entries from KernelFastCache.
486- std::unique_lock<std::mutex> Lock (MKernelFastCacheMutex);
487+ KernelFastCacheWriteLockT Lock (MKernelFastCacheMutex);
487488 if (auto FastCacheKeyItr =
488489 MProgramToKernelFastCacheKeyMap.find (NativePrg);
489490 FastCacheKeyItr != MProgramToKernelFastCacheKeyMap.end ()) {
@@ -630,7 +631,7 @@ class KernelProgramCache {
630631 std::lock_guard<std::mutex> EvictionListLock (MProgramEvictionListMutex);
631632 std::lock_guard<std::mutex> L1 (MProgramCacheMutex);
632633 std::lock_guard<std::mutex> L2 (MKernelsPerProgramCacheMutex);
633- std::lock_guard<std::mutex> L3 (MKernelFastCacheMutex);
634+ KernelFastCacheWriteLockT L3 (MKernelFastCacheMutex);
634635 MCachedPrograms = ProgramCache{};
635636 MKernelsPerProgramCache = KernelCacheT{};
636637 MKernelFastCache = KernelFastCacheT{};
@@ -758,7 +759,10 @@ class KernelProgramCache {
758759 KernelCacheT MKernelsPerProgramCache;
759760 ContextPtr MParentContext;
760761
761- std::mutex MKernelFastCacheMutex;
762+ using KernelFastCacheMutexT = SpinLock;
763+ using KernelFastCacheReadLockT = std::lock_guard<KernelFastCacheMutexT>;
764+ using KernelFastCacheWriteLockT = std::lock_guard<KernelFastCacheMutexT>;
765+ KernelFastCacheMutexT MKernelFastCacheMutex;
762766 KernelFastCacheT MKernelFastCache;
763767
764768 // Map between fast kernel cache keys and program handle.
0 commit comments