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-04 10:52:23 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(offloadTranspMap.find(opTag) == offloadTranspMap.end()
      69              :         || offloadTranspMap[opTag].find(linkData) == offloadTranspMap[opTag].end())) {
      70            0 :         HCCL_WARNING("offload opTag=%s, linkData=%s find transport is null", opTag.c_str(), linkData.Describe().c_str());
      71            0 :         return nullptr;
      72              :     }
      73            0 :     return offloadTranspMap[opTag][linkData].get();
      74              : }
      75              : 
      76            1 : void MemTransportLiteMgr::ParseOffloadPackedData(const std::string &opTag, std::vector<char> &data)
      77              : {
      78              :     u32          mapSize;
      79            1 :     BinaryStream binaryStream(data);
      80            1 :     binaryStream >> mapSize;
      81              : 
      82            3 :     HCCL_INFO("Build New Offload OpTag=%s transports", opTag.c_str());
      83            2 :     for (u32 idx = 0; idx < mapSize; idx++) {
      84            1 :         std::vector<char> linkUniqueId;
      85            1 :         binaryStream >> linkUniqueId;
      86            1 :         LinkData link(linkUniqueId);
      87              : 
      88            1 :         std::vector<char> transpUniqueId;
      89            1 :         binaryStream >> transpUniqueId;
      90            1 :         auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
      91            1 :         auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
      92            3 :         HCCL_INFO("MemTransportLiteMgr::ParseOffloadPackedData: %s, %s", link.Describe().c_str(), lite->Describe().c_str());
      93            1 :         offloadTranspMap[opTag][link] = std::move(lite);
      94            1 :     }
      95            1 : }
      96              : 
      97            1 : void MemTransportLiteMgr::ParseOpbaseAllPackedData(BinaryStream &binaryStream)
      98              : {
      99              :     u32 opbasedMapSize;
     100            1 :     binaryStream >> opbasedMapSize;
     101              : 
     102            2 :     for (u32 idx = 0; idx < opbasedMapSize; idx++) {
     103            1 :         std::vector<char> linkUniqueId;
     104            1 :         binaryStream >> linkUniqueId;
     105            1 :         LinkData link(linkUniqueId);
     106              : 
     107            1 :         std::vector<char> transpUniqueId;
     108            1 :         binaryStream >> transpUniqueId;
     109              : 
     110            1 :         if (!IsOpbaseExist(link)) {
     111            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
     112            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
     113            3 :             HCCL_INFO("Build New OpBase Link=%s, transport=%s", link.Describe().c_str(), lite->Describe().c_str());
     114            1 :             opBaseTranspMap[link] = std::move(lite);
     115            1 :         }
     116            1 :     }
     117            1 : }
     118              : 
     119            1 : void MemTransportLiteMgr::ParseOffloadAllPackedData(BinaryStream &binaryStream)
     120              : {
     121              :     u32 opTagNum;
     122            1 :     binaryStream >> opTagNum;
     123            3 :     HCCL_INFO("ParseOffloadAllPackedData: opTagNum=%u", opTagNum);
     124            2 :     for (u32 idx = 0; idx < opTagNum; idx++) {
     125            1 :         std::vector<char> opTagVec;
     126            1 :         binaryStream >> opTagVec;
     127            1 :         std::string opTag(opTagVec.begin(), opTagVec.end());
     128            3 :         HCCL_INFO("ParseOffloadAllPackedData: opTag=%s", opTag.c_str());
     129              :         u32 offloadMapSize;
     130            1 :         binaryStream >> offloadMapSize;
     131            2 :         for (u32 j = 0; j < offloadMapSize; j++) {
     132            1 :             std::vector<char> linkUniqueId;
     133            1 :             binaryStream >> linkUniqueId;
     134            1 :             LinkData link(linkUniqueId);
     135              : 
     136            1 :             std::vector<char> transpUniqueId;
     137            1 :             binaryStream >> transpUniqueId;
     138            1 :             auto transportCallbackLite = MemTransportCallbackLite(link, *mirrorTaskMgrLite_);
     139            1 :             auto lite = std::make_unique<MemTransportLite>(transpUniqueId, transportCallbackLite);
     140            3 :             HCCL_INFO("MemTransportLiteMgr::ParseOffloadAllPackedData: %s, %s",
     141              :                        link.Describe().c_str(), lite->Describe().c_str());
     142            1 :             offloadTranspMap[opTag][link] = std::move(lite);
     143            1 :         }
     144            1 :     }
     145            1 : }
     146              : 
     147            1 : void MemTransportLiteMgr::ParseAllPackedData(std::vector<char> &data)
     148              : {
     149            1 :     BinaryStream binaryStream(data);
     150            1 :     ParseOpbaseAllPackedData(binaryStream);
     151            1 :     ParseOffloadAllPackedData(binaryStream);
     152            1 : }
     153              : 
     154              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1