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: 14.3 % 7 1
Test Date: 2026-08-18 17:47:01 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          182 :     ~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(
      47              :         TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport);
      48              :     virtual HcclResult CalcLevel1CommInfo(
      49              :         TransportMemType inputType, TransportMemType outputType,
      50              :         std::vector<LevelNSubCommTransport>& opTransport); // 默认情况下可根据algType_支持NHR、NHRV1、NB、HD、Ring算法。
      51              :     virtual HcclResult CalcLevel2CommInfo(
      52              :         TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport);
      53              :     virtual HcclResult CalcStreamNum(u32& streamNum);
      54              :     virtual HcclResult CalcScratchMemSize(u64& scratchMemSize);
      55              :     virtual HcclResult CalcNotifyNum(u32 streamNum, u32& notifyNum);
      56              :     virtual HcclResult CalcAivBufferRequest(u64& aivBufferRequest);
      57              : 
      58              :     // 考虑新建一个资源计算类ResourceCalculator,将资源推导、资源解析的都放进去。
      59              :     // 推导通信域信息的公用函数,不同Executor的在计算Level0、Level1、Level2时使用。
      60              :     HcclResult CalcCommPlaneInfo(
      61              :         const std::string& tag, const CommParaInfo& commParaInfo, std::vector<SingleSubCommTransport>& commTransport,
      62              :         TransportMemType inPutMemType, TransportMemType outPutMemType);
      63              :     HcclResult BuildResourceRequest(
      64              :         u64 scratchMemSize, u32 streamNum, u32 notifyNum, u64 aivBufferRequest,
      65              :         std::vector<LevelNSubCommTransport>& opTransport, AlgResourceRequest& resourceRequest);
      66              :     HcclResult PrintTransportRequest(AlgResourceRequest& resourceRequest);
      67              :     virtual HcclResult CalcOptimalIntraRing(const OpParam& param);
      68              :     HcclResult SetCommInfoForARS(u32 ringSize);
      69              :     HcclResult SetCommInfoForIntraARS(u32 intraRingsize, std::vector<u32> commPlaneVector);
      70              :     HcclResult SetCommInfoForInterARS(u32 intraRingsize, std::vector<u32> commPlaneVector);
      71              :     /* *************** 算法编排 *************** */
      72              :     // 非零拷贝场景走KernelRun
      73              :     virtual HcclResult KernelRun(const OpParam& param, ExecMem& execMem);
      74              :     // 零拷贝场景走KernelRunIntraServerPre、KernelRunInterServer、KernelRunIntraServerPost
      75            0 :     virtual HcclResult KernelRunInterServer([[maybe_unused]] const OpParam& param, [[maybe_unused]] ExecMem& execMem)
      76              :     {
      77            0 :         return HCCL_SUCCESS;
      78              :     }
      79            0 :     virtual HcclResult KernelRunIntraServerPre([[maybe_unused]] const OpParam& param, [[maybe_unused]] ExecMem& execMem)
      80              :     {
      81            0 :         return HCCL_SUCCESS;
      82              :     }
      83              :     virtual HcclResult
      84            0 :     KernelRunIntraServerPost([[maybe_unused]] const OpParam& param, [[maybe_unused]] ExecMem& execMem)
      85              :     {
      86            0 :         return HCCL_SUCCESS;
      87              :     }
      88              :     virtual HcclResult Getlevel1CommRank(SubCommInfo& level1CommInfo);
      89              :     virtual HcclResult SelectTempAlg(std::unique_ptr<AlgTemplateBase>& level1TempAlg, u32 level1RankSize);
      90              :     virtual HcclResult GetDevNumInlocalPod(u32& devNumInlocalPod);
      91              : 
      92              :     // 图模式下激活从流
      93              :     HcclResult ActiveSlaveStreams(const Stream& stream);
      94              :     // 将从流添加至Profiling
      95              :     HcclResult AddSubStreamToProfiling();
      96              :     // 检查通信域大小
      97              :     HcclResult CheckCommSize(const CommPlane levelIndex, const u32 subLevelIndex);
      98              : 
      99              :     // 获取不同类型通信域中的 transport 信息
     100              :     // 为了避免循环调用时反复校验Range引发性能问题,此处不做Range校验,建议调用该接口前先调用CheckCommSize避免OutOfRange问题
     101              :     SubCommInfo GetSubCommInfo(const CommPlane levelIndex, const u32 subLevelIndex);
     102              : 
     103              :     HcclResult GetRankByUserRank(CommPlane levelIndex, u32 subLevelIndex, u32 userRank, u32& rank);
     104              :     HcclResult GetUserRankByRank(CommPlane levelIndex, u32 subLevelIndex, u32 rank, u32& userRank);
     105              :     HcclResult GenerateStreams(PrepareData& prepareData, std::vector<Stream>& streams);
     106              :     HcclResult NotifySubStreamStart(
     107              :         Stream& stream, std::vector<Stream>& substreams, std::vector<std::shared_ptr<LocalNotify>>& signalsSubToMain,
     108              :         u32 substreamNum);
     109              :     HcclResult WaitSubStreamFinish(
     110              :         Stream& stream, std::vector<Stream>& substreams, std::vector<std::shared_ptr<LocalNotify>>& signalsMainToSub,
     111              :         u32 substreamNum);
     112              :     HcclResult GenerateRecordWaitStreams(
     113              :         std::vector<Stream>& streams, u32 recordStreamNum, u32 waitStreamNum, std::vector<Stream>& recordStreams,
     114              :         std::vector<Stream>& waitStreams);
     115              :     HcclResult
     116              :     HoldAllRanksOnCurrentOp(const OpParam& param, ExecMem& execMem, PrepareData& prepareData, std::vector<LINK> links);
     117              :     HcclResult HoldAllRanksOnCurrentOpWithSingleStream(OpParam& param, ExecMem& execMem, std::vector<LINK> links);
     118              :     HcclResult SendRecvSignalOnLinks(OpParam& param, ExecMem& execMem, std::vector<LINK> links);
     119              :     bool OpSyncCheckCommSize(const CommPlane levelIndex, const u32 expectedSize);
     120              :     HcclResult PostSyncWithSubstream(OpParam& param, ExecMem& execMem, PrepareData& prepareData);
     121              :     HcclResult PostSyncWithoutSubstream(OpParam& param, ExecMem& execMem);
     122              :     HcclResult InplaceOpSync(OpParam& param, ExecMem& execMem);
     123              : 
     124              :     virtual HcclResult
     125              :     CopyAivCommInfoToDevice(const CommPlane levelIndex, const u32 subLevelIndex, AlgResourceResponse& algResource);
     126              : 
     127              :     HcclResult SetOpCache(
     128              :         const AivOpArgs& opArgs, const AivTopoArgs& topoArgs, const AivResourceArgs& resourceArgs,
     129              :         const AivAlgArgs& algArgs, ExtraArgs& extraArgs, AivProfilingInfo& aivProfilingInfo, bool isA3CrossNode);
     130              : 
     131              :     void SetWorkflowMode(HcclWorkflowMode workflowMode) override;
     132              :     HcclWorkflowMode GetExecutorWorkflowMode() const override;
     133              : 
     134              :     /* ---------------以下为 protected 成员变量定义领域-------------------------- */
     135              :     std::string tag_;
     136              :     u32 root_ = INVALID_VALUE_RANKID;
     137              :     AlgResourceResponse* algResResp_ = nullptr;
     138              :     HcclCMDType opType_ = HcclCMDType::HCCL_CMD_INVALID;
     139              : 
     140              :     // Infos got from topoMatcher_
     141              :     const HcclTopoInfo topoAttr_;
     142              :     const HcclAlgoInfo algoAttr_;
     143              :     TopoType topoType_;
     144              :     bool is310P3Common_ = false;
     145              :     bool aicpuUnfoldMode_ = false;
     146              :     HcclWorkflowMode workflowMode_;
     147              : };
     148              : std::vector<std::vector<u32>> GetARSRingsOrder(u32 ranksSize, TopoType topoType, std::vector<u32>& RingList);
     149              : } // namespace hccl
     150              : #endif
        

Generated by: LCOV version 2.0-1