2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2019-2021 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/compiler_interface/compiler_cache.h"
|
2019-10-16 22:21:04 +02:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
|
|
|
|
#include "shared/source/helpers/file_io.h"
|
|
|
|
|
#include "shared/source/helpers/hash.h"
|
|
|
|
|
#include "shared/source/helpers/hw_info.h"
|
|
|
|
|
#include "shared/source/utilities/debug_settings_reader.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
|
|
|
|
#include "config.h"
|
2018-10-10 16:02:19 +02:00
|
|
|
#include "os_inc.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <mutex>
|
2019-02-27 11:39:32 +01:00
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2019-10-21 15:47:04 +02:00
|
|
|
std::mutex CompilerCache::cacheAccessMtx;
|
|
|
|
|
const std::string CompilerCache::getCachedFileName(const HardwareInfo &hwInfo, const ArrayRef<const char> input,
|
|
|
|
|
const ArrayRef<const char> options, const ArrayRef<const char> internalOptions) {
|
2017-12-21 00:45:38 +01:00
|
|
|
Hash hash;
|
|
|
|
|
|
|
|
|
|
hash.update("----", 4);
|
|
|
|
|
hash.update(&*input.begin(), input.size());
|
|
|
|
|
hash.update("----", 4);
|
|
|
|
|
hash.update(&*options.begin(), options.size());
|
|
|
|
|
hash.update("----", 4);
|
|
|
|
|
hash.update(&*internalOptions.begin(), internalOptions.size());
|
|
|
|
|
|
|
|
|
|
hash.update("----", 4);
|
2019-05-08 16:00:24 +02:00
|
|
|
hash.update(reinterpret_cast<const char *>(&hwInfo.platform), sizeof(hwInfo.platform));
|
2017-12-21 00:45:38 +01:00
|
|
|
hash.update("----", 4);
|
2019-05-08 16:00:24 +02:00
|
|
|
hash.update(reinterpret_cast<const char *>(&hwInfo.featureTable), sizeof(hwInfo.featureTable));
|
2017-12-21 00:45:38 +01:00
|
|
|
hash.update("----", 4);
|
2019-05-08 16:00:24 +02:00
|
|
|
hash.update(reinterpret_cast<const char *>(&hwInfo.workaroundTable), sizeof(hwInfo.workaroundTable));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
auto res = hash.finish();
|
|
|
|
|
std::stringstream stream;
|
|
|
|
|
stream << std::setfill('0')
|
|
|
|
|
<< std::setw(sizeof(res) * 2)
|
|
|
|
|
<< std::hex
|
|
|
|
|
<< res;
|
|
|
|
|
return stream.str();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 15:47:04 +02:00
|
|
|
CompilerCache::CompilerCache(const CompilerCacheConfig &cacheConfig)
|
|
|
|
|
: config(cacheConfig){};
|
2018-10-10 16:02:19 +02:00
|
|
|
|
2019-10-21 15:47:04 +02:00
|
|
|
bool CompilerCache::cacheBinary(const std::string kernelFileHash, const char *pBinary, uint32_t binarySize) {
|
2017-12-21 00:45:38 +01:00
|
|
|
if (pBinary == nullptr || binarySize == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-10-21 15:47:04 +02:00
|
|
|
std::string filePath = config.cacheDir + PATH_SEPARATOR + kernelFileHash + config.cacheFileExtension;
|
2017-12-21 00:45:38 +01:00
|
|
|
std::lock_guard<std::mutex> lock(cacheAccessMtx);
|
2019-08-29 15:10:51 +02:00
|
|
|
return 0 != writeDataToFile(filePath.c_str(), pBinary, binarySize);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-21 15:47:04 +02:00
|
|
|
std::unique_ptr<char[]> CompilerCache::loadCachedBinary(const std::string kernelFileHash, size_t &cachedBinarySize) {
|
|
|
|
|
std::string filePath = config.cacheDir + PATH_SEPARATOR + kernelFileHash + config.cacheFileExtension;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-08-29 15:10:51 +02:00
|
|
|
std::lock_guard<std::mutex> lock(cacheAccessMtx);
|
|
|
|
|
return loadDataFromFile(filePath.c_str(), cachedBinarySize);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|