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 : void EraseCaptureModelId(u64 modelId);
527 :
528 : private:
529 : bool IsEnableRoce();
530 : bool IsEnableBackupLink();
531 : HcclResult CheckOneSidedBackupAndSetDevId(
532 : u32& backupDevPhyId, u32& backupDevLogicId, std::vector<HcclIpAddress>& localIpList,
533 : bool& isOneSidedTaskAndBackupInitA3);
534 : HcclResult OneSidedBackupInitNetResource(
535 : HcclNetDevCtx& nicPortBackUpCtx, u32& backupDevPhyId, u32& backupDevLogicId,
536 : std::vector<HcclIpAddress>& localIpList);
537 : HcclResult OneSidedBackupServerInit(HcclNetDevCtx& nicPortBackUpCtx);
538 : void SetAttrs();
539 : u32 HcclGetCmdTimeout();
540 : HcclResult InitCommParams(HcclCommParams& params);
541 : HcclResult InitRankInfo(const RankTable_t& rankTable);
542 : HcclResult InitRankInfoSubGroup(WorldGroupInfo& groupCommonData);
543 : HcclResult CheckSingleServerComm(const std::vector<RankInfo_t>& rankList) const;
544 : HcclResult SetRanksPort(const std::vector<RankInfo_t>& rankList);
545 : HcclResult InitNetResource(const RankTable_t& rankTable);
546 : HcclResult InitDebug();
547 : HcclResult InitDebugSubGroup();
548 : HcclResult InitATraceInfo();
549 : HcclResult InitNotifyManager();
550 : HcclResult InitDispatcher();
551 : HcclResult InitStreamManager();
552 : HcclResult InitSocketManager();
553 : HcclResult InitTransportManager();
554 : HcclResult InitHcclAlg();
555 : HcclResult InitAlgResource();
556 : HcclResult InitProfiling();
557 : HcclResult DeinitProfiling();
558 : HcclResult InitProfiler();
559 : HcclResult InitOneSidedService(const RankTable_t& rankTable);
560 :
561 : HcclResult RegistTaskExceptionHandler() const;
562 : HcclResult UnRegistTaskExceptionHandler() const;
563 : HcclResult UnRegisterBackGroundThread();
564 : HcclResult
565 : UnRegisterBackGroundThread(std::shared_ptr<HDCommunicate>& controlH2D, std::shared_ptr<HDCommunicate>& statusD2H);
566 : HcclResult DestroyAicpuComm();
567 : HcclResult DestroyAicpuComm(std::shared_ptr<HDCommunicate>& controlH2D, std::shared_ptr<HDCommunicate>& statusD2H);
568 : HcclResult InitPreResource(const RankTable_t& rankTable);
569 : HcclResult InitTcpMode(const RankTable_t& rankTable) const;
570 : HcclResult InitRaResource();
571 : HcclResult InitRaNetResource();
572 : HcclResult InitRaNic();
573 : HcclResult InitDevicePrimaryNic(bool isMC2ReInit, bool isOneSidedTaskAndBackupInitA3);
574 : HcclResult InitDeviceBackupNic(
575 : u32 backupDevPhyId, u32 backupDevLogicId, std::vector<HcclIpAddress>& localIpList,
576 : bool isOneSidedTaskAndBackupInitA3);
577 : HcclResult InitNicDeviceDeploy(
578 : bool isMC2ReInit, u32 backupDevPhyId, u32 backupDevLogicId, std::vector<HcclIpAddress>& localIpList,
579 : bool isOneSidedTaskAndBackupInitA3);
580 : HcclResult InitNicHostDeploy();
581 : bool IsNeedNicInit();
582 : HcclResult InitNic(bool isMC2ReInit = false);
583 : HcclResult DeinitNic();
584 : HcclResult DeinitNicHostDeploy();
585 : HcclResult AddOpInfoToHeartBeat(const OpInfoDesc& opInfo, const std::string& tag);
586 : void DeleteOpInfoToHeartBeat();
587 : HcclResult RegisterToHeartBeat();
588 : HcclResult RegisterToHeartBeat(u32 peerRankId, std::string& tag);
589 : void UnRegisterToHeartBeat();
590 : void UnRegisterToCommConfiger();
591 : HcclResult PrintOpbaseKeyTraceInfo(void);
592 : HcclResult InitPara();
593 : HcclResult GetComm(const std::string& tag, CommBase** comm);
594 : HcclResult Mc2CreateAndLaunchContext(
595 : rtStream_t aiCpuStream, bool isOpbaseMode, void** commContext, const std::string& tag = "");
596 : HcclResult SetCommResource(
597 : u64 commBufferSize, void* commInPtr, void* commOutPtr, void* commExpPtr, CommBase* comm,
598 : level1StreamInfo_t& streamInfo, Stream& stream);
599 : HcclResult GetAicpuOpStreamAndNotify(HcclRtStream* opStream, u8 aicpuNotifyNum, void** aicpuNotify);
600 : HcclResult SetAicpuNotifyInvalid();
601 : HcclResult AicpuKfcTilingDataLaunch(
602 : const OpParam& opParam, const HcclCMDType& opType, const DeviceMem& deviceContext,
603 : const std::string& kernelName, const AicpuOpTiling opTilingInfo);
604 : HcclResult AicpuKfcTilingDataLaunchExt(
605 : const OpParam& opParam, const HcclCMDType& opType, const DeviceMem& deviceContext,
606 : const std::string& kernelName, const AicpuOpTiling opTilingInfo, bool isCustom = false);
607 : u64 CalcOpTilingDynamicDataSize(
608 : const OpParam& opParam, const HcclCMDType& opType, const u32& rankSize, const std::string& algName = "");
609 : u64 CalcOpTilingVDataDesVDataLen(const u32 rankSize) const;
610 : HcclResult AicpuInitOpTilingDataFromOpParam(
611 : const OpParam& opParam, const HcclCMDType& opType, struct OpTilingData* opTilingData);
612 : HcclResult AicpuInitOpTilingDataAicpuCache(
613 : const OpParam& opParam, const HcclCMDType& opType, struct OpTilingData* opTilingData);
614 : HcclResult AicpuInitOpTilingDataBuf(
615 : const OpParam& opParam, const HcclCMDType& opType, const std::string& kernelName,
616 : const AicpuOpTiling opTilingInfo, u64 dynamicDataSize);
617 : HcclResult AicpuKfcTilingDataLaunchIn(
618 : const OpParam& opParam, const DeviceMem& deviceContext, const std::string& kernelName,
619 : const AicpuOpTiling opTilingInfo, u64 opTilingDataSize, bool isCustom = false);
620 : HcclResult AllReduceAicpuUnfold(
621 : const std::string& tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op,
622 : HcclRtStream stream);
623 : HcclResult CreateMutiStreamResFor310P(const std::string& tag, level1StreamInfo_t& streamInfo);
624 : HcclResult SetDynamicTilingDataAlltoall(const OpParam& opParam, HostMem& dynamicDataMem);
625 : HcclResult UnRegisterDfxInfo(const OpParam& param, const std::vector<Stream>& slaveStreams);
626 : HcclResult RegisterDfxInfo(
627 : const OpParam& param, AlgType algType, const std::vector<Stream>& slaveStreams, bool isAiv = false,
628 : const std::string& tag = "");
629 : HcclResult AddGroupTagInfo(const std::string& tag, bool isAiv);
630 : HcclResult
631 : SetDynamicTilingDataAlltoallv(const OpParam& opParam, HostMem& dynamicDataMem, const std::string& algName = "");
632 : HcclResult SetDynamicTilingDataAlltoallvc(const OpParam& opParam, HostMem& dynamicDataMem);
633 : HcclResult SetDynamicTilingDataV(const OpParam& opParam, HostMem& dynamicDataMem);
634 : HcclResult GetReportHcclMC2Info(const Stream& kfcStream, const std::vector<Stream>& aicpuStreams);
635 : u8 GetOrderLaunchMode(bool isCapture);
636 :
637 : HcclResult ReAllocTransports(const std::string& tag, const std::string& newTag);
638 : HcclResult SetTransportStatusImpl(
639 : OpCommTransport& opCommTransport, bool statusStop, const HcclOpIdentifier& opId, u32 remoteRank,
640 : const std::map<u32, bool>& remoteRankPortMap, bool isUseDefault);
641 : HcclResult SetBsrTransportStatusImpl(
642 : OpCommTransport& opCommTransport, bool statusStop, const HcclOpIdentifier& opId, u32 remoteRank);
643 : HcclResult SetTransportStatusImplForChange(
644 : OpCommTransport& opCommTransport, const HcclOpIdentifier& opId, u32 remoteRank,
645 : const std::map<u32, bool>& remoteRankPortMap, bool isUseDefault, const std::map<u32, bool>& isChangeLinkMap,
646 : bool isCurTag);
647 : HcclResult SetTransportResumeStatus(
648 : const std::map<u32, bool>& remoteRankPortMap, const std::map<u32, bool>& isChangeLinkMap, bool isChangeLinkFlag,
649 : bool statusStop);
650 : HcclResult ResumeTransportsImplForChange(
651 : OpCommTransport& opCommTransport, const std::map<u32, bool>& remoteRankPortMap,
652 : const std::map<u32, bool>& isChangeLinkMap, bool isUseDefault);
653 : HcclResult ResumeTransportsImpl(
654 : OpCommTransport& opCommTransport, const std::map<u32, bool>& remoteRankPortMap, bool isUseDefault,
655 : bool statusStop);
656 : HcclResult SetBsrTransportStatusImplforchange(
657 : OpCommTransport& opCommTransport, const HcclOpIdentifier& opId, u32 remoteRank,
658 : const std::map<u32, bool>& remoteRankPortMap, bool isUseDefault, const std::map<u32, bool>& isChangeLinkMap,
659 : bool isCurTag);
660 : void ClearOpTransportResponseLinks(OpCommTransport& opTransportResponse);
661 : HcclResult SetSignalTransport(SingleSubCommTransport& singleSubCommTransport, u32 linkIdx, bool statusStop);
662 : void InsertNewTagToTagMap(std::string& newTag, std::string& tag);
663 : HcclResult GetTagFromNewTag(const std::string& newTag, std::string& tag);
664 : HcclResult
665 : ParseSwitchRanks(uint32_t nRanks, uint32_t* ranks, bool* useBackup, std::unordered_map<u32, bool>& switchRanks);
666 : HcclResult PrepareLinkForSwitchNic(std::unordered_map<u32, bool>& switchRanks, ChangeLinkInfo& changeLinkInfo);
667 : HcclResult SetRemoteRankLinkInfo(std::unordered_map<u32, bool>& switchRanks, ChangeLinkInfo& changeLinkInfo);
668 : HcclResult
669 : SetSingleLinkInfo(std::unordered_map<u32, bool>& switchRanks, u32 remoteRankId, ChangeLinkInfo& changeLinkInfo);
670 : HcclResult
671 : ActiveStoppedLink(std::map<u32, bool>& remoteRankPortMap, OpCommTransport& opTransportResponse, bool isBackup);
672 : HcclResult setVnicIpToRankInfoList();
673 : HcclResult GetRemoteUserMemResource();
674 :
675 : HcclResult Suspend(std::shared_ptr<HDCommunicate>& controlH2D, std::shared_ptr<HDCommunicate>& statusD2H);
676 : HcclResult StopExec(std::shared_ptr<HDCommunicate>& controlH2D, std::shared_ptr<HDCommunicate>& statusD2H);
677 : HcclResult Clean(std::shared_ptr<HDCommunicate>& controlH2D, std::shared_ptr<HDCommunicate>& statusD2H);
678 : HcclResult SwitchNic(
679 : uint32_t nRanks, uint32_t* ranks, bool* useBackup, std::shared_ptr<HDCommunicate>& controlH2D,
680 : std::shared_ptr<HDCommunicate>& statusD2H);
681 : HcclResult SaveRankInfoHasLinked(const AlgResourceRequest& resRequest);
682 : HcclResult RecordOpPara(HcclCMDType opType, const OpParam& opParam);
683 : HcclResult SaveTopoDesc(std::string& identifier);
684 :
685 : HcclResult SetAicpuUnfoldFlag();
686 : bool GetAicpuUnfoldFlag();
687 :
688 : HcclResult ReAllocScratchMemForAlltoall(
689 : HcclCMDType opType, const OpParam& opParam, AlgResourceRequest& resRequest,
690 : AlgResourceResponse& algResResponse);
691 :
692 : HcclResult HandleExistAlgResource(
693 : const std::string& newTag, const std::string& algName, HcclCMDType opType, const OpParam& opParam,
694 : std::unique_ptr<CollAlgOperator>& algOperator, bool selectAivAlg, bool aicpuUnfoldModeFor910B,
695 : bool needRecreateAlltoallComm);
696 : u32 deviceNumPerServer_;
697 : HcclDispatcher dispatcher_; // dispatcher放到最后析构
698 : DispatcherCtxPtr dispatcherCtx_{nullptr};
699 : HcclDispatcher vDispatcher_; // virtualDispatcher放到最后析构
700 : std::unique_ptr<NotifyPool> notifyPool_;
701 : std::unique_ptr<HcclCallbackTask> callbackTask_;
702 : std::atomic_flag initializedFlag_;
703 : u32 userRank_; // 本group中的userrank
704 : u32 realUserRank_; // world group中的userrank
705 : u32 userRankSize_;
706 : std::vector<RankInfo> rankInfoList_; // world group内rank的信息, 按照rank id递增依次排列
707 : std::vector<RankInfo> rankInfoListIntraServer_; // 节点内rank信息,用于零拷贝
708 : bool drvInit_; // ra是否初始化
709 : ServRankInfo_t servRankInfo_;
710 : std::string serverId_;
711 : std::unordered_map<u32, std::unordered_map<int, std::vector<int>>> pairLinkInfo_; // server内所有device间的链路类型
712 : bool inlineReduceSwitchOn_;
713 : NICDeployment nicDeployment_;
714 : u32 devicePhyId_;
715 : u32 deviceBackUpPhyId_;
716 : s32 deviceLogicId_;
717 : u32 deviceBackUpLogicId_;
718 : std::unordered_set<s32> aicpuStreamIds_;
719 : std::vector<HcclIpAddress> devIpAddr_;
720 : std::vector<HcclIpAddress> devBackupIpAddr_;
721 : u32 devBackupPort_{HCCL_INVALID_PORT};
722 : HcclIpAddress hostIp_;
723 : HcclIpAddress deviceVnicIp_;
724 : u32 hostPort_{HCCL_INVALID_PORT};
725 : u32 localRank_;
726 : SocketHandle hostSocketHandle_;
727 : SocketHandle loopbackHeterogSocketHandle_;
728 : bool isUsedRdmaLevel0_; // 节点内是否使用rdma, 包括a+x和标卡
729 : std::atomic<s32> nicInitialized_;
730 : bool hcomGroupNicInit_;
731 : // profiling 相关资源
732 : HcomProfilingMode profilingMode_;
733 : std::string profilingOption_;
734 : ProfilingDeviceCommResInfo hcclMc2Info_;
735 : bool raResourceInit_;
736 : bool interServer_;
737 : std::unique_ptr<WorkspaceResource> workSpaceRes_;
738 : std::vector<u32> enableP2PDevices_;
739 : std::unordered_set<u32> enableP2PRankIds_;
740 : bool isSingleMeshAggregation_;
741 : CCLBufferManager cclBufferManager_;
742 : bool isExecuteProfilingInit_;
743 : DevType deviceType_;
744 : std::string collectiveId_;
745 : HcclComm commHandle_;
746 : std::vector<u32> nicRanksPort_;
747 : std::vector<u32> groupNicRanksPort_;
748 : std::vector<u32> vnicRanksPort_;
749 : std::vector<u32> groupVnicRanksPort_;
750 : std::unordered_map<std::string, std::map<u32, HcclIpAddress>> rankDevicePhyIdNicInfoMap_;
751 : std::unordered_map<u32, HcclRtContext> rtCtxMap_; // {devPhyId, rtCtx}
752 : WorkMode commWorkMode_;
753 : u32 meshAggregationRankSize_;
754 : std::map<HcomOperationType, std::string> opTypeTagMap_;
755 : bool isHaveCpuRank_;
756 : bool isUseRankPort_{true};
757 : bool isSetHDCModeInfo_{false};
758 : std::map<std::string, HostMem> tagWorkSpaceMem_;
759 : std::string identifier_;
760 : u32 ranktableCrc_;
761 : s32 devicePid_;
762 : bool multiModuleDiffDeviceNumMode_;
763 : bool multiSuperPodDiffServerNumMode_;
764 : bool multiSuperPodDiffDeviceNumMode_;
765 : DeviceMem commContext_;
766 : std::shared_ptr<ProfilerManager> profilerManager_;
767 : bool isStandardCard_ = false;
768 : bool is310PDuoCard_ = false;
769 : bool isCommon310P3DUO_ = false;
770 : s32 hccsPortNum_ = -1;
771 : std::string superPodId_;
772 : u32 superDeviceId_ = INVALID_UINT;
773 : bool useSuperPodMode_ = false;
774 : bool isUsedInterHccsMode_ = false;
775 : bool isNeedInitNic_ = false;
776 : std::vector<RankInfo> worldRankInfoList_;
777 : std::unique_ptr<HcclTraceInfo> opBaseAtraceInfo_;
778 : bool aivClearEnable_ = false;
779 : u32 numBlocks_ = 0;
780 : std::map<OpParam, HcclCacheInfo> hcclCacheMap_; // 存储aiv cache信息
781 : std::string cclBuffName_;
782 : bool isShareComm_ = false; // 是否共享cclbuffer
783 : private:
784 : bool IsAtomicInit();
785 : HcclResult MigrateLinkToStopOrResume(LINK& link, bool isStop);
786 : HcclResult MigrateLinkVectorToStopOrResume(const std::vector<LINK>& links, bool isStop);
787 : HcclResult TraverseLinkVector(std::vector<std::unique_ptr<CommBase>>& commBaseVector, bool isStop);
788 : HcclResult CheckSuspendingStatus();
789 : HcclResult InitCombinOpara();
790 : HcclResult RegisterRanksToDca();
791 : HcclResult InitWorkSpace();
792 : void ReleaseWorkSpacebuffer();
793 : HcclResult CreateWorkSpace(u64 size, DeviceMem& buffer) const;
794 : HcclResult GetWorkSpace(u64* workSpaceSize, u64* workSpace) const;
795 : void ReleaseCommContextbuffer();
796 : HcclResult CreateDeviceCommContext(u64 size, DeviceMem& buffer) const;
797 : HcclResult CreateAndGetAiCpuNotify(std::shared_ptr<LocalNotify>& localNotify, HcclSignalInfo& notifyInfo);
798 : HcclResult GetAiCpuNotifyData(const std::shared_ptr<LocalNotify>& localNotify, HcclSignalInfo& notifyInfo);
799 : HcclResult ReplaceCommInfoByTag(const std::string& tag, std::unique_ptr<CommInfo>& commInfo);
800 : HcclResult CreateCommAndStreamRes(const std::string& tag, Stream& stream);
801 : HcclResult SetInfoToDevice(const std::unique_ptr<PreProcessMetaInfo>& preMetaInfo, Stream& stream);
802 : HcclResult GetInfoFromDevice(
803 : const std::unique_ptr<PreProcessMetaInfo>& preMetaInfo, const HcclWorkflowMode& mode,
804 : HostMem& hostCollectBuffer);
805 : HcclResult RegressCalPreOp(
806 : AlltoAllOperator*& alltoAllOperator, const OpParam& opParam, std::unique_ptr<PreProcessMetaInfo>& preMetaInfo);
807 : HcclResult RegressCalPreOp(
808 : AlltoAllOperator*& alltoAllOperator, const OpParam& opParam, std::unique_ptr<PreProcessMetaInfo>& preMetaInfo,
809 : Stream& preProcessStream);
810 : DevType NslbGetDeviceType();
811 : u32 NslbGetServerNum();
812 : HcclResult NslbDp_CollectOperTable(HcclCMDType opType, OpParam& opParam, AlgType nslbAlgType, std::string& algName);
813 : HcclResult
814 : NslbDp_CollectSendAdjTable(HcclCMDType opType, OpParam& opParam, AlgType nslbAlgType, AdjInfo& nslbAdjInfo);
815 : HcclResult ExecOp(HcclCMDType opType, OpParam& opParam, bool isCustom = false);
816 : // alltoall专用
817 : HcclResult ExecOpAlltoAll(HcclCMDType opType, OpParam& opParam, bool isCustom = false);
818 : HcclResult FreeScratchMemOnOpBaseMode(DeviceMem& scratchMem, const OpParam& opParam, const HcclCMDType& opType);
819 : HcclResult
820 : CalcTinySendRecvMem(const OpParam& opParam, AlgResourceResponse& algResResponse, DeviceMem& tinySendRecvMem);
821 : bool IsForceAicpuOpBaseMode(const OpParam& opParam, const HcclCMDType& opType);
822 : HcclResult AllocOpBaseModeScratchMem(
823 : HcclCMDType opType, const OpParam& opParam, AlgResourceRequest& resRequest,
824 : AlgResourceResponse& algResResponse);
825 : HcclResult AllocAlgResource(
826 : const std::string& newTag, HcclCMDType opType, const OpParam& opParam, AlgResourceRequest& resRequest,
827 : AlgResourceResponse& algResResponse, bool selectAivAlg = false);
828 : HcclResult IncreAllocLink(
829 : const std::string& newTag, const OpParam& opParam, AlgResourceRequest& resRequest,
830 : AlgResourceResponse& algResResponse);
831 : bool HasRoceTransportLinks(OpCommTransport& opTransportReq);
832 : HcclResult CleanTransportLinks(OpCommTransport& opTransportReq, OpCommTransport& opTransportResponse);
833 : DeviceMem GetWorkspaceScracthMem(const std::string& tag, u64 allocMemSize);
834 : std::vector<Stream> GetWorkspaceSubStreams(const std::string& tag, u32 num);
835 : // HcclImplBase中Comm资源是否存在
836 8 : inline bool IsExistCommRes(const std::string& tag)
837 : {
838 8 : std::unique_lock<std::mutex> commLock(commLock_);
839 16 : return (tagCommInfo_.find(tag) != tagCommInfo_.end());
840 8 : }
841 : // HcclImplBase中MutiStream资源是否存在
842 1 : inline bool IsExistMutiStreamRes(const std::string& tag)
843 : {
844 1 : std::unique_lock<std::mutex> mutiStreamLock(tagStreamInfoLock_);
845 2 : return (tagStreamInfo_.find(tag) != tagStreamInfo_.end());
846 1 : }
847 : void GetAndSetSyncMode(SyncMode& preSyncMode, SyncMode newSyncMode);
848 : void RestorePreSyncMode(SyncMode preSyncMode, SyncMode newSyncMode);
849 : HcclResult AicpuUnfold(
850 : const std::string& tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op,
851 : HcclRtStream stream, HcclCMDType cmdType);
852 : u32 GetHostPort(s32 devicePhyId);
853 : u32 GetLocalNicPort(NicType nicType);
854 : std::string GetSupportDataType(bool needReduce);
855 : HcclResult InitHDCommunicate();
856 : bool GetSupportHDCommunicate();
857 : HcclResult InitOpRetry();
858 : HcclResult InitOpResPara();
859 : bool IsSupportSymmetricMemory(HcclCMDType opType, OpParam& opParam);
860 : bool IsSupportZeroCopy(const OpParam& opParam);
861 : HcclResult PrepareZeroCopy(const std::string& algName, const AlgDesc& algDesc, OpParam& opParam);
862 : HcclResult UpdateZeroCopy(const OpParam& opParam, const AlgResourceResponse& algResource);
863 : HcclResult BuildZeroCopyParam();
864 : HcclResult AllocAndClearHostMem(u64 size, std::shared_ptr<HostMem>& bufferPtr) const;
865 : HcclResult AllocAndClearDeviceMem(u64 size, std::shared_ptr<DeviceMem>& bufferPtr) const;
866 : HcclResult updateList() const;
867 : HcclResult BuildOpLocalResParam(const AlgResourceResponse& algResource, const std::string& newTag);
868 : HcclResult BuildOpLocalScratchMemResParam(
869 : const AlgResourceResponse& algResource, const std::string& newTag, LocalResInfoV2* localResHostPtr);
870 : HcclResult BuildOpTopoResTlvParam(
871 : const std::string& algName, const std::vector<std::vector<std::vector<u32>>>& inputVectorInfo,
872 : DeviceMem& dstTlvDeviceMem, u64& tlvLen);
873 : HcclResult BuildOpTopoResVectorTlvParam(
874 : const std::string& algName, const std::vector<std::vector<std::vector<std::vector<u32>>>>& inputVectorInfo,
875 : DeviceMem& dstTlvDeviceMem, u64& tlvLen);
876 : HcclResult BuildPairLinkCounter(const std::string& algName);
877 : HcclResult BuildIsUsedRdmaRank(const std::string& algName);
878 : HcclResult BuildNicList(const std::string& algName);
879 : HcclResult BuildBridgeRank(const std::string& algName);
880 : HcclResult BuildCommPlanRank(const std::string& algName);
881 : HcclResult BuildServerAndsuperPodRank(const std::string& algName);
882 : HcclResult BuildCommPlaneSubGroupRank(const std::string& algName);
883 : HcclResult BuildHierarchicalAlgOption(u32* ahcConfInfo);
884 : HcclResult BuildOpTopoResParam(const std::string& algName, const AlgResourceResponse& algResource);
885 : HcclResult BuildAicpuCustomParam();
886 : HcclResult BuildAicpuOrderLaunchNotify();
887 : HcclResult BuildOpRemoteResParam(
888 : const AlgResourceResponse& algResource, const std::string& newTag, const HcclCMDType opType,
889 : bool isRetry = false);
890 : HcclResult BuildOpResParam(
891 : const std::string& algName, const AlgResourceResponse& algResource, const std::string& newTag,
892 : const HcclCMDType opType, const rtStream_t aicpuStream);
893 : HcclResult BuildCustomOpResParam();
894 : HcclResult BuildOpRetryParam(const AlgResourceResponse& algResource, const std::string& newTag);
895 : HcclResult CopyHostListResToDeviceParam(const std::string& newTag, const ListCommon* headHostList, const u64 size);
896 : HcclResult
897 : CopyHostAirmaInfoToDeviceParam(const std::string& newTag, const HcclCMDType opType, const rtStream_t aiCpuStream);
898 : HcclResult CopyHostOpRemoteResToDeviceParam(const std::string& newTag);
899 : HcclResult CopyHostOpResToDeviceParam(const std::string& newTag);
900 : HcclResult AicpuResourceInit(
901 : const std::string& algName, const AlgResourceResponse& algResource, const std::string& newTag,
902 : const rtStream_t& aicpuStream, const HcclCMDType opType, bool isCustom = false);
903 : HcclResult
904 : AicpuResourceRefresh(const AlgResourceResponse& algResource, const std::string& newTag, const HcclCMDType opType);
905 : HcclResult OrchestrateAicpu(
906 : const HcclCMDType& opType, const std::string& algName, const OpParam& param,
907 : const AlgResourceResponse& algResource, const std::string& newTag, AlgType algType, bool isCustom = false,
908 : bool needIncreLink = false, bool needRecreateAlltoallComm = false);
909 : template <typename T>
910 : HcclResult CopyVectorToDeviceMem(const u64 len, DeviceMem& dstDeviceMem, const std::vector<T>& srcVec);
911 : template <typename T>
912 : HcclResult CreateListNode(T** resHostPtr, T** resDevicePtr);
913 : HcclResult ParseRemoteDataToMem(
914 : const OpCommTransport& opTransportResponse, const std::string& newTag, const HcclCMDType opType,
915 : bool isBackup = false, bool isRetry = false);
916 : HcclResult BuildRelationResByRemoteRankId(
917 : const TransportRequest& transportRequest, const LINK& link, HcclRankRelationResV2*& rankRelationResHostPtr,
918 : HcclRankRelationResV2*& rankRelationResDevicePtr);
919 : HcclResult BuildRemoteResByTag(
920 : const std::string& newTag, const u32& usrRankId, HcclRankRelationResV2*& rankRelationResHostPtr,
921 : HcclRankRelationResV2*& rankRelationResDevicePtr, bool isBackup, bool isRetry);
922 : HcclResult BuildOpRemoteLinkP2pResParam(
923 : const LINK& link, HccltagRemoteResV3& tagRemoteRes, TransportLinkType linkType = TransportLinkType::RESERVED);
924 : HcclResult BuildOpRemoteLinkRoceResParam(
925 : const LINK& link, HccltagRemoteResV3& tagRemoteRes, bool isBackup, bool isRetry, bool isSecondBuild);
926 : HcclResult BuildAiRmaInfoParam(const std::string& newTag, const std::string& algName, const HcclCMDType opType);
927 : HcclResult CheckNotifyOrQPMaxNum(u64& existNum, const u64& MaxNum, const bool& isNotifyRes);
928 : HcclResult AllocAlgNotifys(
929 : const std::string& tag, const NotifyLoadType notifyLoadType, const u32 notifyNum,
930 : std::vector<std::shared_ptr<LocalNotify>>& notifiesMain,
931 : std::vector<std::shared_ptr<LocalNotify>>& notifiesAux);
932 : HcclResult CreateAndGetAiCpuNotifyWithNotifyRes(HcclSignalInfo& notifyInfo);
933 : void SaveLinkRes(const OpCommTransport& opTransportResponse);
934 : HcclResult
935 : SetDevIbverbsData(CommBase* comm, bool isSupportNormalQP, u64 commBufferSize, void* commInPtr, void* commOutPtr);
936 :
937 : // 获取 Transport 本端内存信息
938 : HcclResult
939 : GetTransportLocalMem(const std::shared_ptr<Transport>& transport, UserMemType memType, MemDetails& detail);
940 : // 获取 Transport 远端内存信息
941 : HcclResult
942 : GetTransportRemoteMem(const std::shared_ptr<Transport>& transport, UserMemType memType, MemDetails& detail);
943 :
944 : // 收集全部 Transport 内存/QP信息
945 : HcclResult GenAiRMAInfo(CommBase* comm);
946 : HcclResult GenAiRMAInfoV2(const std::string& tag);
947 : // 同步全部信息到Device
948 : HcclResult H2DAiRMAInfo(const std::string& tag, rtStream_t aiCpuStream);
949 : HcclResult H2DAiRMAInfoV2(const std::string& tag, rtStream_t aiCpuStream);
950 : HcclResult GetAIVNormalQPInfo(CommBase* comm, const std::string& tag);
951 : HcclResult GetAIVNormalQPInfoV2(std::vector<LINK>& links, const std::string& tag);
952 : template <typename T>
953 : HcclResult
954 : GenIbvAiRMAInfo(u32 rankid, const std::shared_ptr<Transport>& transport, const std::string& tag, T* aiRMAInfoPtr);
955 : HcclResult GetAivQPInfoV2(std::vector<LINK>& links, const std::string& tag);
956 : HcclResult CaptureSlaveStreams(rtStream_t mainStream, std::vector<Stream>& slaveStreams);
957 : HcclResult HandleAclGraphFirstOpAivBuff(rtStream_t mainStream);
958 : bool StreamIsCapture(rtStream_t mainStream);
959 : HcclResult AllocAndGetStreamContextBuff(u32 streamId, u64& addr, u64& size);
960 : u32 UpdateOpIndex(const OpParam& opParam); // 更新opIndex
961 : HcclResult LoadCustomFile(
962 : const char* binPath, aclrtBinaryLoadOptionType optionType, uint32_t cpuKernelMode, aclrtBinHandle& binHandle);
963 : void UnloadBinary(aclrtBinHandle& binHandle);
964 : bool IsEnableCustom();
965 : void UnloadCustomKernel(void);
966 : HcclResult LoadCustomKernel(void);
967 : HcclResult LoadAICPUKernel(void);
968 : void UnloadAICPUKernel(void);
969 : u32 LargestPowerOfTwoLessThan(const u32 localRankSize);
970 : u32 CalcStreamNumForReduceOrderPreservation();
971 :
972 : HcclResult CheckSetRetryStateToWaitResume();
973 : HcclResult CheckExitWaitResumeState(bool& isChangedLink);
974 :
975 : HcclResult RegisterToSnapshot();
976 : HcclResult UnRegisterFromSnapshot();
977 :
978 : bool EnableAicpuUnfold(bool isCapture = false);
979 :
980 : // reduce类算子的prod操作或者int64数据类型不支持重执行
981 : bool IsReduceWithInt64OrProd(HcclCMDType opType, const OpParam& opParam) const;
982 : // 控制当前通信域首次检测到reduce类算子的prod操作或者int64数据类型时打印不能重执行的约束
983 : bool needWarnAboutReduceProdInt64_{true};
984 :
985 : bool isOnlyAiv_{false};
986 : HcclIpAddress loopBackIp_;
987 : bool profilingInitiated_;
988 : u64 callbackThreadId_;
989 : u32 role_;
990 : std::map<u64, std::vector<rtStream_t>> callbackStreamMap_;
991 : bool isHostUseDevNic_;
992 : std::mutex socketListenMutex_;
993 :
994 : std::unique_ptr<HcclAlg> implAlg_ = nullptr;
995 : HcclCommunicatorAttrs attrCollector_;
996 :
997 : u32 deviceNumPerAggregation_;
998 : std::vector<u32> nicList_;
999 : std::unordered_map<u32, u32> pairLinkCounter_; // server内所有device间的链路类型计数
1000 : bool isAllRankSamePlane_;
1001 : std::unique_ptr<TopoInfoParse> topoInfoParse_; // 对rank table device选取的校验模块
1002 : u32 serverNum_;
1003 : u32 moduleNum_;
1004 : u32 superPodNum_ = 0;
1005 : bool isAlgoLevel1Default_ = false;
1006 : std::shared_ptr<HostMem> combinOparaMem_ = nullptr;
1007 : Stream opStream_;
1008 : Stream aicpuInitStream_;
1009 : std::vector<Stream> attachedStreams_;
1010 : std::vector<std::shared_ptr<LocalNotify>> localAiCpuNotifyRes_;
1011 : std::shared_ptr<LocalNotify> localAiCpuOpNotify_[AICPU_LOCAL_NOTIFY_SIZE] = {nullptr};
1012 : HcclRtEvent localAicpuOpEvent_[AICPU_LOCAL_EVENT_SIZE] = {nullptr}; // 用于控制Aclgraph模式按序下发控制流入图的event
1013 : u32 workSpaceSize_;
1014 : DeviceMem workSpace_;
1015 : DeviceMem mc2DeviceMem_;
1016 : std::vector<DeviceMem> extraMem_;
1017 : #ifndef CCL_KERNEL_AICPU
1018 : // aclgraph 销毁时投递 HcclKfcClearOpResTilingData 的 HBM buffer,lazy alloc,RAII 析构
1019 : DeviceMem aicpuCleanupBuf_;
1020 : // host 侧 payload buffer(heap 持有),避免 ~2.5MB 结构体在栈上 value-init 爆栈
1021 : std::unique_ptr<HcclKfcClearOpResTilingData> aicpuCleanupHostBuf_;
1022 : #endif
1023 : std::vector<HcclRtEvent> aiCpuNoIpcEvnet_;
1024 : bool isDiffDeviceModule_;
1025 : bool isDiffDeviceType_;
1026 : bool isARSDoubleRing_;
1027 : u32 gcdDeviceNumPerAggregation_;
1028 : tagCommInfo_t tagCommInfo_; // 以tag为粒度分配comm实例和资源
1029 : std::mutex commLock_;
1030 : tagStreamInfo_t tagStreamInfo_;
1031 : std::mutex tagStreamInfoLock_;
1032 :
1033 : std::vector<Stream> auxRingCommStreamsDev_;
1034 : bool isServerInter_{false};
1035 : bool isSupportRdmaLite_{false}; // 是否支持RDMA Lite
1036 : bool isSupportHccsAndSio_{false}; // 是否支持hccs sio并发
1037 :
1038 : HcclIpAddress localVnicIp_;
1039 : u32 localVnicListenPort_;
1040 : std::map<HcclIpAddress, HcclNetDevCtx> netDevCtxMap_;
1041 :
1042 : std::unique_ptr<OpBaseStreamManager> opStreamManager_ = {nullptr};
1043 : std::unique_ptr<QueueNotifyManager> queueNotifyManager_ = {nullptr};
1044 : std::unique_ptr<QueueNotifyManager> queueNotifyManagerRefac_ = {nullptr};
1045 : std::unique_ptr<HcclSocketManager> socketManager_;
1046 : std::unique_ptr<TransportManager> transportManager_ = {nullptr};
1047 : std::unique_ptr<TransportManager> indptOpTransportManager_ = {nullptr};
1048 :
1049 : std::unique_ptr<ZeroCopyMemoryAgent> zeroCopyMemoryAgent_ = {nullptr};
1050 :
1051 : std::unordered_map<std::string, AlgResourceResponse> resMap_; // tag : AlgResourceResponse
1052 : std::unordered_set<std::string> hostResMap_;
1053 : std::unordered_set<std::string> hbSendRecvTags_;
1054 : std::vector<DeviceMem> deviceResOrigMem_;
1055 : bool isSuspending = false;
1056 : bool retryEnable_ = false;
1057 : bool rtsSupportChangeLink_
1058 : = true; // RTS是否支持借轨(部分ASCEND_RT_VISIBLE_DEVICES自定义场景不支持访问同chip内的另一个die)
1059 : bool inplaceSupportRetry_ = false; // inplace是否支持重执行
1060 : u8 isInplaceStatus_ = 0; // 算子是不是inplace的状态
1061 : // 算子在inplace时,是否支持重执行的状态
1062 : InplaceSupportRetryStatus inPlaceSupportRetryStatus_ = InplaceSupportRetryStatus::INPLACE_STATUS_END;
1063 : bool isInplacePreSync_ = false;
1064 : bool isPostSync_ = false;
1065 : HcclWorkflowMode retryOrigWorkflowMode_ = HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED;
1066 : HcclOpResParam opResPara_{};
1067 : DeviceMem opResDevicePara_;
1068 : HcclOpResParam* opResDeviceParaPtr_;
1069 : Stream opMainStream_;
1070 : Stream aicpuOrderStream_;
1071 : bool isContextLaunched_{false};
1072 : std::vector<std::shared_ptr<DeviceMem>> deviceMemVec_;
1073 : std::vector<std::shared_ptr<HostMem>> hostMemVec_;
1074 : DeviceMem nicListDevice_;
1075 : DeviceMem complanRankDevice_;
1076 : DeviceMem pairLinkCounterDevice_;
1077 : DeviceMem isUsedRdmaRankPairDevice_;
1078 : std::unordered_set<std::string> newTagResAlloced_;
1079 : DeviceMem bridgeRankDevice_;
1080 : DeviceMem serverAndsuperPodToRankDevice_;
1081 : DeviceMem commplaneSubGroupRankDevice_;
1082 : DeviceMem hierarchicalAlgOptionDevice_;
1083 :
1084 : // aicpu-custom共享内存区
1085 : std::unordered_map<u32, DeviceMem> streamIdToStreamContext_;
1086 : DeviceMem aicpuCustomDev_; // aicpu-custom共享内存区,对应AicpuCustomParam结构体
1087 :
1088 : std::unordered_map<s32, u32>
1089 : opIndexMap_; // 记录aicpu/custom的算子计数, key值用来区分, bsr: -1, sendrecv: 对端rank, 其他算子: 本端rank
1090 :
1091 : std::unique_ptr<IHcclOneSidedService> oneSideService_ = {nullptr};
1092 : HcclIpAddress onesidedServiceNicIpAddr_;
1093 : HcclRankLinkInfo hcclRankLinkInfo_{};
1094 : std::atomic<bool> isOneSidedServiceNetDevCtxInited{false};
1095 : std::atomic<bool> isOneSidedServiceNicInited{false};
1096 : std::atomic<bool> isOneSidedServiceNicStartListen_{false};
1097 :
1098 : std::unique_ptr<OpRetryManager> opRetryManager_ = {nullptr};
1099 : std::shared_ptr<HcclOpStreamRes> opRetryStreamPtr_;
1100 : std::unordered_set<u64> captureModelIds_;
1101 :
1102 : std::unordered_map<u32, std::unordered_map<std::string, HccltagRemoteResV3>>
1103 : rankTagRemoteRes_; // 以rankid&tag粒度保存HccltagRemoteResV3
1104 : // aicpu进程使用的host-device共享内存
1105 : std::shared_ptr<HDCommunicate> kfcControlTransferH2D_;
1106 : std::shared_ptr<HDCommunicate> kfcStatusTransferD2H_;
1107 : // custom进程使用的host-device共享内存
1108 : std::shared_ptr<HDCommunicate> customControlTransferH2D_;
1109 : std::shared_ptr<HDCommunicate> customStatusTransferD2H_;
1110 :
1111 : HcclCommConnections commConnections_;
1112 : HcclSocketPortConfig commPortConfig_;
1113 : std::shared_ptr<PetersonLock> hostDeviceLock_;
1114 : bool isNsRecovery_{false};
1115 : bool isAicpuCommEngine_{false};
1116 : bool isAicpuUnfold_{false};
1117 : HostMem opTilingDataBuf_;
1118 : HostMem apiTilingDataMem_;
1119 : DeviceMem tilingDataMemDevice_;
1120 : // 单机场景下多卡间能互相访问的共享buffer,除了自己rank是申请的,其余均是Ipc打开的
1121 : DeviceMem zeroCopyLocalBuffer_;
1122 : void* zeroCopyIpcPtrs_[AICPU_ZERO_COPY_MAX_DEVICE_NUM_A3]{};
1123 : std::atomic<HcclCommState> state_{HcclCommState::IDLE};
1124 : std::unordered_map<std::string, std::string> newTagToTagMap_;
1125 : // zerocopy hex prefix tag + cnt 副本 _CaptureN tag,跨 iter 累积新 entry
1126 : std::unordered_set<std::string> tagsRequiringHostCleanup_;
1127 : // 保护 rankTagRemoteRes_ / hostMemVec_ / deviceMemVec_ / tagsRequiringHostCleanup_ /
1128 : // ibverbsLocalNotify_ / ibverbsRemoteNotify_ / resMap_ 的并发访问
1129 : std::mutex commResMutex_;
1130 : static std::mutex linkResMapMutex_;
1131 : static std::unordered_map<Transport*, LinkInfo> linkResMap_;
1132 : std::shared_ptr<HostMem> transDevIbverbsDataMem_ = nullptr;
1133 : bool isA2MC2MultiServer_{false};
1134 : bool isA2MC2IntraHie_{false};
1135 : DeviceMem ibverbsDataBuffer_;
1136 : std::unordered_map<std::string, std::list<DeviceMem>> ibverbsLocalNotify_;
1137 : std::unordered_map<std::string, std::list<DeviceMem>> ibverbsRemoteNotify_;
1138 :
1139 : // 按序下发notify的工作区
1140 : DeviceMem aicpuOrderNotifyAddr_;
1141 : u32 graphId_;
1142 :
1143 : // alltoallv
1144 : HostMem hostCollectBuffer_;
1145 :
1146 : // batchsendrecv
1147 : std::set<u32> ranksLinked_{};
1148 :
1149 : // AIV通信同步标识
1150 : s32 aivOpbaseTag_ = 1; // 动态图或者单算子非Capture模式的tag
1151 : s32 aivOffloadTag_ = 1; // 静态图或者Capture模式的tag
1152 : std::vector<DeviceMem> aivOffloadCommInfoMem_; // 图模式每个算子单独一块内存维护通信域信息
1153 :
1154 : // Host侧收集的数据
1155 : std::shared_ptr<HostMem> aiRMAInfoMem_ = nullptr;
1156 : std::shared_ptr<HostMem> rmaInfoMem_ = nullptr; // for aiv
1157 : std::shared_ptr<HostMem> aiSqMem_ = nullptr;
1158 : std::shared_ptr<HostMem> aiScqMem_ = nullptr;
1159 : std::shared_ptr<HostMem> aiRqMem_ = nullptr;
1160 : std::shared_ptr<HostMem> aiRcqMem_ = nullptr;
1161 : std::shared_ptr<HostMem> aiMemMem_ = nullptr;
1162 : std::shared_ptr<HostMem> aiMemDetailsMem_ = nullptr;
1163 :
1164 : // Host侧同步到Device的内存空间
1165 : DeviceMem aiRMAInfoDev_;
1166 : DeviceMem aiSqDev_;
1167 : DeviceMem aiScqDev_;
1168 : DeviceMem aiRqDev_;
1169 : DeviceMem aiRcqDev_;
1170 : DeviceMem aiMemDev_;
1171 : DeviceMem aiMemDetailsDev_;
1172 :
1173 : // 通信能力支持信息,提供给融合算子获取
1174 : std::shared_ptr<HostMem> combinedCapabilityMem_ = nullptr;
1175 : DeviceMem combinedCapabilityBuffer_;
1176 :
1177 : aclrtBinHandle binHandle_ = nullptr;
1178 : aclrtBinHandle binCustomHandle_ = nullptr;
1179 :
1180 : std::unique_ptr<ZeroCopyAclGraph> zeroCopyAclGraph_;
1181 :
1182 : u32 switchRanksNum_{0};
1183 : u32 switchRankList_[AICPU_MAX_RANK_NUM]{};
1184 : bool switchUseBackup_[AICPU_MAX_RANK_NUM]{};
1185 : u8 remoteRankNicStatus_[AICPU_MAX_RANK_NUM]{};
1186 : bool needCheckDefaultNic_{false};
1187 : bool needCheckBackupNic_{false};
1188 : bool switchNicWaitingResult_{false};
1189 : u32 captureCnt_ = 0;
1190 : bool isUserMemRegisted_{false}; // 是否已注册user Mem,与ccl buffer互斥
1191 : std::unordered_map<void*, std::shared_ptr<DeviceMem>> userMemMap_; // key: window handle, value: window ptr
1192 : OpCommTransport userMemTransport_;
1193 : std::vector<LINK> channelLinks_{};
1194 :
1195 : void* p2pCclBuf_[AICPU_MAX_RANK_NUM]{};
1196 : void* cclBuf_[AICPU_MAX_RANK_NUM]{};
1197 : std::map<u32, TransportType> remoteTransportMap_;
1198 : uint32_t netLayer_[COMM_LAYER_NUM_MAX]{};
1199 : #ifndef CCL_KERNEL_AICPU
1200 : RankGraphV1 rankGraph_;
1201 : std::unique_ptr<DpuManager> dpuManager_;
1202 : #endif
1203 : uint32_t myRankConnectMode_{0}; // 0: normal mode 1: host nic对接device nic异构模式
1204 :
1205 : // for group
1206 : bool isGroupMode_{false};
1207 :
1208 : // 独立算子
1209 : std::vector<std::shared_ptr<DeviceMem>> channelRemoteParamMem_;
1210 : CommConfig commConfig_;
1211 : std::function<bool()> getAicpuCommState_; // 获取自定义算子aicpu通信域是否初始化
1212 : bool isInvalidComm_{false};
1213 : std::function<HcclResult()> releaseChannel_ = nullptr;
1214 :
1215 : u32 hcclQos_ = EnvConfig::HCCL_QOS_DEFAULT;
1216 : u32 rankInParentComm_{0}; // 父通信域中的rank ID (MC2场景使用)
1217 : std::shared_ptr<SymmetricMemoryAgent> symmetricMemoryAgent_;
1218 : std::unique_ptr<SymmetricMemory> symmetricMemory_;
1219 : };
1220 : } // end namespace hccl
1221 : #endif // HCCL_IMPL_BASE_H
|