Files
compute-runtime/shared/source/compiler_interface/compiler_cache.h
Fabian Zwolinski 1f1af5bb36 refactor: windows cl_cache eviction mechanism
Refactored eviction mechanism works as follows:
- eviction is needed only if
total size of cache binaries + size of the new binary exceed cache limit
- single evition call removes files with a summed size of 1/3 of the cache limit
- if new binary can not fit in the cache size limit
even after eviction, it will not be saved
- cache limit applies only to
files in cache directory with .cl_cache/.l0_cache extension.
Only these files are counted and only these files are removed

Related-To: NEO-8092
Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
2023-10-03 16:20:28 +02:00

60 lines
2.1 KiB
C++

/*
* Copyright (C) 2019-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/os_interface/os_handle.h"
#include "shared/source/utilities/arrayref.h"
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
namespace NEO {
struct HardwareInfo;
struct CompilerCacheConfig {
bool enabled = true;
std::string cacheFileExtension;
std::string cacheDir;
size_t cacheSize = 0;
};
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;
const CompilerCacheConfig &getConfig() {
return config;
}
const std::string getCachedFileName(const HardwareInfo &hwInfo, ArrayRef<const char> input,
ArrayRef<const char> options, ArrayRef<const char> internalOptions,
ArrayRef<const char> specIds, ArrayRef<const char> specValues,
ArrayRef<const char> igcRevision, size_t igcLibSize, time_t igcLibMTime);
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);
protected:
MOCKABLE_VIRTUAL bool evictCache(uint64_t &bytesEvicted);
MOCKABLE_VIRTUAL bool renameTempFileBinaryToProperName(const std::string &oldName, const std::string &kernelFileHash);
MOCKABLE_VIRTUAL bool createUniqueTempFileAndWriteData(char *tmpFilePathTemplate, const char *pBinary, size_t binarySize);
MOCKABLE_VIRTUAL void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize);
static std::mutex cacheAccessMtx;
CompilerCacheConfig config;
};
} // namespace NEO