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

Method createKVCacheFile

source/core/KVCacheManager.cpp:27–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27void 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
45void KVCacheManager::removeKVCacheFile() {
46 std::string pathk = mBaseFileName + ".k";

Callers

nothing calls this directly

Calls 5

addrToHexFunction · 0.85
MNNFilePathConcatFunction · 0.85
MNNCreateFileFunction · 0.85
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected