Skip to content

Commit 0e00170

Browse files
committed
Remove boost usages
1 parent 5c68269 commit 0e00170

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

sycl/source/detail/kernel_program_cache.hpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {

sycl/unittests/kernel-and-program/InMemCacheEviction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ TEST(InMemCacheEvictionTests, TestConcurrentEvictionSameQueue) {
168168
queue q(Ctx, default_selector_v);
169169

170170
// One program is of 10000 bytes, so 20005 eviction threshold can
171-
// accommodate two program.
171+
// accommodate two programs.
172172
setCacheEvictionEnv("20005");
173173

174174
constexpr size_t ThreadCount = 200;

0 commit comments

Comments
 (0)