LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/resource_manager/transport/aicpu - mem_transport_lite_mgr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.8 % 98 89
Test Date: 2026-08-18 17:47:01 Functions: 88.9 % 9 8

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "mem_transport_lite_mgr.h"
      12              : #include "binary_stream.h"
      13              : 
      14              : namespace Hccl {
      15              : 
      16            2 : bool MemTransportLiteMgr::IsOpbaseExist(const LinkData& linkData)
      17              : {
      18            2 :     if (opBaseTranspMap.find(linkData) == opBaseTranspMap.end()) {
      19            2 :         return false;
      20              :     }
      21            0 :     return true;
      22              : }
      23              : 
      24            2 : MemTransportLite* MemTransportLiteMgr::GetOpbase(const LinkData& linkData)
      25              : {
      26            2 :     if (UNLIKELY(opBaseTranspMap.find(linkData) == opBaseTranspMap.end())) {
      27            6 :         HCCL_WARNING("OpBase linkData=%s find transport is null", linkData.Describe().c_str());
      28            2 :         return nullptr;
      29              :     }
      30            0 :     return opBaseTranspMap[linkData].get();
      31              : }
      32              : 
      33            2 : void MemTransportLiteMgr::Reset()
      34              : {
      35            6 :     HCCL_INFO("Reset OpbaseTransport");
      36            2 :     opBaseTranspMap.clear();
      37            2 :     for (auto& it : offloadTranspMap) {
      38            0 :         HCCL_INFO("Reset OffloadTransport opTag=%s", it.first.c_str());
      39            0 :         offloadTranspMap[it.first].clear();
      40              :     }
      41            2 :     offloadTranspMap.clear();
      42            2 : }
      43              : 
      44            1 : void MemTransportLiteMgr::ParseOpbasePackedData(std::vector<char>& data)
      45              : {
      46              :     u32 mapSize;
      47            1 :     BinaryStream binaryStream(data);
      48            1 :     binaryStream >> mapSize;
      49              : 
      50            2 :     for (u32 idx = 0; idx < mapSize; idx++) {
      51            1 :         std::vector<char> linkUniqueId;
      52            1 :         binaryStream >> linkUniqueId;
      53            1 :         LinkData link(linkUniqueId);
      54              : 
      55            1 :         std::vector<char> transpUniqueId;
      56            1 :         binaryStream >> transpUniqueId;
      57              : 
      58            1 :         if (!IsOpbaseExist(link)) {
      59            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
      60            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
      61            3 :             HCCL_INFO("Build New OpBase Link=%s, transport=%s", link.Describe().c_str(), lite->Describe().c_str());
      62            1 :             opBaseTranspMap[link] = std::move(lite);
      63            1 :         }
      64            1 :     }
      65            1 : }
      66              : 
      67            0 : MemTransportLite* MemTransportLiteMgr::GetOffload(const std::string& opTag, const LinkData& linkData)
      68              : {
      69            0 :     if (UNLIKELY(
      70              :             offloadTranspMap.find(opTag) == offloadTranspMap.end()
      71              :             || offloadTranspMap[opTag].find(linkData) == offloadTranspMap[opTag].end())) {
      72            0 :         HCCL_WARNING(
      73              :             "offload opTag=%s, linkData=%s find transport is null", opTag.c_str(), linkData.Describe().c_str());
      74            0 :         return nullptr;
      75              :     }
      76            0 :     return offloadTranspMap[opTag][linkData].get();
      77              : }
      78              : 
      79            1 : void MemTransportLiteMgr::ParseOffloadPackedData(const std::string& opTag, std::vector<char>& data)
      80              : {
      81              :     u32 mapSize;
      82            1 :     BinaryStream binaryStream(data);
      83            1 :     binaryStream >> mapSize;
      84              : 
      85            3 :     HCCL_INFO("Build New Offload OpTag=%s transports", opTag.c_str());
      86            2 :     for (u32 idx = 0; idx < mapSize; idx++) {
      87            1 :         std::vector<char> linkUniqueId;
      88            1 :         binaryStream >> linkUniqueId;
      89            1 :         LinkData link(linkUniqueId);
      90              : 
      91            1 :         std::vector<char> transpUniqueId;
      92            1 :         binaryStream >> transpUniqueId;
      93            1 :         auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
      94            1 :         auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
      95            3 :         HCCL_INFO(
      96              :             "MemTransportLiteMgr::ParseOffloadPackedData: %s, %s", link.Describe().c_str(), lite->Describe().c_str());
      97            1 :         offloadTranspMap[opTag][link] = std::move(lite);
      98            1 :     }
      99            1 : }
     100              : 
     101            1 : void MemTransportLiteMgr::ParseOpbaseAllPackedData(BinaryStream& binaryStream)
     102              : {
     103              :     u32 opbasedMapSize;
     104            1 :     binaryStream >> opbasedMapSize;
     105              : 
     106            2 :     for (u32 idx = 0; idx < opbasedMapSize; idx++) {
     107            1 :         std::vector<char> linkUniqueId;
     108            1 :         binaryStream >> linkUniqueId;
     109            1 :         LinkData link(linkUniqueId);
     110              : 
     111            1 :         std::vector<char> transpUniqueId;
     112            1 :         binaryStream >> transpUniqueId;
     113              : 
     114            1 :         if (!IsOpbaseExist(link)) {
     115            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
     116            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
     117            3 :             HCCL_INFO("Build New OpBase Link=%s, transport=%s", link.Describe().c_str(), lite->Describe().c_str());
     118            1 :             opBaseTranspMap[link] = std::move(lite);
     119            1 :         }
     120            1 :     }
     121            1 : }
     122              : 
     123            1 : void MemTransportLiteMgr::ParseOffloadAllPackedData(BinaryStream& binaryStream)
     124              : {
     125              :     u32 opTagNum;
     126            1 :     binaryStream >> opTagNum;
     127            3 :     HCCL_INFO("ParseOffloadAllPackedData: opTagNum=%u", opTagNum);
     128            2 :     for (u32 idx = 0; idx < opTagNum; idx++) {
     129            1 :         std::vector<char> opTagVec;
     130            1 :         binaryStream >> opTagVec;
     131            1 :         std::string opTag(opTagVec.begin(), opTagVec.end());
     132            3 :         HCCL_INFO("ParseOffloadAllPackedData: opTag=%s", opTag.c_str());
     133              :         u32 offloadMapSize;
     134            1 :         binaryStream >> offloadMapSize;
     135            2 :         for (u32 j = 0; j < offloadMapSize; j++) {
     136            1 :             std::vector<char> linkUniqueId;
     137            1 :             binaryStream >> linkUniqueId;
     138            1 :             LinkData link(linkUniqueId);
     139              : 
     140            1 :             std::vector<char> transpUniqueId;
     141            1 :             binaryStream >> transpUniqueId;
     142            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
     143            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
     144            3 :             HCCL_INFO(
     145              :                 "MemTransportLiteMgr::ParseOffloadAllPackedData: %s, %s", link.Describe().c_str(),
     146              :                 lite->Describe().c_str());
     147            1 :             offloadTranspMap[opTag][link] = std::move(lite);
     148            1 :         }
     149            1 :     }
     150            1 : }
     151              : 
     152            1 : void MemTransportLiteMgr::ParseAllPackedData(std::vector<char>& data)
     153              : {
     154            1 :     BinaryStream binaryStream(data);
     155            1 :     ParseOpbaseAllPackedData(binaryStream);
     156            1 :     ParseOffloadAllPackedData(binaryStream);
     157            1 : }
     158              : 
     159              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1