LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/pub_inc - hccl_impl_pub.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 61 61
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 5 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 HCCL_IMPL_PUB_H
      12              : #define HCCL_IMPL_PUB_H
      13              : 
      14              : #include "comm_base_pub.h"
      15              : #include "threadManage.h"
      16              : 
      17              : namespace hccl {
      18              : constexpr s32 PROF_RANKSIZE_OFFSET_OF_PLANEID = 16;
      19              : constexpr s32 PROF_RINGINDEX_OFFSET_OF_PLANEID = 28;
      20              : 
      21              : constexpr u32 PROF_STAGE_0 = 0;
      22              : constexpr u32 PROF_STAGE_1 = 1;
      23              : constexpr u32 PROF_STAGE_2 = 2;
      24              : 
      25              : using level1StreamInfo_t = struct Level1StreamInfo {
      26              :     u32 ringNum; /* 至少有1个ring */
      27              :     std::vector<std::shared_ptr<LocalNotify>> ringSignal;
      28              :     std::vector<std::shared_ptr<LocalNotify>> ringSignalAux;
      29              :     std::vector<Stream> ringStreams;
      30              :     std::vector<std::shared_ptr<ThreadManage>> ringThreadsManage;
      31              :     std::vector<uint32_t> tidInfo;
      32              :     std::vector<Stream> ringDeviceStreams;
      33              :     std::vector<std::shared_ptr<LocalNotify>> ringDeviceSignal;
      34              :     std::vector<std::shared_ptr<LocalNotify>> ringDeviceSignalAux;
      35              : 
      36            2 :     Level1StreamInfo() : ringNum(1) {}
      37              : };
      38              : 
      39              : using tagStreamInfo_t = std::map<std::string, Level1StreamInfo>;
      40              : 
      41              : using CommInfo = struct TagCommInfo {
      42              :     std::vector<std::unique_ptr<CommBase>> commLevel1;
      43              :     std::vector<std::unique_ptr<CommBase>> commLevel1Rdma;
      44              :     std::vector<std::unique_ptr<CommBase>> commLevel0;
      45              :     std::vector<std::unique_ptr<CommBase>> commLevel0Rdma;
      46              :     std::vector<std::unique_ptr<CommBase>> commLevel2;
      47              :     std::vector<std::unique_ptr<CommBase>> commP2P;
      48              :     std::unique_ptr<CommBase> commIntraServer;
      49              : 
      50           11 :     TagCommInfo()
      51           22 :         : commLevel1(0),
      52           22 :           commLevel1Rdma(0),
      53           22 :           commLevel0(0),
      54           22 :           commLevel0Rdma(0),
      55           22 :           commP2P(0),
      56           22 :           commIntraServer(nullptr)
      57           11 :     {}
      58              : };
      59              : using tagCommInfo_t = std::map<std::string, CommInfo>;
      60              : 
      61              : using HcclAlgoAttr = struct HcclAlgoAttrDef {
      62              :     bool isHaveCpuRank;        // 是否有cpu参与通信
      63              :     bool inlineReduceSwitchOn; // 收到数量时同时完成Reduce计算
      64              :     bool isUsedRdmaLevel0;     // Level0 通信域是否使用RDMA
      65              :     bool isUsedInterHccsMode;  // 超节点内节点间是否使用HCCS模式
      66              :     std::string identifier;
      67              :     std::string collectiveId;
      68              :     NICDeployment nicDeployment;
      69              :     WorkMode commWorkMode;
      70              :     std::map<HcclCMDType, std::vector<HcclAlgoType>> commAlgoConfig;
      71              : 
      72         1060 :     HcclAlgoAttrDef()
      73         1060 :         : isHaveCpuRank(false),
      74         1060 :           inlineReduceSwitchOn(true),
      75         1060 :           isUsedRdmaLevel0(false),
      76         1060 :           isUsedInterHccsMode(false),
      77         2120 :           identifier(""),
      78         2120 :           collectiveId(""),
      79         1060 :           nicDeployment(NICDeployment::NIC_DEPLOYMENT_DEVICE),
      80         1060 :           commWorkMode(WorkMode::HCCL_MODE_NORMAL)
      81              :     {
      82         1060 :         SetDefaultAlgo();
      83         1060 :     }
      84         1060 :     void SetDefaultAlgo()
      85              :     {
      86       111300 :         for (u32 opType = 0; opType < static_cast<u32>(HcclCMDType::HCCL_CMD_MAX); opType++) {
      87       110240 :             commAlgoConfig[static_cast<HcclCMDType>(opType)]
      88       220480 :                 = std::vector<HcclAlgoType>(HCCL_ALGO_LEVEL_NUM, HcclAlgoType::HCCL_ALGO_TYPE_DEFAULT);
      89              :         }
      90         1060 :     }
      91              : };
      92              : 
      93              : struct HcclTopoAttr {
      94              :     u32 serverNum;               // 集群中总的服务器数
      95              :     u32 superPodNum;             // 集群中总的超节点数
      96              :     u32 moduleNum;               // 集群中的总的module数
      97              :     u32 deviceNumPerServer;      // 服务器上的Device数量
      98              :     u32 deviceNumPerAggregation; // 每个module中的Device数量
      99              :     bool multiModuleDiffDeviceNumMode; // 每个module内的设备数是否相等,如果不相同即为多module不同卡模式 (走大RING环)
     100              :     bool multiSuperPodDiffServerNumMode; // 每个超节点内的server数是否相等
     101              :     bool multiSuperPodDiffDeviceNumMode; // 每个超节点内的总rank数是否相等
     102              : 
     103              :     bool isDiffDeviceType;
     104              :     u32 gcdDeviceNumPerAggregation;
     105              : 
     106              :     u32 meshAggregationRankSize;
     107              :     bool isDiffDeviceModule;
     108              :     bool isSingleMeshAggregation;
     109              :     bool isAllRankSamePlane; // 通信域所有Rank是否在同一平面
     110              : 
     111              :     u32 userRank; // 通信域 RankID
     112              :     u32 realUserRank;
     113              :     u32 userRankSize;                   // 通信域的 Rank数量
     114              :     std::vector<RankInfo> rankInfoList; // world group内rank的信息, 按照rank id递增依次排列
     115              : 
     116              :     u32 devicePhyId;
     117              :     s32 deviceLogicId;
     118              :     bool useSuperPodMode; // 使用SDID作为DeviceId做相关查询操作
     119              : 
     120              :     DevType deviceType;
     121              :     bool isStandardCard;
     122              :     bool is310PDuoCard;
     123              :     bool isCommon310P3DUO; // 310p duo 2卡4芯场景
     124              :     s32 hccsPortNum;
     125              : 
     126              :     std::vector<u32> nicList;
     127              :     std::unordered_map<u32, u32> pairLinkCounter; // server内所有device间的链路类型计数
     128              :     std::unordered_map<u32, std::unordered_map<int, std::vector<int>>> pairLinkInfo; // server内所有device间的链路类型
     129              :     bool isSupportRdmaLite;                                                          // 是否支持rdma lite
     130              :     bool isSupportHccsAndSio;                                                        // 是否支持hccs sio并发
     131              :     u32 localNicPort;
     132              :     bool isNeedInitNic; // 是否需要初始化Nic,心跳使用
     133              :     bool isARSDoubleRing;
     134              : 
     135         2678 :     HcclTopoAttr()
     136         2678 :         : serverNum(0),
     137         2678 :           superPodNum(0),
     138         2678 :           moduleNum(0),
     139         2678 :           deviceNumPerServer(0),
     140         2678 :           deviceNumPerAggregation(0),
     141         2678 :           multiModuleDiffDeviceNumMode(false),
     142         2678 :           multiSuperPodDiffServerNumMode(false),
     143         2678 :           multiSuperPodDiffDeviceNumMode(false),
     144         2678 :           isDiffDeviceType(false),
     145         2678 :           gcdDeviceNumPerAggregation(0),
     146         2678 :           meshAggregationRankSize(0),
     147         2678 :           isDiffDeviceModule(false),
     148         2678 :           isSingleMeshAggregation(false),
     149         2678 :           isAllRankSamePlane(false),
     150         2678 :           userRank(0),
     151         2678 :           realUserRank(0),
     152         2678 :           userRankSize(0),
     153         5356 :           rankInfoList(0),
     154         2678 :           devicePhyId(0),
     155         2678 :           deviceLogicId(0),
     156         2678 :           useSuperPodMode(false),
     157         2678 :           deviceType(DevType::DEV_TYPE_COUNT),
     158         2678 :           isStandardCard(false),
     159         2678 :           is310PDuoCard(false),
     160         2678 :           isCommon310P3DUO(false),
     161         2678 :           hccsPortNum(-1),
     162         5356 :           nicList(0),
     163         5356 :           pairLinkCounter(0),
     164         5354 :           pairLinkInfo(0),
     165         2677 :           isSupportRdmaLite(false),
     166         2677 :           isSupportHccsAndSio(false),
     167         2677 :           localNicPort(0),
     168         2677 :           isNeedInitNic(false),
     169         2677 :           isARSDoubleRing(true)
     170         2677 :     {}
     171              : };
     172              : 
     173              : using RegisterToHeartBeatCallBack = HcclResult (*)(
     174              :     s32 deviceLogicID, u32 userRank, DevType devType, std::vector<RankInfo>& rankInfoList, const u32 port,
     175              :     const bool isNeedNic, u32 peerRankId, const std::string& commIdentifier, const std::string& tag,
     176              :     bool useSuperPodMode, bool isUsedRdmaLevel0);
     177              : using UnRegisterToHeartBeatCallBack
     178              :     = void (*)(s32 deviceLogicID, DevType devType, const std::string& commIdentifier, const std::string& tag);
     179              : using SetRankPortInfoCallBack = HcclResult (*)(s32 deviceLogicID, bool isUseRankPort, std::vector<u32>& ranksPort);
     180              : #ifdef __cplusplus
     181              : extern "C" {
     182              : #endif // __cplusplus
     183              : void RegisterHeartBeatCallBack(
     184              :     RegisterToHeartBeatCallBack p1, UnRegisterToHeartBeatCallBack p2, SetRankPortInfoCallBack p3);
     185              : #ifdef __cplusplus
     186              : }
     187              : #endif // __cplusplus
     188              : } // namespace hccl
     189              : #endif /** HCCL_IMPL_PUB_H */
        

Generated by: LCOV version 2.0-1