Skip to content

[SYCL] Persistent program cache #3391

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

Merged
merged 35 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7d98ed8
Initial implementation
vladimirlaz Mar 10, 2021
6854e84
[SYCL] Remove redundant build options processing
vladimirlaz Mar 11, 2021
4db44a5
Raw implementation
vladimirlaz Mar 19, 2021
b7fa3f6
Merge remote-tracking branch 'intel_llvm/sycl' into jit_cache_2
vladimirlaz Mar 19, 2021
95f4e99
Fix LIT tests
vladimirlaz Mar 22, 2021
3f1ab43
Fix CI issues
vladimirlaz Mar 23, 2021
4d847f3
Enable Windows and brush up code
vladimirlaz Mar 23, 2021
f776006
Fix failure
vladimirlaz Mar 23, 2021
414780c
Fix issues
vladimirlaz Mar 23, 2021
d3283f3
Move on-disk cache to separate module
vladimirlaz Mar 24, 2021
5f94856
revert unnecessary change
vladimirlaz Mar 24, 2021
eece33e
Apply review comments and fix CI issues
vladimirlaz Mar 25, 2021
5b26cd6
Apply review comments and remove redundant change
vladimirlaz Mar 25, 2021
09d3ee7
Update sycl/doc/KernelProgramCache.md
vladimirlaz Mar 25, 2021
8eff1a2
Fix misprint
vladimirlaz Mar 26, 2021
ed915f5
Apply review comments and remove redundant code
vladimirlaz Mar 26, 2021
9cd8c22
Apply review comments
vladimirlaz Mar 28, 2021
76a433d
Fix status
vladimirlaz Mar 30, 2021
a78d7a5
Revert API changes to simplify migration to std::filesystem
vladimirlaz Mar 31, 2021
a1be142
Upload for testing
vladimirlaz Mar 31, 2021
4f38f47
Updates
vladimirlaz Apr 1, 2021
c626288
Merge remote-tracking branch 'intel_llvm/sycl' into jit_cache_2
vladimirlaz Apr 1, 2021
6946c8f
Fix CI issues
vladimirlaz Apr 1, 2021
d4f395e
Fix comments
vladimirlaz Apr 1, 2021
5253e54
Apply review comment and fix CUDA failure
vladimirlaz Apr 2, 2021
76fbc2c
Remove duplicated and recursive functions
vladimirlaz Apr 5, 2021
349920c
Save code with obsoleting .lock files
vladimirlaz Apr 6, 2021
cdda42e
Implement non-nlocking lock files
vladimirlaz Apr 6, 2021
2c95c35
Fix comments
vladimirlaz Apr 6, 2021
8dad336
Apply review remarks
vladimirlaz Apr 7, 2021
9775e50
Added image sized thresholds
vladimirlaz Apr 7, 2021
b0c6a6d
Aply review comments
vladimirlaz Apr 8, 2021
b395ed7
Merge remote-tracking branch sycl into jit_cache_2
vladimirlaz Apr 8, 2021
740408b
Disable test on CUDA because non-SPIRV target are not covered by pers…
vladimirlaz Apr 8, 2021
163fb07
Apply suggestions from code review
vladimirlaz Apr 8, 2021
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
8 changes: 8 additions & 0 deletions sycl/doc/EnvironmentVariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ subject to change. Do not rely on these variables in production code.
| SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING | Any(\*) | Disables automatic rounding-up of parallel_for invocation ranges. |
| SYCL_ENABLE_PCI | Integer | When set to 1, enables obtaining the GPU PCI address when using the Level Zero backend. The default is 0. |
| SYCL_HOST_UNIFIED_MEMORY | Integer | Enforce host unified memory support or lack of it for the execution graph builder. If set to 0, it is enforced as not supported by all devices. If set to 1, it is enforced as supported by all devices. |
| SYCL_CACHE_DIR | Path | Path to persistent cache root directory. Default values are `%AppData%\libsycl_cache` for Windows and `$XDG_CACHE_HOME/libsycl_cache` on Linux, if XDG_CACHE_HOME is not set then `$HOME/.cache/libsycl_cache`. |
| SYCL_CACHE_TRACE | Any(\*) | Enables printing messages to std::cerr when non-blocking failures happen (e.g. unable to access cache item file). Default values if off. |
| SYCL_CACHE_DISABLE_PERSISTENT | Any(\*) | Switches persistent cache switch off. Default value is ON. |
| SYCL_CACHE_EVICTION_DISABLE | Any(\*) | Switches cache eviction off. Default value is ON. |
| SYCL_CACHE_MAX_SIZE | Positive integer | 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 | Cache eviction threshold in days (default value is 7 for 1 week). Set to 0 for disabling time-based cache eviction. |
| SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE | Positive integer | Minimum size of device code image in bytes which is reasonable to cache on disk because disk access operation may take more time than do JIT compilation for it. Default value is 0 to cache all images. |
| SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE | Positive integer | Maximum size of device image in bytes which is cached. Too big kernels may overload disk too fast. Default value is 1 GB. |

`(*) Note: Any means this environment variable is effective when set to any non-null value.`

Expand Down
11 changes: 2 additions & 9 deletions sycl/doc/KernelProgramCache.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,8 @@ three sources of build options:

## Cache configuration

