From a07269aeefd3d394d21f0113f6ce7df86f2e4e07 Mon Sep 17 00:00:00 2001 From: Chang Guo Date: Wed, 7 Aug 2024 12:56:39 -0400 Subject: [PATCH 1/3] get block start and count by MinBlocksInfo to support partial overlap in KVCache --- source/adios2/engine/bp5/BP5Reader.cpp | 39 ++++++++++++++++++- .../toolkit/format/bp5/BP5Deserializer.h | 4 ++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/source/adios2/engine/bp5/BP5Reader.cpp b/source/adios2/engine/bp5/BP5Reader.cpp index 9c7010355f..d38fe20e63 100644 --- a/source/adios2/engine/bp5/BP5Reader.cpp +++ b/source/adios2/engine/bp5/BP5Reader.cpp @@ -382,18 +382,48 @@ void BP5Reader::PerformRemoteGetsWithKVCache() }; std::vector remoteRequestsInfo; std::vector cachedRequestsInfo; + std::unordered_map MinBlocksInfoMap; for (size_t req_seq = 0; req_seq < GetRequests.size(); req_seq++) { - const auto &Req = GetRequests[req_seq]; + auto &Req = GetRequests[req_seq]; const DataType varType = m_IO.InquireVariableType(Req.VarName); + std::string keyPrefix = m_Fingerprint + "|" + Req.VarName + std::to_string(Req.RelStep); + if (Req.BlockID != -1) + { + MinVarInfo *minBlocksInfo = nullptr; + if (MinBlocksInfoMap.find(keyPrefix) == MinBlocksInfoMap.end()) + { + VariableBase *VB = m_BP5Deserializer->GetVariableBaseFromBP5VarRec(Req.VarRec); + minBlocksInfo = MinBlocksInfo(*VB, Req.RelStep); + MinBlocksInfoMap[keyPrefix] = minBlocksInfo; + } + else + { + minBlocksInfo = MinBlocksInfoMap[keyPrefix]; + } + Req.Start.resize(minBlocksInfo->Dims); + Req.Count.resize(minBlocksInfo->Dims); + for (auto &blockInfo : minBlocksInfo->BlocksInfo) + { + if (Req.BlockID == blockInfo.BlockID) + { + for (int i = 0; i < minBlocksInfo->Dims; i++) + { + Req.Start[i] = blockInfo.Start[i]; + Req.Count[i] = blockInfo.Count[i]; + } + break; + } + } + } + RequestInfo ReqInfo(Req.Count.size()); ReqInfo.ReqSeq = req_seq; ReqInfo.TypeSize = helper::GetDataTypeSize(varType); kvcache::QueryBox targetBox(Req.Start, Req.Count); - std::string keyPrefix = m_Fingerprint + "|" + Req.VarName + std::to_string(Req.RelStep); std::string targetKey = keyPrefix + targetBox.toString(); // Exact Match: check if targetKey exists @@ -509,6 +539,11 @@ void BP5Reader::PerformRemoteGetsWithKVCache() auto &ReqInfo = remoteRequestsInfo[handle_seq]; m_KVCache.ExecuteBatch(ReqInfo.CacheKey.c_str(), 0, 0, nullptr); } + + for (auto& item : MinBlocksInfoMap) { + delete item.second; + } + MinBlocksInfoMap.clear(); } void BP5Reader::PerformRemoteGets() diff --git a/source/adios2/toolkit/format/bp5/BP5Deserializer.h b/source/adios2/toolkit/format/bp5/BP5Deserializer.h index fb9db65596..dd3ae493b3 100644 --- a/source/adios2/toolkit/format/bp5/BP5Deserializer.h +++ b/source/adios2/toolkit/format/bp5/BP5Deserializer.h @@ -247,6 +247,10 @@ class BP5Deserializer : virtual public BP5Base /* We assume operators are not thread-safe, call Decompress() one at a time */ std::mutex mutexDecompress; + +public: + VariableBase *GetVariableBaseFromBP5VarRec(void *VarRec) {return static_cast(static_cast(VarRec)->Variable);}; + }; } // end namespace format From d6c5fb88c57749f07296c10eca999c932824e2cc Mon Sep 17 00:00:00 2001 From: Chang Guo Date: Mon, 12 Aug 2024 10:18:36 -0400 Subject: [PATCH 2/3] move MinBlocksInfoMap as a private member and free it up in EndStep() --- source/adios2/engine/bp5/BP5Reader.cpp | 11 +++++------ source/adios2/engine/bp5/BP5Reader.h | 1 + source/adios2/toolkit/format/bp5/BP5Deserializer.h | 6 ++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/adios2/engine/bp5/BP5Reader.cpp b/source/adios2/engine/bp5/BP5Reader.cpp index d38fe20e63..46e42edb82 100644 --- a/source/adios2/engine/bp5/BP5Reader.cpp +++ b/source/adios2/engine/bp5/BP5Reader.cpp @@ -200,6 +200,11 @@ void BP5Reader::EndStep() m_BetweenStepPairs = false; PERFSTUBS_SCOPED_TIMER("BP5Reader::EndStep"); PerformGets(); + for (auto &item : MinBlocksInfoMap) + { + delete item.second; + } + MinBlocksInfoMap.clear(); } std::pair BP5Reader::ReadData(adios2::transportman::TransportMan &FileManager, @@ -382,7 +387,6 @@ void BP5Reader::PerformRemoteGetsWithKVCache() }; std::vector remoteRequestsInfo; std::vector cachedRequestsInfo; - std::unordered_map MinBlocksInfoMap; for (size_t req_seq = 0; req_seq < GetRequests.size(); req_seq++) { @@ -539,11 +543,6 @@ void BP5Reader::PerformRemoteGetsWithKVCache() auto &ReqInfo = remoteRequestsInfo[handle_seq]; m_KVCache.ExecuteBatch(ReqInfo.CacheKey.c_str(), 0, 0, nullptr); } - - for (auto& item : MinBlocksInfoMap) { - delete item.second; - } - MinBlocksInfoMap.clear(); } void BP5Reader::PerformRemoteGets() diff --git a/source/adios2/engine/bp5/BP5Reader.h b/source/adios2/engine/bp5/BP5Reader.h index 5e352935cd..45db4c5e60 100644 --- a/source/adios2/engine/bp5/BP5Reader.h +++ b/source/adios2/engine/bp5/BP5Reader.h @@ -104,6 +104,7 @@ class BP5Reader : public BP5Engine, public Engine /* KVCache for remote data */ kvcache::KVCacheCommon m_KVCache; + std::unordered_map MinBlocksInfoMap; /* Fingerprint to verify local validity against remote data */ std::string m_Fingerprint = ""; diff --git a/source/adios2/toolkit/format/bp5/BP5Deserializer.h b/source/adios2/toolkit/format/bp5/BP5Deserializer.h index dd3ae493b3..1dd97aa14d 100644 --- a/source/adios2/toolkit/format/bp5/BP5Deserializer.h +++ b/source/adios2/toolkit/format/bp5/BP5Deserializer.h @@ -249,8 +249,10 @@ class BP5Deserializer : virtual public BP5Base std::mutex mutexDecompress; public: - VariableBase *GetVariableBaseFromBP5VarRec(void *VarRec) {return static_cast(static_cast(VarRec)->Variable);}; - + VariableBase *GetVariableBaseFromBP5VarRec(void *VarRec) + { + return static_cast(static_cast(VarRec)->Variable); + }; }; } // end namespace format From 315dd45b2cc1a8742d5d379d32c23eb3831c4c46 Mon Sep 17 00:00:00 2001 From: Chang Guo Date: Mon, 12 Aug 2024 15:24:19 -0400 Subject: [PATCH 3/3] resolve warning for 'Req.BlockID != -1' --- source/adios2/engine/bp5/BP5Reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adios2/engine/bp5/BP5Reader.cpp b/source/adios2/engine/bp5/BP5Reader.cpp index 46e42edb82..81786246cc 100644 --- a/source/adios2/engine/bp5/BP5Reader.cpp +++ b/source/adios2/engine/bp5/BP5Reader.cpp @@ -394,7 +394,7 @@ void BP5Reader::PerformRemoteGetsWithKVCache() const DataType varType = m_IO.InquireVariableType(Req.VarName); std::string keyPrefix = m_Fingerprint + "|" + Req.VarName + std::to_string(Req.RelStep); - if (Req.BlockID != -1) + if (Req.BlockID != std::numeric_limits::max()) { MinVarInfo *minBlocksInfo = nullptr; if (MinBlocksInfoMap.find(keyPrefix) == MinBlocksInfoMap.end())