@@ -27,13 +27,6 @@ using Format = LlvmOfflineCache::Format;
27
27
constexpr char kMetadataFilename [] = " metadata" ;
28
28
constexpr char kMetadataFileLockName [] = " metadata.lock" ;
29
29
30
- static bool is_current_llvm_cache_version (
31
- const LlvmOfflineCache::Version &ver) {
32
- // TODO(PGZXB): Do more detailed checking
33
- return ver[0 ] == TI_VERSION_MAJOR && ver[1 ] == TI_VERSION_MINOR &&
34
- ver[2 ] == TI_VERSION_PATCH;
35
- }
36
-
37
30
static std::string get_llvm_cache_metadata_file_path (const std::string &dir) {
38
31
return taichi::join_path (dir, std::string (kMetadataFilename ) + " .tcb" );
39
32
}
@@ -60,13 +53,6 @@ struct CacheCleanerUtils<LlvmOfflineCache> {
60
53
using MetadataType = LlvmOfflineCache;
61
54
using KernelMetaData = typename MetadataType::KernelMetadata;
62
55
63
- // To load metadata from file
64
- static bool load_metadata (const CacheCleanerConfig &config,
65
- MetadataType &result) {
66
- return read_from_binary_file (
67
- result, taichi::join_path (config.path , config.metadata_filename ));
68
- }
69
-
70
56
// To save metadata as file
71
57
static bool save_metadata (const CacheCleanerConfig &config,
72
58
const MetadataType &data) {
@@ -84,12 +70,6 @@ struct CacheCleanerUtils<LlvmOfflineCache> {
84
70
return true ;
85
71
}
86
72
87
- // To check version
88
- static bool check_version (const CacheCleanerConfig &config,
89
- const Version &version) {
90
- return is_current_llvm_cache_version (version);
91
- }
92
-
93
73
// To get cache files name
94
74
static std::vector<std::string> get_cache_files (
95
75
const CacheCleanerConfig &config,
@@ -106,6 +86,13 @@ struct CacheCleanerUtils<LlvmOfflineCache> {
106
86
static void remove_other_files (const CacheCleanerConfig &config) {
107
87
// Do nothing
108
88
}
89
+
90
+ // To check if a file is cache file
91
+ static bool is_valid_cache_file (const CacheCleanerConfig &config,
92
+ const std::string &name) {
93
+ std::string ext = filename_extension (name);
94
+ return ext == " ll" || ext == " bc" ;
95
+ }
109
96
};
110
97
111
98
} // namespace offline_cache
@@ -126,20 +113,12 @@ bool LlvmOfflineCacheFileReader::load_meta_data(
126
113
LlvmOfflineCache &data,
127
114
const std::string &cache_file_path,
128
115
bool with_lock) {
116
+ using offline_cache::load_metadata_with_checking;
117
+ using Error = offline_cache::LoadMetadataError;
129
118
const auto tcb_path = get_llvm_cache_metadata_file_path (cache_file_path);
130
- {
131
- // No the best way to check for filepath existence, but whatever... See
132
- // https://stackoverflow.com/questions/12774207/fastest-way-to-check-if-a-file-exists-using-standard-c-c11-14-17-c
133
- std::ifstream fs (tcb_path, std::ios::in | std::ios::binary);
134
- if (!fs.good ()) {
135
- TI_DEBUG (" LLVM cache {} does not exist" , cache_file_path);
136
- return false ;
137
- }
138
- }
139
119
140
120
if (!with_lock) {
141
- read_from_binary_file (data, tcb_path);
142
- return true ;
121
+ return Error::kNoError == load_metadata_with_checking (data, tcb_path);
143
122
}
144
123
145
124
std::string lock_path =
@@ -150,8 +129,7 @@ bool LlvmOfflineCacheFileReader::load_meta_data(
150
129
TI_WARN (" Unlock {} failed" , lock_path);
151
130
}
152
131
});
153
- read_from_binary_file (data, tcb_path);
154
- return true ;
132
+ return Error::kNoError == load_metadata_with_checking (data, tcb_path);
155
133
}
156
134
TI_WARN (" Lock {} failed" , lock_path);
157
135
return false ;
@@ -389,10 +367,6 @@ void LlvmOfflineCacheFileWriter::mangle_offloaded_task_name(
389
367
for (auto &offload : compiled_data.tasks ) {
390
368
std::string mangled_name =
391
369
offline_cache::mangle_name (offload.name , kernel_key);
392
- TI_DEBUG (
393
- " Mangle offloaded-task from internal name '{}' to offline cache "
394
- " key '{}'" ,
395
- offload.name , mangled_name);
396
370
auto func = compiled_data.module ->getFunction (offload.name );
397
371
TI_ASSERT (func != nullptr );
398
372
func->setName (mangled_name);
0 commit comments