LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor - coll_native_executor_base.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 25.0 % 4 1
Test Date: 2026-07-28 12:11:00 Functions: 20.0 % 5 1

            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 COLL_NATIVE_EXECUTOR_BASE_H
      12              : #define COLL_NATIVE_EXECUTOR_BASE_H
      13              : 
      14              : #include "coll_executor_base.h"
      15              : #include "device_capacity.h"
      16              : #include "dispatcher.h"
      17              : #include "stream_active_manager.h"
      18              : #include "comm_factory_pub.h"
      19              : #include "rank_consistentcy_checker.h"
      20              : #include "hccl_aiv.h"
      21              : #include "config_log.h"
      22              : 
      23              : namespace hccl {
      24              : constexpr u64 HCCL_INPLACE_MEMCOPY_SIZE = 131072; // 128K数据量 = 131072B数据量
      25              : constexpr u64 HCCL_POST_SYNC_MEMCOPY_SIZE = 131072; // 128K数据量 = 131072B数据量
      26              : struct ExecMem {
      27              :     u64 count = 0;
      28              :     DeviceMem inputMem;         /* 单算子模式时是InCCLMem, 图模式时是InUserMem */
      29              :     DeviceMem outputMem;        /* 单算子模式时是OutCCLMem, 图模式时是OutUserMem */
      30              :     DeviceMem scratchMem;
      31              :     void *inputPtr = nullptr;   /* InUserMem的地址,图模式时与inputMem的地址相同 */
      32              :     void *outputPtr = nullptr;  /* OutUserMem的地址,图模式时与outputMem的地址相同 */
      33              : };
      34              : 
      35              : class CollNativeExecutorBase : public CollExecutorBase {
      36              : public:
      37              :     CollNativeExecutorBase(const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher);
      38          184 :     ~CollNativeExecutorBase() override = default;
      39              : 
      40              :     HcclResult CalcResRequest(const OpParam& param, AlgResourceRequest &resourceRequest) override;
      41              : 
      42              : protected:
      43              :     /* *************** 资源计算 *************** */
      44              :     virtual void ParseParam(const OpParam& param);
      45              :     virtual HcclResult CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport);
      46              :     virtual HcclResult CalcLevel0CommInfo(TransportMemType inputType,
      47              :         TransportMemType outputType,
      48              :         std::vector<LevelNSubCommTransport>& opTransport);
      49              :     virtual HcclResult CalcLevel1CommInfo(TransportMemType inputType,
      50              :         TransportMemType outputType,
      51              :         std::vector<LevelNSubCommTransport>& opTransport); // 默认情况下可根据algType_支持NHR、NHRV1、NB、HD、Ring算法。
      52              :     virtual HcclResult CalcLevel2CommInfo(TransportMemType inputType,
      53              :         TransportMemType outputType,
      54              :         std::vector<LevelNSubCommTransport>& opTransport);
      55              :     virtual HcclResult CalcStreamNum(u32& streamNum);
      56              :     virtual HcclResult CalcScratchMemSize(u64& scratchMemSize);
      57              :     virtual HcclResult CalcNotifyNum(u32 streamNum, u32 &notifyNum);
      58              :     virtual HcclResult CalcAivBufferRequest(u64 &aivBufferRequest);
      59              : 
      60              :     // 考虑新建一个资源计算类ResourceCalculator,将资源推导、资源解析的都放进去。
      61              :     // 推导通信域信息的公用函数,不同Executor的在计算Level0、Level1、Level2时使用。
      62              :     HcclResult CalcCommPlaneInfo(const std::string &tag, const CommParaInfo &commParaInfo,
      63              :         std::vector<SingleSubCommTransport> &commTransport, TransportMemType inPutMemType,
      64              :         TransportMemType outPutMemType);
      65              :     HcclResult BuildResourceRequest(u64 scratchMemSize, u32 streamNum, u32 notifyNum, u64 aivBufferRequest,
      66              :         std::vector<LevelNSubCommTransport>& opTransport, AlgResourceRequest& resourceRequest);
      67              :     HcclResult PrintTransportRequest(AlgResourceRequest& resourceRequest);
      68              :     virtual HcclResult CalcOptimalIntraRing(const OpParam& param);
      69              :     HcclResult SetCommInfoForARS(u32 ringSize);
      70              :     HcclResult SetCommInfoForIntraARS(u32 intraRingsize, std::vector<u32> commPlaneVector);
      71              :     HcclResult SetCommInfoForInterARS(u32 intraRingsize, std::vector<u32> commPlaneVector);
      72              :     /* *************** 算法编排 *************** */
      73              :     // 非零拷贝场景走KernelRun
      74              :     virtual HcclResult KernelRun(const OpParam &param, ExecMem &execMem);
      75              :     // 零拷贝场景走KernelRunIntraServerPre、KernelRunInterServer、KernelRunIntraServerPost
      76            0 :     virtual HcclResult KernelRunInterServer(const OpParam &param, ExecMem &execMem) {return HCCL_SUCCESS;}
      77            0 :     virtual HcclResult KernelRunIntraServerPre(const OpParam &param, ExecMem &execMem) {return HCCL_SUCCESS;}
      78            0 :     virtual HcclResult KernelRunIntraServerPost(const OpParam &param, ExecMem &execMem) {return HCCL_SUCCESS;}
      79              :     virtual HcclResult Getlevel1CommRank(SubCommInfo& level1CommInfo);
      80              :     virtual HcclResult SelectTempAlg(std::unique_ptr<AlgTemplateBase> &level1TempAlg, u32 level1RankSize);
      81              :     virtual HcclResult GetDevNumInlocalPod(u32& devNumInlocalPod);
      82              : 
      83              :     // 图模式下激活从流
      84              :     HcclResult ActiveSlaveStreams(const Stream &stream);
      85              :     // 将从流添加至Profiling
      86              :     HcclResult AddSubStreamToProfiling();
      87              :     // 检查通信域大小
      88              :     HcclResult CheckCommSize(const CommPlane levelIndex, const u32 subLevelIndex);
      89              : 
      90              :     // 获取不同类型通信域中的 transport 信息
      91              :     // 为了避免循环调用时反复校验Range引发性能问题,此处不做Range校验,建议调用该接口前先调用CheckCommSize避免OutOfRange问题
      92              :     SubCommInfo GetSubCommInfo(const CommPlane levelIndex, const u32 subLevelIndex);
      93              : 
      94              :     HcclResult GetRankByUserRank(CommPlane levelIndex, u32 subLevelIndex, u32 userRank, u32 &rank);
      95              :     HcclResult GetUserRankByRank(CommPlane levelIndex, u32 subLevelIndex, u32 rank, u32 &userRank);
      96              :     HcclResult GenerateStreams(PrepareData &prepareData, std::vector<Stream> &streams);
      97              :     HcclResult NotifySubStreamStart(
      98              :         Stream &stream,
      99              :         std::vector<Stream> &substreams,
     100              :         std::vector<std::shared_ptr<LocalNotify>> &signalsSubToMain,
     101              :         u32 substreamNum);
     102              :     HcclResult WaitSubStreamFinish(
     103              :         Stream &stream,
     104              :         std::vector<Stream> &substreams,
     105              :         std::vector<std::shared_ptr<LocalNotify>> &signalsMainToSub,
     106              :         u32 substreamNum);
     107              :     HcclResult GenerateRecordWaitStreams(
     108              :         std::vector<Stream> &streams,
     109              :         u32 recordStreamNum, u32 waitStreamNum,
     110              :         std::vector<Stream> &recordStreams, std::vector<Stream> &waitStreams);
     111              :     HcclResult HoldAllRanksOnCurrentOp(const OpParam &param, ExecMem &execMem, PrepareData &prepareData, std::vector<LINK> links);
     112              :     HcclResult HoldAllRanksOnCurrentOpWithSingleStream(OpParam &param, ExecMem &execMem, std::vector<LINK> links);
     113              :     HcclResult SendRecvSignalOnLinks(OpParam &param, ExecMem &execMem, std::vector<LINK> links);
     114              :     bool OpSyncCheckCommSize(const CommPlane levelIndex, const u32 expectedSize);
     115              :     HcclResult PostSyncWithSubstream(OpParam &param, ExecMem &execMem, PrepareData &prepareData);
     116              :     HcclResult PostSyncWithoutSubstream(OpParam &param, ExecMem &execMem);
     117              :     HcclResult InplaceOpSync(OpParam &param, ExecMem &execMem);
     118              : 
     119              :     virtual HcclResult CopyAivCommInfoToDevice(const CommPlane levelIndex, const u32 subLevelIndex,
     120              :         AlgResourceResponse& algResource);
     121              :     
     122              :     HcclResult SetOpCache(const AivOpArgs& opArgs, const AivTopoArgs& topoArgs, const AivResourceArgs& resourceArgs, 
     123              :         const AivAlgArgs& algArgs, ExtraArgs& extraArgs, AivProfilingInfo& aivProfilingInfo, bool isA3CrossNode);
     124              : 
     125              :     void SetWorkflowMode(HcclWorkflowMode workflowMode) override;
     126              :     HcclWorkflowMode GetExecutorWorkflowMode() const override;
     127              : 
     128              :     /* ---------------以下为 protected 成员变量定义领域-------------------------- */
     129              :     std::string tag_;
     130              :     u32 root_ = INVALID_VALUE_RANKID;
     131              :     AlgResourceResponse *algResResp_ = nullptr;
     132              :     HcclCMDType opType_ = HcclCMDType::HCCL_CMD_INVALID;
     133              : 
     134              :     // Infos got from topoMatcher_
     135              :     const HcclTopoInfo topoAttr_;
     136              :     const HcclAlgoInfo algoAttr_;
     137              :     TopoType topoType_;
     138              :     bool is310P3Common_ = false;
     139              :     bool aicpuUnfoldMode_ = false;
     140              :     HcclWorkflowMode workflowMode_;
     141              : };
     142              : std::vector<std::vector<u32>> GetARSRingsOrder(u32 ranksSize, TopoType topoType, std::vector<u32> &RingList);
     143              : }
     144              : #endif
        

Generated by: LCOV version 2.0-1