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 HCCL_AICPU_COMMUNICATOR_IMPL_LITE_H_
12 : #define HCCL_AICPU_COMMUNICATOR_IMPL_LITE_H_
13 :
14 : #include <memory>
15 : #include "ins_executor.h"
16 : #include "data_type.h"
17 : #include "prim_translator.h"
18 :
19 : #include "lite_res_mgr_fetcher.h"
20 : #include "coll_alg_component_lite.h"
21 : #include "types.h"
22 : #include "coll_alg_info.h"
23 : #include "kernel_param_lite.h"
24 : #include "rma_buffer_lite.h"
25 : #include "queue_notify_lite_mgr.h"
26 : #include "cnt_1ton_notify_lite_mgr.h"
27 : #include "host_device_sync_notify_lite_mgr.h"
28 : #include "profiling_reporter_lite.h"
29 : #include "profiling_handler_lite.h"
30 : #include "data_buffer.h"
31 : #include "rmt_data_buffer_mgr.h"
32 : #include "aicpu_hdc_handler.h"
33 : #include "one_sided_component_lite.h"
34 : #include "error_message_v2.h"
35 :
36 : namespace Hccl {
37 :
38 : class CommunicatorImplLite : public ResMgrFetcher {
39 : public:
40 : explicit CommunicatorImplLite(u32 idIndex);
41 131 : ~CommunicatorImplLite() override = default;
42 :
43 : int LoadWithOpBasedMode(HcclKernelParamLite *kernelParam);
44 : int UpdateComm(HcclKernelParamLite *kernelParam);
45 :
46 : HostDeviceSyncNotifyLiteMgr *GetHostDeviceSyncNotifyLiteMgr() override;
47 : StreamLiteMgr *GetStreamLiteMgr() override;
48 : QueueNotifyLiteMgr *GetQueueNotifyLiteMgr() override;
49 : Cnt1tonNotifyLiteMgr *GetCnt1tonNotifyLiteMgr() override;
50 : CntNto1NotifyLiteMgr *GetCntNto1NotifyLiteMgr() override;
51 : ConnectedLinkMgr *GetConnectedLinkMgr() override;
52 : DevId GetDevPhyId() override;
53 : u32 GetExecTimeOut() override;
54 :
55 2 : MemTransportLiteMgr *GetTransportLiteMgr() override
56 : {
57 2 : return transportLiteMgr.get();
58 : }
59 :
60 0 : u64 GetLocAddr(BufferType type) override
61 : {
62 0 : return locBuffer[type];
63 : }
64 :
65 0 : CollOperator GetCurrentOp() override
66 : {
67 0 : return currentOp;
68 : }
69 :
70 2 : void SetCurrentOpMode(OpMode opMode)
71 : {
72 2 : currentOp.opMode = opMode;
73 2 : }
74 :
75 23 : uint32_t GetCommIdIndex() const
76 : {
77 23 : return idIndex_;
78 : }
79 :
80 0 : RmaBufferLite *GetRmaBufferLite(BufferType type) override
81 : {
82 0 : if (rmaBufferLiteVec[type] != nullptr) {
83 0 : return rmaBufferLiteVec[type].get();
84 : } else {
85 0 : return nullptr;
86 : }
87 : }
88 :
89 8 : u64 GetCounterAddr() override
90 : {
91 8 : return opCounterAddr;
92 : }
93 :
94 13 : MirrorTaskManagerLite *GetMirrorTaskMgrLite() override
95 : {
96 13 : return mirrorTaskMgrLite.get();
97 : }
98 :
99 0 : string GetId() const
100 : {
101 0 : return commId;
102 : }
103 :
104 6 : u32 GetRankSize() const
105 : {
106 6 : return rankSize;
107 : }
108 :
109 6 : RankId GetMyRank() const
110 : {
111 6 : return myRank;
112 : }
113 :
114 : KfcCommand BackGroundGetCmd();
115 :
116 2 : void BackGroundSetStatus(KfcStatus status, KfcErrType errorCode = KfcErrType::NONE);
117 :
118 5 : void SetIsCommReady(bool flag)
119 : {
120 5 : isCommReady = flag;
121 5 : }
122 :
123 4 : bool IsCommReady() const
124 : {
125 4 : return isCommReady;
126 : }
127 :
128 2 : void SetNeedClean(bool flag)
129 : {
130 2 : needClean = flag;
131 2 : }
132 :
133 1 : bool IsNeedClean() const
134 : {
135 1 : return needClean;
136 : }
137 :
138 1 : void SetIsSuspended(bool status)
139 : {
140 1 : isSuspended = status;
141 1 : }
142 :
143 1 : bool IsSuspended() const
144 : {
145 1 : return isSuspended;
146 : }
147 :
148 : const ProfilingReporterLite* GetProfilingReporterLite() const
149 : {
150 : return profilingReporterLite.get();
151 : }
152 :
153 : bool IsFirstUsed() const
154 : {
155 : return isFirstUsed;
156 : }
157 :
158 0 : void SetIsFirstUsedToFalse()
159 : {
160 0 : isFirstUsed = false;
161 0 : }
162 :
163 168 : bool IsUsed() const
164 : {
165 168 : return isUsed;
166 : }
167 :
168 9 : void SetIsUsed(bool used)
169 : {
170 9 : isUsed = used;
171 9 : }
172 :
173 9 : std::mutex& GetAicpuMc2Mutex()
174 : {
175 9 : return aicpuMc2Mutex;
176 : }
177 :
178 5 : InsExecutor* GetInsExecutor()
179 : {
180 5 : return insExecutor.get();
181 : }
182 :
183 8 : ProfilingReporterLite* GetProfilingReporterLite()
184 : {
185 8 : return profilingReporterLite.get();
186 : }
187 :
188 : HcclResult SendErrorMessageReportToHost(ErrorMessageReport &errMsgInfo);
189 0 : u32 GetUserStreamId() const
190 : {
191 0 : return userStreamId_;
192 : }
193 :
194 0 : bool IsErrorReported() const
195 : {
196 0 : return isErrorReported_;
197 : }
198 :
199 0 : void SetErrorReported() {
200 0 : isErrorReported_ = true;
201 0 : }
202 :
203 1 : void ResetErrorReported() {
204 1 : isErrorReported_ = false;
205 1 : }
206 :
207 : void UnfoldOp(HcclKernelParamLite *kernelParam);
208 : void RegisterRtsqCallback();
209 :
210 : void CheckOpExecStatus() const;
211 : bool CheckNeedUpdateRes(HcclKernelParamLite *kernelParam);
212 : void UpdateCommParam(HcclKernelParamLite *kernelParam);
213 : void UpdateLocBuffer(HcclKernelParamLite *kernelParam);
214 : void UpdateRes(HcclKernelParamLite *kernelParam);
215 : void UpdateTransports(HcclKernelParamLite *kernelParam);
216 : void UpdateHDCommnicate(HcclKernelParamLite *kernelParam);
217 : void CreateCollAlgComponentLite();
218 : void InitCurrentOp(HcclKernelParamLite *kernelParam);
219 : void UpdateUserStreamId(HcclKernelParamLite *kernelParam);
220 : std::shared_ptr<InsQueue> GetInsQueue(HcclKernelParamLite *kernelParam);
221 : void SetDfxOpInfo(uint64_t beginTime);
222 :
223 : private:
224 : std::unique_ptr<StreamLiteMgr> streamLiteMgr = std::make_unique<StreamLiteMgr>();
225 : std::unique_ptr<QueueNotifyLiteMgr> queueNotifyLiteMgr = std::make_unique<QueueNotifyLiteMgr>();
226 : std::unique_ptr<Cnt1tonNotifyLiteMgr> cnt1tonNotifyLiteMgr = std::make_unique<Cnt1tonNotifyLiteMgr>();
227 : std::unique_ptr<CntNto1NotifyLiteMgr> cntNto1NotifyLiteMgr = std::make_unique<CntNto1NotifyLiteMgr>();
228 : std::unique_ptr<ConnectedLinkMgr> connectedLinkMgr = std::make_unique<ConnectedLinkMgr>();
229 : std::unique_ptr<PrimTranslator> primTranslator = std::make_unique<PrimTranslator>();
230 : std::unique_ptr<InsExecutor> insExecutor = std::make_unique<InsExecutor>(this);
231 : std::unique_ptr<MirrorTaskManagerLite> mirrorTaskMgrLite = std::make_unique<MirrorTaskManagerLite>();
232 : std::unique_ptr<ProfilingReporterLite> profilingReporterLite
233 : = std::make_unique<ProfilingReporterLite>(mirrorTaskMgrLite.get(), &ProfilingHandlerLite::GetInstance());
234 :
235 : HcclResult InitProfilingReporterLite();
236 :
237 : std::unique_ptr<MemTransportLiteMgr> transportLiteMgr = std::make_unique<MemTransportLiteMgr>( mirrorTaskMgrLite.get());
238 :
239 : std::unique_ptr<HostDeviceSyncNotifyLiteMgr> hostDeviceSyncNotifyLiteMgr
240 : = std::make_unique<HostDeviceSyncNotifyLiteMgr>();
241 :
242 : std::unique_ptr<CollAlgComponentLite> algComponentLite{};
243 :
244 : void RestoreOpRes(const string &opTag, const string &tagKey, u64 addr, u64 bufSize);
245 :
246 : void RestoreAllTransports(u64 addr, u64 bufSize);
247 : unique_ptr<HDCommunicateLite> kfcControlTransferH2D = std::make_unique<HDCommunicateLite>();
248 : unique_ptr<HDCommunicateLite> kfcStatusTransferD2H = std::make_unique<HDCommunicateLite>();
249 : unique_ptr<AicpuHdcHandler> hdcHandler{};
250 : std::mutex hdcShmLock_;
251 :
252 : u32 idIndex_;
253 : u32 myRank{0};
254 : u32 rankSize{0};
255 : u32 devPhyId{0};
256 : u32 hcclExecTimeout{1836};
257 : u64 scratchSize{0};
258 : u64 locBuffer[BufferType::__COUNT__]{};
259 : u64 opCounterAddr{0};
260 : u32 opIndex_;
261 : std::string commId;
262 : bool isUpdateComm {false};
263 : CollOperator currentOp;
264 :
265 : bool isCommReady{false}; // 是否初始化完成
266 : bool needClean{false}; // 是否有待清理资源
267 : bool isSuspended{false}; // 是否处于暂停状态
268 :
269 : void InitRmaBufferLite(HcclAicpuLocBufLite &bufLite, BufferType type);
270 : void UpdateDynamicOpData(HcclKernelParamLite *kernelParam) const;
271 :
272 : std::vector<std::unique_ptr<RmaBufferLite>> rmaBufferLiteVec;
273 : DevType devType;
274 :
275 : std::unordered_map<std::string, AlgTopoInfo> algTopoInfoMap;
276 :
277 : std::unique_ptr<CollAlgInfo> collAlgInfo;
278 : std::unique_ptr<RmtDataBufferMgr> rmtDataBufferMgr;
279 :
280 : std::unordered_set<std::string> offloadOpSet;
281 :
282 : void CreateOneSidedComponentLite();
283 : std::unique_ptr<OneSidedComponentLite> oneSidedComponentLite{};
284 : std::shared_ptr<InsQueue> GetOneSidedInsQueue(HcclKernelParamLite *kernelParam);
285 :
286 : bool isUsed{false};
287 : bool isFirstUsed{true};
288 : std::mutex aicpuMc2Mutex;
289 : u32 userStreamId_{0};
290 : bool isErrorReported_{false};
291 :
292 : std::unordered_set<std::string> loadedOpSet{};
293 : };
294 :
295 : } // namespace Hccl
296 :
297 : #endif // HCCL_AICPU_COMMUNICATOR_IMPL_LITE_H_
|