Skip to content

Commit 3e9ed1d

Browse files
authored
[SYCL] Fix persistent cache keys comparison (#3656)
1 parent 3678449 commit 3e9ed1d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

sycl/source/detail/persistent_device_code_cache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ bool PersistentDeviceCodeCache::isCacheItemSrcEqual(
272272
FileStream.read((char *)&Size, sizeof(Size));
273273
res.resize(Size);
274274
FileStream.read(&res[0], Size);
275-
if (BuildOptionsString.compare(0, Size, res.data()))
275+
if (BuildOptionsString.compare(res))
276276
return false;
277277

278278
FileStream.read((char *)&Size, sizeof(Size));

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,33 @@ class PersistenDeviceCodeCache : public ::testing::Test {
145145
std::unique_ptr<unittest::PiMock> Mock;
146146
};
147147

148+
/* Checks that key values with \0 symbols are processed correctly
149+
*/
150+
TEST_F(PersistenDeviceCodeCache, KeysWithNullTermSymbol) {
151+
if (Plt.is_host() || Plt.get_backend() != backend::opencl) {
152+
return;
153+
}
154+
std::string Key{'1', '\0', '3', '4', '\0'};
155+
std::vector<unsigned char> SpecConst(Key.begin(), Key.end());
156+
std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath(
157+
Dev, Img, SpecConst, Key);
158+
llvm::sys::fs::remove_directories(ItemDir);
159+
160+
detail::PersistentDeviceCodeCache::putItemToDisc(Dev, Img, SpecConst, Key,
161+
NativeProg);
162+
auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc(Dev, Img,
163+
SpecConst, Key);
164+
assert(Res.size() != 0 && "Failed to load cache item");
165+
for (int i = 0; i < Res.size(); ++i) {
166+
assert(Res[i].size() != 0 && "Failed to device image");
167+
for (int j = 0; j < Res[i].size(); ++j) {
168+
assert(Res[i][j] == i && "Corrupted image loaded from persistent cache");
169+
}
170+
}
171+
172+
llvm::sys::fs::remove_directories(ItemDir);
173+
}
174+
148175
/* Do read/write for the same cache item to/from 300 threads for small device
149176
* code size. Make sure that there is no data corruption or crashes.
150177
*/

0 commit comments

Comments
 (0)