feature: Add new environment variables for compiler cache

This patch add new environment variables to control compiler cache.
Works as follow: If persistent cache is set driver check if NEO_CACHE_DIR
is set. If not then driver checks XDG_CACHE_HOME - If exists
then driver create neo_compiler_cache folder, if
not then driver checks HOME directory. If each NEO_CACHE_DIR,
XDG_CACHE_HOME and HOME are not set then compiler cache is disabled.
Current support is for Linux only.

Signed-off-by: Diedrich, Kamil <kamil.diedrich@intel.com>

Related-To: NEO-4262
This commit is contained in:
Diedrich, Kamil
2023-05-09 00:39:55 +02:00
committed by Compute-Runtime-Automation
parent 268dcb0777
commit 5a4a2ab8ab
16 changed files with 1257 additions and 585 deletions

View File

@@ -23,16 +23,19 @@ set(NEO_CORE_COMPILER_INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/intermediate_representations.h
${CMAKE_CURRENT_SOURCE_DIR}/linker.h
${CMAKE_CURRENT_SOURCE_DIR}/linker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_compiler_cache_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/tokenized_string.h
)
if(WIN32)
list(APPEND NEO_CORE_COMPILER_INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/windows/compiler_cache_windows.cpp
${CMAKE_CURRENT_SOURCE_DIR}/windows/os_compiler_cache_helper.cpp
)
else()
list(APPEND NEO_CORE_COMPILER_INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/linux/compiler_cache_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linux/os_compiler_cache_helper.cpp
)
endif()

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/source/utilities/debug_settings_reader.h"
namespace NEO {
bool createCompilerCachePath(std::string &cacheDir) {
if (NEO::SysCalls::pathExists(cacheDir)) {
if (NEO::SysCalls::pathExists(cacheDir + "neo_compiler_cache")) {
cacheDir = cacheDir + "neo_compiler_cache";
return true;
}
if (NEO::SysCalls::mkdir(cacheDir + "neo_compiler_cache") == 0) {
cacheDir = cacheDir + "neo_compiler_cache";
return true;
} else {
if (errno == EEXIST) {
cacheDir = cacheDir + "neo_compiler_cache";
return true;
}
}
}
cacheDir = "";
return false;
}
bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader) {
std::string emptyString = "";
cacheDir = reader->getSetting(reader->appSpecificLocation("XDG_CACHE_HOME"), emptyString);
if (cacheDir.empty()) {
cacheDir = reader->getSetting(reader->appSpecificLocation("HOME"), emptyString);
if (cacheDir.empty()) {
return false;
}
cacheDir = cacheDir + ".cache/";
return createCompilerCachePath(cacheDir);
}
if (NEO::SysCalls::pathExists(cacheDir)) {
return createCompilerCachePath(cacheDir);
}
return false;
}
} // namespace NEO

View File

@@ -0,0 +1,14 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <string>
namespace NEO {
class SettingsReader;
bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader);
} // namespace NEO

View File

@@ -0,0 +1,14 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
namespace NEO {
bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader) {
return false;
}
} // namespace NEO

View File

@@ -17,6 +17,7 @@
namespace NEO {
namespace SysCalls {
int close(int fileDescriptor);
int mkdir(const std::string &path);
int open(const char *file, int flags);
int openWithMode(const char *file, int flags, int mode);
void *dlopen(const char *filename, int flag);

View File

@@ -51,6 +51,10 @@ unsigned long getNumThreads() {
return taskStat.st_nlink - 2;
}
int mkdir(const std::string &path) {
return ::mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
}
int close(int fileDescriptor) {
return ::close(fileDescriptor);
}