LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/pub_inc - coll_alg_operator.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 2 2

            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 ALG_OPERATOR_BASE_H
      12              : #define ALG_OPERATOR_BASE_H
      13              : 
      14              : #include <vector>
      15              : #include "hccl_impl.h"
      16              : #include "parallel_task_loader.h"
      17              : #include "dispatcher.h"
      18              : #include "ccl_buffer_manager.h"
      19              : #include "hccl_trace_info.h"
      20              : #include "device_capacity.h"
      21              : #include "topo_matcher.h"
      22              : 
      23              : #include "coll_alg_param.h"
      24              : #include "coll_executor_base.h"
      25              : #include "coll_alg_utils.h"
      26              : #include "alg_configurator.h"
      27              : #include "hccl_aiv.h"
      28              : #include "config_log.h"
      29              : 
      30              : namespace hccl {
      31              : struct PreProcessMetaInfo {
      32              :     HcclCMDType opType;
      33              :     std::vector<u64> inputData;
      34              :     u64 inputSize;
      35              :     u64 outputSize;
      36              : };
      37              : 
      38              : class CollAlgOperator {
      39              : public:
      40              :     CollAlgOperator(
      41              :         AlgConfigurator* algConfigurator, CCLBufferManager& cclBufferManager, HcclDispatcher dispatcher,
      42              :         std::unique_ptr<TopoMatcher>& topoMatcher, HcclCMDType opType);
      43          103 :     virtual ~CollAlgOperator() = default;
      44              : 
      45              :     virtual HcclResult
      46              :     SelectAlg(const std::string& tag, const OpParam& param, std::string& algName, std::string& newTag);
      47              :     virtual HcclResult SelectAlg(
      48              :         const std::string& tag, const OpParam& param, std::string& algName, std::string& newTag,
      49              :         const ResourceLimit& limit);
      50              :     HcclResult SelectAlg(
      51              :         const std::string& tag, const OpParam& param, const ResourceLimit& limit, std::string& algName,
      52              :         AlgDesc& algDesc, std::string& newTag);
      53              :     virtual HcclResult
      54              :     CalcResRequest(const std::string& algName, const OpParam& param, AlgResourceRequest& resourceRequest);
      55              :     virtual HcclResult Orchestrate(const std::string& algName, OpParam& param, AlgResourceResponse& algResource);
      56              :     // AIV判断是否需要拷贝通信域信息到device上
      57              :     HcclResult PrepareCommInfoToDevice(const std::string& algName, AlgResourceResponse& algResource);
      58              :     virtual HcclResult
      59              :     GetAdjInfo(const std::string& algName, OpParam& param, AlgResourceResponse& algResource, AdjInfo& nslbAdjInfo);
      60              :     // batchsendrecv判断是否需要增量建链
      61              :     HcclResult CalcIncreLinkRequest(
      62              :         const std::string& algName, const OpParam& param, std::set<u32>& ranksHasLinked,
      63              :         AlgResourceRequest& resourceRequest, bool& needIncreLink);
      64              :     AlgType GetAlgType();
      65              :     void SetLegacyHcclImpl(std::unique_ptr<hcclImpl>& impl);
      66              :     HcclResult SetAlgOpContext(AlgOpContext algOpContext);
      67              :     HcclResult SetRetryEnable(bool retryEnable);
      68              :     HcclResult
      69              :     GetAivExecParam(std::string& algName, const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args);
      70              :     HcclResult CalNumBlocks(std::string& algName, const OpParam& param, u32& numBlocks, int32_t aivCoreLimit = 0);
      71              :     HcclResult SetAivClearEnable(bool aivClearEnable);
      72              :     bool SupportRetryWithInplaceCheck(
      73              :         const HcclCMDType& opType, OpParam& param, std::string& algName, u8& isInplaceStatus,
      74              :         InplaceSupportRetryStatus& inPlaceSupportRetryStatus);
      75              :     HcclResult GetNumBlocks(u32& numBlocks);
      76              :     HcclResult SetNumBlocks(const u32& numBlocks);
      77              :     HcclResult GetCache(HcclCacheInfo& cacheInfo);
      78              :     HcclResult SetOpCounter(const OpCounterInfo& opCounter);
      79              :     u32 CalcOptimalIntraRingsize(u64 count, HcclDataType dataType, HcclCMDType opType);
      80              :     HcclResult SetRmaInfo(void* rmaInfo);
      81              :     HcclResult GetOpExpansionStr(const OpParam& param, const AlgDesc& algDesc, std::string& opExpansionStr);
      82              : 
      83              : protected:
      84              :     std::string GenerateNewTagByAlgTypeLevel1(std::string tag, std::string algTypeLevel1Tag) const;
      85              :     u32 CalcContextNumForPipeline(HcclCMDType hcclCMDType);
      86              :     HcclResult AutoSelectAlgTypeLevel1(
      87              :         HcclCMDType hcclCMDType, u64 countSize, u64 cclBufferSize, std::string& algTypeLevel1Tag,
      88              :         bool isInlineReduce = false, bool isRdmaReduce = false, bool isAivMode = false);
      89              :     bool SingleMeshInlineReduce(void* inputPtr, void* outputPtr, HcclDataType dataType, HcclReduceOp op);
      90              :     bool Is2U2PInfer();
      91              :     bool IsMultiMeshInlineReduce(void* inputPtr, void* outputPtr, HcclDataType dataType, HcclReduceOp op);
      92              :     bool Is910BSingleMesh();
      93              :     bool NeedCreateSingleMeshPlane(const bool isInlineReduce);
      94              :     virtual HcclResult SetExecutorAttr(const OpParam& param);
      95              :     HcclResult SelectAlgforAHC(u64 dataSize, AHCOpType ahcOpType);
      96              :     HcclResult AHCAlgSelect(
      97              :         AlgTypeLevel1& algType, std::vector<std::vector<std::vector<u32>>>& globalSubGroups,
      98              :         std::map<AHCConcOpType, TemplateType>& ahcAlgOption, AHCAlgSelectParam& ahcAlgSelectParam);
      99              :     HcclResult AHCAlgOptionSelect(
     100              :         const AlgTypeLevel1& algType, std::vector<std::vector<std::vector<u32>>>& globalSubGroups,
     101              :         std::map<AHCConcOpType, TemplateType>& ahcAlgOption, const AHCAlgSelectParam& ahcAlgSelectParam);
     102              : 
     103              :     bool IsNeedStrictMode(const OpParam& param);
     104              :     bool CheckStrictCondition(const OpParam& param) const;
     105              : 
     106              :     AlgType algType_; // 算法类型
     107              :     TopoType topoType_;
     108              :     bool isAlgoLevel1Default_ = false;
     109              :     bool isHaveCpuRank_;
     110              :     bool inlineReduceSwitchOn_;
     111              :     std::string identifier_;
     112              :     OpMode opMode;
     113              : 
     114              :     AlgConfigurator* algConfigurator_ = nullptr;
     115              :     CCLBufferManager& cclBufferManager_;
     116              : 
     117              :     u32 serverNum_;
     118              :     u32 moduleNum_;
     119              :     u32 superPodNum_;
     120              :     u32 deviceNumPerServer_;
     121              :     u32 deviceNumPerAggregation_;
     122              :     bool multiModuleDiffDeviceNumMode_;
     123              :     bool multiSuperPodDiffServerNumMode_;
     124              :     bool multiSuperPodDiffDeviceNumMode_;
     125              :     u32 meshAggregationRankSize_;
     126              :     bool isDiffDeviceModule_;
     127              :     bool isDiffDeviceType_;
     128              :     u32 gcdDeviceNumPerAggregation_;
     129              :     bool isSingleMeshAggregation_ = false;
     130              :     bool meshSinglePlane_ = false;
     131              :     bool isAllRankSamePlane_ = false;
     132              :     bool is310PDuoCard_;
     133              :     bool isCommon310P3DUO_;
     134              :     s32 hccsPortNum_;
     135              :     bool isSupportRdmaLite_ = false;   // 是否支持rdma lite
     136              :     bool isSupportHccsAndSio_ = false; // 是否支持hccs,sio并行
     137              :     bool useSuperPodMode_ = false;
     138              :     bool isARSDoubleRing_ = true;
     139              :     u32 userRank_;     // 本group中的userrank
     140              :     u32 realUserRank_; // world group中的userrank
     141              :     u32 userRankSize_;
     142              :     u32 devicePhyId_;
     143              :     s32 deviceLogicId_;
     144              :     DevType deviceType_;
     145              :     std::vector<u32> nicList_;
     146              :     std::unordered_map<u32, u32> pairLinkCounter_; // server内所有device间的链路类型计数
     147              :     hcclImpl* hcclImpl_ = nullptr;
     148              :     std::unique_ptr<CollExecutorBase> executor_;
     149              :     HcclDispatcher dispatcher_;
     150              :     std::unique_ptr<TopoMatcher>& topoMatcher_;
     151              :     HcclWorkflowMode workflowMode_;
     152              :     bool retryEnable_ = false;
     153              :     bool aivClearEnable_ = false;
     154              :     AlgOpContext algOpContext_;
     155              :     OpCounterInfo opCounter_;
     156              : 
     157              : private:
     158              :     virtual HcclResult
     159              :     SelectAlgoTypeForReduceScatter(float delay, u64 recvCurSize, float bandWidth, AlgTypeLevel1& algType);
     160              :     HcclResult SelectAlgoTypeForAllGather(float delay, u64 sendCurSize, float bandWidth, AlgTypeLevel1& algType);
     161              :     HcclResult SelectAlgoTypeForAllGatherV(float delay, u64 sendCurSize, float bandWidth, AlgTypeLevel1& algType);
     162              :     HcclResult SelectAlgoTypeForGather(float delay, u64 sendCurSize, float bandWidth, AlgTypeLevel1& algType);
     163              :     HcclResult SelectAlgoTypeForAllReduce(float delay, u64 curSize, float bandWidth, AlgTypeLevel1& algType);
     164              :     HcclResult SelectAlgoTypeForBroadcast(float delay, u64 curSize, float bandWidth, AlgTypeLevel1& algType);
     165              :     HcclResult SelectAlgoTypeForReduce(float delay, u64 curSize, float bandWidth, AlgTypeLevel1& algType);
     166              :     HcclResult SelectAlgFor91093WithCoreLimit(const OpParam& param, const ResourceLimit& limit, std::string& algName);
     167              : 
     168              :     HcclResult AppendTag(const AlgTypeLevel1& algTypeLevel1, std::string& tag);
     169              :     HcclResult
     170              :     SelectAlgoForComm(HcclCMDType hcclCMDType, float delay, u64 curSize, float bandWidth, AlgTypeLevel1& algType);
     171              :     HcclResult GetDefaultAlgoLevel1V2(
     172              :         HcclCMDType hcclCMDType, u64 curSize, u64 cclBufferSize, AlgTypeLevel1& algType, bool isInlineReduce = false,
     173              :         bool isRdmaReduce = false, bool isAivMode = false);
     174              :     void SetAlgoAttr(AlgConfigurator* algConfigurator);
     175              :     void SetTopoAttr(AlgConfigurator* algConfigurator);
     176              : 
     177              :     std::map<HcclCMDType, std::function<HcclResult(float, u64, float, AlgTypeLevel1&)>> selectFuncMap_ = {
     178              :         {HcclCMDType::HCCL_CMD_REDUCE_SCATTER,
     179              :          std::bind(
     180              :              &CollAlgOperator::SelectAlgoTypeForReduceScatter, this, std::placeholders::_1, std::placeholders::_2,
     181              :              std::placeholders::_3, std::placeholders::_4)},
     182              :         {HcclCMDType::HCCL_CMD_ALLGATHER, std::bind(
     183              :                                               &CollAlgOperator::SelectAlgoTypeForAllGather, this, std::placeholders::_1,
     184              :                                               std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)},
     185              :         {HcclCMDType::HCCL_CMD_ALLREDUCE, std::bind(
     186              :                                               &CollAlgOperator::SelectAlgoTypeForAllReduce, this, std::placeholders::_1,
     187              :                                               std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)},
     188              :         {HcclCMDType::HCCL_CMD_ALLGATHER_V,
     189              :          std::bind(
     190              :              &CollAlgOperator::SelectAlgoTypeForAllGatherV, this, std::placeholders::_1, std::placeholders::_2,
     191              :              std::placeholders::_3, std::placeholders::_4)},
     192              :     };
     193              : };
     194              : } // namespace hccl
     195              : 
     196              : #endif /** __ALG_OPERATOR_BASE_H__ */
        

Generated by: LCOV version 2.0-1