MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / getCached

Method getCached

deps/GraphBLAS/CUDA/GB_jit_cache.h:264–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262 // 3) compiles and caches the result and returns the program
263 template <typename T, typename FallbackFunc>
264 named_prog<T> getCached(
265 std::string const& name,
266 umap_str_shptr<T>& map,
267 FallbackFunc func) {
268
269 // Find memory cached T object
270 auto it = map.find(name);
271 if ( it != map.end()) {
272// std::cout<<"found memory-cached prog "<<name<<std::endl;
273 return std::make_pair(name, it->second);
274 }
275 else { // Find file cached T object
276 bool successful_read = false;
277 std::string serialized;
278 #if defined(JITIFY_USE_CACHE)
279 std::string cache_dir = getCacheDir();
280 if (not cache_dir.empty() ) {
281 // TODO: Use OS-agnostic path separator
282 std::string file_name = cache_dir + "/" + name;
283 //std::cout<<"looking for prog in file "<<file_name<<std::endl;
284
285 cacheFile file{file_name};
286 serialized = file.read_file();
287 successful_read = file.is_read_successful();
288 }
289 #endif
290 if (not successful_read) {
291 // JIT compile and write to file if possible
292// std::cout << "compiling now" << std::endl;
293 auto f = func();
294
295// std::cout << "completed func()" << std::endl;
296 serialized = f.serialize();
297// std::cout<<" compiled serialized prog "<<name<<std::endl;
298
299 #if defined(JITIFY_USE_CACHE)
300 if (not cache_dir.empty()) {
301 std::string file_name = cache_dir + "/" + name;
302// std::cout<<"writing prog in file "<<file_name<<std::endl;
303 cacheFile file{file_name};
304 file.write(serialized);
305 }
306 #endif
307 }
308 // Add deserialized T to cache and return
309 auto program = std::make_shared<T>(T::deserialize(serialized));
310 map[name] = program;
311 //std::cout<<"storing prog in memory "<<name<<std::endl;
312 return std::make_pair(name, program);
313 }
314 }
315};
316
317} // namespace jit

Callers

nothing calls this directly

Calls 4

deserializeFunction · 0.85
endMethod · 0.80
is_read_successfulMethod · 0.80
serializeMethod · 0.45

Tested by

no test coverage detected