Skip to content

Commit 3181939

Browse files
committed
[3/N] compiler interface refactor - cache
Change-Id: Iac1f36f7f505b100e65c2b44dff7f1689f99bfe5
1 parent 0bb2458 commit 3181939

File tree

17 files changed

+257
-258
lines changed

17 files changed

+257
-258
lines changed

core/compiler_interface/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
set(NEO_COMPILER_INTERFACE
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/compiler_cache.h
10+
${CMAKE_CURRENT_SOURCE_DIR}/compiler_cache.cpp
911
${CMAKE_CURRENT_SOURCE_DIR}/linker.h
1012
${CMAKE_CURRENT_SOURCE_DIR}/linker.cpp
1113
)

runtime/compiler_interface/binary_cache.cpp renamed to core/compiler_interface/compiler_cache.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
*
66
*/
77

8-
#include "runtime/compiler_interface/binary_cache.h"
8+
#include "core/compiler_interface/compiler_cache.h"
99

1010
#include "core/helpers/aligned_memory.h"
1111
#include "core/helpers/file_io.h"
1212
#include "core/helpers/hash.h"
1313
#include "core/utilities/debug_settings_reader.h"
1414
#include "runtime/helpers/hw_info.h"
15-
#include "runtime/os_interface/ocl_reg_path.h"
16-
#include "runtime/os_interface/os_inc_base.h"
1715

1816
#include "config.h"
1917
#include "os_inc.h"
@@ -25,9 +23,9 @@
2523
#include <string>
2624

2725
namespace NEO {
28-
std::mutex BinaryCache::cacheAccessMtx;
29-
const std::string BinaryCache::getCachedFileName(const HardwareInfo &hwInfo, const ArrayRef<const char> input,
30-
const ArrayRef<const char> options, const ArrayRef<const char> internalOptions) {
26+
std::mutex CompilerCache::cacheAccessMtx;
27+
const std::string CompilerCache::getCachedFileName(const HardwareInfo &hwInfo, const ArrayRef<const char> input,
28+
const ArrayRef<const char> options, const ArrayRef<const char> internalOptions) {
3129
Hash hash;
3230

3331
hash.update("----", 4);
@@ -53,26 +51,20 @@ const std::string BinaryCache::getCachedFileName(const HardwareInfo &hwInfo, con
5351
return stream.str();
5452
}
5553

56-
BinaryCache::BinaryCache() {
57-
std::string keyName = oclRegPath;
58-
keyName += "cl_cache_dir";
59-
std::unique_ptr<SettingsReader> settingsReader(SettingsReader::createOsReader(false, keyName));
60-
clCacheLocation = settingsReader->getSetting(settingsReader->appSpecificLocation(keyName), static_cast<std::string>(CL_CACHE_LOCATION));
61-
};
54+
CompilerCache::CompilerCache(const CompilerCacheConfig &cacheConfig)
55+
: config(cacheConfig){};
6256

63-
BinaryCache::~BinaryCache(){};
64-
65-
bool BinaryCache::cacheBinary(const std::string kernelFileHash, const char *pBinary, uint32_t binarySize) {
57+
bool CompilerCache::cacheBinary(const std::string kernelFileHash, const char *pBinary, uint32_t binarySize) {
6658
if (pBinary == nullptr || binarySize == 0) {
6759
return false;
6860
}
69-
std::string filePath = clCacheLocation + PATH_SEPARATOR + kernelFileHash + ".cl_cache";
61+
std::string filePath = config.cacheDir + PATH_SEPARATOR + kernelFileHash + config.cacheFileExtension;
7062
std::lock_guard<std::mutex> lock(cacheAccessMtx);
7163
return 0 != writeDataToFile(filePath.c_str(), pBinary, binarySize);
7264
}
7365

74-
std::unique_ptr<char[]> BinaryCache::loadCachedBinary(const std::string kernelFileHash, size_t &cachedBinarySize) {
75-
std::string filePath = clCacheLocation + PATH_SEPARATOR + kernelFileHash + ".cl_cache";
66+
std::unique_ptr<char[]> CompilerCache::loadCachedBinary(const std::string kernelFileHash, size_t &cachedBinarySize) {
67+
std::string filePath = config.cacheDir + PATH_SEPARATOR + kernelFileHash + config.cacheFileExtension;
7668

7769
std::lock_guard<std::mutex> lock(cacheAccessMtx);
7870
return loadDataFromFile(filePath.c_str(), cachedBinarySize);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2017-2019 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "core/utilities/arrayref.h"
11+
12+
#include <cstdint>
13+
#include <cstring>
14+
#include <memory>
15+
#include <mutex>
16+
#include <string>
17+
18+
namespace NEO {
19+
struct HardwareInfo;
20+
21+
struct CompilerCacheConfig {
22+
bool enabled = true;
23+
std::string cacheFileExtension;
24+
std::string cacheDir;
25+
};
26+
27+
class CompilerCache {
28+
public:
29+
static const std::string getCachedFileName(const HardwareInfo &hwInfo, ArrayRef<const char> input,
30+
ArrayRef<const char> options, ArrayRef<const char> internalOptions);
31+
32+
CompilerCache(const CompilerCacheConfig &config);
33+
virtual ~CompilerCache() = default;
34+
35+
CompilerCache(const CompilerCache &) = delete;
36+
CompilerCache(CompilerCache &&) = delete;
37+
CompilerCache &operator=(const CompilerCache &) = delete;
38+
CompilerCache &operator=(CompilerCache &&) = delete;
39+
40+
MOCKABLE_VIRTUAL bool cacheBinary(const std::string kernelFileHash, const char *pBinary, uint32_t binarySize);
41+
MOCKABLE_VIRTUAL std::unique_ptr<char[]> loadCachedBinary(const std::string kernelFileHash, size_t &cachedBinarySize);
42+
43+
protected:
44+
static std::mutex cacheAccessMtx;
45+
CompilerCacheConfig config;
46+
};
47+
} // namespace NEO

core/unit_tests/compiler_interface/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
set(NEO_CORE_COMPILER_INTERFACE_TESTS
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/compiler_cache_tests.cpp
910
${CMAKE_CURRENT_SOURCE_DIR}/linker_mock.h
1011
${CMAKE_CURRENT_SOURCE_DIR}/linker_tests.cpp
1112
)
1213

13-
set_property(GLOBAL PROPERTY NEO_CORE_COMPILER_INTERFACE_TESTS ${NEO_CORE_COMPILER_INTERFACE_TESTS})
14+
set_property(GLOBAL PROPERTY NEO_CORE_COMPILER_INTERFACE_TESTS ${NEO_CORE_COMPILER_INTERFACE_TESTS})

0 commit comments

Comments
 (0)