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) const;
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 KernelRunInterServer(
80 : [[maybe_unused]] const OpParam& param, [[maybe_unused]] ExecMem& execMem, [[maybe_unused]] u64 baseOffset)
81 : {
82 0 : return HCCL_SUCCESS;
83 : }
84 0 : virtual HcclResult KernelRunIntraServerPre([[maybe_unused]] const OpParam& param, [[maybe_unused]] ExecMem& execMem)
85 : {
86 0 : return HCCL_SUCCESS;
87 : }
88 : virtual HcclResult
89 0 : KernelRunIntraServerPost([[maybe_unused]] const OpParam& param, [[maybe_unused]] ExecMem& execMem)
90 : {
91 0 : return HCCL_SUCCESS;
92 : }
93 : virtual HcclResult Getlevel1CommRank(SubCommInfo& level1CommInfo);
94 : virtual HcclResult SelectTempAlg(std::unique_ptr<AlgTemplateBase>& level1TempAlg, u32 level1RankSize);
95 : virtual HcclResult GetDevNumInlocalPod(u32& devNumInlocalPod);
96 :
97 : // 图模式下激活从流
98 : HcclResult ActiveSlaveStreams(const Stream& stream);
99 : // 将从流添加至Profiling
100 : HcclResult AddSubStreamToProfiling();
101 : // 检查通信域大小
102 : HcclResult CheckCommSize(const CommPlane levelIndex, const u32 subLevelIndex);
103 :
104 : // 获取不同类型通信域中的 transport 信息
105 : // 为了避免循环调用时反复校验Range引发性能问题,此处不做Range校验,建议调用该接口前先调用CheckCommSize避免OutOfRange问题
106 : SubCommInfo GetSubCommInfo(const CommPlane levelIndex, const u32 subLevelIndex);
107 :
108 : HcclResult GetRankByUserRank(CommPlane levelIndex, u32 subLevelIndex, u32 userRank, u32& rank);
109 : HcclResult GetUserRankByRank(CommPlane levelIndex, u32 subLevelIndex, u32 rank, u32& userRank);
110 : HcclResult GenerateStreams(PrepareData& prepareData, std::vector<Stream>& streams);
111 : HcclResult NotifySubStreamStart(
112 : Stream& stream, std::vector<Stream>& substreams, std::vector<std::shared_ptr<LocalNotify>>& signalsSubToMain,
113 : u32 substreamNum);
114 : HcclResult WaitSubStreamFinish(
115 : Stream& stream, std::vector<Stream>& substreams, std::vector<std::shared_ptr<LocalNotify>>& signalsMainToSub,
116 : u32 substreamNum);
117 : HcclResult GenerateRecordWaitStreams(
118 : std::vector<Stream>& streams, u32 recordStreamNum, u32 waitStreamNum, std::vector<Stream>& recordStreams,
119 : std::vector<Stream>& waitStreams);
120 : HcclResult
121 : HoldAllRanksOnCurrentOp(const OpParam& param, ExecMem& execMem, PrepareData& prepareData, std::vector<LINK> links);
122 : HcclResult HoldAllRanksOnCurrentOpWithSingleStream(OpParam& param, ExecMem& execMem, std::vector<LINK> links);
123 : HcclResult SendRecvSignalOnLinks(OpParam& param, ExecMem& execMem, std::vector<LINK> links);
124 : bool OpSyncCheckCommSize(const CommPlane levelIndex, const u32 expectedSize);
125 : HcclResult PostSyncWithSubstream(OpParam& param, ExecMem& execMem, PrepareData& prepareData);
126 : HcclResult PostSyncWithoutSubstream(OpParam& param, ExecMem& execMem);
127 : HcclResult InplaceOpSync(OpParam& param, ExecMem& execMem);
128 :
129 : virtual HcclResult
130 : CopyAivCommInfoToDevice(const CommPlane levelIndex, const u32 subLevelIndex, AlgResourceResponse& algResource);
131 :
132 : HcclResult SetOpCache(
133 : const AivOpArgs& opArgs, const AivTopoArgs& topoArgs, const AivResourceArgs& resourceArgs,
134 : const AivAlgArgs& algArgs, ExtraArgs& extraArgs, AivProfilingInfo& aivProfilingInfo, bool isA3CrossNode);
135 :
136 : void SetWorkflowMode(HcclWorkflowMode workflowMode) override;
137 : HcclWorkflowMode GetExecutorWorkflowMode() const override;
138 :
139 : /* ---------------以下为 protected 成员变量定义领域-------------------------- */
140 : std::string tag_;
141 : u32 root_ = INVALID_VALUE_RANKID;
142 : AlgResourceResponse* algResResp_ = nullptr;
143 : HcclCMDType opType_ = HcclCMDType::HCCL_CMD_INVALID;
144 :
145 : // Infos got from topoMatcher_
146 : const HcclTopoInfo topoAttr_;
147 : const HcclAlgoInfo algoAttr_;
148 : TopoType topoType_;
149 : bool is310P3Common_ = false;
150 : bool aicpuUnfoldMode_ = false;
151 : HcclWorkflowMode workflowMode_;
152 : };
153 : std::vector<std::vector<u32>> GetARSRingsOrder(u32 ranksSize, TopoType topoType, std::vector<u32>& RingList);
154 : } // namespace hccl
155 : #endif
|