LCOV - code coverage report
Current view: top level - coll_communicator_mgr/rank_graph/phy_topo - phy_topo.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
Test Date: 2026-08-25 19:18:03 Functions: 71.4 % 7 5

            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              : #ifndef PHY_TOPO_H
      12              : #define PHY_TOPO_H
      13              : 
      14              : #include <vector>
      15              : #include <set>
      16              : #include <memory>
      17              : #include "topo_common_types.h"
      18              : #include "iterator.h"
      19              : #include "graph.h"
      20              : 
      21              : namespace Hccl {
      22              : 
      23              : class PhyTopo {
      24              : public:
      25              :     static std::unique_ptr<PhyTopo>& GetInstance();
      26              :     class ConnInterface {
      27              :     public:
      28              :         // 使用地址信息、位置信息、链路类型、链路协议构造接口
      29              :         ConnInterface(
      30              :             const std::set<std::string> inputPorts, const AddrPosition inputPos, const LinkType inputLinkType,
      31              :             std::set<LinkProtocol> inputLinkProtocols);
      32              :         std::set<std::string> GetPorts() const;
      33              :         AddrPosition GetPos() const;
      34              :         LinkType GetLinkType() const;
      35              :         std::set<LinkProtocol> GetLinkProtocols() const;
      36              :         std::string Describe() const;
      37              :         bool operator==(const ConnInterface& rhs) const;
      38              :         bool operator!=(const ConnInterface& rhs) const;
      39              : 
      40              :     private:
      41              :         std::set<std::string> ports{};
      42              :         AddrPosition pos{};
      43              :         LinkType linkType{};
      44              :         std::set<LinkProtocol> linkProtocols{};
      45              :     };
      46              : 
      47              :     class Node {
      48              :     public:
      49              :         using IfaceIterator = BaseConstIterator<std::vector, std::shared_ptr<PhyTopo::ConnInterface>>;
      50          856 :         MAKE_ENUM(NodeType, PEER, FABRIC);
      51              :         explicit Node(const NodeType inputType);
      52              :         NodeType GetType() const;
      53              :         void AddConnInterface(const std::shared_ptr<PhyTopo::ConnInterface>& interface);
      54              :         IfaceIterator IterIfaces() const;
      55              :         virtual std::string Describe() const;
      56              : 
      57              :     private:
      58              :         NodeType type{};
      59              :         std::vector<std::shared_ptr<PhyTopo::ConnInterface>> interfaces{};
      60              :     };
      61              : 
      62              :     class Peer : public Node {
      63              :     public:
      64              :         explicit Peer(const LocalId localId);
      65              :         LocalId GetLocalId() const;
      66              :         static NodeId GetId(const LocalId localId);
      67              :         std::string Describe() const override;
      68              : 
      69              :     private:
      70              :         LocalId localId{};
      71              :     };
      72              : 
      73              :     class Fabric : public Node {
      74              :     public:
      75              :         explicit Fabric();
      76              :         static NodeId GetId();
      77              :         std::string Describe() const override;
      78              :     };
      79              : 
      80              :     struct LinkAttributes {
      81              :         LinkType linktype;
      82              :         std::set<LinkProtocol> protocols;
      83              :     };
      84              : 
      85              :     class Link {
      86              :     public:
      87              :         // 使用源节点、目的节点、链路类型、链路协议、topo类型、topoInstId 构造链路
      88              :         Link(
      89              :             std::shared_ptr<PhyTopo::Node> inputSource, std::shared_ptr<PhyTopo::Node> inputTarget,
      90              :             const LinkAttributes& linkAttrs, const TopoType topoType, const u32 topoInstId);
      91              :         void SetSourceIface(std::shared_ptr<PhyTopo::ConnInterface> inputSourceIface);
      92              :         void SetTargetIface(std::shared_ptr<PhyTopo::ConnInterface> inputTargetIface);
      93              :         LinkType GetType() const;
      94              :         std::set<LinkProtocol> GetLinkProtocols() const;
      95              :         LinkDirection GetLinkDirection() const;
      96              :         TopoType GetTopoType() const;
      97              :         u32 GetTopoInstId() const;
      98              :         u32 GetHop() const;
      99              :         std::shared_ptr<PhyTopo::ConnInterface> GetSourceIFace();
     100              :         std::shared_ptr<PhyTopo::ConnInterface> GetTargetIFace();
     101              :         std::shared_ptr<PhyTopo::Node> GetSourceNode();
     102              :         std::shared_ptr<PhyTopo::Node> GetTargetNode();
     103              :         std::string Describe() const;
     104              : 
     105              :     private:
     106              :         std::shared_ptr<PhyTopo::ConnInterface> sourceIface{nullptr};
     107              :         std::shared_ptr<PhyTopo::ConnInterface> targetIface{nullptr}; // 如果target为Fabric节点,则为空
     108              :         std::shared_ptr<PhyTopo::Node> source{nullptr};
     109              :         std::shared_ptr<PhyTopo::Node> target{nullptr};
     110              :         std::set<LinkProtocol> linkProtocols{};
     111              :         LinkType linkType{};
     112              :         LinkDirection direction{LinkDirection::BOTH};
     113              :         TopoType topoType{TopoType::CLOS};
     114              :         u32 topoInstId{0};
     115              :         u32 hop{1};
     116              :     };
     117              : 
     118              :     void AddTopoGraph(std::shared_ptr<Graph<PhyTopo::Node, PhyTopo::Link>> topo);
     119              :     std::shared_ptr<Graph<PhyTopo::Node, PhyTopo::Link>> GetTopoGraph() const;
     120              :     void InitFinish();
     121              :     bool IsInitFinished() const;
     122              :     void Clear();
     123              :     void Dump() const;
     124              : 
     125              : private:
     126              :     std::shared_ptr<Graph<PhyTopo::Node, PhyTopo::Link>> topo_{nullptr};
     127              :     bool initFlag{false};
     128              : };
     129              : } // namespace Hccl
     130              : 
     131              : #endif // PHY_TOPO_H
        

Generated by: LCOV version 2.0-1