diff --git a/opencl/doc/FAQ.md b/opencl/doc/FAQ.md index 7210b69f0b..69e6641d34 100644 --- a/opencl/doc/FAQ.md +++ b/opencl/doc/FAQ.md @@ -57,7 +57,7 @@ which improves performance. ##### Environment flags (Linux only) NEO_CACHE_PERSISTENT - integer value to enable (1)/disable (0) on-disk binary cache. When enabled - Neo will try to cache and reuse compiled binaries. Default is off. + Neo will try to cache and reuse compiled binaries. Default is on. NEO_CACHE_DIR - path to persistent cache directory. Default values are $XDG_CACHE_HOME/neo_compiler_cache if $XDG_CACHE_HOME is set, $HOME/.cache/neo_compiler_cache otherwise. If none of environment diff --git a/opencl/source/compiler_interface/default_cache_config.cpp b/opencl/source/compiler_interface/default_cache_config.cpp index 860ba08219..6fdfe68214 100644 --- a/opencl/source/compiler_interface/default_cache_config.cpp +++ b/opencl/source/compiler_interface/default_cache_config.cpp @@ -32,7 +32,7 @@ CompilerCacheConfig getDefaultCompilerCacheConfig() { auto cachePersistentKey = oclRegPath + NeoCachePersistent; - if (settingsReader->getSetting(settingsReader->appSpecificLocation(cachePersistentKey), 0l) != 0) { + if (settingsReader->getSetting(settingsReader->appSpecificLocation(cachePersistentKey), defaultCacheEnabled()) != 0) { ret.enabled = true; std::string emptyString = ""; ret.cacheDir = settingsReader->getSetting(settingsReader->appSpecificLocation(NeoCacheDir), emptyString); diff --git a/opencl/test/unit_test/compiler_interface/CMakeLists.txt b/opencl/test/unit_test/compiler_interface/CMakeLists.txt index ba445daa83..b197034340 100644 --- a/opencl/test/unit_test/compiler_interface/CMakeLists.txt +++ b/opencl/test/unit_test/compiler_interface/CMakeLists.txt @@ -7,11 +7,12 @@ set(IGDRCL_SRCS_tests_compiler_interface ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/cl_compiler_interface_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/default_cl_cache_config_tests.cpp ) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_compiler_interface}) if(NOT WIN32) target_sources(igdrcl_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/linux/default_cl_cache_config_tests.cpp) +else() + target_sources(igdrcl_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/windows/default_cl_cache_config_tests.cpp) endif() diff --git a/opencl/test/unit_test/compiler_interface/linux/default_cl_cache_config_tests.cpp b/opencl/test/unit_test/compiler_interface/linux/default_cl_cache_config_tests.cpp index 20207315ef..68663d193d 100644 --- a/opencl/test/unit_test/compiler_interface/linux/default_cl_cache_config_tests.cpp +++ b/opencl/test/unit_test/compiler_interface/linux/default_cl_cache_config_tests.cpp @@ -19,6 +19,47 @@ namespace SysCalls { extern bool pathExistsMock; } +namespace LegacyPathWorksIfNewEnvIsSetToDisabled { +bool pathExistsMock(const std::string &path) { + if (path.find("cl_cache") != path.npos) + return true; + + return false; +} +} // namespace LegacyPathWorksIfNewEnvIsSetToDisabled + +TEST(CompilerCache, GivenDefaultClCacheConfigWithPathExistsAndNewEnvSetToDisabledThenValuesAreProperlyPopulated) { + std::unordered_map mockableEnvs; + mockableEnvs["NEO_CACHE_PERSISTENT"] = "0"; + + VariableBackup *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs); + VariableBackup pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, LegacyPathWorksIfNewEnvIsSetToDisabled::pathExistsMock); + + auto cacheConfig = NEO::getDefaultCompilerCacheConfig(); + EXPECT_STREQ("cl_cache", cacheConfig.cacheDir.c_str()); + EXPECT_STREQ(".cl_cache", cacheConfig.cacheFileExtension.c_str()); + EXPECT_TRUE(cacheConfig.enabled); +} + +namespace NewEnvIsDisabledAndLegacyPathDoesNotExist { +bool pathExistsMock(const std::string &path) { + return false; +} +} // namespace NewEnvIsDisabledAndLegacyPathDoesNotExist + +TEST(CompilerCache, GivenDefaultClCacheConfigWithNotExistingPathAndNewEnvSetToDisabledThenValuesAreProperlyPopulated) { + std::unordered_map mockableEnvs; + mockableEnvs["NEO_CACHE_PERSISTENT"] = "0"; + + VariableBackup *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs); + VariableBackup pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, NewEnvIsDisabledAndLegacyPathDoesNotExist::pathExistsMock); + + auto cacheConfig = NEO::getDefaultCompilerCacheConfig(); + EXPECT_STREQ("cl_cache", cacheConfig.cacheDir.c_str()); + EXPECT_STREQ(".cl_cache", cacheConfig.cacheFileExtension.c_str()); + EXPECT_FALSE(cacheConfig.enabled); +} + namespace AllVariablesCorrectlySet { bool pathExistsMock(const std::string &path) { if (path.find("ult/directory/") != path.npos) diff --git a/opencl/test/unit_test/compiler_interface/default_cl_cache_config_tests.cpp b/opencl/test/unit_test/compiler_interface/windows/default_cl_cache_config_tests.cpp similarity index 100% rename from opencl/test/unit_test/compiler_interface/default_cl_cache_config_tests.cpp rename to opencl/test/unit_test/compiler_interface/windows/default_cl_cache_config_tests.cpp diff --git a/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp b/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp index 919ba9d339..bb4022083a 100644 --- a/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp +++ b/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp @@ -17,6 +17,10 @@ #include namespace NEO { +int64_t defaultCacheEnabled() { + return 1l; +} + std::string makePath(const std::string &lhs, const std::string &rhs) { if (lhs.size() == 0) { return rhs; diff --git a/shared/source/compiler_interface/os_compiler_cache_helper.h b/shared/source/compiler_interface/os_compiler_cache_helper.h index 9da4a650de..3a9b426568 100644 --- a/shared/source/compiler_interface/os_compiler_cache_helper.h +++ b/shared/source/compiler_interface/os_compiler_cache_helper.h @@ -10,6 +10,7 @@ namespace NEO { class SettingsReader; +int64_t defaultCacheEnabled(); std::string makePath(const std::string &lhs, const std::string &rhs); bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader); time_t getFileModificationTime(const std::string &path); diff --git a/shared/source/compiler_interface/windows/os_compiler_cache_helper.cpp b/shared/source/compiler_interface/windows/os_compiler_cache_helper.cpp index 8438c07552..9a84be4c8b 100644 --- a/shared/source/compiler_interface/windows/os_compiler_cache_helper.cpp +++ b/shared/source/compiler_interface/windows/os_compiler_cache_helper.cpp @@ -8,7 +8,9 @@ #include "shared/source/compiler_interface/os_compiler_cache_helper.h" namespace NEO { - +int64_t defaultCacheEnabled() { + return 0l; +} std::string makePath(const std::string &lhs, const std::string &rhs) { return lhs + rhs; }