feature: enable cl_cache by default on Linux

Resolves: NEO-4262

Signed-off-by: Kacper Kasper <kacper.k.kasper@intel.com>
This commit is contained in:
Kacper Kasper
2023-08-31 11:14:30 +00:00
committed by Compute-Runtime-Automation
parent 154530ad23
commit 269cba1659
8 changed files with 53 additions and 4 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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()

View File

@@ -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<std::string, std::string> mockableEnvs;
mockableEnvs["NEO_CACHE_PERSISTENT"] = "0";
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> 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<std::string, std::string> mockableEnvs;
mockableEnvs["NEO_CACHE_PERSISTENT"] = "0";
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> 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)

View File

@@ -17,6 +17,10 @@
#include <link.h>
namespace NEO {
int64_t defaultCacheEnabled() {
return 1l;
}
std::string makePath(const std::string &lhs, const std::string &rhs) {
if (lhs.size() == 0) {
return rhs;

View File

@@ -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);

View File

@@ -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;
}