Skip to content

Commit c85c220

Browse files
committed
Address reviews.
1 parent b3fdca2 commit c85c220

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ compiler and runtime.
1414
| `SYCL_CACHE_DISABLE_PERSISTENT (deprecated)` | Any(\*) | Has no effect. |
1515
| `SYCL_CACHE_PERSISTENT` | Integer | Controls persistent device compiled code cache. Turns it on if set to '1' and turns it off if set to '0'. When cache is enabled SYCL runtime will try to cache and reuse JIT-compiled binaries. Default is off. |
1616
| `SYCL_CACHE_IN_MEM` | '1' or '0' | Enable ('1') or disable ('0') in-memory caching of device compiled code. When cache is enabled SYCL runtime will try to cache and reuse JIT-compiled binaries. Default is '1'. |
17-
| `SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD` | Positive integer | `SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD` accepts an integer that specifies the maximum size of the in-memory Program cache in bytes. Eviction is performed when the cache size exceeds the threshold. The default value is 0 which means that eviction is disabled. |
17+
| `SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD` | Positive integer | `SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD` accepts an integer that specifies the maximum size of the in-memory program cache in bytes. Eviction is performed when the cache size exceeds the threshold. The default value is 0 which means that eviction is disabled. |
1818
| `SYCL_CACHE_EVICTION_DISABLE` | Any(\*) | Switches persistent cache eviction off when the variable is set. |
1919
| `SYCL_CACHE_MAX_SIZE` | Positive integer | Persistent cache eviction is triggered once total size of cached images exceeds the value in megabytes (default - 8 192 for 8 GB). Set to 0 to disable size-based cache eviction. |
2020
| `SYCL_CACHE_THRESHOLD` | Positive integer | Persistent cache eviction threshold in days (default value is 7 for 1 week). Set to 0 for disabling time-based cache eviction. |

