mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:18:24 +08:00
feature: Add process safety to Windows compiler cache
Related-To: NEO-8092 Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com> Co-authored-by: Diedrich, Kamil <kamil.diedrich@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
41914be8c3
commit
10675134e1
@@ -9,6 +9,7 @@
|
||||
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/helpers/file_io.h"
|
||||
#include "shared/source/helpers/path.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
#include "shared/source/utilities/io_functions.h"
|
||||
@@ -59,7 +60,7 @@ bool CompilerCache::evictCache() {
|
||||
vec.reserve(static_cast<size_t>(filesCount));
|
||||
for (int i = 0; i < filesCount; ++i) {
|
||||
ElementsStruct fileElement = {};
|
||||
fileElement.path = makePath(config.cacheDir, files[i]->d_name);
|
||||
fileElement.path = joinPath(config.cacheDir, files[i]->d_name);
|
||||
if (NEO::SysCalls::stat(fileElement.path.c_str(), &fileElement.statEl) == 0) {
|
||||
vec.push_back(std::move(fileElement));
|
||||
}
|
||||
@@ -125,7 +126,7 @@ void unlockFileAndClose(int fd) {
|
||||
NEO::SysCalls::close(fd);
|
||||
}
|
||||
|
||||
void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, int &fd, size_t &directorySize) {
|
||||
void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, HandleType &fd, size_t &directorySize) {
|
||||
bool countDirectorySize = false;
|
||||
errno = 0;
|
||||
fd = NEO::SysCalls::open(configFilePath.c_str(), O_RDWR);
|
||||
@@ -172,7 +173,7 @@ void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath,
|
||||
std::string_view fileName = files[i]->d_name;
|
||||
if (fileName.find(config.cacheFileExtension) != fileName.npos) {
|
||||
ElementsStruct fileElement = {};
|
||||
fileElement.path = makePath(config.cacheDir, files[i]->d_name);
|
||||
fileElement.path = joinPath(config.cacheDir, files[i]->d_name);
|
||||
if (NEO::SysCalls::stat(fileElement.path.c_str(), &fileElement.statEl) == 0) {
|
||||
vec.push_back(std::move(fileElement));
|
||||
}
|
||||
@@ -208,8 +209,8 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p
|
||||
std::unique_lock<std::mutex> lock(cacheAccessMtx);
|
||||
constexpr std::string_view configFileName = "config.file";
|
||||
|
||||
std::string configFilePath = makePath(config.cacheDir, configFileName.data());
|
||||
std::string filePath = makePath(config.cacheDir, kernelFileHash + config.cacheFileExtension);
|
||||
std::string configFilePath = joinPath(config.cacheDir, configFileName.data());
|
||||
std::string filePath = joinPath(config.cacheDir, kernelFileHash + config.cacheFileExtension);
|
||||
|
||||
int fd = -1;
|
||||
size_t directorySize = 0u;
|
||||
@@ -237,7 +238,7 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p
|
||||
|
||||
std::string tmpFileName = "cl_cache.XXXXXX";
|
||||
|
||||
std::string tmpFilePath = makePath(config.cacheDir, tmpFileName);
|
||||
std::string tmpFilePath = joinPath(config.cacheDir, tmpFileName);
|
||||
|
||||
if (!createUniqueTempFileAndWriteData(tmpFilePath.data(), pBinary, binarySize)) {
|
||||
unlockFileAndClose(fd);
|
||||
@@ -259,7 +260,7 @@ bool CompilerCache::cacheBinary(const std::string &kernelFileHash, const char *p
|
||||
}
|
||||
|
||||
std::unique_ptr<char[]> CompilerCache::loadCachedBinary(const std::string &kernelFileHash, size_t &cachedBinarySize) {
|
||||
std::string filePath = makePath(config.cacheDir, kernelFileHash + config.cacheFileExtension);
|
||||
std::string filePath = joinPath(config.cacheDir, kernelFileHash + config.cacheFileExtension);
|
||||
|
||||
return loadDataFromFile(filePath.c_str(), cachedBinarySize);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
|
||||
|
||||
#include "shared/source/helpers/path.h"
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
#include "shared/source/utilities/debug_settings_reader.h"
|
||||
#include "shared/source/utilities/io_functions.h"
|
||||
@@ -21,35 +22,19 @@ int64_t defaultCacheEnabled() {
|
||||
return 1l;
|
||||
}
|
||||
|
||||
std::string makePath(const std::string &lhs, const std::string &rhs) {
|
||||
if (lhs.size() == 0) {
|
||||
return rhs;
|
||||
}
|
||||
|
||||
if (rhs.size() == 0) {
|
||||
return lhs;
|
||||
}
|
||||
|
||||
if (*lhs.rbegin() == PATH_SEPARATOR) {
|
||||
return lhs + rhs;
|
||||
}
|
||||
|
||||
return lhs + PATH_SEPARATOR + rhs;
|
||||
}
|
||||
|
||||
bool createCompilerCachePath(std::string &cacheDir) {
|
||||
if (NEO::SysCalls::pathExists(cacheDir)) {
|
||||
if (NEO::SysCalls::pathExists(makePath(cacheDir, "neo_compiler_cache"))) {
|
||||
cacheDir = makePath(cacheDir, "neo_compiler_cache");
|
||||
if (NEO::SysCalls::pathExists(joinPath(cacheDir, "neo_compiler_cache"))) {
|
||||
cacheDir = joinPath(cacheDir, "neo_compiler_cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NEO::SysCalls::mkdir(makePath(cacheDir, "neo_compiler_cache")) == 0) {
|
||||
cacheDir = makePath(cacheDir, "neo_compiler_cache");
|
||||
if (NEO::SysCalls::mkdir(joinPath(cacheDir, "neo_compiler_cache")) == 0) {
|
||||
cacheDir = joinPath(cacheDir, "neo_compiler_cache");
|
||||
return true;
|
||||
} else {
|
||||
if (errno == EEXIST) {
|
||||
cacheDir = makePath(cacheDir, "neo_compiler_cache");
|
||||
cacheDir = joinPath(cacheDir, "neo_compiler_cache");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +55,7 @@ bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader)
|
||||
}
|
||||
|
||||
// .cache might not exist on fresh installation
|
||||
cacheDir = makePath(cacheDir, ".cache/");
|
||||
cacheDir = joinPath(cacheDir, ".cache/");
|
||||
if (!NEO::SysCalls::pathExists(cacheDir)) {
|
||||
NEO::SysCalls::mkdir(cacheDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user