Files
compute-runtime/shared/source/compiler_interface/default_cache_config.cpp
Fabian Zwolinski 52430762ac fix: cl_cache L0 env vars + refactor code structure
Added support for new Compiler Cache
environment variables in Level Zero.

Moved
`opencl/source/compiler_interface/default_cache_config.cpp`
`level_zero/core/source/compiler_interface/default_cache_config.cpp`
to shared directory
`source/compiler_interface/default_cache_config.cpp`

Switched enabling cache by default from per OS to per API.
Changed default state of cl_cache in Level Zero to disabled.

Related-To: NEO-10045
Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
2024-03-01 17:35:08 +01:00

75 lines
2.4 KiB
C++

/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/default_cache_config.h"
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
#include "shared/source/helpers/api_specific_config.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"
#include <string>
namespace NEO {
const std::string neoCachePersistent = "NEO_CACHE_PERSISTENT";
const std::string neoCacheMaxSize = "NEO_CACHE_MAX_SIZE";
const std::string neoCacheDir = "NEO_CACHE_DIR";
const int64_t neoCacheMaxSizeDefault = static_cast<int64_t>(MemoryConstants::gigaByte);
CompilerCacheConfig getDefaultCompilerCacheConfig() {
CompilerCacheConfig ret;
NEO::EnvironmentVariableReader envReader;
if (envReader.getSetting(neoCachePersistent.c_str(), ApiSpecificConfig::compilerCacheDefaultEnabled()) != 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 = ApiSpecificConfig::compilerCacheFileExtension();
ret.cacheSize = static_cast<size_t>(envReader.getSetting(neoCacheMaxSize.c_str(), neoCacheMaxSizeDefault));
if (ret.cacheSize == 0u) {
ret.cacheSize = std::numeric_limits<size_t>::max();
}
return ret;
}
ret.cacheDir = envReader.getSetting(ApiSpecificConfig::compilerCacheDir().c_str(), ApiSpecificConfig::compilerCacheLocation());
if (NEO::SysCalls::pathExists(ret.cacheDir)) {
ret.enabled = true;
ret.cacheSize = static_cast<size_t>(neoCacheMaxSizeDefault);
ret.cacheFileExtension = ApiSpecificConfig::compilerCacheFileExtension();
} else {
ret.enabled = false;
ret.cacheSize = 0u;
ret.cacheFileExtension = ApiSpecificConfig::compilerCacheFileExtension();
}
return ret;
}
} // namespace NEO