MCPcopy Create free account
hub / github.com/alibaba/MNN / setCache

Method setCache

express/Executor.cpp:360–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358
359
360void Executor::RuntimeManager::setCache(std::string cacheName) {
361 std::lock_guard<std::mutex> _l(mLock);
362
363 mInside->mCache.reset(new Cache);
364 mInside->mCache->cacheFile = cacheName;
365 mInside->mInfo->onSetCachePath(cacheName.c_str(), 0);
366 if (nullptr == mInside->mCache->cacheFile.c_str()) {
367 MNN_ERROR("Empty cacheFile\n");
368 return;
369 }
370 std::unique_ptr<FileLoader> loader(new FileLoader(mInside->mCache->cacheFile.c_str(), true));
371 if (!loader->valid()) {
372 MNN_ERROR("Load Cache file error.\n");
373 return;
374 }
375 bool result = loader->read();
376 if (!result) {
377 MNN_ERROR("Load Cache file error.\n");
378 return;
379 }
380 if (loader->size() == 0) {
381 MNN_ERROR("Load Cache file error.\n");
382 return;
383 }
384 bool success = loader->merge(mInside->mCache->cacheBuffer);
385 if (!success) {
386 MNN_ERROR("Alloc memory for Cache error.\n");
387 return;
388 }
389
390 // load cache
391 bool valid = loadCache(mInside->mInfo, mInside->mCache->cacheBuffer.get() + mInside->mCache->cacheOffset,
392 mInside->mCache->cacheBuffer.size() - mInside->mCache->cacheOffset);
393 if(!valid) {
394 // Reset cache
395 loadCache(mInside->mInfo, nullptr, 0);
396 MNN_PRINT("Cache invalid, will be reset\n");
397 } else {
398 mInside->mCache->lastCacheSize = mInside->mCache->cacheBuffer.size() - mInside->mCache->cacheOffset;
399 }
400}
401
402void Executor::RuntimeManager::setExternalFile(std::string fileName) {
403 mInside->mContent->mExternalFile = fileName;

Callers 15

_compileWholeModuleFunction · 0.45
_compileSubModuleFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
ChineseBertMethod · 0.45
EnglishBertMethod · 0.45
TTSGeneratorMethod · 0.45
ChineseBertMethod · 0.45
EnglishBertMethod · 0.45
TTSGeneratorMethod · 0.45
loadMethod · 0.45

Calls 9

loadCacheFunction · 0.85
resetMethod · 0.45
onSetCachePathMethod · 0.45
c_strMethod · 0.45
validMethod · 0.45
readMethod · 0.45
sizeMethod · 0.45
mergeMethod · 0.45
getMethod · 0.45

Tested by 2

mainFunction · 0.36
runMethod · 0.36