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 OP_BASE_H
12 : #define OP_BASE_H
13 :
14 : #include <functional>
15 : #include <string>
16 : #include <vector>
17 : #include <hccl/hccl_comm.h>
18 : #include <hccl/hccl_inner.h>
19 : #include <hccl/hccl_types.h>
20 :
21 : #include "hccl/base.h"
22 : #include "hccl/hccl_rank_graph.h"
23 : #include "hccl_mem_defs.h"
24 : #include "hcomm_res_defs.h"
25 : #include "acl/acl_rt.h"
26 : #include "task_param.h"
27 : #include "op_base_pub.h"
28 : #include "hccl_comm_pub.h"
29 : // ltm指定config路径
30 : #include "common/src/config.h"
31 : #include "../common/src/topo/topoinfo_detect.h"
32 : #include "legacy_op_hcom_info.h"
33 :
34 : namespace Hccl {
35 : using ProfCallback = std::function<HcclResult(const TaskParam&, uint64_t)>;
36 : using ReportCallback = std::function<HcclResult()>;
37 : } // namespace Hccl
38 :
39 : #ifdef __cplusplus
40 : extern "C" {
41 : #endif
42 :
43 : HcclResult HcclCommDestroyV2(HcclComm comm);
44 :
45 : HcclResult __attribute__((weak)) HcclCommInitClusterInfoV2(const char* clusterInfo, uint32_t rank, HcclComm* comm);
46 :
47 : HcclResult __attribute__((weak))
48 : HcclCommInitClusterInfoConfigV2(const char* clusterInfo, uint32_t rank, HcclCommConfig* config, HcclComm* comm);
49 :
50 : HcclResult __attribute__((weak)) HcclCommInitAllV2(uint32_t ndev, int32_t* devices, HcclComm* comms);
51 :
52 : HcclResult __attribute__((weak))
53 : HcclCommInitClusterInfoMemConfigV2(const char* rankTableString, uint32_t rank, HcclCommConfig* config, HcclComm* comm);
54 :
55 : HcclResult __attribute__((weak)) HcclAlltoAllV2(
56 : const void* sendBuf, uint64_t sendCount, HcclDataType sendType, const void* recvBuf, uint64_t recvCount,
57 : HcclDataType recvType, HcclComm comm, aclrtStream stream);
58 :
59 : HcclResult __attribute__((weak)) HcclAlltoAllVV2(
60 : const void* sendBuf, const void* sendCounts, const void* sdispls, HcclDataType sendType, const void* recvBuf,
61 : const void* recvCounts, const void* rdispls, HcclDataType recvType, HcclComm comm, aclrtStream stream);
62 :
63 : HcclResult __attribute__((weak)) HcclCreateSubCommConfigV2(
64 : HcclComm* comm, uint32_t rankNum, uint32_t* rankIds, uint64_t subCommId, uint32_t subCommRankId,
65 : HcclCommConfig* config, HcclComm* subComm);
66 :
67 : HcclResult __attribute__((weak)) HcclGetRankIdV2(HcclComm comm, uint32_t* rank);
68 :
69 : HcclResult __attribute__((weak)) HcclGetRootInfoV2(HcclRootInfo* rootInfo);
70 :
71 : HcclResult __attribute__((weak)) HcclGetCommNameV2(HcclComm commHandle, char* commName);
72 :
73 : HcclResult __attribute__((weak)) HcclCommInitRootInfoV2(
74 : uint32_t nRanks, const HcclRootInfo* rootInfo, uint32_t rank, HcclComm* comm, std::string& identifier);
75 :
76 : HcclResult __attribute__((weak)) HcclCommInitRootInfoConfigV2(
77 : uint32_t nRanks, const HcclRootInfo* rootInfo, uint32_t rank, const HcclCommConfig* config, HcclComm* comm);
78 :
79 : HcclResult __attribute__((weak)) HcclGetRankSize(HcclComm comm, uint32_t* rankSize);
80 :
81 : HcclResult __attribute__((weak)) HcclAlltoAllVCV2(
82 : const void* sendBuf, const void* sendCountMatrix, HcclDataType sendType, const void* recvBuf, HcclDataType recvType,
83 : HcclComm comm, rtStream_t stream);
84 :
85 : HcclResult __attribute__((weak)) HcclReduceV2(
86 : void* sendBuf, void* recvBuf, uint64_t count, HcclDataType dataType, HcclReduceOp op, uint32_t root, HcclComm comm,
87 : aclrtStream stream);
88 :
89 : HcclResult __attribute__((weak)) HcclAllReduceV2(
90 : void* sendBuf, void* recvBuf, uint64_t count, HcclDataType dataType, HcclReduceOp op, HcclComm comm,
91 : aclrtStream stream);
92 :
93 : HcclResult __attribute__((weak))
94 : HcclBroadcastV2(void* buf, uint64_t count, HcclDataType dataType, uint32_t root, HcclComm comm, aclrtStream stream);
95 :
96 : HcclResult __attribute__((weak)) HcclGetTopoDescV2();
97 :
98 : HcclResult __attribute__((weak)) HcclScatterV2(
99 : void* sendBuf, void* recvBuf, uint64_t recvCount, HcclDataType dataType, uint32_t root, HcclComm comm,
100 : aclrtStream stream);
101 :
102 : HcclResult __attribute__((weak)) HcclCommSuspend(HcclComm comm);
103 :
104 : HcclResult __attribute__((weak)) HcclReduceScatterV2(
105 : void* sendBuf, void* recvBuf, uint64_t recvCount, HcclDataType dataType, HcclReduceOp op, HcclComm comm,
106 : aclrtStream stream);
107 :
108 : HcclResult __attribute__((weak)) HcclReduceScatterVV2(
109 : void* sendBuf, void* sendCounts, void* sendDispls, void* recvBuf, uint64_t recvCount, HcclDataType dataType,
110 : HcclReduceOp op, HcclComm comm, aclrtStream stream);
111 :
112 : HcclResult __attribute__((weak)) HcclAllGatherV2(
113 : void* sendBuf, void* recvBuf, uint64_t sendCount, HcclDataType dataType, HcclComm comm, aclrtStream stream);
114 :
115 : HcclResult __attribute__((weak)) HcclAllGatherVV2(
116 : void* sendBuf, uint64_t sendCount, void* recvBuf, void* recvCounts, void* recvDispls, HcclDataType dataType,
117 : HcclComm comm, aclrtStream stream);
118 :
119 : HcclResult __attribute__((weak))
120 : HcclSendV2(void* sendBuf, uint64_t count, HcclDataType dataType, uint32_t destRank, HcclComm comm, aclrtStream stream);
121 :
122 : HcclResult __attribute__((weak))
123 : HcclRecvV2(void* recvBuf, uint64_t count, HcclDataType dataType, uint32_t srcRank, HcclComm comm, aclrtStream stream);
124 :
125 : HcclResult __attribute__((weak))
126 : HcclBatchSendRecvV2(HcclSendRecvItem* sendRecvInfo, uint32_t itemNum, HcclComm comm, aclrtStream stream);
127 :
128 : HcclResult __attribute__((weak)) HcclGetRankSizeV2(HcclComm comm, uint32_t* rankSize);
129 :
130 : HcclResult __attribute__((weak))
131 : HcclAllocComResourceByTilingV2(HcclComm comm, const void* stream, void* mc2Tiling, void** commContext);
132 :
133 : HcclResult __attribute__((weak)) HcclCommSuspendV2(HcclComm comm);
134 :
135 : HcclResult __attribute__((weak)) HcclCommResumeV2(HcclComm comm);
136 :
137 : HcclResult __attribute__((weak)) HcclCommResumeImplV2(HcclComm comm);
138 :
139 : HcclResult __attribute__((weak)) HcclGetCommAsyncErrorV2();
140 :
141 : HcclResult __attribute__((weak)) HcclGetRawCommHandle(const char* commName, HcclComm* commHandle);
142 :
143 : HcclResult __attribute__((weak)) HcclSetConfigV2(HcclConfig config, HcclConfigValue configValue);
144 :
145 : HcclResult __attribute__((weak)) HcclGetConfigV2(HcclConfig config, HcclConfigValue* configValue);
146 :
147 : HcclResult __attribute__((weak)) HcclBarrierV2(HcclComm comm, aclrtStream stream);
148 :
149 : HcclResult __attribute__((weak)) HcclGetHeterogModeV2(HcclComm comm, HcclHeterogMode* mode);
150 :
151 : HcclResult __attribute__((weak)) HcclGetRankGraphV2(const HcclComm* comm, void** rankGraph);
152 :
153 : HcclResult __attribute__((weak))
154 : HcclGetCclBuffer(HcclComm comm, uintptr_t& cclBufferAddr, size_t& cclBufferSize, HcclMemType& cclBufferMemType);
155 :
156 : HcclResult __attribute__((weak))
157 : HcclCommWorkingDevNicSetV2(const HcclComm comm, uint32_t* ranks, bool* useBackup, uint32_t nRanks);
158 :
159 : HcclResult __attribute__((weak))
160 : HcclCommSetMemoryRangeV2(const HcclComm comm, void* baseVirPtr, size_t size, size_t alignment, uint64_t flags);
161 :
162 : HcclResult __attribute__((weak)) HcclCommUnsetMemoryRangeV2(const HcclComm comm, void* baseVirPtr);
163 :
164 : HcclResult __attribute__((weak)) HcclCommActivateCommMemoryV2(
165 : const HcclComm comm, void* virPtr, size_t size, size_t offset, void* handle, uint64_t flags);
166 :
167 : HcclResult __attribute__((weak)) HcclCommDeactivateCommMemoryV2(const HcclComm comm, void* virPtr);
168 :
169 : HcclResult __attribute__((weak)) HcommFlushV2();
170 :
171 : uint32_t __attribute__((weak)) HcclGetCommConfigCapabilityV2();
172 :
173 : #if (!defined(HCCD)) && (!defined(CCL_KERNEL_AICPU))
174 : HcclResult __attribute__((weak)) HcclGetCcuTaskInfoLegacy(HcclComm comm, void* tilingData, void* ccuTaskGroup);
175 :
176 : HcclResult __attribute__((weak)) HcclGetNetLayersV2(HcclComm comm, uint32_t** netLayers, uint32_t* netLayerNum);
177 :
178 : HcclResult __attribute__((weak)) HcclGetInstSizeByNetLayerV2(HcclComm comm, uint32_t netLayer, uint32_t* rankNum);
179 :
180 : HcclResult __attribute__((weak)) HcclGetInstTopoTypeByNetLayerV2(HcclComm comm, uint32_t netLayer, uint32_t* topoType);
181 :
182 : HcclResult __attribute__((weak)) CommGetCCLBufSizeCfgV2(HcclComm comm, uint64_t* cclBufSize);
183 :
184 : HcclResult __attribute__((weak))
185 : HcclGetInstRanksByNetLayerV2(HcclComm comm, uint32_t netLayer, uint32_t** ranks, uint32_t* rankNum);
186 :
187 : HcclResult __attribute__((weak))
188 : HcclGetInstSizeListByNetLayerV2(HcclComm comm, uint32_t netLayer, uint32_t** instSizeList, uint32_t* listSize);
189 :
190 : HcclResult __attribute__((weak)) HcclGetLinksV2(
191 : HcclComm comm, uint32_t netLayer, uint32_t srcRank, uint32_t dstRank, CommLink** linkList, uint32_t* listSize);
192 :
193 : HcclResult __attribute__((weak))
194 : HcclGetTopoInstsByLayerV2(HcclComm comm, uint32_t netLayer, uint32_t** topoInsts, uint32_t* topoInstNum);
195 :
196 : HcclResult __attribute__((weak))
197 : HcclGetTopoTypeV2(HcclComm comm, uint32_t netLayer, uint32_t topoInstId, CommTopo* topoType);
198 :
199 : HcclResult __attribute__((weak))
200 : HcclGetRanksByTopoInstV2(HcclComm comm, uint32_t netLayer, uint32_t topoInstId, uint32_t** ranks, uint32_t* rankNum);
201 :
202 : HcclResult __attribute__((weak))
203 : HcclRankGraphGetEndpointNumV2(HcclComm comm, uint32_t layer, uint32_t topoInstId, uint32_t* num);
204 :
205 : HcclResult __attribute__((weak)) HcclRankGraphGetEndpointDescV2(
206 : HcclComm comm, uint32_t layer, uint32_t topoInstId, uint32_t* descNum, EndpointDesc* endpointDesc);
207 :
208 : HcclResult __attribute__((weak)) HcclRankGraphGetEndpointInfoV2(
209 : HcclComm comm, uint32_t rankId, const EndpointDesc* endpointDesc, EndpointAttr endpointAttr, uint32_t infoLen,
210 : void* info);
211 :
212 : HcclResult __attribute__((weak)) HcclGetOpArgsV2(void** opArgs);
213 :
214 : HcclResult __attribute__((weak)) HcclFreeOpArgsV2(void* opArgs);
215 :
216 : HcclResult __attribute__((weak)) HcclSetOpSrcDataTypeV2(void* opArgs, uint8_t srcDataType);
217 :
218 : HcclResult __attribute__((weak)) HcclSetOpDstDataTypeV2(void* opArgs, uint8_t dstDataType);
219 :
220 : HcclResult __attribute__((weak)) HcclSetOpReduceTypeV2(void* opArgs, uint32_t reduceType);
221 :
222 : HcclResult __attribute__((weak)) HcclSetOpCountV2(void* opArgs, uint64_t count);
223 :
224 : HcclResult __attribute__((weak)) HcclSetOpAlgConfigV2(void* opArgs, char* algConfig);
225 :
226 : HcclResult __attribute__((weak)) HcclSetOpCommEngineV2(void* opArgs, uint8_t commEngine);
227 :
228 : HcclResult __attribute__((weak)) HcclCommResPrepareV2(HcclComm comm, char* opName, void* opArgs, void** addr);
229 :
230 : HcclResult __attribute__((weak))
231 : HcclDevMemAcquireV2(HcclComm comm, const char* memTag, uint64_t* size, void** addr, bool* newCreated);
232 :
233 : HcclResult __attribute__((weak)) HcclGetHcclBufferV2(HcclComm comm, void** addr, uint64_t* size);
234 :
235 : HcclResult __attribute__((weak))
236 : HcclGetRemoteIpcHcclBufV2(HcclComm comm, uint64_t remoteRank, void** addr, uint64_t* size);
237 :
238 : HcclResult __attribute__((weak))
239 : HcclGetAicpuOpStreamAndNotifyV2(HcclComm comm, rtStream_t* opstream, u8 aicpuNotifyNum, void** aicpuNotify);
240 :
241 : typedef int32_t(Callback)(uint64_t, int32_t);
242 : HcclResult __attribute__((weak)) HcclTaskRegisterV2(HcclComm comm, const char* msgTag, Callback cb);
243 : HcclResult __attribute__((weak)) HcclTaskUnRegisterV2(HcclComm comm, const char* msgTag);
244 : HcclResult __attribute__((weak)) HcclTaskRegisterProfV2(HcclComm comm, Hccl::ProfCallback profCallback);
245 : HcclResult __attribute__((weak)) HcclTaskReportRegisterV2(HcclComm comm, Hccl::ReportCallback reportCallback);
246 : HcclResult __attribute__((weak)) HcclGetDpuSteamIdV2(HcclComm comm, u32& dpuStreamId);
247 : HcclResult __attribute__((weak)) HcclCheckTaskServiceExist(const std::string& commId, s32 deviceId);
248 : #endif
249 :
250 : #ifdef __cplusplus
251 : }
252 : #endif
253 :
254 : constexpr uint32_t MAX_HCOM_NUM = 3U;
255 :
256 : HcclResult InitOtherInfo(hccl::HcclCommParams& params, const char* rankTable);
257 :
258 : HcclResult CallMsprofReportHostApi(
259 : hccl::hcclComm* hcclComm, HcclCMDType cmdType, uint64_t beginTime, u64 count, HcclDataType dataType,
260 : const std::string& tag);
261 :
262 : HcclResult ReduceScatterLoop(
263 : const std::string& tag, void* inputPtr, void* outputPtr, const u64& count, HcclDataType dataType, HcclReduceOp op,
264 : hccl::hcclComm* hcclComm, rtStream_t stream);
265 :
266 : HcclResult HcclGetOpBasedMemSize(const HcclCMDType& opType, u64& size, const HcomCollOpInfo& opInfo);
267 :
268 : HcclResult ReduceLoop(
269 : const std::string& tag, void* inputPtr, void* outputPtr, const u64 count, HcclDataType dataType, HcclReduceOp op,
270 : const u32 root, hccl::hcclComm* hcclComm, rtStream_t stream);
271 :
272 : HcclResult HcclGatherAlltoAllV(HcomGatherAllToAllVParams params, HcclComm comm, aclrtStream stream);
273 :
274 : HcclResult RunGather(u64* sendCounts, u64* sdispls, void* sendDevBuf, GatherPara& gatherPara);
275 :
276 : void GatherMemCopyThread(void* baseAddr, u64 offset, std::vector<u64>& addrInfo, OpBaseMemPara memCpyPara);
277 :
278 : HcclResult HcclGetCommAll(uint32_t ndev, int32_t* devices, HcclComm* comms);
279 :
280 : HcclResult
281 : GetDeviceComm(uint32_t ndev, const HcclRootInfo& rootHandle, const s32 rank, const s32 logicDeviceId, HcclComm& comm);
282 :
283 : HcclResult SetOverFlowAddr(hccl::hcclComm* hcclComm);
284 :
285 : HcclResult HcclGetCommHandle(const char* commName, std::shared_ptr<hccl::hcclComm>& comm);
286 :
287 : HcclResult CheckScatterInputPara(HcclComm comm, void* recvBuf);
288 :
289 : HcclResult HcclMc2ComResourceByTiling(HcclComm comm, uint32_t* pVersion, void* mc2Tiling, rtStream_t& aicpuStream);
290 :
291 : HcclResult HcclCreateComResourceByComm(
292 : HcclComm comm, u32 streamMode, bool isOpbaseMode, void** commContext, bool isMC2 = false,
293 : void* mc2Tiling = nullptr);
294 :
295 : HcclResult HcclDeviceRefresh(s32& deviceLogicId);
296 :
297 : HcclResult HcclBatchSendRecvGroup(HcclSendRecvItem* sendRecvInfo, uint32_t itemNum, HcclComm comm, aclrtStream stream);
298 :
299 : HcclResult HcclSetIfProfile(void);
300 :
301 : void HcclResetIfProfile(void);
302 :
303 : void PrintCountsAndDispls(const u32 length, const void* counts, const void* displs, const std::string& tag);
304 :
305 : void CheckCountsAndDispls(const u32 length, const void* counts, const void* displs, const std::string& tag);
306 :
307 : HcclResult GetCaptureInfo(aclrtStream stream, aclmdlRICaptureStatus& captureStatus, uint64_t& modelId, bool& isCapture);
308 :
309 : HcclResult HcclGetInitTilingList(const void* mc2Tiling, const void* p[], uint32_t& cnt);
310 :
311 : HcclResult HcclCommInitCollComm(uint32_t rank, void** commV2, const HcclCommConfig* config, HcclComm* comm);
312 : HcclResult HcclMc2ComOpResCtx(
313 : HcclComm comm, uint8_t opType, HcclDataType srcDataType, HcclDataType dstDataType, HcclReduceOp reduceType,
314 : uint64_t count, char* algConfig, uint32_t commEngine, rtStream_t& aicpuStream);
315 :
316 : #ifdef __cplusplus
317 : extern "C" {
318 : #endif // __cplusplus
319 :
320 : HcclResult
321 : HcclCommInitClusterInfoMemConfig(const char* rankTableString, uint32_t rank, HcclCommConfig* config, HcclComm* comm);
322 :
323 : #if (!defined(HCCD)) && (!defined(CCL_KERNEL_AICPU))
324 : HcclResult HcclCommStateNotify(HcclComm comm, HcclCommStatePhase state);
325 :
326 2 : static inline HcclResult HcclCommResumePostCallback(HcclComm comm)
327 : {
328 2 : return HcclCommStateNotify(comm, HcclCommStatePhase::HCCL_COMM_STATE_PHASE_RESUME_POST);
329 : }
330 : #endif
331 : #ifdef __cplusplus
332 : }
333 : #endif // __cplusplus
334 : #endif // OP_BASE_H
|