There is set of configuration parameters which can be set as environment variables or parameters in `sycl.conf` and affect cache behavior:
| Environment variable | Values | Description |
| -------------------- | ------ | ----------- |
| `SYCL_CACHE_DIR`| Path | Path to persistent cache root directory. Default values are `%AppData%\Intel\sycl_program_cache` for Windows and `$HOME/intel/sycl_program_cache` on Linux. |
| `SYCL_CACHE_ENABLED` | ON, OFF | Switches persistent cache switch on or off. Default value is ON. |
| `SYCL_CACHE_MAX_SIZE` | Positive integer | 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 | Cache eviction threshold in days (default value is 7 for 1 week). Set to 0 for disabling time-based cache eviction. |
| `SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE` | Positive integer | Minimum size of device code image in kilobytes which is reasonable to cache on disk because disk access operation may take more time than do JIT compilation for it. Default value is 0 to cache all images. |
| `SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE` | Positive integer | Maximum size of device image in megabytes which is cached. Too big kernels may overload disk too fast. Default value is 0 to cache all images. |
The environment variables which affect cache behavior are described in
[EnvironmentVariables.md](https://github.com/intel/llvm/blob/sycl/sycl/doc/EnvironmentVariables.md).

## Implementation details

Expand Down
16 changes: 16 additions & 0 deletions sycl/include/CL/sycl/detail/os_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <cstdint>
#include <cstdlib>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>

#ifdef _WIN32
#define __SYCL_RT_OS_WINDOWS
Expand Down Expand Up @@ -80,6 +82,20 @@ class __SYCL_EXPORT OSUtil {

/// Deallocates the memory referenced by \p Ptr.
static void alignedFree(void *Ptr);

/// Make directory recursively and returns zero code on success
static int makeDir(const char *Dir);

/// Checks if specified path is present
static inline bool isPathPresent(const std::string &Path) {
#ifdef __SYCL_RT_OS_WINDOWS
struct _stat Stat;
return !_stat(Path.c_str(), &Stat);
#else
struct stat Stat;
return !stat(Path.c_str(), &Stat);
#endif
}
};

} // namespace detail
Expand Down
1 change: 1 addition & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ set(SYCL_SOURCES
"detail/queue_impl.cpp"
"detail/online_compiler/online_compiler.cpp"
"detail/os_util.cpp"
"detail/persistent_device_code_cache.cpp"
"detail/platform_util.cpp"
"detail/reduction.cpp"
"detail/sampler_impl.cpp"
Expand Down
9 changes: 9 additions & 0 deletions sycl/source/detail/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ CONFIG(SYCL_DEVICE_FILTER, 1024, __SYCL_DEVICE_FILTER)
CONFIG(SYCL_PROGRAM_LINK_OPTIONS, 64, __SYCL_PROGRAM_LINK_OPTIONS)
CONFIG(SYCL_PROGRAM_COMPILE_OPTIONS, 64, __SYCL_PROGRAM_COMPILE_OPTIONS)
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, 1, __SYCL_CACHE_TRACE)
CONFIG(SYCL_CACHE_DISABLE_PERSISTENT, 1, __SYCL_CACHE_DISABLE_PERSISTENT)
CONFIG(SYCL_CACHE_EVICTION_DISABLE, 1, __SYCL_CACHE_EVICTION_DISABLE)
CONFIG(SYCL_CACHE_MAX_SIZE, 16, __SYCL_CACHE_MAX_SIZE)
CONFIG(SYCL_CACHE_THRESHOLD, 16, __SYCL_CACHE_THRESHOLD)
CONFIG(SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE, 16, __SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE)
CONFIG(SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE, 16, __SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE)
41 changes: 41 additions & 0 deletions sycl/source/detail/os_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
#include <libgen.h> // for dirname
#include <link.h>
#include <linux/limits.h> // for PATH_MAX
#include <sys/stat.h>
#include <sys/sysinfo.h>

#elif defined(__SYCL_RT_OS_WINDOWS)

#include <Windows.h>
#include <direct.h>
#include <malloc.h>
#include <shlwapi.h>

Expand Down Expand Up @@ -211,6 +213,19 @@ std::string OSUtil::getCurrentDSODir() {
return Path;
}

std::string OSUtil::getDirName(const char *Path) {
std::string Tmp(Path);
// Remove trailing directory separators
Tmp.erase(Tmp.find_last_not_of("/\\") + 1, std::string::npos);

int pos = Tmp.find_last_of("/\\");
if (pos != std::string::npos)
return Tmp.substr(0, pos);

// If no directory separator is present return initial path like dirname does
return Tmp;
}

#elif defined(__SYCL_RT_OS_DARWIN)
OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) {
Dl_info Res;
Expand Down Expand Up @@ -258,6 +273,32 @@ void OSUtil::alignedFree(void *Ptr) {
#endif
}

/* This is temporary solution until std::filesystem is available when SYCL RT
* is moved to c++17 standard*/

/* Create directory recursively and return non zero code on success*/
int OSUtil::makeDir(const char *Dir) {
assert((Dir != nullptr) && "Passed null-pointer as directory name.");
if (isPathPresent(Dir))
return 0;

std::string Path{Dir}, CurPath;
size_t pos = 0;

do {
pos = Path.find_first_of("/\\", ++pos);
CurPath = Path.substr(0, pos);
#if defined(__SYCL_RT_OS_LINUX)
auto Res = mkdir(CurPath.c_str(), 0777);
#else
auto Res = _mkdir(CurPath.c_str());
#endif
if (Res && errno != EEXIST)
return Res;
} while (pos != std::string::npos);
return 0;
}

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
Loading