mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-28 00:03:14 +08:00
fix: enable cache env variables for level-zero
Related-To: NEO-4262 Signed-off-by: Kacper Kasper <kacper.k.kasper@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
f931c25307
commit
74689fa58a
@@ -9,7 +9,9 @@
|
||||
|
||||
#include "shared/source/compiler_interface/default_cache_config.h"
|
||||
|
||||
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/os_interface/debug_env_reader.h"
|
||||
#include "shared/source/os_interface/sys_calls_common.h"
|
||||
#include "shared/source/utilities/debug_settings_reader.h"
|
||||
|
||||
@@ -18,13 +20,44 @@
|
||||
#include <string>
|
||||
|
||||
namespace NEO {
|
||||
CompilerCacheConfig getDefaultCompilerCacheConfig() {
|
||||
NEO::CompilerCacheConfig ret;
|
||||
std::string NeoCachePersistent = "NEO_CACHE_PERSISTENT";
|
||||
std::string NeoCacheMaxSize = "NEO_CACHE_MAX_SIZE";
|
||||
std::string NeoCacheDir = "NEO_CACHE_DIR";
|
||||
std::string L0CacheDir = "l0_cache_dir";
|
||||
|
||||
std::string keyName = L0::registryPath;
|
||||
keyName += "l0_cache_dir";
|
||||
std::unique_ptr<NEO::SettingsReader> settingsReader(NEO::SettingsReader::createOsReader(false, keyName));
|
||||
ret.cacheDir = settingsReader->getSetting(settingsReader->appSpecificLocation(keyName), static_cast<std::string>(L0_CACHE_LOCATION));
|
||||
CompilerCacheConfig getDefaultCompilerCacheConfig() {
|
||||
CompilerCacheConfig ret;
|
||||
NEO::EnvironmentVariableReader envReader;
|
||||
|
||||
if (envReader.getSetting(NeoCachePersistent.c_str(), defaultCacheEnabled()) != 0) {
|
||||
ret.enabled = true;
|
||||
std::string emptyString = "";
|
||||
ret.cacheDir = envReader.getSetting(NeoCacheDir.c_str(), emptyString);
|
||||
|
||||
if (ret.cacheDir.empty()) {
|
||||
if (!checkDefaultCacheDirSettings(ret.cacheDir, envReader)) {
|
||||
ret.enabled = false;
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
if (!NEO::SysCalls::pathExists(ret.cacheDir)) {
|
||||
ret.cacheDir = "";
|
||||
ret.enabled = false;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret.cacheFileExtension = ".l0_cache";
|
||||
ret.cacheSize = static_cast<size_t>(envReader.getSetting(NeoCacheMaxSize.c_str(), static_cast<int64_t>(MemoryConstants::gigaByte)));
|
||||
|
||||
if (ret.cacheSize == 0u) {
|
||||
ret.cacheSize = std::numeric_limits<size_t>::max();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.cacheDir = envReader.getSetting(L0CacheDir.c_str(), static_cast<std::string>(L0_CACHE_LOCATION));
|
||||
|
||||
if (NEO::SysCalls::pathExists(ret.cacheDir)) {
|
||||
ret.enabled = true;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(NEO_L0_COMPILER_INTERFACE_TESTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${NEO_L0_COMPILER_INTERFACE_TESTS}
|
||||
)
|
||||
|
||||
if(NOT WIN32)
|
||||
target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/linux/default_l0_cache_config_tests.cpp)
|
||||
else()
|
||||
target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/windows/default_l0_cache_config_tests.cpp)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/compiler_interface/default_cache_config.h"
|
||||
#include "shared/source/os_interface/sys_calls_common.h"
|
||||
#include "shared/source/utilities/io_functions.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/mocks/mock_io_functions.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
namespace SysCalls {
|
||||
extern bool pathExistsMock;
|
||||
}
|
||||
|
||||
namespace LegacyPathWorksIfNewEnvIsSetToDisabled {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("l0_cache") != path.npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace LegacyPathWorksIfNewEnvIsSetToDisabled
|
||||
|
||||
TEST(CompilerCache, GivenDefaultL0CacheConfigWithPathExistsAndNewEnvSetToDisabledThenValuesAreProperlyPopulated) {
|
||||
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("l0_cache", cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(".l0_cache", cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
namespace NewEnvIsDisabledAndLegacyPathDoesNotExist {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
return false;
|
||||
}
|
||||
} // namespace NewEnvIsDisabledAndLegacyPathDoesNotExist
|
||||
|
||||
TEST(CompilerCache, GivenDefaultL0CacheConfigWithNotExistingPathAndNewEnvSetToDisabledThenValuesAreProperlyPopulated) {
|
||||
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("l0_cache", cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(".l0_cache", cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
namespace AllVariablesCorrectlySet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("ult/directory/") != path.npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace AllVariablesCorrectlySet
|
||||
|
||||
TEST(CompilerCache, GivenAllEnvVarWhenProperlySetThenProperConfigIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, AllVariablesCorrectlySet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "ult/directory/");
|
||||
}
|
||||
|
||||
namespace NonExistingPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
return false;
|
||||
}
|
||||
} // namespace NonExistingPathIsSet
|
||||
|
||||
TEST(CompilerCache, GivenNonExistingPathWhenGetCompilerCacheConfigThenConfigWithDisabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, NonExistingPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
EXPECT_TRUE(cacheConfig.cacheDir.empty());
|
||||
}
|
||||
|
||||
namespace XDGEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace XDGEnvPathIsSet
|
||||
|
||||
TEST(CompilerCache, GivenXdgCachePathSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XDGEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(CompilerCache, GivenXdgCachePathWithoutTrailingSlashSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XDGEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
namespace HomeEnvPathIsSet {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace HomeEnvPathIsSet
|
||||
|
||||
TEST(CompilerCache, GivenHomeCachePathSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(CompilerCache, GivenHomeCachePathWithoutTrailingSlashSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(CompilerCache, GivenCacheMaxSizeSetTo0WhenGetDefaultConfigThenCacheSizeIsSetToMaxSize) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "0";
|
||||
mockableEnvs["NEO_CACHE_DIR"] = "ult/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, AllVariablesCorrectlySet::pathExistsMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, std::numeric_limits<size_t>::max());
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "ult/directory/");
|
||||
}
|
||||
|
||||
namespace HomeEnvPathIsSetButDotCacheDoesNotExist {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
static bool called = false;
|
||||
if (path.find("home/directory/.cache/neo_compiler_cache") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
if (path.find("home/directory/.cache/") != path.npos) {
|
||||
bool result = called;
|
||||
called = true;
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
} // namespace HomeEnvPathIsSetButDotCacheDoesNotExist
|
||||
|
||||
TEST(CompilerCache, GivenHomeCachePathSetWithoutExistingDotCacheWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSetButDotCacheDoesNotExist::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomeEnvPathIsSetButDotCacheDoesNotExist::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(CompilerCache, GivenHomeCachePathWithoutExistingDotCacheWithoutTrailingSlashSetWhenGetCompilerCacheConfigThenConfigWithEnabledCacheIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["HOME"] = "home/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, HomeEnvPathIsSetButDotCacheDoesNotExist::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, HomeEnvPathIsSetButDotCacheDoesNotExist::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "home/directory/.cache/neo_compiler_cache");
|
||||
}
|
||||
|
||||
namespace XdgPathIsSetAndNeedToCreate {
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
}
|
||||
if (path.find("xdg/directory") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int mkdirMock(const std::string &dir) {
|
||||
return 0;
|
||||
}
|
||||
} // namespace XdgPathIsSetAndNeedToCreate
|
||||
|
||||
TEST(CompilerCache, GivenXdgEnvWhenNeoCompilerCacheNotExistsThenCreateNeoCompilerCacheFolder) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory/";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XdgPathIsSetAndNeedToCreate::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
TEST(CompilerCache, GivenXdgEnvWithoutTrailingSlashWhenNeoCompilerCacheNotExistsThenCreateNeoCompilerCacheFolder) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory";
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XdgPathIsSetAndNeedToCreate::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndNeedToCreate::mkdirMock);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
}
|
||||
|
||||
namespace XdgPathIsSetAndOtherProcessCreatesPath {
|
||||
bool mkdirCalled = false;
|
||||
|
||||
bool pathExistsMock(const std::string &path) {
|
||||
if (path.find("xdg/directory/neo_compiler_cache") != path.npos) {
|
||||
return false;
|
||||
}
|
||||
if (path.find("xdg/directory/") != path.npos) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int mkdirMock(const std::string &dir) {
|
||||
if (dir.find("xdg/directory/neo_compiler_cache") != dir.npos) {
|
||||
mkdirCalled = true;
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace XdgPathIsSetAndOtherProcessCreatesPath
|
||||
|
||||
TEST(CompilerCache, GivenXdgEnvWhenOtherProcessCreatesNeoCompilerCacheFolderThenProperConfigIsReturned) {
|
||||
std::unordered_map<std::string, std::string> mockableEnvs;
|
||||
mockableEnvs["NEO_CACHE_PERSISTENT"] = "1";
|
||||
mockableEnvs["NEO_CACHE_MAX_SIZE"] = "22";
|
||||
mockableEnvs["XDG_CACHE_HOME"] = "xdg/directory/";
|
||||
bool mkdirCalledTemp = false;
|
||||
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&NEO::IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPathExists)> pathExistsBackup(&NEO::SysCalls::sysCallsPathExists, XdgPathIsSetAndOtherProcessCreatesPath::pathExistsMock);
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsMkdir)> mkdirBackup(&NEO::SysCalls::sysCallsMkdir, XdgPathIsSetAndOtherProcessCreatesPath::mkdirMock);
|
||||
VariableBackup<bool> mkdirCalledBackup(&XdgPathIsSetAndOtherProcessCreatesPath::mkdirCalled, mkdirCalledTemp);
|
||||
|
||||
auto cacheConfig = getDefaultCompilerCacheConfig();
|
||||
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
EXPECT_EQ(cacheConfig.cacheFileExtension, ".l0_cache");
|
||||
EXPECT_EQ(cacheConfig.cacheSize, 22u);
|
||||
EXPECT_EQ(cacheConfig.cacheDir, "xdg/directory/neo_compiler_cache");
|
||||
EXPECT_TRUE(XdgPathIsSetAndOtherProcessCreatesPath::mkdirCalled);
|
||||
}
|
||||
} // namespace NEO
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/compiler_interface/default_cache_config.h"
|
||||
#include "shared/source/os_interface/sys_calls_common.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
namespace SysCalls {
|
||||
extern bool pathExistsMock;
|
||||
}
|
||||
|
||||
TEST(CompilerCache, GivenDefaultL0CacheConfigWithPathExistsThenValuesAreProperlyPopulated) {
|
||||
bool pathExistsMock = true;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
EXPECT_STREQ("l0_cache", cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(".l0_cache", cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_TRUE(cacheConfig.enabled);
|
||||
}
|
||||
|
||||
TEST(CompilerCache, GivenDefaultL0CacheConfigWithNonExistingPathThenValuesAreProperlyPopulated) {
|
||||
bool pathExistsMock = false;
|
||||
VariableBackup<bool> pathExistsMockBackup(&NEO::SysCalls::pathExistsMock, pathExistsMock);
|
||||
auto cacheConfig = NEO::getDefaultCompilerCacheConfig();
|
||||
EXPECT_STREQ("l0_cache", cacheConfig.cacheDir.c_str());
|
||||
EXPECT_STREQ(".l0_cache", cacheConfig.cacheFileExtension.c_str());
|
||||
EXPECT_FALSE(cacheConfig.enabled);
|
||||
}
|
||||
} // namespace NEO
|
||||
@@ -17,4 +17,59 @@ Mechanism to cache binary representations of GPU kernels passed to zeModuleCreat
|
||||
to avoid compilation overheads in subsequent calls. Please see more information in
|
||||
https://github.com/intel/compute-runtime/blob/master/opencl/doc/FAQ.md#feature-cl_cache.
|
||||
|
||||
To enable it, please create a *l0_cache* directory in the working directory.
|
||||
### Linux
|
||||
|
||||
#### Official instructions
|
||||
|
||||
##### Environment flags
|
||||
|
||||
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 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
|
||||
variables are set then on-disk cache is disabled.
|
||||
|
||||
NEO_CACHE_MAX_SIZE - Cache eviction is triggered once total size of cached binaries exceeds the value in
|
||||
bytes (default is 1GB). Set to 0 to disable size-based cache eviction.
|
||||
|
||||
#### Legacy approach
|
||||
|
||||
In the working directory, manually create *l0_cache* directory.
|
||||
The driver will use this directory to store the binary representations of the compiled kernels.
|
||||
Note: This will work on all supported OSes.
|
||||
|
||||
##### Configuring l0_cache location
|
||||
|
||||
Cached kernels can be stored in a different directory than the default one.
|
||||
This is useful when the application is installed into a directory
|
||||
for which the user doesn't have permissions.
|
||||
|
||||
Set the environment variable named `l0_cache_dir` to new location of l0_cache directory.
|
||||
|
||||
### Windows
|
||||
|
||||
#### Official instructions (implementation pending)
|
||||
|
||||
##### Environment flags
|
||||
|
||||
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_CACHE_DIR - path to persistent cache directory. Default values are %LocalAppData%\NEO\neo_compiler_cache
|
||||
if %LocalAppData% is found. If none of environment
|
||||
variables are set then on-disk cache is disabled.
|
||||
|
||||
NEO_CACHE_MAX_SIZE - Cache eviction is triggered once total size of cached binaries exceeds the value in
|
||||
bytes (default is 1GB). Set to 0 to disable size-based cache eviction.
|
||||
#### Legacy approach
|
||||
|
||||
##### Windows configuration
|
||||
|
||||
To set the new location of cl_cache directory - add new environment variable:
|
||||
1. variable name: `l0_cache_dir`
|
||||
1. variable value: <destination_directory_for_l0_cache>
|
||||
|
||||
#### Known limitations
|
||||
|
||||
Please refer to OpenCL documentation: https://github.com/intel/compute-runtime/blob/master/opencl/doc/FAQ.md#what-are-the-known-limitations-of-cl_cache-for-windows
|
||||
Reference in New Issue
Block a user