Skip to content

Commit adf4fdb

Browse files
committed
fix-jenkins-failures(01) Fix file-based binary cache https://github.com/AMDComputeLibraries/MLOpen/issues/2450
1 parent 3ed5e85 commit adf4fdb

4 files changed

Lines changed: 53 additions & 25 deletions

File tree

src/binary_cache.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace miopen {
4545

4646
MIOPEN_DECLARE_ENV_VAR(MIOPEN_DISABLE_CACHE)
4747

48-
boost::filesystem::path ComputeSysCachePath()
48+
static boost::filesystem::path ComputeSysCachePath()
4949
{
5050
std::string cache_dir = GetSystemDbPath();
5151
auto p = boost::filesystem::path{miopen::ExpandUser(cache_dir)};
@@ -55,7 +55,7 @@ boost::filesystem::path ComputeSysCachePath()
5555
return p;
5656
}
5757

58-
boost::filesystem::path ComputeUserCachePath()
58+
static boost::filesystem::path ComputeUserCachePath()
5959
{
6060
#ifdef MIOPEN_CACHE_DIR
6161
std::string cache_dir = MIOPEN_CACHE_DIR;
@@ -73,6 +73,7 @@ boost::filesystem::path ComputeUserCachePath()
7373
#endif
7474
}
7575

76+
#if !MIOPEN_ENABLE_SQLITE_KERN_CACHE
7677
boost::filesystem::path GetCachePath(bool is_system)
7778
{
7879
static const boost::filesystem::path user_path = ComputeUserCachePath();
@@ -82,8 +83,9 @@ boost::filesystem::path GetCachePath(bool is_system)
8283
else
8384
return user_path;
8485
}
86+
#endif // !MIOPEN_ENABLE_SQLITE_KERN_CACHE
8587

86-
bool IsCacheDisabled()
88+
static bool IsCacheDisabled()
8789
{
8890
#ifdef MIOPEN_CACHE_DIR
8991
return miopen::IsEnabled(MIOPEN_DISABLE_CACHE{});
@@ -106,6 +108,8 @@ KDb GetDb(const std::string& device, size_t num_cu)
106108
sys_path = boost::filesystem::path{};
107109
return {sys_path.string(), user_path.string(), device, num_cu};
108110
}
111+
112+
#if !MIOPEN_ENABLE_SQLITE_KERN_CACHE
109113
boost::filesystem::path GetCacheFile(const std::string& device,
110114
const std::string& name,
111115
const std::string& args,
@@ -114,7 +118,9 @@ boost::filesystem::path GetCacheFile(const std::string& device,
114118
std::string filename = (is_kernel_str ? miopen::md5(name) : name) + ".o";
115119
return GetCachePath(false) / miopen::md5(device + ":" + args) / filename;
116120
}
121+
#endif
117122

123+
#if MIOPEN_ENABLE_SQLITE_KERN_CACHE
118124
std::string LoadBinary(const std::string& device,
119125
const size_t num_cu,
120126
const std::string& name,
@@ -124,7 +130,6 @@ std::string LoadBinary(const std::string& device,
124130
if(miopen::IsCacheDisabled())
125131
return {};
126132

127-
#if MIOPEN_ENABLE_SQLITE_KERN_CACHE
128133
auto db = GetDb(device, num_cu);
129134
std::string filename = (is_kernel_str ? miopen::md5(name) : name) + ".o";
130135
KernelConfig cfg{filename, args, ""};
@@ -134,20 +139,8 @@ std::string LoadBinary(const std::string& device,
134139
return record.get();
135140
else
136141
return {};
137-
#else
138-
(void)num_cu;
139-
auto f = GetCacheFile(device, name, args, is_kernel_str);
140-
if(boost::filesystem::exists(f))
141-
{
142-
return f.string();
143-
}
144-
else
145-
{
146-
return {};
147-
}
148-
#endif
149142
}
150-
#if MIOPEN_ENABLE_SQLITE_KERN_CACHE
143+
151144
void SaveBinary(const std::string& hsaco,
152145
const std::string& device,
153146
const std::size_t num_cu,
@@ -166,6 +159,27 @@ void SaveBinary(const std::string& hsaco,
166159
db.StoreRecord(cfg);
167160
}
168161
#else
162+
boost::filesystem::path LoadBinary(const std::string& device,
163+
const size_t num_cu,
164+
const std::string& name,
165+
const std::string& args,
166+
bool is_kernel_str)
167+
{
168+
if(miopen::IsCacheDisabled())
169+
return {};
170+
171+
(void)num_cu;
172+
auto f = GetCacheFile(device, name, args, is_kernel_str);
173+
if(boost::filesystem::exists(f))
174+
{
175+
return f.string();
176+
}
177+
else
178+
{
179+
return {};
180+
}
181+
}
182+
169183
void SaveBinary(const boost::filesystem::path& binary_path,
170184
const std::string& device,
171185
const std::string& name,

src/include/miopen/binary_cache.hpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,41 @@
2727
#ifndef GUARD_MLOPEN_BINARY_CACHE_HPP
2828
#define GUARD_MLOPEN_BINARY_CACHE_HPP
2929

30-
#include <string>
30+
#include <miopen/config.h>
31+
32+
#if !MIOPEN_ENABLE_SQLITE_KERN_CACHE
3133
#include <boost/filesystem/path.hpp>
34+
#endif
3235

33-
#include <miopen/config.h>
36+
#include <string>
3437

3538
namespace miopen {
3639

40+
#if !MIOPEN_ENABLE_SQLITE_KERN_CACHE
3741
boost::filesystem::path GetCacheFile(const std::string& device,
3842
const std::string& name,
3943
const std::string& args,
4044
bool is_kernel_str);
4145

4246
boost::filesystem::path GetCachePath(bool is_system);
43-
std::string LoadBinary(const std::string& device,
44-
std::size_t num_cu,
45-
const std::string& name,
46-
const std::string& args,
47-
bool is_kernel_str = false);
48-
#if !MIOPEN_ENABLE_SQLITE_KERN_CACHE
47+
48+
boost::filesystem::path LoadBinary(const std::string& device,
49+
std::size_t num_cu,
50+
const std::string& name,
51+
const std::string& args,
52+
bool is_kernel_str = false);
4953
void SaveBinary(const boost::filesystem::path& binary_path,
5054
const std::string& device,
5155
const std::string& name,
5256
const std::string& args,
5357
bool is_kernel_str = false);
5458
#else
59+
std::string LoadBinary(const std::string& device,
60+
std::size_t num_cu,
61+
const std::string& name,
62+
const std::string& args,
63+
bool is_kernel_str = false);
64+
5565
void SaveBinary(const std::string& hsaco,
5666
const std::string& device,
5767
std::size_t num_cu,

src/include/miopen/load_file.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#ifndef MIOPEN_GUARD_MLOPEN_LOAD_FILE_HPP
22
#define MIOPEN_GUARD_MLOPEN_LOAD_FILE_HPP
33

4+
#include <boost/filesystem/path.hpp>
45
#include <string>
56

67
namespace miopen {
78

89
std::string LoadFile(const std::string& s);
10+
std::string LoadFile(const boost::filesystem::path& p);
911

1012
} // namespace miopen
1113

src/load_file.cpp

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

55
namespace miopen {
66

7+
std::string LoadFile(const boost::filesystem::path& p) { return LoadFile(p.string()); }
8+
79
std::string LoadFile(const std::string& s)
810
{
911
std::ifstream t(s);

0 commit comments

Comments
 (0)