mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 08:53:55 +08:00
feature: add new environment variables for compiler cache on Windows
Changes: - replaced registry keys with environment variables for cl_cache in OCL - added compiler cache helpers - implemented support for new env vars on Windows - added tests New env vars mechanism works as follows: If `PERSISTENT_CACHE` is set, driver checks if `NEO_CACHE_DIR` is set. If `NEO_CACHE_DIR` is not set, driver uses `%LocalAppData%\NEO\neo_compiler_cache` as `cl_cache` destination folder. If `NEO_CACHE_DIR` is not set and `%LocalAppData%` path could not be obtained, compiler cache is disabled. In the current Windows implementation, special characters in the folder path are not supported. Related-To: NEO-8092 Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
5569dac6d0
commit
e96dd344c3
@@ -8,8 +8,8 @@
|
||||
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
|
||||
|
||||
#include "shared/source/helpers/path.h"
|
||||
#include "shared/source/os_interface/debug_env_reader.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"
|
||||
|
||||
#include "os_inc.h"
|
||||
@@ -44,12 +44,12 @@ bool createCompilerCachePath(std::string &cacheDir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader) {
|
||||
bool checkDefaultCacheDirSettings(std::string &cacheDir, NEO::EnvironmentVariableReader &reader) {
|
||||
std::string emptyString = "";
|
||||
cacheDir = reader->getSetting(reader->appSpecificLocation("XDG_CACHE_HOME"), emptyString);
|
||||
cacheDir = reader.getSetting("XDG_CACHE_HOME", emptyString);
|
||||
|
||||
if (cacheDir.empty()) {
|
||||
cacheDir = reader->getSetting(reader->appSpecificLocation("HOME"), emptyString);
|
||||
cacheDir = reader.getSetting("HOME", emptyString);
|
||||
if (cacheDir.empty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader)
|
||||
time_t getFileModificationTime(const std::string &path) {
|
||||
struct stat st;
|
||||
if (NEO::SysCalls::stat(path, &st) == 0) {
|
||||
return st.st_mtim.tv_sec;
|
||||
return st.st_mtime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <string>
|
||||
|
||||
namespace NEO {
|
||||
class SettingsReader;
|
||||
class EnvironmentVariableReader;
|
||||
int64_t defaultCacheEnabled();
|
||||
bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader);
|
||||
bool checkDefaultCacheDirSettings(std::string &cacheDir, NEO::EnvironmentVariableReader &reader);
|
||||
time_t getFileModificationTime(const std::string &path);
|
||||
size_t getFileSize(const std::string &path);
|
||||
} // namespace NEO
|
||||
@@ -7,17 +7,96 @@
|
||||
|
||||
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
|
||||
|
||||
#include "shared/source/helpers/path.h"
|
||||
#include "shared/source/os_interface/windows/sys_calls.h"
|
||||
#include "shared/source/utilities/debug_settings_reader.h"
|
||||
|
||||
#include <ShlObj.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace NEO {
|
||||
int64_t defaultCacheEnabled() {
|
||||
return 0l;
|
||||
}
|
||||
bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader) {
|
||||
|
||||
std::string getKnownFolderPath(REFKNOWNFOLDERID rfid) {
|
||||
PWSTR path = nullptr;
|
||||
auto result = SysCalls::shGetKnownFolderPath(rfid, 0, nullptr, &path);
|
||||
if (result != S_OK) {
|
||||
SysCalls::coTaskMemFree(path);
|
||||
return std::string();
|
||||
}
|
||||
std::wstring temp(path);
|
||||
SysCalls::coTaskMemFree(path);
|
||||
std::string ret(temp.length(), 0);
|
||||
std::transform(temp.begin(), temp.end(), ret.begin(), [](wchar_t c) {
|
||||
return static_cast<char>(c);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool createCompilerCachePath(std::string &cacheDir) {
|
||||
if (NEO::SysCalls::pathExists(cacheDir)) {
|
||||
cacheDir = joinPath(cacheDir, "neo_compiler_cache");
|
||||
if (NEO::SysCalls::pathExists(cacheDir)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto result = SysCalls::createDirectoryA(cacheDir.c_str(), NULL);
|
||||
if (result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (SysCalls::getLastError() == ERROR_ALREADY_EXISTS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
cacheDir = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkDefaultCacheDirSettings(std::string &cacheDir, NEO::EnvironmentVariableReader &reader) {
|
||||
cacheDir = getKnownFolderPath(FOLDERID_LocalAppData);
|
||||
|
||||
if (cacheDir.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cacheDir = joinPath(cacheDir, "NEO\\");
|
||||
if (!SysCalls::pathExists(cacheDir)) {
|
||||
SysCalls::createDirectoryA(cacheDir.c_str(), NULL);
|
||||
}
|
||||
|
||||
if (NEO::SysCalls::pathExists(cacheDir)) {
|
||||
return createCompilerCachePath(cacheDir);
|
||||
}
|
||||
|
||||
cacheDir = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t getFileModificationTime(const std::string &path) {
|
||||
return 0;
|
||||
WIN32_FIND_DATAA ffd;
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
hFind = SysCalls::findFirstFileA(path.c_str(), &ffd);
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
return 0;
|
||||
}
|
||||
ULARGE_INTEGER uli;
|
||||
uli.LowPart = ffd.ftLastWriteTime.dwLowDateTime;
|
||||
uli.HighPart = ffd.ftLastWriteTime.dwHighDateTime;
|
||||
return uli.QuadPart;
|
||||
}
|
||||
|
||||
size_t getFileSize(const std::string &path) {
|
||||
return 0;
|
||||
WIN32_FIND_DATAA ffd;
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
hFind = SysCalls::findFirstFileA(path.c_str(), &ffd);
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
return 0u;
|
||||
}
|
||||
return static_cast<size_t>((ffd.nFileSizeHigh * (MAXDWORD + 1)) + ffd.nFileSizeLow);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user