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_COMMUNICATOR_H
12 : #define HCCL_COMMUNICATOR_H
13 :
14 : #include <atomic>
15 : #include <memory>
16 : #include <vector>
17 : #include <hccl/hccl_types.h>
18 : #include "acl/acl_rt.h"
19 : #include "hccl_communicator_attrs.h"
20 : #include "hccl/base.h"
21 : #include "hccl_impl_pub.h"
22 : #include "opexecounter_pub.h"
23 : #include "op_base_stream_manager_pub.h"
24 : #include "offload_stream_manager_pub.h"
25 : #include "prof_common.h"
26 : #include "profiler_manager.h"
27 :
28 : #include "topoinfo_parse.h"
29 : #include "hccl_alg.h"
30 : #include "hccl_aiv.h"
31 : #include "ccl_buffer_manager.h"
32 : #include "hccl_trace_info.h"
33 : #include "hccl_callback_task.h"
34 : #include "aicpu_operator_pub.h"
35 : #include "h2d_dto/transport_h2d.h"
36 : #include "transport_pub.h"
37 : #include "mr_manager.h"
38 : #include "transport_heterog_def.h"
39 : #include "resource_manager/queue_notify_manager.h"
40 : #include "hccl_network_pub.h"
41 : #include "comm.h"
42 : #include "device_capacity.h"
43 : #include "transport_manager.h"
44 : #include "zero_copy/zero_copy_memory_agent.h"
45 : #include "coll_alg_operator.h"
46 : #include "alltoall_operator.h"
47 : #include "peterson_lock.h"
48 : #include "coll_alg_utils.h"
49 : #include "heartbeat.h"
50 : #include "../nslbdp/hccl_nslbdp_pub.h"
51 : #include "i_hccl_one_sided_service.h"
52 : #include "opretry_manager.h"
53 : #include "aclgraph/zero_copy_acl_graph.h"
54 : #include "../nslbdp/hccl_nslbdp.h"
55 : #include "hccl/hccl_res.h"
56 : #include "independent_op.h"
57 : #include "comm_config_pub.h"
58 : #include "new/hccl_dispatcher_ctx.h"
59 : #include "rank_graph.h"
60 : #include "symmetric_memory/symmetric_memory.h"
61 : #include "hccl_dpu_manager.h"
62 : #include "../../../unified_platform/resource/buffer/dev_buffer.h"
63 :
64 : namespace hccl {
65 : using ServRankInfo_t = std::map<std::string, std::vector<RankInfo_t> >;
66 :
67 : constexpr u32 COMM_MAX_WORK_SPACE_SIZE = 16 * 1024 * 1024; // 默认16MB
68 : constexpr u32 INPUT = 0;
69 : constexpr u32 OUTPUT = 1;
70 : const std::string COMM_LOOPBACK_IP = "127.0.0.1";
71 : constexpr u8 INPLACE_PRESYNC_STATUS_SEVEN = 7;
72 : constexpr u32 NSLBDP_HCCP_VERSION = 1;
73 : constexpr u32 NSLBDP_HCCP_NICPOSION = 1;
74 : constexpr u32 AICPU_LOCAL_NOTIFY_SIZE = 8; // aicpu场景本地控制时序的notify数量,对应枚举:enum AicpuLocalNotifyIdx
75 : constexpr u32 AICPU_LOCAL_EVENT_SIZE = 2; // aicpu场景本地控制时序的event数量,对应枚举:enum AicpuLocalEventIdx
76 : constexpr u32 CACHEMAP_MAXSIZE = 65536;
77 : constexpr float CACHEMAP_CLEARPERCENT = 0.1;
78 : constexpr u32 RDMA_NOTIFY_MIN_NUM = 3;
79 : constexpr u32 RDMA_NOTIFY_MAX_NUM = 8192;
80 : constexpr u32 COMM_LAYER_NUM_MAX = 2;
81 :
82 : struct RemoteRes {
83 : u64 inbufferSize;
84 : u64 outbufferSize;
85 : u64 inbuffer;
86 : u32 inbufferKey;
87 : u64 outbuffer;
88 : u32 outbufferKey;
89 : };
90 : constexpr u32 HCCL_AICPU_HOST_BASE_TIME_MS = 50*1000; // 50秒, 停流的超时时间可能为46s,停止npu的超时时间需要比停流时间长
91 : struct AicpuOpTiling {
92 : std::string newTag;
93 : std::string algName;
94 : AlgType algType;
95 : bool isUsedMainStream = false;
96 : u8 floatOverflowMode = ACL_RT_OVERFLOW_MODE_UNDEF;
97 : u8 dumpDebug = false;
98 : };
99 :
100 : struct InitTask
101 : {
102 : u64 context;
103 : bool isCustom;
104 : };
105 :
106 : using rankTagSignalInfo_t = std::unordered_map<u32, std::unordered_map<std::string, std::vector<HcclSignalInfo>>>;
107 : using rankTagKey_t = std::unordered_map<u32, std::unordered_map<std::string, std::vector<u32>>>;
108 : using rankTagAddr_t = std::unordered_map<u32, std::unordered_map<std::string, std::vector<u64>>>;
109 : using rankTagChipId_t = std::unordered_map<u32, std::unordered_map<std::string, s64>>;
110 :
111 : class HcclCommunicator {
112 : public:
113 : explicit HcclCommunicator();
114 : explicit HcclCommunicator(const CommConfig &commConfig);
115 :
116 : virtual ~HcclCommunicator();
117 :
118 : virtual HcclResult Stop();
119 : virtual HcclResult Resume();
120 : HcclResult Suspend();
121 : HcclResult TraverseAlgResourceResponse(bool isStop);
122 : HcclResult TraverseOpCommTransport(OpCommTransport &opCommTransport, bool isStop);
123 : HcclResult TraverseLevelNSubCommTransport(LevelNSubCommTransport &levelNSubCommTransport, bool isStop);
124 : HcclResult TraverseSingleSubCommTransport(SingleSubCommTransport &commTransport, bool isStop);
125 :
126 : // 对外接口
127 : virtual HcclResult StopExec();
128 : virtual HcclResult Clean();
129 : virtual HcclResult Init(HcclCommParams ¶ms, const RankTable_t &rankTable);
130 : virtual HcclResult Init(HcclCommParams ¶ms, const std::vector<RankInfo> &rankList,
131 : WorldGroupInfo &groupCommonData);
132 :
133 : virtual HcclResult GetAlgType(AlgType &algType, HcclCMDType opType);
134 : virtual HcclResult InitHccpChannel();
135 : virtual std::vector<RankInfo> GetRankLists();
136 :
137 : virtual HcclResult GetDeviceNumPerAggregation(u32 &deviceNumPerAggregation);
138 :
139 : virtual HcclResult GetBandWidthPerNPU(u32 level, float &bandWidth);
140 :
141 : u32 GetRankTableCrc();
142 :
143 : u32 GetServerNum();
144 :
145 : u32 GetModuleNum();
146 :
147 : u32 GetRealUserRank();
148 :
149 : HcclResult InitMyRankConnectMode(HcclCommParams ¶ms, const RankTable_t &rankTable);
150 : uint32_t GetConnectMode();
151 : HcclResult GetDevMemWorkSpace(const std::string &memTag, uint64_t *size, void **addr, bool *newCreated);
152 :
153 : HcclResult GetCommParams(HcclCommParams ¶ms); // 逆向解析获取HcclCommParams参数
154 :
155 : HcclResult GetCommRankTable(RankTable_t &rankTable); // 逆向解析获取RankTable_t参数
156 :
157 : virtual HcclResult AllGather(const std::string &tag, void *inputPtr, void *outputPtr, u64 inputCount,
158 : HcclDataType dataType, HcclRtStream stream, HcomCollOpInfo *opInfo = nullptr);
159 :
160 : virtual HcclResult AllGatherV(const std::string &tag, const void *sendBuf, u64 sendCount, const void *recvBuf,
161 : const void *recvCounts, const void *rdispls, HcclDataType dataType, HcclRtStream stream);
162 :
163 : virtual HcclResult AllGatherOutPlace(const std::string &tag, void *inputPtr, void *outputPtr, u64 inputCount,
164 : HcclDataType dataType, HcclRtStream stream);
165 :
166 : virtual HcclResult AllGatherVOutPlace(const std::string &tag, void *inputPtr, void *outputPtr,
167 : u64 inputCount, const void *outputCounts, const void *outputDispls, HcclDataType dataType, HcclRtStream stream);
168 :
169 : virtual HcclResult AllReduce(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
170 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream,
171 : SyncMode syncMode = SyncMode::DEFAULT_TIMEWAITSYNCMODE, const HcomCollOpInfo *opInfo = nullptr);
172 :
173 : virtual HcclResult AllReduceOutPlace(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
174 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream,
175 : SyncMode syncMode = SyncMode::DEFAULT_TIMEWAITSYNCMODE);
176 :
177 : virtual HcclResult AlltoAllV(const void *sendBuf, const void *sendCounts, const void *sdispls,
178 : HcclDataType sendType, const void *recvBuf, const void *recvCounts, const void *rdispls, HcclDataType recvType,
179 : rtStream_t stream, const std::string &tag);
180 :
181 : virtual HcclResult AlltoAllVOutPlace(const void *sendBuf, const void *sendCounts, const void *sdispls,
182 : HcclDataType sendType, const void *recvBuf, const void *recvCounts, const void *rdispls, HcclDataType recvType,
183 : rtStream_t stream, const std::string &tag);
184 :
185 : virtual HcclResult AlltoAllVC(const void *sendBuf, const void *sendCountMatrix, HcclDataType sendType,
186 : const void *recvBuf, HcclDataType recvType, rtStream_t stream, const std::string &tag);
187 :
188 : virtual HcclResult AlltoAllVCOutPlace(const void *sendBuf, const void *sendCountMatrix, HcclDataType sendType,
189 : const void *recvBuf, HcclDataType recvType, rtStream_t stream, const std::string &tag);
190 :
191 : virtual HcclResult AlltoAll(const void *sendBuf, u64 sendCount, HcclDataType sendType,
192 : const void *recvBuf, u64 recvCount, HcclDataType recvType, rtStream_t stream, const std::string &tag);
193 :
194 : virtual HcclResult Broadcast(const std::string &tag, void *ptr, u64 count, HcclDataType dataType, u32 root,
195 : HcclRtStream stream);
196 :
197 : virtual HcclResult BroadcastOutPlace(const std::string &tag, void *ptr, u64 count, HcclDataType dataType, u32 root,
198 : HcclRtStream stream);
199 :
200 : virtual HcclResult Scatter(const std::string &tag, void *inputPtr, void *outputPtr, u64 recvCount,
201 : HcclDataType dataType, u32 root, HcclRtStream stream);
202 :
203 : virtual HcclResult ScatterOutPlace(const std::string &tag, void *inputPtr, void *outputPtr, u64 recvCount,
204 : HcclDataType dataType, u32 root, HcclRtStream stream);
205 :
206 : virtual HcclResult Reduce(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
207 : HcclDataType dataType, HcclReduceOp op, u32 root, HcclRtStream stream);
208 :
209 : virtual HcclResult ReduceOutPlace(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
210 : HcclDataType dataType, HcclReduceOp op, u32 root, HcclRtStream stream);
211 :
212 : virtual HcclResult ReduceScatter(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
213 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream, HcomCollOpInfo *opInfo = nullptr);
214 :
215 : virtual HcclResult ReduceScatterOutPlace(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
216 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream);
217 :
218 : virtual HcclResult ReduceScatterV(const std::string &tag, void *inputPtr,
219 : const void *inputCounts, const void *inputDispls, void *outputPtr, u64 outputCount,
220 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream, HcomCollOpInfo *opInfo = nullptr);
221 :
222 : virtual HcclResult ReduceScatterVOutPlace(const std::string &tag, void *inputPtr, void *outputPtr,
223 : const void *inputCounts, const void *inputDispls, u64 outputCount,
224 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream);
225 :
226 : virtual HcclResult BatchSendRecv(const std::string &tag, HcclSendRecvItem* sendRecvItemsPtr,
227 : u32 itemNum, rtStream_t stream);
228 :
229 : virtual HcclResult Send(const std::string &tag, void *inputPtr, u64 count, HcclDataType dataType,
230 : u32 destRank, rtStream_t stream, u32 srTag = 0, u32 localGroupRank = 0);
231 :
232 : virtual HcclResult SendOutPlace(const std::string &tag, void *inputPtr, u64 count, HcclDataType dataType,
233 : u32 destRank, rtStream_t stream);
234 :
235 : virtual HcclResult Receive(const std::string &tag, void *outputPtr, u64 count, HcclDataType dataType,
236 : u32 srcRank, rtStream_t stream, u32 srTag = 0, u32 localGroupRank = 0);
237 :
238 : virtual HcclResult ReceiveOutPlace(const std::string &tag, void *outputPtr, u64 count, HcclDataType dataType,
239 : u32 srcRank, rtStream_t stream);
240 :
241 : virtual HcclResult SupportDeterministicOptim(bool &isDeterministicOptim);
242 :
243 : virtual HcclResult GetCqeError(HcclResult &result);
244 :
245 : virtual HcclResult GetOpInconsistentError(HcclResult &result);
246 :
247 : // 对内接口
248 : virtual HcclResult CheckDataType(const HcclDataType dataType, bool needReduce);
249 :
250 : virtual HcclResult CheckReduceDataType(const HcclDataType dataType, const HcclReduceOp op);
251 :
252 : virtual HcclResult ReleaseCommInfos();
253 :
254 : virtual HcclResult GetAlltoAllStagedWorkSpaceMemSize(u64 *sendCounts, u64 *sdispls, HcclDataType sendType,
255 : u64 *recvCounts, u64 *rdispls, HcclDataType recvType, u64 &memSize);
256 :
257 : virtual HcclResult GetAlltoAllStagedWorkSpaceMemSize(std::vector<SendRecvInfo> &allMeshAggregationSendRecvInfo,
258 : u64 &memSize);
259 :
260 : virtual HcclResult GetAllReduceScratchSize(const u64 count, const HcclDataType dataType, u64 &scratchSize) const;
261 :
262 : virtual bool IsStandardCard();
263 :
264 : virtual bool Is310PDuoCard();
265 :
266 : HcclResult HcclSelectAlg(HcclCMDType opType, u64 count, void* counts, HcclDataType dataType,
267 : HcclReduceOp op, int32_t aivCoreLimit, bool &ifAiv, std::string &algName);
268 :
269 : HcclResult HcclCalcNumBlocks(HcclCMDType opType, u64 count, void* counts, HcclDataType dataType, int32_t aivCoreLimit,
270 : std::string &algName, u32 &numBlocks);
271 :
272 : HcclResult HcclGetAlgExecParam(const std::string &tag, HcclCMDType opType, u64 count, void *inputPtr, void *outputPtr,
273 : bool clearEnable, HcclDataType dataType, HcclReduceOp op, void *&commContext, u64 &len, u32 aivCoreLimit);
274 :
275 : HcclResult GetAivTag(s32 tagNum, bool isCapture, s32 &aivTag);
276 :
277 : HcclResult CheckDeviceType(const DevType deviceType) const;
278 :
279 : HcclResult CheckReductionOp(const HcclReduceOp op) const;
280 :
281 : HcclResult CheckUserRank(const u32 userRank) const;
282 :
283 : HcclResult CheckCount(const u64 count) const;
284 :
285 : HcclResult GetGroupCommonData(WorldGroupInfo &groupCommonData) const;
286 :
287 : HcclResult GetHccsLinkNum(u32 &numHccsLink);
288 :
289 : HcclResult GetGroupRanksInfo(const std::vector<u32> &groupRanks, std::vector<RankInfo> &ranksInfo);
290 :
291 : static bool CompareWithUserRank(const RankInfo &left, const RankInfo &right);
292 :
293 : static bool CompareWithServerId(const ServerInfo_t &left, const ServerInfo_t &right);
294 :
295 : static bool CompareWithNicName(const NetworkInfo_t &left, const NetworkInfo_t &right);
296 :
297 : HcclResult GetOneSidedService(IHcclOneSidedService** service);
298 : HcclResult InitOneSidedServiceNetDevCtx(u32 remoteRankId);
299 : HcclResult OneSidedServiceStartListen(NicType nicType, HcclNetDevCtx netDevCtx);
300 : HcclResult GetOneSidedServiceDevIpAndPort(NicType nicType, HcclIpAddress& ipAddress, u32& port);
301 : HcclResult DeInitOneSidedServiceNetDevCtx();
302 : HcclResult DeinitOneSidedService();
303 :
304 : u32 GetUserRank();
305 : u32 GetGroupRank();
306 : u32 GetRankSize();
307 : u32 GetRankInParentComm(); // 获取父通信域中的rank ID (MC2场景使用)
308 : /* * 以下两函数用于防止重复初始化 */
309 : HcclResult AtomicInitSet();
310 : HcclResult HostMC2EnvResume();
311 : HcclResult ClearWinBuffer();
312 : HcclResult AivResume();
313 : void AtomicInitClear();
314 : bool GetNicInitialized();
315 : void DestroyAlgResource(AlgResourceResponse &res, bool aclGraphDestroyCbk = false);
316 : void DestroyOpTransportResponse(OpCommTransport &opTransportResponse, bool aclGraphDestroyCbk = false);
317 : HcclResult ReleasePreemptSocket();
318 : HcclResult DestroyNetworkResources();
319 : HcclResult DisablePreResource();
320 : HcclResult GetWorkspaceSubStreamNum(u64 count, HcclDataType dataType, HcclReduceOp op,
321 : const std::string &algName, u64 &streamNum, u64 dataSize, bool ifAiv, HcclCMDType opType);
322 : HcclResult GetWorkspaceMemSize(const std::string &opType, u64 count, HcclDataType dataType,
323 : u32 &rankSize, u64 &memSize, DevType &deviceType) const;
324 : HcclResult SetWorkspaceResource(const std::string &tag, void *memPtr, u64 &maxSize,
325 : std::vector<rtStream_t> &stream);
326 : HcclResult CreateOpBasedResources(const HcclCMDType &opType, const std::string &tag,
327 : const HcomCollOpInfo &opInfo);
328 : HcclResult CreateRemoteOpBasedResources(u64 memSize, const std::string &tag);
329 : HcclResult DestroyRemoteOpBasedMem(const std::string &tag);
330 : void DestroyWorkspaceResource(const std::string &tag);
331 : HcclResult GetInCCLbuffer(void* &buffer, u64 &size);
332 : HcclResult GetOutCCLbuffer(void* &buffer, u64 &size);
333 : void ReleaseCommCCLbuffer();
334 : HcclResult CreateCommCCLbuffer();
335 : HcclResult InitCCLbuffer(u64 inCCLbufferSize, u64 outCCLbufferSize);
336 :
337 : // 目前支持按tag对资源释放、解绑定
338 : HcclResult ClearResMap(const std::string &tag, bool &findTag, bool aclGraphDestroyCbk = false);
339 : virtual HcclResult ClearOpResource(const std::string &tag, bool aclGraphDestroyCbk = false);
340 : HcclResult SetClearAivSyncBuf(bool aivClearEnable);
341 :
342 : HcclResult SetGlobalWorkSpace(std::vector<void *> &globalWorkSpaceAddr);
343 : HcclResult SetAttachedStream(u32 graphId, const std::vector<rtStream_t> &streams);
344 : // 获得rdma with reduce算子溢出的task信息后清除
345 : HcclResult GetandClearOverFlowTasks(std::vector<HcclDumpInfo> &hcclDumpInfo);
346 :
347 : HcclResult GetDeviceId(s32 &deviceId) const;
348 : virtual void Break();
349 : HcclResult SetDevicePid(s32 devicePid);
350 : HcclResult DestroyCDomainResource(s32 tag);
351 :
352 : std::unordered_map<std::string, std::map<u32, HcclIpAddress>> GetPhyIdNicInfo();
353 : std::vector<u32> GetRanksPort();
354 : std::vector<RankInfo> GetRanksList();
355 : HcclResult SetWorldGroupInfo(
356 : std::unordered_map<std::string, std::map<u32, HcclIpAddress>> phyIdNicInfoMap,
357 : std::vector<RankInfo> worldRankInfoList, std::vector<u32> &nicRanksPort, std::vector<u32> &vnicRanksPort);
358 : virtual HcclResult SaveTraceInfo(std::string &logInfo);
359 : virtual bool GetCommResource(const std::string &tag, void **commContext);
360 : virtual bool GetCommResource(void *&commContext);
361 :
362 : virtual HcclResult GetAicpuOpStreamNotify(HcclRtStream *opStream, u8 aicpuNotifyNum, void** aicpuNotify);
363 :
364 : HcclResult GetAlgInfo(const std::string &algConfig, const std::string &tag, HcclCMDType commType,
365 : std::string &algName, std::string &newTag);
366 : HcclResult GetAlgInfo(const std::string &algConfig, const std::string &tag, std::string &algName);
367 : HcclResult FillOpParam(const HcclCMDType commType, OpParam& opParam,
368 : const uint64_t count, void *pCount, void *pDispls);
369 : HcclResult AllocComResource(const std::string &newTag, const std::string &algName,
370 : const HcclCMDType commType, const OpParam& opParam, rtStream_t stream, bool isNeedHostSlaveStream = true);
371 : HcclResult AllocComResourceByTiling(const std::string &algConfig, void *param);
372 :
373 : virtual HcclResult CreateCommResource(const std::string &tag, rtStream_t aiCpuStream, bool isOpbaseMode,
374 : void **commContext, const std::string &algConfig = "");
375 : virtual HcclResult AiCpuKernelLaunch(const rtStream_t stm, u64 addr, const std::string &kernelName);
376 : virtual HcclResult AicpuUnfoldKernelLaunch(void *inputPtr, void *outputPtr, const rtStream_t stm, u64 addr,
377 : void* tilingDataPtr, u32 tilingDataSize, const std::string &kernelName, HcclWorkflowMode mode,
378 : const std::string &tag);
379 : virtual HcclResult AicpuUnfoldKernelLaunchV2(void *inputPtr, void *outputPtr, const rtStream_t stm, u64 addr,
380 : void* tilingDataPtr, u32 tilingDataSize, const std::string &kernelName, HcclWorkflowMode mode,
381 : const std::string &tag, bool isCustom);
382 : HcclResult KernelLaunchChooseAicpuOrCustom(void *inputPtr, void *outputPtr, const rtStream_t stm, u64 addr,
383 : void* tilingDataPtr, u32 tilingDataSize, const std::string &kernelName, HcclWorkflowMode mode,
384 : const std::string &tag, bool isCustom);
385 : HcclResult InitAndCheckAicpuOrderNotify(u8 &orderLaunchMode);
386 : // aclgraph 销毁时批量清理 aicpu 端 tags;走 RunAicpuKfcClearOpRes kernel,超 MAX_BATCH 分批
387 : HcclResult AicpuKfcClearOpResLaunch(const std::unordered_set<std::string> &tags);
388 : HcclResult ClearAclgraphHostLinks(const std::unordered_set<std::string> &tags);
389 : virtual HcclResult Mc2AiCpuStreamAllocAndGet(u32 streamMode, rtStream_t &aiCpuStream);
390 : HcclResult Mc2AiCpuInitStreamAllocAndGet(u32 streamMode, rtStream_t &aiCpuStream);
391 : HcclResult GetTopoDesc(HcclTopoDescs *topoDescs, uint32_t topoSize);
392 : static std::string GetUniqueId(void);
393 :
394 : u8 GetDeterministicConfig() const; // 获取确定性计算配置
395 : HcclResult SetDeterministicConfig(const u8 deterministic); // 设置确定性计算配置
396 : HcclResult SetAivModeConfig(const bool aivMode); // 设置aiv模式配置
397 : HcclResult SetOnlyAivModeConfig(const bool isOnlyAiv); // 设置aiv only模式配置
398 : HcclResult SetAicpuUnfoldConfig(const bool aicpuUnfold); // 设置aicpu配置
399 : HcclResult SetExecTimeOutConfig(const s32 execTimeOut); // 设置HCCL执行超时时间
400 : HcclResult SetAlgoConfig(const std::map<HcclCMDType, std::vector<HcclAlgoType>>& algoMap); // 设置HCCL_ALGO
401 : bool GetAivModeConfig(); // 获取通信域粒度aiv模式配置
402 : bool GetConfigIsOnlyAivMode(); // 获取通信域粒度aiv only模式配置
403 : bool GetAicpuUnfoldConfig(); // 获取通信域粒度aicpu配置
404 : void SetQpQosAttr(u32 trafficClass, u32 serviceLevel); // 设置TC/SL配置
405 : HcclResult SetMC2EnvFlag();
406 : bool GetMC2EnvFlag();
407 : bool GetAicpuCommEngine();
408 : HcclResult SetAicpuCommEngine(bool isAicpuCommEngine);
409 : HcclResult SetStopFlag(bool value);
410 : HcclResult SetState(HcclCommState state);
411 : HcclCommState GetState();
412 : HcclResult ResetNotify();
413 : HcclResult ResetNotifyForDestRank(s64 destRank);
414 : HcclResult InitZeroCopyMemoryAgent();
415 : HcclResult DeinitZeroCopyMemoryAgent(bool inDestructor = false);
416 : u8 GetConfigAclGraphZeroCopyEnable(); // 从commConfig_里通过函数获取用户配置的aclGraphZeroCopyEnable值
417 : HcclResult SetMemoryRange(void *baseVirPtr, size_t size, size_t alignment, uint64_t flags);
418 : HcclResult UnsetMemoryRange(void *baseVirPtr);
419 : HcclResult ActivateCommMemory(void *virPtr, size_t size, size_t offset, void* handle, uint64_t flags);
420 : HcclResult DeactivateCommMemory(void *virPtr);
421 13 : HcclResult GetNumBlocks(u32& numBlocks){
422 13 : numBlocks = numBlocks_;
423 13 : return HCCL_SUCCESS;
424 : }
425 : HcclResult SetAivCoreLimit(u32 aivCoreLimit);
426 : HcclResult SwitchNic(uint32_t nRanks, uint32_t *ranks, bool *useBackup);
427 : HcclResult GetSwitchRanks(u32 *distSwitchRankList, bool *distSwitchUseBackup, u32 &distSwitchRankNum,
428 : u8 *distRemoteRankNicStatus, u32 &distNicStatusNum, bool &needCheckDefaultNic, bool &needCheckBackupNic);
429 : HcclResult SetTransportStatus(const HcclOpIdentifier &opId, bool statusStop,
430 : const std::map<u32, bool> &remoteRankPortMap, const std::map<u32, bool> &isChangeLinkMap, bool isChangeLinkFlag);
431 : static HcclResult GetTransportCqeErrors(const HcclNetDevCtx netDevCtx, std::vector<ErrCqeInfo> &infos, u32 &num);
432 : ErrorMessageReport GetAicpuTaskException();
433 :
434 : // 独立算子专用
435 : HcclResult IndOpTransportAlloc(const std::string &tag, OpCommTransport &opCommTransport,
436 : TransportIOMem& transMem, bool isAicpuModeEn);
437 : aclrtBinHandle GetBinHandle();
438 : HcclResult GetHDCommunicate(HDCommunicateParams &kfcControlTransferH2DParams,
439 : HDCommunicateParams &kfcStatusTransferD2HParams);
440 : HcclResult SetGetAicpuCommState(std::function<bool()> getAicpuCommState);
441 : CCLBufferManager& GetCCLbufferManager();
442 :
443 : HcclResult RegisterCommUserMem(void* addr, u64 size, void **handle);
444 : HcclResult DeregisterCommUserMem(void* handle);
445 : HcclResult ExchangeCommUserMem(void* handle, std::vector<u32>& peerRanks);
446 : HcclResult GetCommUserMemSize(uint64_t &size);
447 : HcclResult GetCacheMap(std::unique_ptr<CollAlgOperator>& algOperator, OpParam& opParam,
448 : AlgType& algType, bool selectAivAlg, std::string& newTag);
449 : HcclResult ExecOpCache(HcclCMDType opType, OpParam &opParam, HcclCacheInfo& cacheInfo);
450 : void SplitBsrData(OpParam &opParam, std::vector<u8>& isDirectRemoteRank,
451 : std::vector<HcclSendRecvItem>& hostSendRecvInfo, std::vector<HcclSendRecvItem>& aicpuSendRecvInfo);
452 : HcclResult SetInvalidComm(bool isInvalid);
453 : HcclResult SnapshotCheckPreProcess();
454 : HcclResult SnapshotCheckPostProcess();
455 :
456 : //decouple for MC2
457 : HcclResult GetLocalCCLBuf(void **addr, uint64_t *size);
458 : HcclResult GetRemoteCCLBuf(uint32_t remoteRank, void **addr, uint64_t *size);
459 : HcclResult GetKFCWorkSpace(void **addr, uint64_t *size);
460 :
461 : HcclResult CommGetNetLayers(uint32_t **netLayers, uint32_t *netLayerNum);
462 : HcclResult CommGetInstSizeByNetLayer(uint32_t netLayer, uint32_t *rankNum);
463 : HcclResult CommGetInstTopoTypeByNetLayer(uint32_t netLayer, u32 *topoType);
464 : HcclResult GetNetLayers(uint32_t **netLayers, uint32_t *netLayerNum);
465 : HcclResult GetInstSizeByNetLayer(uint32_t netLayer, uint32_t *rankNum);
466 : HcclResult GetInstTopoTypeByNetLayer(uint32_t netLayer, CommTopo *topoType);
467 : HcclResult GetInstRanksByNetLayer(uint32_t netLayer, uint32_t **rankList, uint32_t *rankNum);
468 : HcclResult GetInstSizeListByNetLayer(uint32_t netLayer, uint32_t **instSizeList, uint32_t *listSize);
469 :
470 : HcclResult GetTopoInstsByLayer(uint32_t netLayer, uint32_t **topoInsts, uint32_t *topoInstNum);
471 : HcclResult GetTopoType(uint32_t netLayer, uint32_t topoInstId, CommTopo *topoType);
472 : HcclResult GetRanksByTopoInst(uint32_t netLayer, uint32_t topoInstId, uint32_t **ranks, uint32_t *rankNum);
473 : HcclResult GetEndpointNum(uint32_t netLayer, uint32_t topoInstId, uint32_t *num);
474 : HcclResult GetEndpointDesc(uint32_t netLayer, uint32_t topoInstId, uint32_t *descNum, EndpointDesc *endpointDesc);
475 : HcclResult GetEndpointInfo(uint32_t rankId, const EndpointDesc *endPointDesc, EndpointAttr endpointAttr,
476 : uint32_t infoLen, void *info);
477 :
478 : HcclResult GetRankGraph(GraphType type, void **graph, uint32_t *len);
479 : void* GetRankGraphV1(); // 获取V1 RankGraph指针,用于CollComm初始化
480 :
481 : HcclResult GetLinks(uint32_t netLayer, uint32_t srcRank, uint32_t dstRank,
482 : CommLink **linkList, uint32_t *listSize);
483 : HcclResult GetHeterogMode(HcclHeterogMode *mode);
484 : HcclTopoAttr GetTopoAttr();
485 : void ForceProf(bool isForce);
486 : // for Group
487 : HcclResult SetGroupMode(bool isGroup);
488 : bool GetGroupMode();
489 :
490 : void SetReleaseChannel(std::function<HcclResult()> releaseChannel);
491 :
492 : void SetHcclQos(u32 hcclQos);
493 : u32 GetHcclQos();
494 : HcclResult RegisterWindow(void* ptr, size_t size, HcclCommSymWindow *winHandle);
495 : HcclResult DeregisterWindow(HcclCommSymWindow winHandle);
496 : HcclResult InitSymmetricMemory();
497 : HcclResult GetCommSymWin(void* ptr, size_t size, HcclCommSymWindow *winHandle, size_t *offset);
498 : private:
499 :
500 : bool IsEnableRoce();
501 : bool IsEnableBackupLink();
502 : HcclResult CheckOneSidedBackupAndSetDevId(u32 &backupDevPhyId, u32 &backupDevLogicId, std::vector<HcclIpAddress> &localIpList, bool &isOneSidedTaskAndBackupInitA3);
503 : HcclResult OneSidedBackupInitNetResource(HcclNetDevCtx &nicPortBackUpCtx, u32 &backupDevPhyId, u32 &backupDevLogicId, std::vector<HcclIpAddress> &localIpList);
504 : HcclResult OneSidedBackupServerInit(HcclNetDevCtx &nicPortBackUpCtx);
505 : void SetAttrs();
506 : u32 HcclGetCmdTimeout();
507 : HcclResult InitCommParams(HcclCommParams ¶ms);
508 : HcclResult InitRankInfo(const RankTable_t &rankTable);
509 : HcclResult InitRankInfoSubGroup(WorldGroupInfo &groupCommonData);
510 : HcclResult CheckSingleServerComm(const std::vector<RankInfo_t> &rankList) const;
511 : HcclResult SetRanksPort(const std::vector<RankInfo_t> &rankList);
512 : HcclResult InitNetResource(const RankTable_t &rankTable);
513 : HcclResult InitDebug();
514 : HcclResult InitDebugSubGroup();
515 : HcclResult InitATraceInfo();
516 : HcclResult InitNotifyManager();
517 : HcclResult InitDispatcher();
518 : HcclResult InitStreamManager();
519 : HcclResult InitSocketManager();
520 : HcclResult InitTransportManager();
521 : HcclResult InitHcclAlg();
522 : HcclResult InitAlgResource();
523 : HcclResult InitProfiling();
524 : HcclResult DeinitProfiling();
525 : HcclResult InitProfiler();
526 : HcclResult InitOneSidedService(const RankTable_t &rankTable);
527 :
528 : HcclResult RegistTaskExceptionHandler() const;
529 : HcclResult UnRegistTaskExceptionHandler() const;
530 : HcclResult UnRegisterBackGroundThread();
531 : HcclResult UnRegisterBackGroundThread(std::shared_ptr<HDCommunicate> &controlH2D,
532 : std::shared_ptr<HDCommunicate> &statusD2H);
533 : HcclResult DestroyAicpuComm();
534 : HcclResult DestroyAicpuComm(std::shared_ptr<HDCommunicate> &controlH2D, std::shared_ptr<HDCommunicate> &statusD2H);
535 : HcclResult InitPreResource(const RankTable_t &rankTable);
536 : HcclResult InitTcpMode(const RankTable_t &rankTable) const;
537 : HcclResult InitRaResource();
538 : HcclResult InitRaNetResource();
539 : HcclResult InitRaNic();
540 : HcclResult InitDevicePrimaryNic(bool isMC2ReInit, bool isOneSidedTaskAndBackupInitA3);
541 : HcclResult InitDeviceBackupNic(u32 backupDevPhyId, u32 backupDevLogicId,
542 : std::vector<HcclIpAddress> &localIpList, bool isOneSidedTaskAndBackupInitA3);
543 : HcclResult InitNicDeviceDeploy(bool isMC2ReInit, u32 backupDevPhyId, u32 backupDevLogicId,
544 : std::vector<HcclIpAddress> &localIpList, bool isOneSidedTaskAndBackupInitA3);
545 : HcclResult InitNicHostDeploy();
546 : bool IsNeedNicInit();
547 : HcclResult InitNic(bool isMC2ReInit = false);
548 : HcclResult DeinitNic();
549 : HcclResult DeinitNicHostDeploy();
550 : HcclResult AddOpInfoToHeartBeat(const OpInfoDesc &opInfo, const std::string &tag);
551 : void DeleteOpInfoToHeartBeat();
552 : HcclResult RegisterToHeartBeat();
553 : HcclResult RegisterToHeartBeat(u32 peerRankId, std::string &tag);
554 : void UnRegisterToHeartBeat();
555 : void UnRegisterToCommConfiger();
556 : HcclResult PrintOpbaseKeyTraceInfo(void);
557 : HcclResult InitPara();
558 : HcclResult GetComm(const std::string &tag, CommBase **comm);
559 : HcclResult Mc2CreateAndLaunchContext(rtStream_t aiCpuStream, bool isOpbaseMode, void **commContext, const std::string &tag = "");
560 : HcclResult SetCommResource(u64 commBufferSize, void *commInPtr, void *commOutPtr, void *commExpPtr,
561 : CommBase *comm, level1StreamInfo_t &streamInfo, Stream &stream);
562 : HcclResult GetAicpuOpStreamAndNotify(HcclRtStream *opStream, u8 aicpuNotifyNum, void** aicpuNotify);
563 : HcclResult SetAicpuNotifyInvalid();
564 : HcclResult AicpuKfcTilingDataLaunch(const OpParam &opParam, const HcclCMDType &opType, const DeviceMem &deviceContext,
565 : const std::string &kernelName, const AicpuOpTiling opTilingInfo);
566 : HcclResult AicpuKfcTilingDataLaunchExt(const OpParam &opParam, const HcclCMDType &opType,
567 : const DeviceMem &deviceContext, const std::string &kernelName, const AicpuOpTiling opTilingInfo, bool isCustom = false);
568 : u64 CalcOpTilingDynamicDataSize(const OpParam &opParam, const HcclCMDType &opType, const u32 &rankSize,
569 : const std::string &algName = "");
570 : u64 CalcOpTilingVDataDesVDataLen(const u32 rankSize) const;
571 : HcclResult AicpuInitOpTilingDataFromOpParam(const OpParam &opParam, const HcclCMDType &opType,
572 : struct OpTilingData* opTilingData);
573 : HcclResult AicpuInitOpTilingDataAicpuCache(const OpParam &opParam, const HcclCMDType &opType, struct OpTilingData *opTilingData);
574 : HcclResult AicpuInitOpTilingDataBuf(const OpParam &opParam, const HcclCMDType &opType,
575 : const std::string &kernelName, const AicpuOpTiling opTilingInfo, u64 dynamicDataSize);
576 : HcclResult AicpuKfcTilingDataLaunchIn(const OpParam &opParam, const DeviceMem &deviceContext,
577 : const std::string &kernelName, const AicpuOpTiling opTilingInfo, u64 opTilingDataSize, bool isCustom = false);
578 : HcclResult AllReduceAicpuUnfold(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
579 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream);
580 : HcclResult CreateMutiStreamResFor310P(const std::string &tag, level1StreamInfo_t &streamInfo);
581 : HcclResult SetDynamicTilingDataAlltoall(const OpParam &opParam, HostMem &dynamicDataMem);
582 : HcclResult UnRegisterDfxInfo(const OpParam ¶m, const std::vector<Stream> &slaveStreams);
583 : HcclResult RegisterDfxInfo(const OpParam ¶m, AlgType algType,
584 : const std::vector<Stream> &slaveStreams, bool isAiv = false, const std::string &tag = "");
585 : HcclResult AddGroupTagInfo(const std::string &tag, bool isAiv);
586 : HcclResult SetDynamicTilingDataAlltoallv(const OpParam &opParam, HostMem &dynamicDataMem,
587 : const std::string &algName = "");
588 : HcclResult SetDynamicTilingDataAlltoallvc(const OpParam &opParam, HostMem &dynamicDataMem);
589 : HcclResult SetDynamicTilingDataV(const OpParam &opParam, HostMem &dynamicDataMem);
590 : HcclResult GetReportHcclMC2Info(const Stream &kfcStream, const std::vector<Stream> &aicpuStreams);
591 : u8 GetOrderLaunchMode (bool isCapture);
592 :
593 : HcclResult ReAllocTransports(const std::string &tag, const std::string &newTag);
594 : HcclResult SetTransportStatusImpl(OpCommTransport &opCommTransport, bool statusStop,
595 : const HcclOpIdentifier &opId, u32 remoteRank, const std::map<u32, bool> &remoteRankPortMap,
596 : bool isUseDefault);
597 : HcclResult SetBsrTransportStatusImpl(OpCommTransport &opCommTransport, bool statusStop,
598 : const HcclOpIdentifier &opId, u32 remoteRank);
599 : HcclResult SetTransportStatusImplForChange(OpCommTransport &opCommTransport, const HcclOpIdentifier &opId,
600 : u32 remoteRank, const std::map<u32, bool> &remoteRankPortMap, bool isUseDefault,
601 : const std::map<u32, bool> &isChangeLinkMap, bool isCurTag);
602 : HcclResult SetTransportResumeStatus(const std::map<u32, bool> &remoteRankPortMap,
603 : const std::map<u32, bool> &isChangeLinkMap, bool isChangeLinkFlag, bool statusStop);
604 : HcclResult ResumeTransportsImplForChange(OpCommTransport &opCommTransport, const std::map<u32, bool> &remoteRankPortMap,
605 : const std::map<u32, bool> &isChangeLinkMap, bool isUseDefault);
606 : HcclResult ResumeTransportsImpl(OpCommTransport &opCommTransport, const std::map<u32, bool> &remoteRankPortMap, bool isUseDefault, bool statusStop);
607 : HcclResult SetBsrTransportStatusImplforchange(OpCommTransport &opCommTransport,
608 : const HcclOpIdentifier &opId, u32 remoteRank, const std::map<u32, bool> &remoteRankPortMap, bool isUseDefault,
609 : const std::map<u32, bool> &isChangeLinkMap, bool isCurTag);
610 : void ClearOpTransportResponseLinks(OpCommTransport &opTransportResponse);
611 : HcclResult SetSignalTransport(SingleSubCommTransport &singleSubCommTransport,
612 : u32 linkIdx, bool statusStop);
613 : void InsertNewTagToTagMap(std::string &newTag, std::string &tag);
614 : HcclResult GetTagFromNewTag(const std::string &newTag, std::string &tag);
615 : HcclResult ParseSwitchRanks(uint32_t nRanks, uint32_t *ranks, bool *useBackup,
616 : std::unordered_map<u32, bool> &switchRanks);
617 : HcclResult PrepareLinkForSwitchNic(std::unordered_map<u32, bool> &switchRanks, ChangeLinkInfo &changeLinkInfo);
618 : HcclResult SetRemoteRankLinkInfo(std::unordered_map<u32, bool> &switchRanks, ChangeLinkInfo &changeLinkInfo);
619 : HcclResult SetSingleLinkInfo(std::unordered_map<u32, bool> &switchRanks, u32 remoteRankId,
620 : ChangeLinkInfo &changeLinkInfo);
621 : HcclResult ActiveStoppedLink(std::map<u32, bool> &remoteRankPortMap, OpCommTransport &opTransportResponse,
622 : bool isBackup);
623 : HcclResult setVnicIpToRankInfoList();
624 : HcclResult GetRemoteUserMemResource();
625 :
626 : HcclResult Suspend(std::shared_ptr<HDCommunicate> &controlH2D, std::shared_ptr<HDCommunicate> &statusD2H);
627 : HcclResult StopExec(std::shared_ptr<HDCommunicate> &controlH2D, std::shared_ptr<HDCommunicate> &statusD2H);
628 : HcclResult Clean(std::shared_ptr<HDCommunicate> &controlH2D, std::shared_ptr<HDCommunicate> &statusD2H);
629 : HcclResult SwitchNic(uint32_t nRanks, uint32_t *ranks, bool *useBackup,
630 : std::shared_ptr<HDCommunicate> &controlH2D, std::shared_ptr<HDCommunicate> &statusD2H);
631 : HcclResult SaveRankInfoHasLinked(const AlgResourceRequest& resRequest);
632 : HcclResult RecordOpPara(HcclCMDType opType, const OpParam &opParam);
633 : HcclResult SaveTopoDesc(std::string &identifier);
634 :
635 : HcclResult SetAicpuUnfoldFlag();
636 : bool GetAicpuUnfoldFlag();
637 :
638 : HcclResult ReAllocScratchMemForAlltoall(HcclCMDType opType, const OpParam &opParam,
639 : AlgResourceRequest &resRequest, AlgResourceResponse &algResResponse);
640 :
641 : HcclResult HandleExistAlgResource(const std::string& newTag, const std::string& algName,
642 : HcclCMDType opType, const OpParam& opParam, std::unique_ptr<CollAlgOperator>& algOperator,
643 : bool selectAivAlg, bool aicpuUnfoldModeFor910B, bool needRecreateAlltoallComm);
644 : u32 deviceNumPerServer_;
645 : HcclDispatcher dispatcher_; // dispatcher放到最后析构
646 : DispatcherCtxPtr dispatcherCtx_{nullptr};
647 : HcclDispatcher vDispatcher_; // virtualDispatcher放到最后析构
648 : std::unique_ptr<NotifyPool> notifyPool_;
649 : std::unique_ptr<HcclCallbackTask> callbackTask_;
650 : std::atomic_flag initializedFlag_;
651 : u32 userRank_; // 本group中的userrank
652 : u32 realUserRank_; // world group中的userrank
653 : u32 userRankSize_;
654 : std::vector<RankInfo> rankInfoList_; // world group内rank的信息, 按照rank id递增依次排列
655 : std::vector<RankInfo> rankInfoListIntraServer_; // 节点内rank信息,用于零拷贝
656 : bool drvInit_; // ra是否初始化
657 : ServRankInfo_t servRankInfo_;
658 : std::string serverId_;
659 : std::unordered_map<u32, std::unordered_map<int, std::vector<int>>> pairLinkInfo_; // server内所有device间的链路类型
660 : bool inlineReduceSwitchOn_;
661 : NICDeployment nicDeployment_;
662 : u32 devicePhyId_;
663 : u32 deviceBackUpPhyId_;
664 : s32 deviceLogicId_;
665 : u32 deviceBackUpLogicId_;
666 : std::unordered_set<s32> aicpuStreamIds_;
667 : std::vector<HcclIpAddress> devIpAddr_;
668 : std::vector<HcclIpAddress> devBackupIpAddr_;
669 : u32 devBackupPort_{HCCL_INVALID_PORT};
670 : HcclIpAddress hostIp_;
671 : HcclIpAddress deviceVnicIp_;
672 : u32 hostPort_{HCCL_INVALID_PORT};
673 : u32 localRank_;
674 : SocketHandle hostSocketHandle_;
675 : SocketHandle loopbackHeterogSocketHandle_;
676 : bool isUsedRdmaLevel0_; // 节点内是否使用rdma, 包括a+x和标卡
677 : std::atomic<s32> nicInitialized_;
678 : bool hcomGroupNicInit_;
679 : // profiling 相关资源
680 : HcomProfilingMode profilingMode_;
681 : std::string profilingOption_;
682 : ProfilingDeviceCommResInfo hcclMc2Info_;
683 : bool raResourceInit_;
684 : bool interServer_;
685 : std::unique_ptr<WorkspaceResource> workSpaceRes_;
686 : std::vector<u32> enableP2PDevices_;
687 : std::unordered_set<u32> enableP2PRankIds_;
688 : bool isSingleMeshAggregation_;
689 : CCLBufferManager cclBufferManager_;
690 : bool isExecuteProfilingInit_;
691 : DevType deviceType_;
692 : std::string collectiveId_;
693 : HcclComm commHandle_;
694 : std::vector<u32> nicRanksPort_;
695 : std::vector<u32> groupNicRanksPort_;
696 : std::vector<u32> vnicRanksPort_;
697 : std::vector<u32> groupVnicRanksPort_;
698 : std::unordered_map<std::string, std::map<u32, HcclIpAddress>> rankDevicePhyIdNicInfoMap_;
699 : std::unordered_map<u32, HcclRtContext> rtCtxMap_; // {devPhyId, rtCtx}
700 : WorkMode commWorkMode_;
701 : u32 meshAggregationRankSize_;
702 : std::map<HcomOperationType, std::string> opTypeTagMap_;
703 : bool isHaveCpuRank_;
704 : bool isUseRankPort_{ true };
705 : bool isSetHDCModeInfo_{ false };
706 : std::map<std::string, HostMem> tagWorkSpaceMem_;
707 : std::string identifier_;
708 : u32 ranktableCrc_;
709 : s32 devicePid_;
710 : bool multiModuleDiffDeviceNumMode_;
711 : bool multiSuperPodDiffServerNumMode_;
712 : bool multiSuperPodDiffDeviceNumMode_;
713 : DeviceMem commContext_;
714 : std::shared_ptr<ProfilerManager> profilerManager_;
715 : bool isStandardCard_ = false;
716 : bool is310PDuoCard_ = false;
717 : bool isCommon310P3DUO_ = false;
718 : s32 hccsPortNum_ = -1;
719 : std::string superPodId_;
720 : u32 superDeviceId_ = INVALID_UINT;
721 : bool useSuperPodMode_ = false;
722 : bool isUsedInterHccsMode_ = false;
723 : bool isNeedInitNic_ = false;
724 : std::vector<RankInfo> worldRankInfoList_;
725 : std::unique_ptr<HcclTraceInfo> opBaseAtraceInfo_;
726 : bool aivClearEnable_ = false;
727 : u32 numBlocks_ = 0;
728 : std::map<OpParam, HcclCacheInfo> hcclCacheMap_; //存储aiv cache信息
729 : std::string cclBuffName_;
730 : bool isShareComm_ = false; // 是否共享cclbuffer
731 : private:
732 :
733 : bool IsAtomicInit();
734 : HcclResult MigrateLinkToStopOrResume(LINK &link, bool isStop);
735 : HcclResult MigrateLinkVectorToStopOrResume(const std::vector<LINK> &links, bool isStop);
736 : HcclResult TraverseLinkVector(std::vector<std::unique_ptr<CommBase> > &commBaseVector, bool isStop);
737 : HcclResult CheckSuspendingStatus();
738 : HcclResult InitCombinOpara();
739 : HcclResult RegisterRanksToDca();
740 : HcclResult InitWorkSpace();
741 : void ReleaseWorkSpacebuffer();
742 : HcclResult CreateWorkSpace(u64 size, DeviceMem &buffer) const;
743 : HcclResult GetWorkSpace(u64 *workSpaceSize, u64 *workSpace) const;
744 : void ReleaseCommContextbuffer();
745 : HcclResult CreateDeviceCommContext(u64 size, DeviceMem &buffer) const;
746 : HcclResult CreateAndGetAiCpuNotify(std::shared_ptr<LocalNotify> &localNotify, HcclSignalInfo ¬ifyInfo);
747 : HcclResult GetAiCpuNotifyData(const std::shared_ptr<LocalNotify> &localNotify, HcclSignalInfo ¬ifyInfo);
748 : HcclResult ReplaceCommInfoByTag(const std::string &tag, std::unique_ptr<CommInfo> &commInfo);
749 : HcclResult CreateCommAndStreamRes(const std::string &tag, Stream &stream);
750 : HcclResult SetInfoToDevice(const std::unique_ptr<PreProcessMetaInfo> &preMetaInfo, Stream &stream);
751 : HcclResult GetInfoFromDevice(const std::unique_ptr<PreProcessMetaInfo> &preMetaInfo,
752 : const HcclWorkflowMode &mode, HostMem& hostCollectBuffer);
753 : HcclResult RegressCalPreOp(AlltoAllOperator* &alltoAllOperator, const OpParam &opParam,
754 : std::unique_ptr<PreProcessMetaInfo> &preMetaInfo);
755 : HcclResult RegressCalPreOp(AlltoAllOperator* &alltoAllOperator, const OpParam &opParam,
756 : std::unique_ptr<PreProcessMetaInfo> &preMetaInfo, Stream &preProcessStream);
757 : DevType NslbGetDeviceType();
758 : u32 NslbGetServerNum();
759 : HcclResult NslbDp_CollectOperTable(HcclCMDType opType, OpParam &opParam,
760 : AlgType nslbAlgType, std::string& algName);
761 : HcclResult NslbDp_CollectSendAdjTable(HcclCMDType opType, OpParam &opParam,
762 : AlgType nslbAlgType, AdjInfo &nslbAdjInfo);
763 : HcclResult ExecOp(HcclCMDType opType, OpParam &opParam, bool isCustom = false);
764 : // alltoall专用
765 : HcclResult ExecOpAlltoAll(HcclCMDType opType, OpParam &opParam, bool isCustom = false);
766 : HcclResult FreeScratchMemOnOpBaseMode(DeviceMem &scratchMem, const OpParam &opParam,
767 : const HcclCMDType &opType);
768 : HcclResult CalcTinySendRecvMem(const OpParam &opParam, AlgResourceResponse &algResResponse,
769 : DeviceMem &tinySendRecvMem);
770 : bool IsForceAicpuOpBaseMode(const OpParam &opParam, const HcclCMDType &opType);
771 : HcclResult AllocOpBaseModeScratchMem(HcclCMDType opType, const OpParam &opParam,
772 : AlgResourceRequest &resRequest, AlgResourceResponse &algResResponse);
773 : HcclResult AllocAlgResource(const std::string &newTag, HcclCMDType opType, const OpParam &opParam,
774 : AlgResourceRequest &resRequest, AlgResourceResponse &algResResponse, bool selectAivAlg = false);
775 : HcclResult IncreAllocLink(const std::string &newTag, const OpParam &opParam,
776 : AlgResourceRequest &resRequest, AlgResourceResponse &algResResponse);
777 : bool HasRoceTransportLinks(OpCommTransport &opTransportReq);
778 : HcclResult CleanTransportLinks(OpCommTransport &opTransportReq, OpCommTransport &opTransportResponse);
779 : DeviceMem GetWorkspaceScracthMem(const std::string &tag, u64 allocMemSize);
780 : std::vector<Stream> GetWorkspaceSubStreams(const std::string &tag, u32 num);
781 : // HcclImplBase中Comm资源是否存在
782 8 : inline bool IsExistCommRes(const std::string &tag)
783 : {
784 8 : std::unique_lock<std::mutex> commLock(commLock_);
785 16 : return (tagCommInfo_.find(tag) != tagCommInfo_.end());
786 8 : }
787 : // HcclImplBase中MutiStream资源是否存在
788 1 : inline bool IsExistMutiStreamRes(const std::string &tag)
789 : {
790 1 : std::unique_lock<std::mutex> mutiStreamLock(tagStreamInfoLock_);
791 2 : return (tagStreamInfo_.find(tag) != tagStreamInfo_.end());
792 1 : }
793 : void GetAndSetSyncMode(SyncMode& preSyncMode, SyncMode newSyncMode);
794 : void RestorePreSyncMode(SyncMode preSyncMode, SyncMode newSyncMode);
795 : HcclResult AicpuUnfold(const std::string &tag, void *inputPtr, void *outputPtr, u64 count,
796 : HcclDataType dataType, HcclReduceOp op, HcclRtStream stream, HcclCMDType cmdType);
797 : u32 GetHostPort(s32 devicePhyId);
798 : u32 GetLocalNicPort(NicType nicType);
799 : std::string GetSupportDataType(bool needReduce);
800 : HcclResult InitHDCommunicate();
801 : bool GetSupportHDCommunicate();
802 : HcclResult InitOpRetry();
803 : HcclResult InitOpResPara();
804 : bool IsSupportSymmetricMemory(HcclCMDType opType, OpParam &opParam);
805 : bool IsSupportZeroCopy(const OpParam &opParam);
806 : HcclResult PrepareZeroCopy(const std::string &algName, const AlgDesc &algDesc, OpParam &opParam);
807 : HcclResult UpdateZeroCopy(const OpParam &opParam, const AlgResourceResponse &algResource);
808 : HcclResult BuildZeroCopyParam();
809 : HcclResult AllocAndClearHostMem(u64 size, std::shared_ptr<HostMem> &bufferPtr) const;
810 : HcclResult AllocAndClearDeviceMem(u64 size, std::shared_ptr<DeviceMem> &bufferPtr) const;
811 : HcclResult updateList() const;
812 : HcclResult BuildOpLocalResParam(const AlgResourceResponse &algResource, const std::string &newTag);
813 : HcclResult BuildOpLocalScratchMemResParam(
814 : const AlgResourceResponse &algResource, const std::string &newTag, LocalResInfoV2 *localResHostPtr);
815 : HcclResult BuildOpTopoResTlvParam(const std::string &algName,
816 : const std::vector<std::vector<std::vector<u32>>> &inputVectorInfo,
817 : DeviceMem &dstTlvDeviceMem, u64 &tlvLen);
818 : HcclResult BuildOpTopoResVectorTlvParam(const std::string &algName,
819 : const std::vector<std::vector<std::vector<std::vector<u32>>>> &inputVectorInfo,
820 : DeviceMem &dstTlvDeviceMem, u64 &tlvLen);
821 : HcclResult BuildPairLinkCounter(const std::string &algName);
822 : HcclResult BuildIsUsedRdmaRank(const std::string &algName);
823 : HcclResult BuildNicList(const std::string &algName);
824 : HcclResult BuildBridgeRank(const std::string &algName);
825 : HcclResult BuildCommPlanRank(const std::string &algName);
826 : HcclResult BuildServerAndsuperPodRank(const std::string &algName);
827 : HcclResult BuildCommPlaneSubGroupRank(const std::string &algName);
828 : HcclResult BuildHierarchicalAlgOption(u32 *ahcConfInfo);
829 : HcclResult BuildOpTopoResParam(
830 : const std::string &algName, const AlgResourceResponse &algResource);
831 : HcclResult BuildAicpuCustomParam();
832 : HcclResult BuildAicpuOrderLaunchNotify();
833 : HcclResult BuildOpRemoteResParam(const AlgResourceResponse &algResource, const std::string &newTag,
834 : const HcclCMDType opType, bool isRetry = false);
835 : HcclResult BuildOpResParam(const std::string &algName, const AlgResourceResponse &algResource,
836 : const std::string &newTag, const HcclCMDType opType, const rtStream_t aicpuStream);
837 : HcclResult BuildCustomOpResParam();
838 : HcclResult BuildOpRetryParam(const AlgResourceResponse &algResource, const std::string &newTag);
839 : HcclResult CopyHostListResToDeviceParam(const std::string &newTag, const ListCommon *headHostList, const u64 size);
840 : HcclResult CopyHostAirmaInfoToDeviceParam(const std::string &newTag, const HcclCMDType opType, const rtStream_t aiCpuStream);
841 : HcclResult CopyHostOpRemoteResToDeviceParam(const std::string &newTag);
842 : HcclResult CopyHostOpResToDeviceParam(const std::string &newTag);
843 : HcclResult AicpuResourceInit(const std::string &algName,
844 : const AlgResourceResponse &algResource, const std::string &newTag, const rtStream_t &aicpuStream,
845 : const HcclCMDType opType, bool isCustom = false);
846 : HcclResult AicpuResourceRefresh(const AlgResourceResponse &algResource, const std::string &newTag,
847 : const HcclCMDType opType);
848 : HcclResult OrchestrateAicpu(const HcclCMDType &opType, const std::string &algName, const OpParam ¶m,
849 : const AlgResourceResponse &algResource, const std::string &newTag, AlgType algType, bool isCustom = false,
850 : bool needIncreLink = false, bool needRecreateAlltoallComm = false);
851 : template <typename T>
852 : HcclResult CopyVectorToDeviceMem(const u64 len, DeviceMem &dstDeviceMem, const std::vector<T> &srcVec);
853 : template <typename T>
854 : HcclResult CreateListNode(T **resHostPtr, T **resDevicePtr);
855 : HcclResult ParseRemoteDataToMem(const OpCommTransport &opTransportResponse, const std::string &newTag,
856 : const HcclCMDType opType, bool isBackup = false, bool isRetry = false);
857 : HcclResult BuildRelationResByRemoteRankId(const TransportRequest &transportRequest, const LINK &link,
858 : HcclRankRelationResV2 *&rankRelationResHostPtr, HcclRankRelationResV2 *&rankRelationResDevicePtr);
859 : HcclResult BuildRemoteResByTag(const std::string &newTag, const u32 &usrRankId,
860 : HcclRankRelationResV2 *&rankRelationResHostPtr, HcclRankRelationResV2 *&rankRelationResDevicePtr,
861 : bool isBackup, bool isRetry);
862 : HcclResult BuildOpRemoteLinkP2pResParam(const LINK &link, HccltagRemoteResV3 &tagRemoteRes,
863 : TransportLinkType linkType = TransportLinkType::RESERVED);
864 : HcclResult BuildOpRemoteLinkRoceResParam(const LINK &link, HccltagRemoteResV3 &tagRemoteRes, bool isBackup,
865 : bool isRetry, bool isSecondBuild);
866 : HcclResult BuildAiRmaInfoParam(const std::string &newTag, const std::string &algName, const HcclCMDType opType);
867 : HcclResult CheckNotifyOrQPMaxNum(u64 &existNum, const u64 &MaxNum, const bool &isNotifyRes);
868 : HcclResult AllocAlgNotifys(const std::string &tag, const NotifyLoadType notifyLoadType, const u32 notifyNum,
869 : std::vector<std::shared_ptr<LocalNotify> > ¬ifiesMain, std::vector<std::shared_ptr<LocalNotify> > ¬ifiesAux);
870 : HcclResult CreateAndGetAiCpuNotifyWithNotifyRes(HcclSignalInfo ¬ifyInfo);
871 : void SaveLinkRes(const OpCommTransport &opTransportResponse);
872 : HcclResult SetDevIbverbsData(CommBase *comm, bool isSupportNormalQP, u64 commBufferSize, void *commInPtr,
873 : void *commOutPtr);
874 :
875 : // 获取 Transport 本端内存信息
876 : HcclResult GetTransportLocalMem(const std::shared_ptr<Transport>& transport,
877 : UserMemType memType, MemDetails& detail);
878 : // 获取 Transport 远端内存信息
879 : HcclResult GetTransportRemoteMem(const std::shared_ptr<Transport>& transport,
880 : UserMemType memType, MemDetails& detail);
881 :
882 : // 收集全部 Transport 内存/QP信息
883 : HcclResult GenAiRMAInfo(CommBase *comm);
884 : HcclResult GenAiRMAInfoV2(const std::string &tag);
885 : // 同步全部信息到Device
886 : HcclResult H2DAiRMAInfo(const std::string &tag, rtStream_t aiCpuStream);
887 : HcclResult H2DAiRMAInfoV2(const std::string &tag, rtStream_t aiCpuStream);
888 : HcclResult GetAIVNormalQPInfo(CommBase *comm, const std::string &tag);
889 : HcclResult GetAIVNormalQPInfoV2(std::vector<LINK>& links, const std::string &tag);
890 : template<typename T>
891 : HcclResult GenIbvAiRMAInfo(u32 rankid, const std::shared_ptr<Transport>& transport, const std::string &tag, T* aiRMAInfoPtr);
892 : HcclResult GetAivQPInfoV2(std::vector<LINK>& links, const std::string &tag);
893 : HcclResult CaptureSlaveStreams(rtStream_t mainStream, std::vector<Stream> &slaveStreams);
894 : HcclResult HandleAclGraphFirstOpAivBuff(rtStream_t mainStream);
895 : bool StreamIsCapture(rtStream_t mainStream);
896 : HcclResult AllocAndGetStreamContextBuff(u32 streamId, u64 &addr, u64 &size);
897 : u32 UpdateOpIndex(const OpParam &opParam); // 更新opIndex
898 : HcclResult LoadCustomFile(const char *binPath, aclrtBinaryLoadOptionType optionType, uint32_t cpuKernelMode,
899 : aclrtBinHandle& binHandle);
900 : void UnloadBinary(aclrtBinHandle& binHandle);
901 : bool IsEnableCustom();
902 : void UnloadCustomKernel(void);
903 : HcclResult LoadCustomKernel(void);
904 : HcclResult LoadAICPUKernel(void);
905 : void UnloadAICPUKernel(void);
906 : u32 LargestPowerOfTwoLessThan(const u32 localRankSize);
907 : u32 CalcStreamNumForReduceOrderPreservation();
908 :
909 : HcclResult CheckSetRetryStateToWaitResume();
910 : HcclResult CheckExitWaitResumeState(bool &isChangedLink);
911 :
912 : HcclResult RegisterToSnapshot();
913 : HcclResult UnRegisterFromSnapshot();
914 :
915 : bool EnableAicpuUnfold(bool isCapture = false);
916 :
917 : // reduce类算子的prod操作或者int64数据类型不支持重执行
918 : bool IsReduceWithInt64OrProd(HcclCMDType opType, const OpParam &opParam) const;
919 : // 控制当前通信域首次检测到reduce类算子的prod操作或者int64数据类型时打印不能重执行的约束
920 : bool needWarnAboutReduceProdInt64_{true};
921 :
922 : bool isOnlyAiv_{false};
923 : HcclIpAddress loopBackIp_;
924 : bool profilingInitiated_;
925 : u64 callbackThreadId_;
926 : u32 role_;
927 : std::map<u64, std::vector<rtStream_t>> callbackStreamMap_;
928 : bool isHostUseDevNic_;
929 : std::mutex socketListenMutex_;
930 :
931 : std::unique_ptr<HcclAlg> implAlg_ = nullptr;
932 : HcclCommunicatorAttrs attrCollector_;
933 :
934 : u32 deviceNumPerAggregation_;
935 : std::vector<u32> nicList_;
936 : std::unordered_map<u32, u32> pairLinkCounter_; // server内所有device间的链路类型计数
937 : bool isAllRankSamePlane_;
938 : std::unique_ptr<TopoInfoParse> topoInfoParse_; // 对rank table device选取的校验模块
939 : u32 serverNum_;
940 : u32 moduleNum_;
941 : u32 superPodNum_ = 0;
942 : bool isAlgoLevel1Default_ = false;
943 : std::shared_ptr<HostMem> combinOparaMem_ = nullptr;
944 : Stream opStream_;
945 : Stream aicpuInitStream_;
946 : std::vector<Stream> attachedStreams_;
947 : std::vector<std::shared_ptr<LocalNotify>> localAiCpuNotifyRes_;
948 : std::shared_ptr<LocalNotify> localAiCpuOpNotify_[AICPU_LOCAL_NOTIFY_SIZE] = { nullptr };
949 : HcclRtEvent localAicpuOpEvent_[AICPU_LOCAL_EVENT_SIZE] = { nullptr }; // 用于控制Aclgraph模式按序下发控制流入图的event
950 : u32 workSpaceSize_;
951 : DeviceMem workSpace_;
952 : DeviceMem mc2DeviceMem_;
953 : std::vector<DeviceMem> extraMem_;
954 : #ifndef CCL_KERNEL_AICPU
955 : // aclgraph 销毁时投递 HcclKfcClearOpResTilingData 的 HBM buffer,lazy alloc,RAII 析构
956 : DeviceMem aicpuCleanupBuf_;
957 : // host 侧 payload buffer(heap 持有),避免 ~2.5MB 结构体在栈上 value-init 爆栈
958 : std::unique_ptr<HcclKfcClearOpResTilingData> aicpuCleanupHostBuf_;
959 : #endif
960 : std::vector<HcclRtEvent> aiCpuNoIpcEvnet_;
961 : bool isDiffDeviceModule_;
962 : bool isDiffDeviceType_;
963 : bool isARSDoubleRing_;
964 : u32 gcdDeviceNumPerAggregation_;
965 : tagCommInfo_t tagCommInfo_; // 以tag为粒度分配comm实例和资源
966 : std::mutex commLock_;
967 : tagStreamInfo_t tagStreamInfo_;
968 : std::mutex tagStreamInfoLock_;
969 :
970 : std::vector<Stream> auxRingCommStreamsDev_;
971 : bool isServerInter_{ false };
972 : bool isSupportRdmaLite_{ false }; // 是否支持RDMA Lite
973 : bool isSupportHccsAndSio_{ false }; // 是否支持hccs sio并发
974 :
975 : HcclIpAddress localVnicIp_;
976 : u32 localVnicListenPort_;
977 : std::map<HcclIpAddress, HcclNetDevCtx> netDevCtxMap_;
978 :
979 : std::unique_ptr<OpBaseStreamManager> opStreamManager_ = { nullptr };
980 : std::unique_ptr<QueueNotifyManager> queueNotifyManager_ = { nullptr };
981 : std::unique_ptr<QueueNotifyManager> queueNotifyManagerRefac_ = { nullptr };
982 : std::unique_ptr<HcclSocketManager> socketManager_;
983 : std::unique_ptr<TransportManager> transportManager_ = { nullptr };
984 : std::unique_ptr<TransportManager> indptOpTransportManager_ = { nullptr };
985 :
986 : std::unique_ptr<ZeroCopyMemoryAgent> zeroCopyMemoryAgent_ = { nullptr };
987 :
988 : std::unordered_map<std::string, AlgResourceResponse> resMap_; // tag : AlgResourceResponse
989 : std::unordered_set<std::string> hostResMap_;
990 : std::unordered_set<std::string> hbSendRecvTags_;
991 : std::vector<DeviceMem> deviceResOrigMem_;
992 : bool isSuspending = false;
993 : bool retryEnable_ = false;
994 : bool rtsSupportChangeLink_ = true; // RTS是否支持借轨(部分ASCEND_RT_VISIBLE_DEVICES自定义场景不支持访问同chip内的另一个die)
995 : bool inplaceSupportRetry_ = false; //inplace是否支持重执行
996 : u8 isInplaceStatus_ = 0; // 算子是不是inplace的状态
997 : // 算子在inplace时,是否支持重执行的状态
998 : InplaceSupportRetryStatus inPlaceSupportRetryStatus_ = InplaceSupportRetryStatus::INPLACE_STATUS_END;
999 : bool isInplacePreSync_ = false;
1000 : bool isPostSync_ = false;
1001 : HcclWorkflowMode retryOrigWorkflowMode_ = HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED;
1002 : HcclOpResParam opResPara_{};
1003 : DeviceMem opResDevicePara_;
1004 : HcclOpResParam *opResDeviceParaPtr_;
1005 : Stream opMainStream_;
1006 : Stream aicpuOrderStream_;
1007 : bool isContextLaunched_{false};
1008 : std::vector<std::shared_ptr<DeviceMem>> deviceMemVec_;
1009 : std::vector<std::shared_ptr<HostMem>> hostMemVec_;
1010 : DeviceMem nicListDevice_;
1011 : DeviceMem complanRankDevice_;
1012 : DeviceMem pairLinkCounterDevice_;
1013 : DeviceMem isUsedRdmaRankPairDevice_;
1014 : std::unordered_set<std::string> newTagResAlloced_;
1015 : DeviceMem bridgeRankDevice_;
1016 : DeviceMem serverAndsuperPodToRankDevice_;
1017 : DeviceMem commplaneSubGroupRankDevice_;
1018 : DeviceMem hierarchicalAlgOptionDevice_;
1019 :
1020 : // aicpu-custom共享内存区
1021 : std::unordered_map<u32, DeviceMem> streamIdToStreamContext_;
1022 : DeviceMem aicpuCustomDev_; // aicpu-custom共享内存区,对应AicpuCustomParam结构体
1023 :
1024 : std::unordered_map<s32, u32> opIndexMap_; // 记录aicpu/custom的算子计数, key值用来区分, bsr: -1, sendrecv: 对端rank, 其他算子: 本端rank
1025 :
1026 : std::unique_ptr<IHcclOneSidedService> oneSideService_ = {nullptr};
1027 : HcclIpAddress onesidedServiceNicIpAddr_;
1028 : HcclRankLinkInfo hcclRankLinkInfo_{};
1029 : std::atomic<bool> isOneSidedServiceNetDevCtxInited{false};
1030 : std::atomic<bool> isOneSidedServiceNicInited{false};
1031 : std::atomic<bool> isOneSidedServiceNicStartListen_{false};
1032 :
1033 : std::unique_ptr<OpRetryManager> opRetryManager_ = { nullptr };
1034 : std::shared_ptr<HcclOpStreamRes> opRetryStreamPtr_;
1035 : std::unordered_set<u64> captureModelIds_;
1036 :
1037 : std::unordered_map<u32, std::unordered_map<std::string, HccltagRemoteResV3>> rankTagRemoteRes_; // 以rankid&tag粒度保存HccltagRemoteResV3
1038 : // aicpu进程使用的host-device共享内存
1039 : std::shared_ptr<HDCommunicate> kfcControlTransferH2D_;
1040 : std::shared_ptr<HDCommunicate> kfcStatusTransferD2H_;
1041 : // custom进程使用的host-device共享内存
1042 : std::shared_ptr<HDCommunicate> customControlTransferH2D_;
1043 : std::shared_ptr<HDCommunicate> customStatusTransferD2H_;
1044 :
1045 : HcclCommConnections commConnections_;
1046 : HcclSocketPortConfig commPortConfig_;
1047 : std::shared_ptr<PetersonLock> hostDeviceLock_;
1048 : bool isNsRecovery_{false};
1049 : bool isAicpuCommEngine_{false};
1050 : bool isAicpuUnfold_{false};
1051 : HostMem opTilingDataBuf_;
1052 : HostMem apiTilingDataMem_;
1053 : DeviceMem tilingDataMemDevice_;
1054 : // 单机场景下多卡间能互相访问的共享buffer,除了自己rank是申请的,其余均是Ipc打开的
1055 : DeviceMem zeroCopyLocalBuffer_;
1056 : void *zeroCopyIpcPtrs_[AICPU_ZERO_COPY_MAX_DEVICE_NUM_A3] {};
1057 : std::atomic<HcclCommState> state_{HcclCommState::IDLE};
1058 : std::unordered_map<std::string, std::string> newTagToTagMap_;
1059 : // zerocopy hex prefix tag + cnt 副本 _CaptureN tag,跨 iter 累积新 entry
1060 : std::unordered_set<std::string> tagsRequiringHostCleanup_;
1061 : // 保护 rankTagRemoteRes_ / hostMemVec_ / deviceMemVec_ / tagsRequiringHostCleanup_ /
1062 : // ibverbsLocalNotify_ / ibverbsRemoteNotify_ / resMap_ 的并发访问
1063 : std::mutex commResMutex_;
1064 : static std::mutex linkResMapMutex_;
1065 : static std::unordered_map<Transport*, LinkInfo> linkResMap_;
1066 : std::shared_ptr<HostMem> transDevIbverbsDataMem_ = nullptr;
1067 : bool isA2MC2MultiServer_{false};
1068 : bool isA2MC2IntraHie_{false};
1069 : DeviceMem ibverbsDataBuffer_;
1070 : std::unordered_map<std::string, std::list<DeviceMem>> ibverbsLocalNotify_;
1071 : std::unordered_map<std::string, std::list<DeviceMem>> ibverbsRemoteNotify_;
1072 :
1073 : // 按序下发notify的工作区
1074 : DeviceMem aicpuOrderNotifyAddr_;
1075 : u32 graphId_;
1076 :
1077 : // alltoallv
1078 : HostMem hostCollectBuffer_;
1079 :
1080 : // batchsendrecv
1081 : std::set<u32> ranksLinked_{};
1082 :
1083 : // AIV通信同步标识
1084 : s32 aivOpbaseTag_ = 1; // 动态图或者单算子非Capture模式的tag
1085 : s32 aivOffloadTag_ = 1; // 静态图或者Capture模式的tag
1086 : std::vector<DeviceMem> aivOffloadCommInfoMem_; // 图模式每个算子单独一块内存维护通信域信息
1087 :
1088 : // Host侧收集的数据
1089 : std::shared_ptr<HostMem> aiRMAInfoMem_ = nullptr;
1090 : std::shared_ptr<HostMem> rmaInfoMem_ = nullptr; // for aiv
1091 : std::shared_ptr<HostMem> aiSqMem_ = nullptr;
1092 : std::shared_ptr<HostMem> aiScqMem_ = nullptr;
1093 : std::shared_ptr<HostMem> aiRqMem_ = nullptr;
1094 : std::shared_ptr<HostMem> aiRcqMem_ = nullptr;
1095 : std::shared_ptr<HostMem> aiMemMem_ = nullptr;
1096 : std::shared_ptr<HostMem> aiMemDetailsMem_ = nullptr;
1097 :
1098 : // Host侧同步到Device的内存空间
1099 : DeviceMem aiRMAInfoDev_;
1100 : DeviceMem aiSqDev_;
1101 : DeviceMem aiScqDev_;
1102 : DeviceMem aiRqDev_;
1103 : DeviceMem aiRcqDev_;
1104 : DeviceMem aiMemDev_;
1105 : DeviceMem aiMemDetailsDev_;
1106 :
1107 : // 通信能力支持信息,提供给融合算子获取
1108 : std::shared_ptr<HostMem> combinedCapabilityMem_ = nullptr;
1109 : DeviceMem combinedCapabilityBuffer_;
1110 :
1111 : aclrtBinHandle binHandle_ = nullptr;
1112 : aclrtBinHandle binCustomHandle_ = nullptr;
1113 :
1114 : std::unique_ptr<ZeroCopyAclGraph> zeroCopyAclGraph_;
1115 :
1116 : u32 switchRanksNum_{ 0 };
1117 : u32 switchRankList_[AICPU_MAX_RANK_NUM] {};
1118 : bool switchUseBackup_[AICPU_MAX_RANK_NUM] {};
1119 : u8 remoteRankNicStatus_[AICPU_MAX_RANK_NUM] {};
1120 : bool needCheckDefaultNic_ { false };
1121 : bool needCheckBackupNic_ { false };
1122 : bool switchNicWaitingResult_ { false };
1123 : u32 captureCnt_ = 0;
1124 : bool isUserMemRegisted_ { false }; // 是否已注册user Mem,与ccl buffer互斥
1125 : std::unordered_map<void*, std::shared_ptr<DeviceMem>> userMemMap_; // key: window handle, value: window ptr
1126 : OpCommTransport userMemTransport_;
1127 : std::vector<LINK> channelLinks_{};
1128 :
1129 : void *p2pCclBuf_[AICPU_MAX_RANK_NUM]{};
1130 : void *cclBuf_[AICPU_MAX_RANK_NUM]{};
1131 : std::map<u32, TransportType> remoteTransportMap_;
1132 : uint32_t netLayer_[COMM_LAYER_NUM_MAX]{};
1133 : #ifndef CCL_KERNEL_AICPU
1134 : RankGraphV1 rankGraph_;
1135 : std::unique_ptr<DpuManager> dpuManager_;
1136 : #endif
1137 : uint32_t myRankConnectMode_{0}; // 0: normal mode 1: host nic对接device nic异构模式
1138 :
1139 : // for group
1140 : bool isGroupMode_ {false};
1141 :
1142 : // 独立算子
1143 : std::vector<std::shared_ptr<DeviceMem>> channelRemoteParamMem_;
1144 : CommConfig commConfig_;
1145 : std::function<bool()> getAicpuCommState_; // 获取自定义算子aicpu通信域是否初始化
1146 : bool isInvalidComm_ { false };
1147 : std::function<HcclResult()> releaseChannel_ = nullptr;
1148 :
1149 : u32 hcclQos_ = EnvConfig::HCCL_QOS_DEFAULT;
1150 : u32 rankInParentComm_{0}; // 父通信域中的rank ID (MC2场景使用)
1151 : std::shared_ptr<SymmetricMemoryAgent> symmetricMemoryAgent_;
1152 : std::unique_ptr<SymmetricMemory> symmetricMemory_;
1153 : };
1154 : } // end namespace hccl
1155 : #endif // HCCL_IMPL_BASE_H
|