Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Implement eviction for in-memory program cache #16062

Merged
merged 14 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sycl/doc/EnvironmentVariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ compiler and runtime.
| `SYCL_CACHE_DISABLE_PERSISTENT (deprecated)` | Any(\*) | Has no effect. |
| `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. |
| `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'. |
| `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. |
uditagarwal97 marked this conversation as resolved.
Show resolved Hide resolved
| `SYCL_CACHE_EVICTION_DISABLE` | Any(\*) | Switches persistent cache eviction off when the variable is set. |
| `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. |
| `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. |
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ CONFIG(SYCL_HOST_UNIFIED_MEMORY, 1, __SYCL_HOST_UNIFIED_MEMORY)
// 260 (Windows limit) - 12 (filename) - 84 (cache directory structure)
CONFIG(SYCL_CACHE_DIR, 164, __SYCL_CACHE_DIR)
CONFIG(SYCL_CACHE_TRACE, 4, __SYCL_CACHE_TRACE)
CONFIG(SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD, 16,
__SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD)
CONFIG(SYCL_CACHE_DISABLE_PERSISTENT, 1, __SYCL_CACHE_DISABLE_PERSISTENT)
CONFIG(SYCL_CACHE_PERSISTENT, 1, __SYCL_CACHE_PERSISTENT)
CONFIG(SYCL_CACHE_EVICTION_DISABLE, 1, __SYCL_CACHE_EVICTION_DISABLE)
Expand Down
49 changes: 49 additions & 0 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,55 @@ template <> class SYCLConfig<SYCL_CACHE_TRACE> {
}
};

// SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD accepts an integer that specifies
// the maximum size of the in-memory Program cache.
// Cache eviction is performed when the cache size exceeds the threshold.
// The thresholds are specified in bytes.
// The default value is "0" which means that eviction is disabled.
template <> class SYCLConfig<SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD> {
using BaseT = SYCLConfigBase<SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD>;

public:
static int get() { return getCachedValue(); }
static void reset() { (void)getCachedValue(true); }

static int getProgramCacheSize() { return getCachedValue(); }

static bool isProgramCacheEvictionEnabled() {
return getProgramCacheSize() > 0;
}

private:
static int getCachedValue(bool ResetCache = false) {
maarquitos14 marked this conversation as resolved.
Show resolved Hide resolved
const auto Parser = []() {
const char *ValStr = BaseT::getRawValue();

// Disable eviction by default.
if (!ValStr)
return 0;

int CacheSize = 0;
try {
CacheSize = std::stoi(ValStr);
if (CacheSize < 0)
throw INVALID_CONFIG_EXCEPTION(BaseT, "Value must be non-negative");
} catch (...) {
std::string Msg = std::string{
"Invalid input to SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD"};
uditagarwal97 marked this conversation as resolved.
Show resolved Hide resolved
throw exception(make_error_code(errc::runtime), Msg);
}

return CacheSize;
};

static auto EvictionThresholds = Parser();
if (ResetCache)
EvictionThresholds = Parser();

return EvictionThresholds;
}
};

#undef INVALID_CONFIG_EXCEPTION

} // namespace detail
Expand Down
Loading
Loading