| 25 | } |
| 26 | |
| 27 | void KVCacheManager::createKVCacheFile(std::string keyPath, std::string valuePath) { |
| 28 | // Each layer has its own kvcache, so we have to create a key file and a value file for each layer and the file name must be unique |
| 29 | // Here we use the address of the mResource as the file name because the addresses of mResource in different layers are guaranteed to be different |
| 30 | std::string fileName = addrToHex(this); |
| 31 | mBaseFileName = MNNFilePathConcat(mConfig.mKVCacheDir, fileName); |
| 32 | |
| 33 | std::string pathk = keyPath.size() > 0 ? keyPath : mBaseFileName + ".k"; |
| 34 | std::string pathv = valuePath.size() > 0 ? valuePath : mBaseFileName + ".v"; |
| 35 | mKeyCacheFD = MNNCreateFile(pathk.c_str()); |
| 36 | mValueCacheFD = MNNCreateFile(pathv.c_str()); |
| 37 | if (mKeyCacheFD == INVALID_FILE) { |
| 38 | MNN_PRINT("Failed to create the file: %s\n", pathk.c_str()); |
| 39 | } |
| 40 | if (mValueCacheFD == INVALID_FILE) { |
| 41 | MNN_PRINT("Failed to create the file: %s\n", pathv.c_str()); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void KVCacheManager::removeKVCacheFile() { |
| 46 | std::string pathk = mBaseFileName + ".k"; |
nothing calls this directly
no test coverage detected