2019-10-21 21:47:04 +08:00
|
|
|
/*
|
2023-01-02 17:56:45 +08:00
|
|
|
* Copyright (C) 2019-2023 Intel Corporation
|
2019-10-21 21:47:04 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-09-15 22:48:06 +08:00
|
|
|
#include "shared/source/os_interface/os_handle.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/arrayref.h"
|
2019-10-21 21:47:04 +08:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
2023-03-09 06:15:36 +08:00
|
|
|
#include <unordered_map>
|
2019-10-21 21:47:04 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
struct HardwareInfo;
|
|
|
|
|
|
|
|
struct CompilerCacheConfig {
|
|
|
|
bool enabled = true;
|
|
|
|
std::string cacheFileExtension;
|
|
|
|
std::string cacheDir;
|
2023-03-09 06:15:36 +08:00
|
|
|
size_t cacheSize = 0;
|
2019-10-21 21:47:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CompilerCache {
|
|
|
|
public:
|
|
|
|
CompilerCache(const CompilerCacheConfig &config);
|
|
|
|
virtual ~CompilerCache() = default;
|
|
|
|
|
|
|
|
CompilerCache(const CompilerCache &) = delete;
|
|
|
|
CompilerCache(CompilerCache &&) = delete;
|
|
|
|
CompilerCache &operator=(const CompilerCache &) = delete;
|
|
|
|
CompilerCache &operator=(CompilerCache &&) = delete;
|
2023-04-27 16:42:36 +08:00
|
|
|
const CompilerCacheConfig &getConfig() {
|
|
|
|
return config;
|
|
|
|
}
|
2019-10-21 21:47:04 +08:00
|
|
|
|
2021-10-28 21:06:49 +08:00
|
|
|
const std::string getCachedFileName(const HardwareInfo &hwInfo, ArrayRef<const char> input,
|
2023-08-21 20:00:06 +08:00
|
|
|
ArrayRef<const char> options, ArrayRef<const char> internalOptions,
|
2023-09-01 20:44:26 +08:00
|
|
|
ArrayRef<const char> specIds, ArrayRef<const char> specValues,
|
2023-08-21 20:00:06 +08:00
|
|
|
ArrayRef<const char> igcRevision, size_t igcLibSize, time_t igcLibMTime);
|
2021-10-28 21:06:49 +08:00
|
|
|
|
2023-03-09 06:15:36 +08:00
|
|
|
MOCKABLE_VIRTUAL bool cacheBinary(const std::string &kernelFileHash, const char *pBinary, size_t binarySize);
|
|
|
|
MOCKABLE_VIRTUAL std::unique_ptr<char[]> loadCachedBinary(const std::string &kernelFileHash, size_t &cachedBinarySize);
|
2019-10-21 21:47:04 +08:00
|
|
|
|
|
|
|
protected:
|
2023-03-09 06:15:36 +08:00
|
|
|
MOCKABLE_VIRTUAL bool evictCache();
|
|
|
|
MOCKABLE_VIRTUAL bool renameTempFileBinaryToProperName(const std::string &oldName, const std::string &kernelFileHash);
|
|
|
|
MOCKABLE_VIRTUAL bool createUniqueTempFileAndWriteData(char *tmpFilePathTemplate, const char *pBinary, size_t binarySize);
|
2023-09-15 22:48:06 +08:00
|
|
|
MOCKABLE_VIRTUAL void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize);
|
2023-03-09 06:15:36 +08:00
|
|
|
|
2019-10-21 21:47:04 +08:00
|
|
|
static std::mutex cacheAccessMtx;
|
|
|
|
CompilerCacheConfig config;
|
|
|
|
};
|
|
|
|
} // namespace NEO
|