Skip to content

Commit 2924479

Browse files
committed
Update SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD env variable
1 parent c04057c commit 2924479

File tree

4 files changed

+31
-85
lines changed

4 files changed

+31
-85
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 7 deletions
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` | See [below](#sycl_in_mem_cache_eviction_threshold) | Controls cache eviction of in-memory caches. |
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. |
@@ -139,12 +139,6 @@ If this environment variable is not set, the preferred work-group size for reduc
139139

140140
Note that conflicting configuration tuples in the same list will favor the last entry. For example, a list `cpu:32,gpu:32,cpu:16` will set the preferred work-group size of reductions to 32 for GPUs and 16 for CPUs. This also applies to `*`, for example `cpu:32,*:16` sets the preferred work-group size of reductions on all devices to 16, while `*:16,cpu:32` sets the preferred work-group size of reductions to 32 on CPUs and to 16 on all other devices.
141141

142-
### `SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD`
143-
144-
`SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD` accepts a string value of the form "ProgramCacheSize:KernelCache_size:FastKernelCacheSize", where ProgramCacheSize, KernelCacheSize, and FastKernelCacheSize are the maximum size of the in-memory Program, kernel, and fast kernel cache. Cache eviction is performed when the cache size exceeds the threshold. The thresholds are specified in bytes and parsed as integers.
145-
146-
The default value is "0:0:0" which means that eviction is disabled.
147-
148142
## Range Rounding Environment Variables
149143

150144
For a description of parallel for range rounding in DPC++ see

sycl/source/detail/config.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CONFIG(SYCL_HOST_UNIFIED_MEMORY, 1, __SYCL_HOST_UNIFIED_MEMORY)
2727
// 260 (Windows limit) - 12 (filename) - 84 (cache directory structure)
2828
CONFIG(SYCL_CACHE_DIR, 164, __SYCL_CACHE_DIR)
2929
CONFIG(SYCL_CACHE_TRACE, 4, __SYCL_CACHE_TRACE)
30-
CONFIG(SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD, 1024,
30+
CONFIG(SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD, 16,
3131
__SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD)
3232
CONFIG(SYCL_CACHE_DISABLE_PERSISTENT, 1, __SYCL_CACHE_DISABLE_PERSISTENT)
3333
CONFIG(SYCL_CACHE_PERSISTENT, 1, __SYCL_CACHE_PERSISTENT)

sycl/source/detail/config.hpp

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -756,75 +756,45 @@ template <> class SYCLConfig<SYCL_CACHE_TRACE> {
756756
}
757757
};
758758

759-
// SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD accepts a string value of the form
760-
// "ProgramCacheSize:KernelCache_size:FastKernelCacheSize", where
761-
// ProgramCacheSize, KernelCacheSize, and FastKernelCacheSize are
762-
// the maximum size of the in-memory Program, kernel, and fast kernel cache.
759+
// SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD accepts an integer that specifies
760+
// the maximum size of the in-memory Program cache.
763761
// Cache eviction is performed when the cache size exceeds the threshold.
764-
// The thresholds are specified in bytes and parsed as integers.
765-
// The default value is "0:0:0" which means that eviction is disabled.
762+
// The thresholds are specified in bytes.
763+
// The default value is "0" which means that eviction is disabled.
766764
template <> class SYCLConfig<SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD> {
767765
using BaseT = SYCLConfigBase<SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD>;
768766

769767
public:
770-
static std::tuple<int, int, int> get() { return getCachedValue(); }
768+
static int get() { return getCachedValue(); }
771769
static void reset() { (void)getCachedValue(true); }
772770

773-
static int getProgramCacheSize() { return std::get<0>(getCachedValue()); }
774-
static int getKernelCacheSize() { return std::get<1>(getCachedValue()); }
775-
static int getFastKernelCacheSize() { return std::get<2>(getCachedValue()); }
771+
static int getProgramCacheSize() { return getCachedValue(); }
776772

777773
static bool isProgramCacheEvictionEnabled() {
778774
return getProgramCacheSize() > 0;
779775
}
780-
static bool isKernelCacheEvictionEnabled() {
781-
return getKernelCacheSize() > 0;
782-
}
783-
static bool isFastKernelCacheEvictionEnabled() {
784-
return getFastKernelCacheSize() > 0;
785-
}
786776

787777
private:
788-
static std::tuple<int, int, int> getCachedValue(bool ResetCache = false) {
778+
static int getCachedValue(bool ResetCache = false) {
789779
const auto Parser = []() {
790780
const char *ValStr = BaseT::getRawValue();
791781

792-
// Ensure the the input string is not null and in correct format.
782+
// Disable eviction by default.
793783
if (!ValStr)
794-
return std::tuple<int, int, int>{0, 0, 0};
795-
796-
std::string InputString{ValStr};
797-
size_t Pos = 0;
798-
std::array<int, 3> CacheSizes;
784+
return 0;
799785

800-
// Ensure that input has exactly 2 ":"
801-
if (std::count(InputString.begin(), InputString.end(), ':') != 2) {
786+
int CacheSize = 0;
787+
try {
788+
CacheSize = std::stoi(ValStr);
789+
if (CacheSize < 0)
790+
throw INVALID_CONFIG_EXCEPTION(BaseT, "Value must be non-negative");
791+
} catch (...) {
802792
std::string Msg = std::string{
803793
"Invalid input to SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD"};
804794
throw exception(make_error_code(errc::runtime), Msg);
805795
}
806796

807-
for (int &CacheSize : CacheSizes) {
808-
size_t NextPos = InputString.find(':', Pos);
809-
if (NextPos == std::string::npos)
810-
NextPos = InputString.size();
811-
std::string CacheSizeStr = InputString.substr(Pos, NextPos - Pos);
812-
try {
813-
CacheSize = std::stoi(CacheSizeStr);
814-
// This exception will anyway be caught by the catch block.
815-
if (CacheSize < 0)
816-
throw exception(make_error_code(errc::runtime), "");
817-
} catch (...) {
818-
819-
std::string Msg = std::string{
820-
"Invalid input to SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD"};
821-
throw exception(make_error_code(errc::runtime), Msg);
822-
}
823-
Pos = NextPos + 1;
824-
}
825-
826-
return std::tuple<int, int, int>{CacheSizes[0], CacheSizes[1],
827-
CacheSizes[2]};
797+
return CacheSize;
828798
};
829799

830800
static auto EvictionThresholds = Parser();

sycl/unittests/config/ConfigTests.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -325,33 +325,21 @@ TEST(ConfigTests, CheckSyclCacheTraceTest) {
325325
TestConfig(0, 0, 0, 0);
326326
}
327327

328-
// SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD accepts a string value of the form
329-
// "ProgramCacheSize:KernelCache_size:FastKernelCacheSize", where
330-
// ProgramCacheSize, KernelCacheSize, and FastKernelCacheSize are
331-
// the maximum size of the in-memory Program, kernel, and fast kernel cache.
328+
// SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD accepts an integer that specifies
329+
// the maximum size of the in-memory Program cache.
332330
// Cache eviction is performed when the cache size exceeds the threshold.
333-
// The thresholds are specified in bytes and parsed as integers.
334-
// The default value is "0:0:0" which means that eviction is disabled.
331+
// The thresholds are specified in bytes.
332+
// The default value is "0" which means that eviction is disabled.
335333
TEST(ConfigTests, CheckSyclCacheEvictionThresholdTest) {
336334

337335
using InMemEvicType =
338336
sycl::detail::SYCLConfig<SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD>;
339337

340338
// Lambda to test parsing of SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD
341-
auto TestConfig = [](int expectedProgramCacheSize,
342-
int expectedKernelCacheSize,
343-
int expectedFastKernelCacheSize) {
339+
auto TestConfig = [](int expectedProgramCacheSize) {
344340
EXPECT_EQ(expectedProgramCacheSize, InMemEvicType::getProgramCacheSize());
345-
EXPECT_EQ(expectedKernelCacheSize, InMemEvicType::getKernelCacheSize());
346-
EXPECT_EQ(expectedFastKernelCacheSize,
347-
InMemEvicType::getFastKernelCacheSize());
348-
349341
EXPECT_EQ(expectedProgramCacheSize > 0,
350342
InMemEvicType::isProgramCacheEvictionEnabled());
351-
EXPECT_EQ(expectedKernelCacheSize > 0,
352-
InMemEvicType::isKernelCacheEvictionEnabled());
353-
EXPECT_EQ(expectedFastKernelCacheSize > 0,
354-
InMemEvicType::isFastKernelCacheEvictionEnabled());
355343
};
356344

357345
// Lambda to set SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD
@@ -369,31 +357,25 @@ TEST(ConfigTests, CheckSyclCacheEvictionThresholdTest) {
369357
SetSyclInMemCacheEvictionThresholdEnv(value);
370358
try {
371359
InMemEvicType::reset();
372-
TestConfig(0, 0, 0);
360+
TestConfig(0);
373361
FAIL() << errMsg;
374362
} catch (...) {
375363
}
376364
};
377365

378366
// Test eviction threshold with zero.
379-
SetSyclInMemCacheEvictionThresholdEnv("0:0:0");
367+
SetSyclInMemCacheEvictionThresholdEnv("0");
380368
sycl::detail::readConfig(true);
381-
TestConfig(0, 0, 0);
369+
TestConfig(0);
382370

383371
// Test invalid values.
384-
TestInvalidValues("-1:0:0", "Should throw exception for negative value");
385-
TestInvalidValues("a:0:0", "Should throw exception for non-integer value");
386-
TestInvalidValues("0:a:0", "Should throw exception for non-integer value");
387-
TestInvalidValues("0:0:a", "Should throw exception for non-integer value");
388-
TestInvalidValues("", "Should throw exception for empty value");
389-
TestInvalidValues("0:0", "Should throw exception for invalid input");
390-
TestInvalidValues("0", "Should throw exception for invalid input");
391-
TestInvalidValues("random", "Should throw exception for invalid input");
372+
TestInvalidValues("-1", "Should throw exception for negative value");
373+
TestInvalidValues("a", "Should throw exception for non-integer value");
392374

393375
// Test valid values.
394-
SetSyclInMemCacheEvictionThresholdEnv("1024:2048:4096");
376+
SetSyclInMemCacheEvictionThresholdEnv("1024");
395377
InMemEvicType::reset();
396-
TestConfig(1024, 2048, 4096);
378+
TestConfig(1024);
397379

398380
// When SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD is not set, it should default to
399381
// 0:0:0.
@@ -403,5 +385,5 @@ TEST(ConfigTests, CheckSyclCacheEvictionThresholdTest) {
403385
unsetenv("SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD");
404386
#endif
405387
InMemEvicType::reset();
406-
TestConfig(0, 0, 0);
388+
TestConfig(0);
407389
}

0 commit comments

Comments
 (0)