@@ -129,11 +129,44 @@ class KernelProgramCache {
129129 using CommonProgramKeyT =
130130 std::pair<std::uintptr_t , std::set<ur_device_handle_t >>;
131131
132+ // A custom hashing and equality function for ProgramCacheKeyT.
133+ // These are used to compare and hash the keys in the cache.
134+ struct ProgramCacheKeyHash {
135+ std::size_t operator ()(const ProgramCacheKeyT &Key) const {
136+ std::size_t Hash = 0 ;
137+ // Hash the serialized object, representing spec consts.
138+ for (const auto &Elem : Key.first .first )
139+ Hash ^= std::hash<unsigned char >{}(Elem);
140+
141+ // Hash the imageId.
142+ Hash ^= std::hash<std::uintptr_t >{}(Key.first .second );
143+
144+ // Hash the devices.
145+ for (const auto &Elem : Key.second )
146+ Hash ^= std::hash<void *>{}(static_cast <void *>(Elem));
147+ return Hash;
148+ }
149+ };
150+
151+ struct ProgramCacheKeyEqual {
152+ bool operator ()(const ProgramCacheKeyT &LHS,
153+ const ProgramCacheKeyT &RHS) const {
154+ // Check equality of SerializedObj (Spec const)
155+ return std::equal (LHS.first .first .begin (), LHS.first .first .end (),
156+ RHS.first .first .begin ()) &&
157+ // Check equality of imageId
158+ LHS.first .second == RHS.first .second &&
159+ // Check equality of devices
160+ std::equal (LHS.second .begin (), LHS.second .end (),
161+ RHS.second .begin (), RHS.second .end ());
162+ }
163+ };
164+
132165 struct ProgramCache {
133166 ::boost::unordered_map<ProgramCacheKeyT, ProgramBuildResultPtr> Cache;
134167 ::boost::unordered_multimap<CommonProgramKeyT, ProgramCacheKeyT> KeyMap;
135168 // Mapping between a UR program and its size.
136- ::boost ::unordered_map<ur_program_handle_t , size_t > ProgramSizeMap;
169+ std ::unordered_map<ur_program_handle_t , size_t > ProgramSizeMap;
137170
138171 size_t ProgramCacheSizeInBytes = 0 ;
139172 inline size_t GetProgramCacheSizeInBytes () const noexcept {
@@ -191,8 +224,8 @@ class KernelProgramCache {
191224 std::list<ProgramCacheKeyT> MProgramEvictionList;
192225
193226 // Mapping between program handle and the iterator to the eviction list.
194- ::boost::unordered_map <ProgramCacheKeyT,
195- std::list<ProgramCacheKeyT>::iterator >
227+ std::unordered_map<ProgramCacheKeyT, std::list <ProgramCacheKeyT>::iterator ,
228+ ProgramCacheKeyHash, ProgramCacheKeyEqual >
196229 MProgramToEvictionListMap;
197230
198231 void clear () {
0 commit comments