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-17 10:19:35 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              : #include "mem_transport_lite_mgr.h"
      11              : #include "binary_stream.h"
      12              : 
      13              : namespace Hccl {
      14              : 
      15            2 : bool MemTransportLiteMgr::IsOpbaseExist(const LinkData& linkData)
      16              : {
      17            2 :     if (opBaseTranspMap.find(linkData) == opBaseTranspMap.end()) {
      18            2 :         return false;
      19              :     }
      20            0 :     return true;
      21              : }
      22              : 
      23            2 : MemTransportLite* MemTransportLiteMgr::GetOpbase(const LinkData& linkData)
      24              : {
      25            2 :     if (UNLIKELY(opBaseTranspMap.find(linkData) == opBaseTranspMap.end())) {
      26            6 :         HCCL_WARNING("OpBase linkData=%s find transport is null", linkData.Describe().c_str());
      27            2 :         return nullptr;
      28              :     }
      29            0 :     return opBaseTranspMap[linkData].get();
      30              : }
      31              : 
      32            2 : void MemTransportLiteMgr::Reset()
      33              : {
      34            6 :     HCCL_INFO("Reset OpbaseTransport");
      35            2 :     opBaseTranspMap.clear();
      36            2 :     for (auto& it : offloadTranspMap) {
      37            0 :         HCCL_INFO("Reset OffloadTransport opTag=%s", it.first.c_str());
      38            0 :         offloadTranspMap[it.first].clear();
      39              :     }
      40            2 :     offloadTranspMap.clear();
      41            2 : }
      42              : 
      43            1 : void MemTransportLiteMgr::ParseOpbasePackedData(std::vector<char>& data)
      44              : {
      45              :     u32 mapSize;
      46            1 :     BinaryStream binaryStream(data);
      47            1 :     binaryStream >> mapSize;
      48              : 
      49            2 :     for (u32 idx = 0; idx < mapSize; idx++) {
      50            1 :         std::vector<char> linkUniqueId;
      51            1 :         binaryStream >> linkUniqueId;
      52            1 :         LinkData link(linkUniqueId);
      53              : 
      54            1 :         std::vector<char> transpUniqueId;
      55            1 :         binaryStream >> transpUniqueId;
      56              : 
      57            1 :         if (!IsOpbaseExist(link)) {
      58            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
      59            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
      60            3 :             HCCL_INFO("Build New OpBase Link=%s, transport=%s", link.Describe().c_str(), lite->Describe().c_str());
      61            1 :             opBaseTranspMap[link] = std::move(lite);
      62            1 :         }
      63            1 :     }
      64            1 : }
      65              : 
      66            0 : MemTransportLite* MemTransportLiteMgr::GetOffload(const std::string& opTag, const LinkData& linkData)
      67              : {
      68            0 :     if (UNLIKELY(
      69              :             offloadTranspMap.find(opTag) == offloadTranspMap.end()
      70              :             || offloadTranspMap[opTag].find(linkData) == offloadTranspMap[opTag].end())) {
      71            0 :         HCCL_WARNING(
      72              :             "offload opTag=%s, linkData=%s find transport is null", opTag.c_str(), linkData.Describe().c_str());
      73            0 :         return nullptr;
      74              :     }
      75            0 :     return offloadTranspMap[opTag][linkData].get();
      76              : }
      77              : 
      78            1 : void MemTransportLiteMgr::ParseOffloadPackedData(const std::string& opTag, std::vector<char>& data)
      79              : {
      80              :     u32 mapSize;
      81            1 :     BinaryStream binaryStream(data);
      82            1 :     binaryStream >> mapSize;
      83              : 
      84            3 :     HCCL_INFO("Build New Offload OpTag=%s transports", opTag.c_str());
      85            2 :     for (u32 idx = 0; idx < mapSize; idx++) {
      86            1 :         std::vector<char> linkUniqueId;
      87            1 :         binaryStream >> linkUniqueId;
      88            1 :         LinkData link(linkUniqueId);
      89              : 
      90            1 :         std::vector<char> transpUniqueId;
      91            1 :         binaryStream >> transpUniqueId;
      92            1 :         auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
      93            1 :         auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
      94            3 :         HCCL_INFO(
      95              :             "MemTransportLiteMgr::ParseOffloadPackedData: %s, %s", link.Describe().c_str(), lite->Describe().c_str());
      96            1 :         offloadTranspMap[opTag][link] = std::move(lite);
      97            1 :     }
      98            1 : }
      99              : 
     100            1 : void MemTransportLiteMgr::ParseOpbaseAllPackedData(BinaryStream& binaryStream)
     101              : {
     102              :     u32 opbasedMapSize;
     103            1 :     binaryStream >> opbasedMapSize;
     104              : 
     105            2 :     for (u32 idx = 0; idx < opbasedMapSize; idx++) {
     106            1 :         std::vector<char> linkUniqueId;
     107            1 :         binaryStream >> linkUniqueId;
     108            1 :         LinkData link(linkUniqueId);
     109              : 
     110            1 :         std::vector<char> transpUniqueId;
     111            1 :         binaryStream >> transpUniqueId;
     112              : 
     113            1 :         if (!IsOpbaseExist(link)) {
     114            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
     115            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
     116            3 :             HCCL_INFO("Build New OpBase Link=%s, transport=%s", link.Describe().c_str(), lite->Describe().c_str());
     117            1 :             opBaseTranspMap[link] = std::move(lite);
     118            1 :         }
     119            1 :     }
     120            1 : }
     121              : 
     122            1 : void MemTransportLiteMgr::ParseOffloadAllPackedData(BinaryStream& binaryStream)
     123              : {
     124              :     u32 opTagNum;
     125            1 :     binaryStream >> opTagNum;
     126            3 :     HCCL_INFO("ParseOffloadAllPackedData: opTagNum=%u", opTagNum);
     127            2 :     for (u32 idx = 0; idx < opTagNum; idx++) {
     128            1 :         std::vector<char> opTagVec;
     129            1 :         binaryStream >> opTagVec;
     130            1 :         std::string opTag(opTagVec.begin(), opTagVec.end());
     131            3 :         HCCL_INFO("ParseOffloadAllPackedData: opTag=%s", opTag.c_str());
     132              :         u32 offloadMapSize;
     133            1 :         binaryStream >> offloadMapSize;
     134            2 :         for (u32 j = 0; j < offloadMapSize; j++) {
     135            1 :             std::vector<char> linkUniqueId;
     136            1 :             binaryStream >> linkUniqueId;
     137            1 :             LinkData link(linkUniqueId);
     138              : 
     139            1 :             std::vector<char> transpUniqueId;
     140            1 :             binaryStream >> transpUniqueId;
     141            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
     142            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
     143            3 :             HCCL_INFO(
     144              :                 "MemTransportLiteMgr::ParseOffloadAllPackedData: %s, %s", link.Describe().c_str(),
     145              :                 lite->Describe().c_str());
     146            1 :             offloadTranspMap[opTag][link] = std::move(lite);
     147            1 :         }
     148            1 :     }
     149            1 : }
     150              : 
     151            1 : void MemTransportLiteMgr::ParseAllPackedData(std::vector<char>& data)
     152              : {
     153            1 :     BinaryStream binaryStream(data);
     154            1 :     ParseOpbaseAllPackedData(binaryStream);
     155            1 :     ParseOffloadAllPackedData(binaryStream);
     156            1 : }
     157              : 
     158              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1