LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/topo/new_topo_builder/phy_topo - phy_topo.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
Test Date: 2026-08-04 10:52:23 Functions: 62.5 % 8 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 <unordered_map>
      17              : #include <memory>
      18              : #include "topo_common_types.h"
      19              : #include "iterator.h"
      20              : #include "graph.h"
      21              : 
      22              : namespace Hccl {
      23              : 
      24              : class PhyTopo {
      25              : public:
      26              :     static std::unique_ptr<PhyTopo> &GetInstance();
      27              :     class ConnInterface {
      28              :     public:
      29              :         // 使用地址信息、位置信息、链路类型、链路协议构造接口
      30              :         ConnInterface(const std::set<std::string> inputPorts, const AddrPosition inputPos,
      31              :                       const LinkType inputLinkType, 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         1530 :         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(std::shared_ptr<PhyTopo::Node> inputSource, std::shared_ptr<PhyTopo::Node> inputTarget,
      89              :              const LinkAttributes &linkAttrs, const TopoType topoType,
      90              :              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(const u32 netLayer, std::shared_ptr<Graph<PhyTopo::Node, PhyTopo::Link>> topo);
     119              :     std::shared_ptr<Graph<PhyTopo::Node, PhyTopo::Link>> GetTopoGraph(const u32 netLayer) const;
     120              :     void                                                 InitFinish();
     121              :     bool                                                 IsInitFinished() const;
     122              :     void                                                 Clear();
     123              :     void                                                 Dump() const;
     124              :     bool                                                 IsNetLayerExisted(const u32 netLayer) const;
     125              : 
     126              : private:
     127              :     std::unordered_map<u32, std::shared_ptr<Graph<PhyTopo::Node, PhyTopo::Link>>> topos;
     128              :     bool                                                                          initFlag{false};
     129              : };
     130              : } // namespace Hccl
     131              : 
     132              : #endif // PHY_TOPO_H
        

Generated by: LCOV version 2.0-1