Skip to content

Commit 3e800d5

Browse files
Add support for dumping cl_cache to specified directory
Change-Id: I782ff17d0d4b17d3d26db543eb7ae222f75ff8a1
1 parent 7dbd0ea commit 3e800d5

19 files changed

+157
-34
lines changed

runtime/compiler_interface/binary_cache.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <runtime/helpers/hw_info.h>
1515
#include <runtime/os_interface/os_inc_base.h>
1616
#include <runtime/program/program.h>
17+
#include <runtime/utilities/debug_settings_reader.h>
18+
#include "os_inc.h"
1719

1820
#include <cstring>
1921
#include <string>
@@ -23,7 +25,6 @@
2325

2426
namespace OCLRT {
2527
std::mutex BinaryCache::cacheAccessMtx;
26-
2728
const std::string BinaryCache::getCachedFileName(const HardwareInfo &hwInfo, const ArrayRef<const char> input,
2829
const ArrayRef<const char> options, const ArrayRef<const char> internalOptions) {
2930
Hash hash;
@@ -51,18 +52,22 @@ const std::string BinaryCache::getCachedFileName(const HardwareInfo &hwInfo, con
5152
return stream.str();
5253
}
5354

55+
BinaryCache::BinaryCache() {
56+
std::unique_ptr<SettingsReader> settingsReader(SettingsReader::createOsReader(CL_CACHE_LOCATION));
57+
clCacheLocation = settingsReader->getSetting(settingsReader->appSpecificLocation("cl_cache_dir"), static_cast<std::string>(CL_CACHE_LOCATION));
58+
};
59+
60+
BinaryCache::~BinaryCache(){};
61+
5462
bool BinaryCache::cacheBinary(const std::string kernelFileHash, const char *pBinary, uint32_t binarySize) {
5563
if (pBinary == nullptr || binarySize == 0) {
5664
return false;
5765
}
58-
59-
std::string hashFilePath = CL_CACHE_LOCATION;
60-
hashFilePath.append(Os::fileSeparator);
61-
hashFilePath.append(kernelFileHash + ".cl_cache");
66+
std::string filePath = clCacheLocation + PATH_SEPARATOR + kernelFileHash + ".cl_cache";
6267

6368
std::lock_guard<std::mutex> lock(cacheAccessMtx);
6469
if (writeDataToFile(
65-
hashFilePath.c_str(),
70+
filePath.c_str(),
6671
pBinary,
6772
binarySize) == 0) {
6873
return false;
@@ -75,13 +80,11 @@ bool BinaryCache::loadCachedBinary(const std::string kernelFileHash, Program &pr
7580
void *pBinary = nullptr;
7681
size_t binarySize = 0;
7782

78-
std::string hashFilePath = CL_CACHE_LOCATION;
79-
hashFilePath.append(Os::fileSeparator);
80-
hashFilePath.append(kernelFileHash + ".cl_cache");
83+
std::string filePath = clCacheLocation + PATH_SEPARATOR + kernelFileHash + ".cl_cache";
8184

8285
{
8386
std::lock_guard<std::mutex> lock(cacheAccessMtx);
84-
binarySize = loadDataFromFile(hashFilePath.c_str(), pBinary);
87+
binarySize = loadDataFromFile(filePath.c_str(), pBinary);
8588
}
8689

8790
if ((pBinary == nullptr) || (binarySize == 0)) {

runtime/compiler_interface/binary_cache.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@
1111
#include <cstring>
1212
#include <string>
1313
#include <mutex>
14-
1514
#include "runtime/utilities/arrayref.h"
1615

1716
namespace OCLRT {
18-
1917
struct HardwareInfo;
2018
class Program;
19+
2120
class BinaryCache {
2221
public:
2322
static const std::string getCachedFileName(const HardwareInfo &hwInfo, ArrayRef<const char> input,
2423
ArrayRef<const char> options, ArrayRef<const char> internalOptions);
25-
26-
virtual ~BinaryCache(){};
27-
24+
BinaryCache();
25+
virtual ~BinaryCache();
2826
virtual bool cacheBinary(const std::string kernelFileHash, const char *pBinary, uint32_t binarySize);
2927
virtual bool loadCachedBinary(const std::string kernelFileHash, Program &program);
3028

3129
protected:
3230
static std::mutex cacheAccessMtx;
31+
std::string clCacheLocation;
3332
};
34-
3533
} // namespace OCLRT

runtime/os_interface/debug_settings_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ DebugSettingsManager<DebugLevel>::DebugSettingsManager() {
4141
}
4242

4343
std::remove(logFileName.c_str());
44-
}
44+
} // namespace OCLRT
4545

4646
template <DebugFunctionalityLevel DebugLevel>
4747
void DebugSettingsManager<DebugLevel>::writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode) {

runtime/os_interface/linux/debug_env_reader.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ SettingsReader *SettingsReader::createOsReader(bool userScope) {
1313
return new EnvironmentVariableReader;
1414
}
1515

16+
SettingsReader *SettingsReader::createOsReader(const std::string &regKey) {
17+
return new EnvironmentVariableReader;
18+
}
19+
const char *EnvironmentVariableReader::appSpecificLocation(const std::string &name) {
20+
return name.c_str();
21+
}
22+
1623
bool EnvironmentVariableReader::getSetting(const char *settingName, bool defaultValue) {
1724
return getSetting(settingName, static_cast<int32_t>(defaultValue)) ? true : false;
1825
}

runtime/os_interface/windows/debug_registry_reader.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ namespace OCLRT {
1616
SettingsReader *SettingsReader::createOsReader(bool userScope) {
1717
return new RegistryReader(userScope);
1818
}
19+
SettingsReader *SettingsReader::createOsReader(const std::string &regKey) {
20+
return new RegistryReader(regKey);
21+
}
22+
void RegistryReader::setUpProcessName() {
23+
char buff[MAX_PATH];
24+
GetModuleFileNameA(nullptr, buff, MAX_PATH);
25+
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
26+
processName = "";
27+
}
28+
processName.assign(buff);
29+
}
30+
const char *RegistryReader::appSpecificLocation(const std::string &name) {
31+
if (processName.length() > 0)
32+
return processName.c_str();
33+
return name.c_str();
34+
}
1935

2036
bool RegistryReader::getSetting(const char *settingName, bool defaultValue) {
2137
return getSetting(settingName, static_cast<int32_t>(defaultValue)) ? true : false;
@@ -27,7 +43,7 @@ int32_t RegistryReader::getSetting(const char *settingName, int32_t defaultValue
2743
DWORD success = ERROR_SUCCESS;
2844

2945
success = RegOpenKeyExA(igdrclHkeyType,
30-
igdrclRegKey.c_str(),
46+
registryReadRootKey.c_str(),
3147
0,
3248
KEY_READ,
3349
&Key);
@@ -52,11 +68,10 @@ int32_t RegistryReader::getSetting(const char *settingName, int32_t defaultValue
5268
std::string RegistryReader::getSetting(const char *settingName, const std::string &value) {
5369
HKEY Key;
5470
DWORD success = ERROR_SUCCESS;
55-
bool retFlag = false;
5671
std::string keyValue = value;
5772

5873
success = RegOpenKeyExA(igdrclHkeyType,
59-
igdrclRegKey.c_str(),
74+
registryReadRootKey.c_str(),
6075
0,
6176
KEY_READ,
6277
&Key);
@@ -80,10 +95,8 @@ std::string RegistryReader::getSetting(const char *settingName, const std::strin
8095
&regType,
8196
(LPBYTE)regData,
8297
&regSize);
83-
8498
keyValue.assign(regData);
8599
delete[] regData;
86-
retFlag = true;
87100
} else if (success == ERROR_SUCCESS && regType == REG_BINARY) {
88101
std::unique_ptr<wchar_t[]> regData(new wchar_t[regSize]);
89102
success = RegQueryValueExA(Key,
@@ -99,11 +112,11 @@ std::string RegistryReader::getSetting(const char *settingName, const std::strin
99112
wcstombs_s(&charsConverted, convertedData.get(), regSize, regData.get(), regSize);
100113

101114
keyValue.assign(convertedData.get());
102-
retFlag = true;
103115
}
104116

105117
RegCloseKey(Key);
106118
}
107119
return keyValue;
108120
}
121+
109122
}; // namespace OCLRT

runtime/os_interface/windows/registry_reader.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#pragma once
99

1010
#include "runtime/utilities/debug_settings_reader.h"
11-
11+
#include "os_inc.h"
1212
#include <string>
1313
#include <stdint.h>
1414
#include <Windows.h>
@@ -21,13 +21,18 @@ class RegistryReader : public SettingsReader {
2121
std::string getSetting(const char *settingName, const std::string &value) override;
2222
RegistryReader(bool userScope) {
2323
igdrclHkeyType = userScope ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
24+
setUpProcessName();
2425
}
2526
RegistryReader(std::string regKey) {
26-
igdrclRegKey = regKey;
27+
registryReadRootKey.append(std::string(1, PATH_SEPARATOR)).append(regKey);
28+
setUpProcessName();
2729
}
30+
const char *appSpecificLocation(const std::string &name) override;
2831

2932
protected:
3033
HKEY igdrclHkeyType = HKEY_LOCAL_MACHINE;
31-
std::string igdrclRegKey = "Software\\Intel\\IGFX\\OCL";
34+
std::string registryReadRootKey = "Software\\Intel\\IGFX\\OCL";
35+
void setUpProcessName();
36+
std::string processName;
3237
};
3338
} // namespace OCLRT

runtime/os_interface/windows/windows_wrapper.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,19 @@
1414
// There is a conflict with max/min defined as macro in windows headers with std::max/std::min
1515
#undef min
1616
#undef max
17+
#undef RegOpenKeyExA
18+
#undef RegQueryValueExA
19+
#pragma warning(disable : 4273)
20+
LSTATUS APIENTRY RegOpenKeyExA(
21+
HKEY hKey,
22+
LPCSTR lpSubKey,
23+
DWORD ulOptions,
24+
REGSAM samDesired,
25+
PHKEY phkResult);
26+
LSTATUS APIENTRY RegQueryValueExA(
27+
HKEY hKey,
28+
LPCSTR lpValueName,
29+
LPDWORD lpReserved,
30+
LPDWORD lpType,
31+
LPBYTE lpData,
32+
LPDWORD lpcbData);

runtime/utilities/debug_file_reader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,8 @@ std::string SettingsFileReader::getSetting(const char *settingName, const std::s
8282

8383
return returnValue;
8484
}
85+
86+
const char *SettingsFileReader::appSpecificLocation(const std::string &name) {
87+
return name.c_str();
88+
}
8589
}; // namespace OCLRT

runtime/utilities/debug_file_reader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ class SettingsFileReader : public SettingsReader {
2424
int32_t getSetting(const char *settingName, int32_t defaultValue) override;
2525
bool getSetting(const char *settingName, bool defaultValue) override;
2626
std::string getSetting(const char *settingName, const std::string &value) override;
27+
const char *appSpecificLocation(const std::string &name) override;
2728

2829
protected:
2930
std::map<std::string, int32_t> settingValueMap;
3031
std::map<std::string, std::string> settingStringMap;
3132
};
32-
}; // namespace OCLRT
33+
}; // namespace OCLRT

runtime/utilities/debug_settings_reader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ class SettingsReader {
2323
return createOsReader(false);
2424
}
2525
static SettingsReader *createOsReader(bool userScope);
26+
static SettingsReader *createOsReader(const std::string &regKey);
2627
static SettingsReader *createFileReader();
2728
virtual int32_t getSetting(const char *settingName, int32_t defaultValue) = 0;
2829
virtual bool getSetting(const char *settingName, bool defaultValue) = 0;
2930
virtual std::string getSetting(const char *settingName, const std::string &value) = 0;
30-
31+
virtual const char *appSpecificLocation(const std::string &name) = 0;
3132
static const char *settingsFileName;
3233
};
3334
}; // namespace OCLRT

0 commit comments

Comments
 (0)