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