LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/selector - base_selector.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 1 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 2 0

            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 HCCLV2_COLL_ALG_BASE_SELECTOR
      12              : #define HCCLV2_COLL_ALG_BASE_SELECTOR
      13              : 
      14              : #include <string>
      15              : #include "coll_alg_params.h"
      16              : #include "coll_operator.h"
      17              : #include "virtual_topo.h"
      18              : #include "log.h"
      19              : #include "env_config_v2.h"
      20              : 
      21              : namespace Hccl {
      22              : constexpr u32 CCU_MS_MODE = 2;
      23              : 
      24              : constexpr u32 BIG_CLOS_RANGE = 8;
      25              : 
      26              : enum class SelectorStatus { MATCH, NOT_MATCH };
      27              : enum class Level0Shape {
      28              :     MESH_1D = 1,
      29              :     MESH_2D = 2,
      30              :     CLOS = 3,
      31              :     MESH_1D_CLOS = 4,
      32              : };
      33              : 
      34              : const std::map<OpType, std::string> OP_TYPE_TO_AICPU_SOLE_ALG_MAP = {
      35              :     {OpType::ALLGATHER, "InsAllGatherMesh"}, {OpType::REDUCESCATTER, "InsReduceScatterNHR"},
      36              :     {OpType::ALLREDUCE, "InsAllReduceNHR"},  {OpType::ALLTOALL, "InsAlltoAllMesh"},
      37              :     {OpType::ALLTOALLV, "InsAlltoAllvMesh"}, {OpType::ALLTOALLVC, "InsAlltoAllvcMesh"},
      38              : };
      39              : 
      40              : class BaseSelector {
      41              : public:
      42            0 :     virtual ~BaseSelector() {};
      43              :     BaseSelector& SetVirtualTopo(RankGraph* rankGraph);
      44              :     BaseSelector& SetDevType(DevType devType);
      45              :     BaseSelector& SetMyRank(RankId myRank);
      46              :     BaseSelector& SetRankSize(u32 rankSize);
      47              :     BaseSelector& SetSeverId(std::string severId);
      48              :     BaseSelector& SetDeviceNumPerSever(u32 deviceNumPerSever);
      49              :     BaseSelector& SetServerNum(u32 serverNum);
      50              :     BaseSelector& SetOpConfig(OpExecuteConfig opConfig);
      51              :     BaseSelector& SetIsMc2(bool isMc2);
      52              : 
      53              :     RankGraph* GetVirtualTopo();
      54              :     DevType GetDevType();
      55              :     RankId GetMyRank() const;
      56              :     u32 GetRankSize() const;
      57              :     std::string GetSeverId();
      58              :     u32 GetDeviceNumPerSever() const;
      59              :     u32 GetServerNum() const;
      60              : 
      61              :     bool IsInputOutputOverlap(const std::shared_ptr<Buffer>& inputMem, const std::shared_ptr<Buffer>& outputMem) const;
      62              :     virtual SelectorStatus Select(const CollAlgOperator& op, CollAlgParams& params, std::string& primQueueGenName) = 0;
      63              : 
      64              : protected:
      65              :     struct NetLayerDetails {
      66              :         u32 netLayerNum;
      67              :         std::set<u32> netLayers;
      68              :         std::vector<u32> netInstNumOfLayer;
      69              :         std::vector<std::vector<u32>> instSizeListOfLayer;
      70              :         std::vector<u32> localNetInsSizeOfLayer;
      71              :     };
      72              :     struct TopoInstDetails {
      73              :         u32 topoInstNum;
      74              :         std::vector<u32> sizeOfTopo;
      75              :         std::vector<TopoType> typeOfTopo;
      76              :         std::vector<std::vector<u32>> ranksInTopo;
      77              :         std::map<TopoType, std::vector<u32>> rankNumForTopoType;
      78              :     };
      79              :     struct TopoInfo {
      80              :         u32 levelNum;
      81              :         Level0Shape level0Shape;
      82              :         NetLayerDetails netLayerDetails;
      83              :         std::vector<TopoInstDetails> topoInstDetailsOfLayer;
      84              : 
      85              :         bool Level0Nhr{false};
      86              :         bool Level1Nhr{false};
      87              : 
      88              :         bool level0PcieMix{false};
      89              :         bool level0BigClosRange{false};
      90              :     };
      91              :     u32 Gcd(u32 a, u32 b) const;                           // 自定义实现的 gcd 函数(兼容旧版本 C++)
      92              :     u32 GcdOfArray(const std::vector<u32>& numbers) const; // 计算数组中所有元素的最大公约数
      93              :     u32 GetLevel0Gcd() const;
      94              :     void CalcTopoShape(TopoInfo& topoInfo) const;
      95              :     bool
      96              :     IsAsymmetricTopoShapeLevel1Nhr(const std::vector<std::vector<u32>>& localIdPerBoard, u32 gcdRankSizeLevel0) const;
      97              :     bool IsTopoShapeLevel0Regular(const std::vector<std::vector<u32>>& localIdPerBoard) const;
      98              :     bool IsLayerAllConnetedWithTopo(const TopoInfo& topoInfo, const u32 netLayer, const TopoType topoType) const;
      99              :     HcclResult CalcLevel0TopoShape(TopoInfo& topoInfo) const;
     100              :     HcclResult ExtractNetLayerDetails(TopoInfo& topoInfo) const;
     101              :     HcclResult ExtractTopoDetails(TopoInfo& topoInfo) const;
     102              :     bool Is2DieFullMesh() const;
     103              :     bool IsLevel0PcieMix() const;
     104              :     RankGraph* rankGraph_ = nullptr;
     105              :     OpExecuteConfig opConfig_;
     106              :     DevType devType_;
     107              :     RankId myRank_;
     108              :     u32 rankSize_;
     109              :     std::string severId_;
     110              :     u32 deviceNumPerSever_;
     111              :     u32 serverNum_;
     112              :     bool isMc2_{false};
     113              : };
     114              : 
     115              : } // namespace Hccl
     116              : #endif
        

Generated by: LCOV version 2.0-1