diff --git a/sycl/source/detail/kernel_program_cache.hpp b/sycl/source/detail/kernel_program_cache.hpp index 0ce1761c27d28..d204fec6f0add 100644 --- a/sycl/source/detail/kernel_program_cache.hpp +++ b/sycl/source/detail/kernel_program_cache.hpp @@ -129,11 +129,44 @@ class KernelProgramCache { using CommonProgramKeyT = std::pair>; + // A custom hashing and equality function for ProgramCacheKeyT. + // These are used to compare and hash the keys in the cache. + struct ProgramCacheKeyHash { + std::size_t operator()(const ProgramCacheKeyT &Key) const { + std::size_t Hash = 0; + // Hash the serialized object, representing spec consts. + for (const auto &Elem : Key.first.first) + Hash ^= std::hash{}(Elem); + + // Hash the imageId. + Hash ^= std::hash{}(Key.first.second); + + // Hash the devices. + for (const auto &Elem : Key.second) + Hash ^= std::hash{}(static_cast(Elem)); + return Hash; + } + }; + + struct ProgramCacheKeyEqual { + bool operator()(const ProgramCacheKeyT &LHS, + const ProgramCacheKeyT &RHS) const { + // Check equality of SerializedObj (Spec const) + return std::equal(LHS.first.first.begin(), LHS.first.first.end(), + RHS.first.first.begin()) && + // Check equality of imageId + LHS.first.second == RHS.first.second && + // Check equality of devices + std::equal(LHS.second.begin(), LHS.second.end(), + RHS.second.begin(), RHS.second.end()); + } + }; + struct ProgramCache { ::boost::unordered_map Cache; ::boost::unordered_multimap KeyMap; // Mapping between a UR program and its size. - ::boost::unordered_map ProgramSizeMap; + std::unordered_map ProgramSizeMap; size_t ProgramCacheSizeInBytes = 0; inline size_t GetProgramCacheSizeInBytes() const noexcept { @@ -191,8 +224,8 @@ class KernelProgramCache { std::list MProgramEvictionList; // Mapping between program handle and the iterator to the eviction list. - ::boost::unordered_map::iterator> + std::unordered_map::iterator, + ProgramCacheKeyHash, ProgramCacheKeyEqual> MProgramToEvictionListMap; void clear() { diff --git a/sycl/unittests/kernel-and-program/InMemCacheEviction.cpp b/sycl/unittests/kernel-and-program/InMemCacheEviction.cpp index 0557dbad1ec21..a0009ede33756 100644 --- a/sycl/unittests/kernel-and-program/InMemCacheEviction.cpp +++ b/sycl/unittests/kernel-and-program/InMemCacheEviction.cpp @@ -168,7 +168,7 @@ TEST(InMemCacheEvictionTests, TestConcurrentEvictionSameQueue) { queue q(Ctx, default_selector_v); // One program is of 10000 bytes, so 20005 eviction threshold can - // accommodate two program. + // accommodate two programs. setCacheEvictionEnv("20005"); constexpr size_t ThreadCount = 200;