Skip to content

Commit cc36361

Browse files
committed
Cleanup
1 parent 06d01a7 commit cc36361

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

sycl/source/detail/os_util.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <sycl/exception.hpp>
1111

1212
#include <cassert>
13-
#include <iostream>
1413
#include <limits>
1514

1615
// For GCC versions less than 8, use experimental/filesystem.
@@ -51,7 +50,6 @@ namespace fs = std::experimental::filesystem;
5150
#elif defined(__SYCL_RT_OS_DARWIN)
5251

5352
#include <dlfcn.h>
54-
#include <sys/stat.h>
5553
#include <sys/sysctl.h>
5654
#include <sys/types.h>
5755

sycl/source/detail/persistent_device_code_cache.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
#include <detail/program_manager/program_manager.hpp>
1313

1414
#include <cerrno>
15+
#include <chrono>
1516
#include <cstdio>
1617
#include <fstream>
1718
#include <optional>
1819

19-
#include <time.h>
20-
2120
#if defined(__SYCL_RT_OS_POSIX_SUPPORT)
2221
#include <unistd.h>
2322
#else
@@ -252,7 +251,7 @@ void PersistentDeviceCodeCache::evictItemsFromCache(
252251
// Create a file eviction_in_progress.lock to indicate that eviction is in
253252
// progress. This file is used to prevent two processes from evicting the
254253
// cache at the same time.
255-
LockCacheItem Lock{CacheRoot + "/eviction_in_progress"};
254+
LockCacheItem Lock{CacheRoot + EvictionInProgressFileSuffix};
256255
if (!Lock.isOwned()) {
257256
// If some other process is evicting the cache, return.
258257
PersistentDeviceCodeCache::trace(
@@ -265,7 +264,7 @@ void PersistentDeviceCodeCache::evictItemsFromCache(
265264
std::vector<std::pair<uint64_t, std::string>> FilesWithAccessTime;
266265

267266
auto CollectFileAccessTime = [&FilesWithAccessTime](const std::string File) {
268-
if (File.find("_access_time.txt") != std::string::npos) {
267+
if (File.find(CacheEntryAccessTimeSuffix) != std::string::npos) {
269268
std::ifstream FileStream{File};
270269
uint64_t AccessTime;
271270
FileStream >> AccessTime;
@@ -300,7 +299,7 @@ void PersistentDeviceCodeCache::evictItemsFromCache(
300299
size_t CurrCacheSize = CacheSize;
301300
for (const auto &File : FilesWithAccessTime) {
302301

303-
int pos = File.second.find("_access_time.txt");
302+
int pos = File.second.find(CacheEntryAccessTimeSuffix);
304303
const std::string FileNameWOExt = File.second.substr(0, pos);
305304
const std::string BinFile = FileNameWOExt + ".bin";
306305
const std::string SrcFile = FileNameWOExt + ".src";
@@ -434,7 +433,7 @@ void PersistentDeviceCodeCache::putItemToDisc(
434433
// Do not insert any new item if eviction is in progress.
435434
// Since evictions are rare, we can afford to spin lock here.
436435
const std::string EvictionInProgressFile =
437-
getRootDir() + "/eviction_in_progress.lock";
436+
getRootDir() + EvictionInProgressFileSuffix;
438437
// Stall until the other process finishes eviction.
439438
while (OSUtil::isPathPresent(EvictionInProgressFile))
440439
continue;
@@ -470,7 +469,7 @@ void PersistentDeviceCodeCache::putItemToDisc(
470469
TotalSize += getFileSize(FileName + ".src");
471470
TotalSize += getFileSize(FileName + ".bin");
472471

473-
saveCurrentTimeInAFile(FileName + "_access_time.txt");
472+
saveCurrentTimeInAFile(FileName + CacheEntryAccessTimeSuffix);
474473
} else {
475474
PersistentDeviceCodeCache::trace("cache lock not owned " + FileName);
476475
}
@@ -565,7 +564,7 @@ std::vector<std::vector<char>> PersistentDeviceCodeCache::getItemFromDisc(
565564
// Explicitly update the access time of the file. This is required for
566565
// eviction.
567566
if (isEvictionEnabled())
568-
saveCurrentTimeInAFile(FileName + "_access_time.txt");
567+
saveCurrentTimeInAFile(FileName + CacheEntryAccessTimeSuffix);
569568

570569
FileNames += FullFileName + ";";
571570
break;

sycl/source/detail/persistent_device_code_cache.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010

11-
#include <chrono>
1211
#include <detail/config.hpp>
1312
#include <detail/device_binary_image.hpp>
1413
#include <fcntl.h>
@@ -236,6 +235,13 @@ class PersistentDeviceCodeCache {
236235
static bool isEvictionEnabled() {
237236
return SYCLConfig<SYCL_CACHE_MAX_SIZE>::isPersistentCacheEvictionEnabled();
238237
}
238+
239+
// Suffix for access time file. Every cache entry will have one.
240+
static inline std::string CacheEntryAccessTimeSuffix = "_access_time.txt";
241+
// Suffix for eviction in progress file. It is created when eviction is
242+
// triggered and removed when eviction is done.
243+
static inline std::string EvictionInProgressFileSuffix =
244+
"_eviction_in_progress";
239245
};
240246
} // namespace detail
241247
} // namespace _V1

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -559,25 +559,15 @@ TEST_P(PersistentDeviceCodeCache, BasicEviction) {
559559

560560
std::string BuildOptions{"--eviction"};
561561
// Put 3 items to the cache.
562-
// On Windows, for NTFS, the file timestamp resolution is 100ns,
563-
// but on Linux, for EXT4, the file timestamp resolution is few milliseconds.
564-
// So, to make this test deterministic, we need to sleep for a while,
565-
// say 20ms, between each putItemToDisc/getItemFromDisc call.
566562
detail::PersistentDeviceCodeCache::putItemToDisc({Dev}, {&Img}, {},
567563
BuildOptions, NativeProg);
568564

569-
std::this_thread::sleep_for(std::chrono::milliseconds(20));
570-
571565
detail::PersistentDeviceCodeCache::putItemToDisc({Dev}, {&Img}, {},
572566
BuildOptions, NativeProg);
573567

574-
std::this_thread::sleep_for(std::chrono::milliseconds(20));
575-
576568
detail::PersistentDeviceCodeCache::putItemToDisc({Dev}, {&Img}, {},
577569
BuildOptions, NativeProg);
578570

579-
std::this_thread::sleep_for(std::chrono::milliseconds(20));
580-
581571
// Retrieve 0.bin from the cache.
582572
auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc(
583573
{Dev}, {&Img}, {}, BuildOptions);

0 commit comments

Comments
 (0)