sycl/source/detail/kernel_program_cache.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ class KernelProgramCache {
233233
::boost::unordered_flat_map<KernelFastCacheKeyT, KernelFastCacheValT>;
234234

235235
// DS to hold data and functions related to Program cache eviction.
236-
struct EvictionListT {
236+
struct EvictionList {
237+
private:
237238
// Linked list of cache entries to be evicted in case of cache overflow.
238239
std::list<ProgramCacheKeyT> MProgramEvictionList;
239240

@@ -242,6 +243,11 @@ class KernelProgramCache {
242243
ProgramCacheKeyHash, ProgramCacheKeyEqual>
243244
MProgramToEvictionListMap;
244245

246+
public:
247+
std::list<ProgramCacheKeyT> &getProgramEvictionList() {
248+
return MProgramEvictionList;
249+
}
250+
245251
void clear() {
246252
MProgramEvictionList.clear();
247253
MProgramToEvictionListMap.clear();
@@ -342,7 +348,7 @@ class KernelProgramCache {
342348
return {MKernelsPerProgramCache, MKernelsPerProgramCacheMutex};
343349
}
344350

345-
Locked<EvictionListT> acquireEvictionList() {
351+
Locked<EvictionList> acquireEvictionList() {
346352
return {MEvictionList, MProgramEvictionListMutex};
347353
}
348354

@@ -447,12 +453,13 @@ class KernelProgramCache {
447453
// Evict programs from the beginning of the cache.
448454
{
449455
std::lock_guard<std::mutex> Lock(MProgramEvictionListMutex);
450-
456+
auto &ProgramEvictionList = MEvictionList.getProgramEvictionList();
451457
size_t CurrCacheSize = MCachedPrograms.ProgramCacheSizeInBytes;
458+
452459
// Traverse the eviction list and remove the LRU programs.
453460
// The LRU programs will be at the front of the list.
454461
while (CurrCacheSize > DesiredCacheSize && !MEvictionList.empty()) {
455-
ProgramCacheKeyT CacheKey = MEvictionList.MProgramEvictionList.front();
462+
ProgramCacheKeyT CacheKey = ProgramEvictionList.front();
456463
auto LockedCache = acquireCachedPrograms();
457464
auto &ProgCache = LockedCache.get();
458465
auto It = ProgCache.Cache.find(CacheKey);
@@ -551,7 +558,7 @@ class KernelProgramCache {
551558

552559
// Store size of the program and check if we need to evict some entries.
553560
// Get Size of the program.
554-
size_t ProgramSize;
561+
size_t ProgramSize = 0;
555562
auto Adapter = getAdapter();
556563

557564
try {
@@ -655,7 +662,7 @@ class KernelProgramCache {
655662
// Build succeeded.
656663
if (NewState == BuildState::BS_Done) {
657664
if constexpr (!std::is_same_v<EvictFT, void *>)
658-
EvictFunc(BuildResult->Val, 0);
665+
EvictFunc(BuildResult->Val, /*IsBuilt=*/false);
659666
return BuildResult;
660667
}
661668

@@ -682,7 +689,7 @@ class KernelProgramCache {
682689
BuildResult->Val = Build();
683690

684691
if constexpr (!std::is_same_v<EvictFT, void *>)
685-
EvictFunc(BuildResult->Val, 1);
692+
EvictFunc(BuildResult->Val, /*IsBuilt=*/true);
686693

687694
BuildResult->updateAndNotify(BuildState::BS_Done);
688695
return BuildResult;
@@ -723,7 +730,7 @@ class KernelProgramCache {
723730
std::unordered_map<ur_program_handle_t, std::vector<KernelFastCacheKeyT>>
724731
MProgramToKernelFastCacheKeyMap;
725732

726-
EvictionListT MEvictionList;
733+
EvictionList MEvictionList;
727734
// Mutexes that will be used when accessing the eviction lists.
728735
std::mutex MProgramEvictionListMutex;
729736

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
921921
return BuildF();
922922

923923
auto EvictFunc = [&Cache, &CacheKey](ur_program_handle_t Program,
924-
int isBuilt) {
924+
bool isBuilt) {
925925
return Cache.registerProgramFetch(CacheKey, Program, isBuilt);
926926
};
927927

@@ -940,13 +940,12 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
940940
// update it here and re-use that lambda.
941941
CacheKey.first.second = BImg->getImageID();
942942
bool DidInsert = Cache.insertBuiltProgram(CacheKey, ResProgram);
943-
if (DidInsert) {
944-
// Add to the eviction list.
945-
Cache.registerProgramFetch(CacheKey, ResProgram, 1);
943+
944+
// Add to the eviction list.
945+
Cache.registerProgramFetch(CacheKey, ResProgram, DidInsert);
946+
if (DidInsert)
946947
// For every cached copy of the program, we need to increment its refcount
947948
Adapter->call<UrApiKind::urProgramRetain>(ResProgram);
948-
} else
949-
Cache.registerProgramFetch(CacheKey, ResProgram, 0);
950949
}
951950

952951
// If caching is enabled, one copy of the program handle will be
@@ -2742,7 +2741,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
27422741
};
27432742

27442743
auto EvictFunc = [&Cache, &CacheKey](ur_program_handle_t Program,
2745-
int isBuilt) {
2744+
bool isBuilt) {
27462745
return Cache.registerProgramFetch(CacheKey, Program, isBuilt);
27472746
};
27482747

sycl/unittests/assert/assert.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ static ur_result_t redefinedProgramGetInfo(void *pParams) {
320320
}
321321

322322
// Required if program cache eviction is enabled.
323-
if (UR_PROGRAM_INFO_BINARY_SIZES == *params.ppropName ||
324-
UR_PROGRAM_INFO_NUM_DEVICES == *params.ppropName) {
325-
323+
if (UR_PROGRAM_INFO_BINARY_SIZES == *params.ppropName) {
326324
size_t BinarySize = 1;
327325

328326
if (*params.ppPropValue)

0 commit comments

Comments
 (0)