LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/topo - virtual_topo.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.2 % 69 65
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 3 3

            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 "virtual_topo.h"
      12              : #include <algorithm>
      13              : #include <string>
      14              : #include <unordered_map>
      15              : #include "internal_exception.h"
      16              : 
      17              : namespace Hccl {
      18              : 
      19            7 : LinkData::LinkData(vector<char>& data)
      20              : {
      21            7 :     BinaryStream binaryStream(data);
      22              :     u32 val;
      23            7 :     binaryStream >> val;
      24            7 :     type = static_cast<PortDeploymentType::Value>(val);
      25            7 :     binaryStream >> val;
      26            7 :     linkProtocol_ = static_cast<LinkProtocol::Value>(val);
      27            7 :     binaryStream >> val;
      28            7 :     direction = static_cast<LinkDirection::Value>(val);
      29            7 :     binaryStream >> localRankId_;
      30            7 :     binaryStream >> remoteRankId_;
      31            7 :     binaryStream >> localPortId_;
      32            7 :     binaryStream >> remotePortId_;
      33            7 :     binaryStream >> readable;
      34            7 :     binaryStream >> writable;
      35            7 :     binaryStream >> hop;
      36            7 :     binaryStream >> localDieId_;
      37            7 :     binaryStream >> portGroupSize;
      38            7 :     binaryStream >> fullmesh;
      39              : 
      40              :     u32 offset;
      41              :     u32 addrSize;
      42            7 :     binaryStream >> offset;
      43            7 :     binaryStream >> addrSize;
      44              : 
      45            7 :     std::vector<char> locAddr;
      46            7 :     if (data.begin() + offset >= data.end()) {
      47            0 :         THROW<InternalException>("[LinkData][LinkData]invalid offset[%u]", offset);
      48              :     }
      49            7 :     if (data.begin() + offset + addrSize >= data.end()) {
      50            0 :         THROW<InternalException>("[LinkData][LinkData]invalid addrSize[%u]", addrSize);
      51              :     }
      52            7 :     std::copy(data.begin() + offset, data.begin() + offset + addrSize, std::back_inserter(locAddr));
      53            7 :     std::vector<char> rmtAddr;
      54            7 :     std::copy(data.begin() + offset + addrSize, data.end(), std::back_inserter(rmtAddr));
      55              : 
      56            7 :     localAddr_ = IpAddress(locAddr);
      57            7 :     remoteAddr_ = IpAddress(rmtAddr);
      58            7 : }
      59              : 
      60            9 : std::vector<char> LinkData::GetUniqueId() const
      61              : {
      62            9 :     BinaryStream binaryStream;
      63            9 :     u32 val = static_cast<u32>(type);
      64            9 :     binaryStream << val;
      65            9 :     val = static_cast<u32>(linkProtocol_);
      66            9 :     binaryStream << val;
      67            9 :     val = static_cast<u32>(direction);
      68            9 :     binaryStream << val;
      69            9 :     binaryStream << localRankId_;
      70            9 :     binaryStream << remoteRankId_;
      71            9 :     binaryStream << localPortId_;
      72            9 :     binaryStream << remotePortId_;
      73            9 :     binaryStream << readable;
      74            9 :     binaryStream << writable;
      75            9 :     binaryStream << hop;
      76            9 :     binaryStream << localDieId_;
      77            9 :     binaryStream << portGroupSize;
      78            9 :     binaryStream << fullmesh;
      79              : 
      80            9 :     vector<char> result;
      81            9 :     binaryStream.Dump(result);
      82              : 
      83            9 :     auto loc = localAddr_.GetUniqueId();
      84            9 :     auto rmt = remoteAddr_.GetUniqueId();
      85           27 :     HCCL_INFO(
      86              :         "[LinkData::%s] localAddr[%s], remoteAddr[%s].", __func__, localAddr_.Describe().c_str(),
      87              :         remoteAddr_.Describe().c_str());
      88              : 
      89            9 :     u32 offset = result.size();
      90            9 :     u32 addrSize = loc.size();
      91              : 
      92            9 :     offset += sizeof(offset) + sizeof(addrSize);
      93              : 
      94            9 :     binaryStream << offset;
      95            9 :     binaryStream << addrSize;
      96              : 
      97            9 :     binaryStream.Dump(result);
      98            9 :     result.insert(result.end(), loc.begin(), loc.end());
      99            9 :     result.insert(result.end(), rmt.begin(), rmt.end());
     100            9 :     return result;
     101            9 : }
     102              : 
     103           85 : void LinkData::UpdateIpAddrWithPCIE()
     104              : {
     105              : #ifndef CCL_KERNEL_AICPU
     106           85 :     if (linkProtocol_ == LinkProtocol::PCIE) {
     107              :         // 更新localAddr和remoteAddr为vinc ip
     108            0 :         HrtRaSocketGetVnicIpInfos(localDeviceId_, DeviceIdType::DEVICE_ID_TYPE_PHY_ID, localDeviceId_, localAddr_);
     109            0 :         HrtRaSocketGetVnicIpInfos(localDeviceId_, DeviceIdType::DEVICE_ID_TYPE_PHY_ID, remoteDeviceId_, remoteAddr_);
     110              :     }
     111              : #endif
     112           85 : }
     113              : 
     114              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1