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 : #include "op_base.h"
12 : #include <algorithm>
13 : #include <future>
14 : #include <map>
15 : #include <string>
16 : #include <hccl/hccl_types.h>
17 :
18 : #include "hccl/base.h"
19 : #include "param_check_pub.h"
20 : #include "rank_consistentcy_checker.h"
21 : #include "externalinput_pub.h"
22 : #include "env_config.h"
23 : #include "../common/src/topo/topoinfo_detect.h"
24 : #include "../common/src/topo/topoinfo_ranktable_partition.h"
25 : #include "../common/src/state_guard.h"
26 : #include "sal_pub.h"
27 : #include "profiling_manager_pub.h"
28 : #include "adapter_prof.h"
29 : #include "adapter_rts_common.h"
30 : #include "device_capacity.h"
31 : #include "mem_host_pub.h"
32 : #include "hcom_common.h"
33 : #include "comm_config_pub.h"
34 : #include "kernel_tiling/kernel_tiling.h"
35 : #include "mmpa_api.h"
36 : #include "aicpu_operator_pub.h"
37 : #include "../nslbdp/hccl_nslbdp.h"
38 : #include "hccl_group.h"
39 : #include "hostdpu/dpu_kernel_entrance.h"
40 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
41 : #include "hcomm_c_adpt.h"
42 : #endif
43 :
44 : #define DOUBLE_SIZE 2
45 :
46 : using namespace std;
47 : using namespace hccl;
48 :
49 : typedef int32_t Callback(uint64_t, int32_t);
50 :
51 : const std::string HCCL_ALLTOALL = "ALLTOALL";
52 : const std::string HCCL_ALLTOALLV = "ALLTOALLV";
53 : const std::string HCCL_ALLTOALLVC = "ALLTOALLVC";
54 :
55 302 : HcclResult CallMsprofReportHostApi(hccl::hcclComm* hcclComm, HcclCMDType cmdType, uint64_t beginTime, u64 count,
56 : HcclDataType dataType, const std::string &tag)
57 : {
58 302 : if (GetIfProfile()) {
59 13 : AlgType algType;
60 13 : if(cmdType == HcclCMDType::HCCL_CMD_BATCH_SEND_RECV){
61 1 : algType.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_PAIRWISE;
62 1 : algType.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RESERVED;
63 12 : } else if (cmdType == HcclCMDType::HCCL_CMD_SEND || cmdType == HcclCMDType::HCCL_CMD_RECEIVE){
64 2 : algType.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_RESERVED;
65 2 : algType.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RESERVED;
66 : } else {
67 10 : CHK_RET(hcclComm->GetAlgType(algType, cmdType));
68 : }
69 :
70 13 : u32 numBlocks = 0;
71 13 : hcclComm->GetNumBlocks(numBlocks);
72 13 : uint64_t groupName = hrtMsprofGetHashId(hcclComm->GetIdentifier().c_str(), hcclComm->GetIdentifier().length());
73 13 : HCCL_INFO("[%s] groupName[%llu], groupNameStr[%s]", __func__, groupName, hcclComm->GetIdentifier().c_str());
74 13 : CHK_RET_AND_PRINT_IDE(ProfilingManagerPub::CallMsprofReportHostApi(cmdType, beginTime, count, dataType, algType,
75 : groupName, numBlocks), tag.c_str());
76 : }
77 302 : hcclComm->SetAivCoreLimit(0);
78 302 : return HCCL_SUCCESS;
79 : }
80 :
81 : thread_local s32 g_hcclDeviceId = INVALID_INT;
82 : std::mutex g_opHcomInfosMutex{};
83 : std::mutex g_opHcomOneSideMutex{};
84 :
85 990 : HcclOpInfoCtx &GetOpHcomInfo(uint32_t devId)
86 : {
87 990 : if (devId >= MAX_MODULE_DEVICE_NUM + 1) {
88 0 : devId = MAX_MODULE_DEVICE_NUM;
89 : }
90 :
91 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
92 : // 临时方案:声明comm各类基础单例
93 : // 仅触发空对象声明,不执行业务动作,故不会失败
94 990 : (void)HcommResMgrInit(devId);
95 : #endif
96 :
97 1320 : static HcclOpInfoCtx g_opHcomInfos[MAX_MODULE_DEVICE_NUM + 1];
98 990 : return g_opHcomInfos[devId];
99 : }
100 :
101 :
102 1004 : HcclResult HcclGetDeviceId(void)
103 : {
104 1004 : if (g_hcclDeviceId == INVALID_INT) {
105 1 : CHK_PRT_RET(hrtGetDevice(&g_hcclDeviceId) != HCCL_SUCCESS,
106 : HCCL_WARNING("[HcclGetDeviceId] get fail deviceLogicId[%d]", g_hcclDeviceId), HCCL_E_INTERNAL);
107 : }
108 : u32 maxDeviceNum;
109 1004 : CHK_RET(GetMaxDevNum(maxDeviceNum));
110 1004 : CHK_PRT_RET(static_cast<u32>(g_hcclDeviceId) >= maxDeviceNum,
111 : HCCL_WARNING("[HcclGetDeviceId]deviceLogicId[%d] is bigger than maxDeviceNum:[%u]",
112 : g_hcclDeviceId, maxDeviceNum), HCCL_E_INTERNAL);
113 1004 : HCCL_INFO("[HcclGetDeviceId] deviceLogicId[%d] ", g_hcclDeviceId);
114 1004 : return HCCL_SUCCESS;
115 : }
116 :
117 23 : s32 HcclGetThreadDeviceId()
118 : {
119 23 : CHK_PRT_RET(HcclGetDeviceId() != HCCL_SUCCESS, HCCL_WARNING("[HcclGetThreadDeviceId] get fail deviceLogicId[%d]",
120 : g_hcclDeviceId), INVALID_INT);
121 23 : return g_hcclDeviceId;
122 : }
123 :
124 : // 由调用者保证device id已经被set
125 984 : HcclOpInfoCtx &GetHcclExistDeviceOpInfoCtx(void)
126 : {
127 984 : std::lock_guard<std::mutex> lock(g_opHcomInfosMutex);
128 984 : auto &opHcomInfo = GetOpHcomInfo(g_hcclDeviceId);
129 984 : if (!opHcomInfo.isUsed) {
130 6 : HCCL_INFO("[GetHcclOpInfoCtx] Set device, use g_hcclDeviceId[%d] ", g_hcclDeviceId);
131 6 : auto &backUpOpHcomInfo = GetOpHcomInfo(MAX_MODULE_DEVICE_NUM);
132 6 : if (backUpOpHcomInfo.isUsed) {
133 0 : g_hcclDeviceId = MAX_MODULE_DEVICE_NUM;
134 0 : HCCL_INFO("[GetHcclOpInfoCtx] Used cover bottom g_hcclDeviceId[%d]", g_hcclDeviceId);
135 0 : return backUpOpHcomInfo;
136 : }
137 : }
138 :
139 984 : HCCL_INFO("[GetHcclExistDeviceOpInfoCtx] use g_hcclDeviceId[%d] opHcomInfos", g_hcclDeviceId);
140 984 : opHcomInfo.isUsed = true;
141 984 : return opHcomInfo;
142 984 : }
143 :
144 981 : HcclOpInfoCtx &GetHcclOpInfoCtx(void)
145 : {
146 981 : if (HcclGetDeviceId() == HCCL_SUCCESS) {
147 981 : return GetHcclExistDeviceOpInfoCtx();
148 : }
149 :
150 0 : std::lock_guard<std::mutex> lock(g_opHcomInfosMutex);
151 0 : for (u32 i = 0; i < MAX_MODULE_DEVICE_NUM; i++) {
152 0 : auto &opHcomInfo = GetOpHcomInfo(i);
153 0 : if (opHcomInfo.isUsed) {
154 0 : g_hcclDeviceId = i;
155 0 : HCCL_INFO("[GetHcclOpInfoCtx] Not set device, Used g_hcclDeviceId[%u] ", i);
156 0 : return opHcomInfo;
157 : }
158 : }
159 :
160 0 : g_hcclDeviceId = MAX_MODULE_DEVICE_NUM;
161 0 : auto &backUpOpHcomInfo = GetOpHcomInfo(g_hcclDeviceId);
162 0 : backUpOpHcomInfo.isUsed = true;
163 0 : HCCL_INFO("[GetHcclOpInfoCtx] Used cover bottom g_hcclDeviceId[%d]", g_hcclDeviceId);
164 0 : return backUpOpHcomInfo;
165 0 : }
166 :
167 0 : HcclResult GetDeviceComm(uint32_t ndev, const HcclRootInfo &rootHandle, const s32 rank, const s32 logicDeviceId,
168 : HcclComm &comm)
169 : {
170 : //给当前线程添加名字
171 0 : SetThreadName("Hccl_GetDevComm");
172 :
173 0 : CHK_PRT_RET(hrtSetDevice(logicDeviceId) != HCCL_SUCCESS,
174 : HCCL_ERROR("[GetDeviceComm] set fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
175 0 : HcclResult ret = HcclCommInitRootInfo(ndev, &rootHandle, rank, &comm);
176 0 : if (ret != HCCL_SUCCESS || comm == nullptr) {
177 0 : comm = nullptr;
178 0 : HCCL_ERROR("[GetDeviceComm] rank[%d] Get device comm failed!", rank);
179 0 : CHK_PRT_RET(hrtResetDevice(logicDeviceId) != HCCL_SUCCESS,
180 : HCCL_ERROR("[GetDeviceComm] reset fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
181 0 : return ret;
182 : }
183 0 : hcclComm *pComm = static_cast<hcclComm *>(comm);
184 0 : pComm->ResetDeviceEnable();
185 0 : return HCCL_SUCCESS;
186 : }
187 :
188 0 : HcclResult HcclGetCommAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
189 : {
190 : // 入参校验
191 0 : CHK_PRT_RET(ndev == 0, HCCL_ERROR("[HcclGetCommAll] ndev is invalid, ndev[%u]", ndev), HCCL_E_PARA);
192 0 : CHK_PTR_NULL(comms);
193 0 : CHK_PTR_NULL(devices);
194 :
195 : //给当前线程添加名字
196 0 : SetThreadName("Hccl_GetCommAll");
197 :
198 0 : CHK_PRT_RET(hrtSetDevice(devices[0]) != HCCL_SUCCESS,
199 : HCCL_ERROR("[HcclGetCommAll] set fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
200 :
201 : // 获取通信域之前, 先把所有通信域设置为空
202 0 : for (uint32_t i = 0; i < ndev; i++) {
203 0 : comms[i] = nullptr;
204 : }
205 :
206 : HcclRootInfo rootHandle;
207 0 : CHK_RET(HcclGetRootInfo(&rootHandle));
208 :
209 0 : std::vector<std::unique_ptr<std::thread>> threads(ndev);
210 0 : for (uint32_t rankId = 0; rankId < ndev; rankId++) {
211 0 : threads[rankId].reset(new (std::nothrow) std::thread(&GetDeviceComm, ndev, std::ref(rootHandle), rankId,
212 0 : devices[rankId], std::ref(comms[rankId])));
213 0 : CHK_PRT_RET(!threads[rankId], HCCL_ERROR("[HcclGetCommAll]threads[%u] reset failed ", rankId), HCCL_E_INTERNAL);
214 : }
215 0 : for (uint32_t i = 0; i < ndev; i++) {
216 0 : threads[i]->join();
217 : }
218 :
219 : // 如果任何一个通信域初始化失败,将所有已经成功创建的通信域销毁
220 0 : bool isFailed = false;
221 0 : for (uint32_t i = 0; i < ndev; ++i) {
222 0 : if (comms[i] == nullptr) {
223 0 : HCCL_ERROR("[HcclGetCommAll] rank[%u] get comm failed!", i);
224 0 : isFailed = true;
225 0 : break;
226 : }
227 : }
228 0 : if (isFailed) {
229 0 : for (uint32_t i = 0; i < ndev; ++i) {
230 0 : if (comms[i] != nullptr) {
231 0 : (void)HcclCommDestroy(comms[i]);
232 : }
233 : }
234 0 : return HCCL_E_INTERNAL;
235 : }
236 :
237 0 : CHK_PRT_RET(hrtResetDevice(devices[0]) != HCCL_SUCCESS,
238 : HCCL_ERROR("[HcclGetCommAll] reset fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
239 :
240 0 : return HCCL_SUCCESS;
241 0 : }
242 :
243 0 : HcclResult GetDeviceCollComm(const s32 rank, HcclCommConfig *config, const s32 logicDeviceId,
244 : HcclComm &comm)
245 : {
246 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
247 : //给当前线程添加名字
248 0 : SetThreadName("Hccl_GetDeviceCollComm");
249 :
250 0 : CHK_PRT_RET(hrtSetDevice(logicDeviceId) != HCCL_SUCCESS,
251 : HCCL_ERROR("[GetDeviceCollComm] set fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
252 :
253 : HcclComm newComm;
254 0 : HcclResult ret = HcclCommInitCollComm(rank, &comm, config, &newComm);
255 0 : if (ret != HCCL_SUCCESS || newComm == nullptr) {
256 0 : newComm = nullptr;
257 0 : HcclCommDestroyV2(comm);
258 0 : comm = nullptr;
259 0 : HCCL_ERROR("[GetDeviceCollComm] rank[%d] Get device coll comm failed!", rank);
260 0 : CHK_PRT_RET(hrtResetDevice(logicDeviceId) != HCCL_SUCCESS,
261 : HCCL_ERROR("[GetDeviceCollComm] reset fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
262 0 : return ret;
263 : }
264 0 : comm = newComm;
265 : #endif
266 0 : return HCCL_SUCCESS;
267 : }
268 :
269 0 : HcclResult HcclGetCollCommAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
270 : {
271 : // 入参校验
272 0 : CHK_PRT_RET(ndev == 0, HCCL_ERROR("[HcclGetCollCommAll] ndev is invalid, ndev[%u]", ndev), HCCL_E_PARA);
273 0 : CHK_PTR_NULL(comms);
274 0 : CHK_PTR_NULL(devices);
275 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
276 : //给当前线程添加名字
277 0 : SetThreadName("Hccl_GetCollCommAll");
278 :
279 0 : CHK_PRT_RET(hrtSetDevice(devices[0]) != HCCL_SUCCESS,
280 : HCCL_ERROR("[HcclGetCollCommAll] set fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
281 :
282 0 : constexpr HcclCommConfig *config = nullptr;
283 0 : std::vector<std::unique_ptr<std::thread>> threads(ndev);
284 0 : for (uint32_t rankId = 0; rankId < ndev; rankId++) {
285 0 : threads[rankId].reset(new (std::nothrow) std::thread(&GetDeviceCollComm, rankId, config,
286 0 : devices[rankId], std::ref(comms[rankId])));
287 0 : CHK_PRT_RET(!threads[rankId], HCCL_ERROR("[HcclGetCollCommAll]threads[%u] reset failed ", rankId), HCCL_E_INTERNAL);
288 : }
289 0 : for (uint32_t i = 0; i < ndev; i++) {
290 0 : threads[i]->join();
291 : }
292 :
293 : // 如果任何一个通信域转换失败,将所有已经成功创建的通信域销毁
294 0 : bool isFailed = false;
295 0 : for (uint32_t i = 0; i < ndev; ++i) {
296 0 : if (comms[i] == nullptr) {
297 0 : HCCL_ERROR("[HcclGetCollCommAll] rank[%u] get comm failed!", i);
298 0 : isFailed = true;
299 0 : break;
300 : }
301 : }
302 0 : if (isFailed) {
303 0 : for (uint32_t i = 0; i < ndev; ++i) {
304 0 : if (comms[i] != nullptr) {
305 0 : (void)HcclCommDestroy(comms[i]);
306 : }
307 : }
308 0 : return HCCL_E_INTERNAL;
309 : }
310 :
311 0 : CHK_PRT_RET(hrtResetDevice(devices[0]) != HCCL_SUCCESS,
312 : HCCL_ERROR("[HcclGetCollCommAll] reset fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
313 : #endif
314 0 : return HCCL_SUCCESS;
315 0 : }
316 :
317 0 : HcclResult HcclCollCommInitAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
318 : {
319 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
320 0 : HcclUs startut = TIME_NOW();
321 0 : std::string devicesStr;
322 0 : for (size_t i = 0; i < ndev; ++i) {
323 0 : std::string deviceStr = std::to_string(devices[i]);
324 0 : devicesStr += deviceStr;
325 0 : if (i != ndev - 1) {
326 0 : devicesStr += " ";
327 : }
328 0 : }
329 0 : HCCL_RUN_INFO("Entry-HcclCollCommInitAll, ndev:[%u], devices:[%s].", ndev, devicesStr.c_str());
330 :
331 0 : std::future<HcclResult> threadResult;
332 0 : std::unique_ptr<std::thread> getCommThread;
333 0 : getCommThread.reset(new (std::nothrow) std::thread(
334 0 : [=, &threadResult]() { threadResult = std::async(std::launch::async, HcclGetCollCommAll, ndev, devices, comms); }));
335 0 : CHK_PRT_RET(!getCommThread, HCCL_ERROR("[HcclCollCommInitAll]thread reset failed "), HCCL_E_INTERNAL);
336 0 : getCommThread->join();
337 :
338 0 : HcclResult ret = threadResult.get();
339 0 : if (ret != HCCL_SUCCESS) {
340 0 : for (uint32_t i = 0; i < ndev; ++i) {
341 0 : if (comms[i] != nullptr) {
342 0 : (void)HcclCommDestroy(comms[i]);
343 0 : comms[i] = nullptr;
344 : }
345 : }
346 0 : HCCL_ERROR("HcclCollCommInitAll failed! threadResult[%d]", ret);
347 0 : return ret;
348 : }
349 0 : s32 deviceLogicId = HcclGetThreadDeviceId();
350 0 : HCCL_RUN_INFO("HcclCollCommInitAll success, take time [%lld]us, deviceLogicId[%d].", DURATION_US(TIME_NOW() - startut),
351 : deviceLogicId);
352 : #endif
353 0 : return HCCL_SUCCESS;
354 0 : }
355 :
356 4 : HcclResult HcclCommInitAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
357 : {
358 4 : HcclUs startut = TIME_NOW();
359 4 : s32 deviceLogicId = 0;
360 4 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
361 :
362 : // 入参校验
363 4 : CHK_PRT_RET(ndev <= 0, HCCL_ERROR("[HcclCommInitAll] ndev is invalid, ndev[%u]", ndev), HCCL_E_PARA);
364 2 : CHK_PTR_NULL(comms);
365 1 : CHK_PTR_NULL(devices);
366 :
367 : // 判断设备List中是否有重复id,报错退出
368 0 : set<int32_t> devSet(devices, devices + ndev);
369 0 : uint32_t devSetSize = devSet.size();
370 0 : CHK_PRT_RET((devSetSize != ndev),
371 : HCCL_ERROR("[HcclCommInitAll] Duplicate device id exist in the device list. devSetSize:[%u], ndev:[%u]",
372 : devSetSize, ndev),
373 : HCCL_E_PARA);
374 :
375 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
376 0 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
377 : CHK_RET(HcclCommInitAllV2(ndev, devices, comms));
378 : CHK_RET(HcclCollCommInitAll(ndev, devices, comms));
379 : return HCCL_SUCCESS;
380 : }());
381 : #endif
382 0 : std::future<HcclResult> threadResult;
383 0 : std::unique_ptr<std::thread> getCommThread;
384 0 : getCommThread.reset(new (std::nothrow) std::thread(
385 0 : [=, &threadResult]() { threadResult = std::async(std::launch::async, HcclGetCommAll, ndev, devices, comms); }));
386 0 : CHK_PRT_RET(!getCommThread, HCCL_ERROR("[HcclCommInitAll]thread reset failed "), HCCL_E_INTERNAL);
387 0 : getCommThread->join();
388 :
389 0 : HcclResult ret = threadResult.get();
390 0 : if (ret != HCCL_SUCCESS) {
391 0 : for (uint32_t i = 0; i < ndev; ++i) {
392 0 : if (comms[i] != nullptr) {
393 0 : (void)HcclCommDestroy(comms[i]);
394 0 : comms[i] = nullptr;
395 : }
396 : }
397 0 : HCCL_ERROR("HcclCommInitAll failed! threadResult[%d]", ret);
398 0 : return ret;
399 : }
400 0 : HCCL_RUN_INFO("HcclCommInitAll success, take time [%lld]us, deviceLogicId[%d]", DURATION_US(TIME_NOW() - startut),
401 : deviceLogicId);
402 0 : return HCCL_SUCCESS;
403 0 : }
404 :
405 : std::unordered_map<s32, std::unordered_map<std::string, std::shared_ptr<HcclOpInfoCtx>>> g_oneSidedCommHcomInfos;
406 : std::set<HcclComm> g_oneSidedCommSet;
407 :
408 : /* 仅提供判断功能, 调用前需校验参数有效性*/
409 235 : bool IsOneSidedComm(HcclComm comm)
410 : {
411 235 : return g_oneSidedCommSet.find(comm) != g_oneSidedCommSet.end();
412 : }
413 :
414 :
415 : /* 仅提供判断功能, 调用前需校验参数有效性*/
416 4 : bool IsCommNameExistInOneSidedComms(s32 deviceLogicId, const std::string &commName)
417 : {
418 4 : bool exist = g_oneSidedCommHcomInfos.count(deviceLogicId) != 0 &&
419 0 : g_oneSidedCommHcomInfos[deviceLogicId].count(commName) != 0;
420 4 : if (exist && g_oneSidedCommHcomInfos[deviceLogicId][commName]->isUsed) {
421 0 : return true;
422 : }
423 4 : return false;
424 : }
425 :
426 0 : HcclResult DeInitOneSidedHcomInfo(s32 deviceLogicId, const std::string &commName)
427 : {
428 0 : CHK_PRT_RET(deviceLogicId == INVALID_INT,
429 : HCCL_ERROR("[HcclCommDestroy][DeInitOneSidedHcomInfo] deviceLogicId is error."),
430 : HCCL_E_PARA);
431 0 : CHK_PRT_RET(commName.empty(),
432 : HCCL_ERROR("[HcclCommDestroy][DeInitOneSidedHcomInfo] commName is error."),
433 : HCCL_E_PARA);
434 0 : g_oneSidedCommHcomInfos[deviceLogicId].erase(commName);
435 0 : return HCCL_SUCCESS;
436 : }
437 :
438 : /*
439 : * g_oneSidedCommHcomInfos 初始化
440 : * s32 deviceLogicId
441 : * const string &commName : 通信域名,用户确保全局唯一
442 : */
443 0 : HcclResult InitOneSidedHcomInfo(s32 deviceLogicId, const std::string &commName)
444 : {
445 0 : CHK_PRT_RET(deviceLogicId == INVALID_INT,
446 : HCCL_ERROR("[InitOneSidedHcomInfo] deviceLogicId is error."),
447 : HCCL_E_PARA);
448 0 : CHK_PRT_RET(commName.empty(),
449 : HCCL_ERROR("[InitOneSidedHcomInfo] commName is error."),
450 : HCCL_E_PARA);
451 : // comm name exit && isUsed = true
452 0 : bool isCommNameExist = IsCommNameExistInOneSidedComms(deviceLogicId, commName);
453 0 : CHK_PRT_RET(isCommNameExist, HCCL_ERROR("[Init][InitOneSidedHcomInfo] comm Name exist."), HCCL_E_PARA);
454 : // 确保 deviceLogicId 和 commName 的 map 已经被初始化
455 0 : if (g_oneSidedCommHcomInfos.find(deviceLogicId) == g_oneSidedCommHcomInfos.end()) {
456 0 : g_oneSidedCommHcomInfos[deviceLogicId] = {};
457 : }
458 : // comm name not exit
459 0 : if (g_oneSidedCommHcomInfos[deviceLogicId].count(commName) == 0) {
460 0 : std::shared_ptr<HcclOpInfoCtx> opBaseHcomPtr;
461 0 : EXCEPTION_CATCH((opBaseHcomPtr = std::make_shared<HcclOpInfoCtx>()), return HCCL_E_PARA);
462 0 : g_oneSidedCommHcomInfos[deviceLogicId][commName] = opBaseHcomPtr;
463 0 : }
464 : // comm name exit && isUsed = False
465 0 : g_oneSidedCommHcomInfos[deviceLogicId][commName]->isUsed = true;
466 0 : return HCCL_SUCCESS;
467 : }
468 :
469 0 : HcclOpInfoCtx &GetOneSidedOpInfoCtx(s32 deviceLogicId, const std::string &commName)
470 : {
471 0 : std::shared_ptr<HcclOpInfoCtx> oneSidedHComPtr = g_oneSidedCommHcomInfos[deviceLogicId][commName];
472 0 : return *oneSidedHComPtr;
473 0 : }
474 :
475 236 : HcclResult CheckOpBasedHcom(HcclOpInfoCtx &opBaseHcom, const uint32_t rank, const CommConfig &commConfig)
476 : {
477 : /* 防止重复调用初始化 */
478 236 : CHK_PRT_RET((opBaseHcom.pComm != nullptr), HCCL_ERROR("[Init][CheckOpBasedHcom]errNo[0x%016llx] rank[%u] "\
479 : "op_base hccl multiple initialization", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), rank), HCCL_E_UNAVAIL);
480 234 : const std::string commIdentifier = commConfig.GetConfigCommName();
481 234 : auto iter = opBaseHcom.opGroup2CommMap.find(commIdentifier);
482 234 : CHK_PRT_RET(iter != opBaseHcom.opGroup2CommMap.end(),
483 : HCCL_ERROR("[Init][CheckOpBasedHcom]errNo[0x%016llx] The comm name[%s] already exists in Group2Comm map.",
484 : HCCL_ERROR_CODE(HCCL_E_PARA),
485 : commIdentifier.c_str()),
486 : HCCL_E_PARA);
487 234 : return HCCL_SUCCESS;
488 234 : }
489 :
490 0 : HcclResult HcclCommInitCollComm(uint32_t rank, void **commV2, HcclCommConfig *config, HcclComm *comm)
491 : {
492 0 : CHK_PTR_NULL(*commV2);
493 0 : HCCL_INFO("[HcclCommInitCollComm] CollComm init start.");
494 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
495 0 : HcclUs startut = TIME_NOW();
496 :
497 : // 图模式
498 0 : u32 rankNum = 0;
499 0 : CHK_RET(HcclGetRankSizeV2(*commV2, &rankNum));
500 0 : char commName[ROOTINFO_INDENTIFIER_MAX_LENGTH] = {};
501 0 : CHK_RET(HcclGetCommNameV2(*commV2, commName));
502 : //获取cclbuffer
503 0 : uintptr_t cclBufferAddr{0};
504 0 : std::size_t cclBufferSize{0};
505 0 : HcclMemType cclBufferMemType{HcclMemType::HCCL_MEM_TYPE_DEVICE};
506 0 : CHK_RET(HcclGetCclBuffer(*commV2, cclBufferAddr, cclBufferSize, cclBufferMemType));
507 : HcclMem cclBuffer;
508 0 : cclBuffer.size = static_cast<uint64_t>(cclBufferSize);
509 0 : cclBuffer.type = cclBufferMemType;
510 0 : cclBuffer.addr = reinterpret_cast<void*>(cclBufferAddr);
511 0 : HcclCommPtr hcclCommPtr = nullptr;
512 0 : EXCEPTION_CATCH(hcclCommPtr = make_shared<hccl::hcclComm>(cclBufferSize, cclBufferSize, commName), return HCCL_E_PTR);
513 0 : CommConfig commConfig(commName);
514 0 : HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
515 0 : CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
516 :
517 0 : void *rankGraph = nullptr;
518 0 : CHK_RET(HcclGetRankGraphV2(commV2, &rankGraph));
519 :
520 : //Collcomm初始化
521 0 : CHK_RET(hcclCommPtr->InitCollComm(*commV2, rankGraph, rank, cclBuffer, commName, config));
522 0 : *comm = static_cast<HcclComm>(hcclCommPtr.get());
523 :
524 0 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
525 0 : opBaseHcom.opGroup2CommMap[hcclCommPtr->GetIdentifier()] = hcclCommPtr;
526 0 : lock.unlock();
527 0 : CHK_RET(HcomSetGroupTopoInfo(commName, rankNum));
528 0 : HCCL_RUN_INFO("[%s] success, take time [%lld]us.", __func__, DURATION_US(TIME_NOW() - startut));
529 : #endif
530 0 : return HCCL_SUCCESS;
531 0 : }
532 :
533 234 : HcclResult InitCommClusterInfo(std::string &rankTableM, const uint32_t rank, const CommConfig &commConfig,
534 : HcclOpInfoCtx& opBaseHcom, HcclComm *comm)
535 : {
536 234 : u32 rankTableSize = 0;
537 234 : HcclResult ret = HcomCheckRankTable(rankTableM.c_str(), rankTableSize);
538 234 : CHK_PRT_RET(ret != HCCL_SUCCESS,
539 : HCCL_ERROR("[Init][CommClusterInfo]check rankTable string error, rankTableSize [%u].",
540 : rankTableSize), HCCL_E_PARA);
541 :
542 234 : const std::string commIdentifier = commConfig.GetConfigCommName();
543 234 : opBaseHcom.pComm.reset(
544 : new (std::nothrow) hccl::hcclComm(
545 468 : commConfig.GetConfigBufferSize(), commConfig.GetConfigBufferSize(), commIdentifier, commConfig.GetConfigBufferName()));
546 234 : CHK_PTR_NULL(opBaseHcom.pComm);
547 :
548 : /* --------------初始化------------------------- */
549 234 : bool errorFlag = false;
550 : do {
551 234 : RankConsistentcyChecker::GetInstance().SetCheckCannVersionSwitch(true); // 打开CANN软件版本校验开关
552 234 : ret = InitOtherInfo(opBaseHcom.params, rankTableM.c_str());
553 235 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] init other Info.",
554 : HCCL_ERROR_CODE(ret)), errorFlag = true);
555 :
556 234 : HCCL_INFO("rootInfo[%s]", opBaseHcom.params.id.internal);
557 :
558 234 : ret = InitWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
559 234 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
560 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] init work flow mode error.",
561 : HCCL_ERROR_CODE(ret)), errorFlag = true);
562 :
563 234 : ret = CfgGetClusterInfo(rankTableM, to_string(rank), opBaseHcom.params, opBaseHcom.rankTable,
564 234 : commConfig.GetConfigInterSuperPodRetryEnable());
565 234 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
566 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx]"\
567 : "info error:rank[%u]", HCCL_ERROR_CODE(ret), rank), errorFlag = true);
568 :
569 233 : ret = opBaseHcom.pComm->init(opBaseHcom.params, commConfig, opBaseHcom.rankTable);
570 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] hcclComm init error.",
571 : HCCL_ERROR_CODE(ret)), errorFlag = true);
572 :
573 : /* 设置确定性计算配置 */
574 233 : ret = opBaseHcom.pComm->SetDeterministicConfig(commConfig.GetConfigDeterministic());
575 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
576 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set deterministic error.", HCCL_ERROR_CODE(ret)),
577 : errorFlag = true);
578 :
579 : // 设置TC/SL配置
580 233 : ret = opBaseHcom.pComm->SetQpQosAttr(commConfig.GetConfigTrafficClass(), commConfig.GetConfigServiceLevel());
581 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
582 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set TC and SL error or Invalid configuration parameter.",
583 : HCCL_ERROR_CODE(ret)), errorFlag = true);
584 233 : if (commConfig.GetConfigJobID() != 0) {
585 0 : HCCL_RUN_INFO("[NSLBDP]GetConfigJobID = %llu,GetConfigWorldRankID = %u.",
586 : commConfig.GetConfigJobID(), commConfig.GetConfigWorldRankID());
587 0 : hcclNslbDp::GetInstance().SetGlobalCommTaskId(commConfig.GetConfigJobID());
588 0 : hcclNslbDp::GetInstance().SetGlobalCommNodeId(commConfig.GetConfigWorldRankID());
589 : }
590 :
591 : /* 设置AIV模式 */
592 233 : ret = opBaseHcom.pComm->SetAivModeConfig(commConfig.GetConfigAivMode());
593 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
594 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set aivMode error.", HCCL_ERROR_CODE(ret)),
595 : errorFlag = true);
596 :
597 : /* 设置only AIV模式 */
598 233 : ret = opBaseHcom.pComm->SetOnlyAivModeConfig(commConfig.GetConfigIsOnlyAivMode());
599 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
600 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set only aivMode error.", HCCL_ERROR_CODE(ret)),
601 : errorFlag = true);
602 :
603 : /* 设置AICPU */
604 233 : ret = opBaseHcom.pComm->SetAicpuUnfoldConfig(commConfig.GetConfigAicpuUnfold());
605 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
606 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set aicpu error.", HCCL_ERROR_CODE(ret)),
607 : errorFlag = true);
608 :
609 : /* 设置HcclExecTimeOut */
610 233 : ret = opBaseHcom.pComm->SetExecTimeOutConfig(commConfig.GetConfigExecTimeOut());
611 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
612 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set execTimeOut error.", HCCL_ERROR_CODE(ret)),
613 : errorFlag = true);
614 :
615 : /* 设置HcclAlgo */
616 233 : ret = opBaseHcom.pComm->SetAlgoConfig(commConfig.GetConfigHcclAlgoMap());
617 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
618 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set hcclAlgo error.", HCCL_ERROR_CODE(ret)),
619 : errorFlag = true);
620 :
621 466 : ret = ShowRanktableConfigInfo(opBaseHcom.cloudFlag, opBaseHcom.params,
622 233 : opBaseHcom.rankTable);
623 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
624 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] put ranktable info error.",
625 : HCCL_ERROR_CODE(ret)), errorFlag = true);
626 : /* 设置独立算子参数 */
627 233 : ret = opBaseHcom.pComm->SetIndependentOpConfig(commConfig, opBaseHcom.rankTable);
628 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
629 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set SetIndependentOpConfig error.", HCCL_ERROR_CODE(ret)),
630 : errorFlag = true);
631 : // 初始化完成的comm指针赋给出参
632 233 : *comm = opBaseHcom.pComm.get();
633 233 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
634 233 : opBaseHcom.opGroup2CommMap[opBaseHcom.pComm->GetIdentifier()] = opBaseHcom.pComm;
635 233 : lock.unlock();
636 :
637 : // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将pComm赋值到hcomInfo.pComm
638 233 : if (opBaseHcom.pComm->GetIdentifier() == HCCL_WORLD_GROUP) {
639 233 : HcomGetCtxHomInfo().pComm = opBaseHcom.pComm;
640 : }
641 233 : ret = HcomSetGroupTopoInfo(opBaseHcom.pComm->GetIdentifier().c_str(), opBaseHcom.rankTable.rankNum);
642 233 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
643 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set group topo info error.",
644 : HCCL_ERROR_CODE(ret)), errorFlag = true);
645 233 : ret = opBaseHcom.pComm->InitHccpChannel();
646 233 : if (ret != HCCL_SUCCESS) {
647 212 : HCCL_WARNING("InitHccp channel unsuccessful ret:[%u].", ret);
648 : }
649 233 : } while (0);
650 :
651 234 : if (errorFlag) {
652 1 : HCCL_ERROR("[Init][CommClusterInfo]HcclCommInitClusterInfo failed, rankNum[%u], rank[%u], server[%s],"\
653 : "device[%d], return[0x%016llx]", opBaseHcom.rankTable.rankNum, rank,
654 : opBaseHcom.params.serverId.c_str(), opBaseHcom.params.logicDevId, HCCL_ERROR_CODE(ret));
655 1 : (void)HcclCommDestroy(opBaseHcom.pComm.get());
656 1 : opBaseHcom.pComm = nullptr;
657 1 : *comm = nullptr;
658 1 : return ret;
659 : }
660 233 : if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0 &&
661 0 : hcclNslbDp::GetInstance().InitNetCo() == HCCL_SUCCESS) {
662 0 : HCCL_INFO("HCCL try to entry SetGlobalRank_RankTableExit.");
663 : /* NSLB 填充 表1 表4 */
664 0 : CHK_RET(hcclNslbDp::GetInstance().SetCommInfo_RankTableExit(opBaseHcom.rankTable));
665 0 : hcclNslbDp::GetInstance().SetGlobalRank_RankTableExit(opBaseHcom.rankTable);
666 0 : hcclNslbDp::GetInstance().SendGlobalRankTable(rank);
667 : }
668 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
669 233 : CHK_RET(opBaseHcom.pComm->InitCollCommInner(rank));
670 : #endif
671 : /* 关键状态记录 */
672 233 : HCCL_INFO("%s success, rankNum[%u], rank[%u], server[%s], device[%d].",
673 : __func__, opBaseHcom.rankTable.rankNum, rank, opBaseHcom.params.serverId.c_str(),
674 : opBaseHcom.params.logicDevId);
675 233 : return HCCL_SUCCESS;
676 234 : }
677 :
678 0 : HcclResult HcclCommInitClusterInfoWrapper(struct hcclAsyncJob* job_){
679 0 : struct hcclCommInitRankTableAsyncJob* job = static_cast<hcclCommInitRankTableAsyncJob*>(job_);
680 0 : uint32_t rank = job->rank;
681 0 : HcclComm* comm = job->initComm;
682 0 : const char *clusterInfo = job->clusterInfo;
683 0 : s32 devId = job->devId;
684 0 : HCCL_DEBUG("[HcclCommInitClusterInfoWrapper] Set device devId: %d", devId);
685 0 : CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
686 : HCCL_ERROR("[HcclCommInitClusterInfoWrapper] set fail device[%d]", devId), HCCL_E_INTERNAL);
687 0 : HCCL_DEBUG("[HcclCommInitClusterInfoWrapper] Done Set device devId: %d", devId);
688 :
689 0 : HcclUs startut = TIME_NOW();
690 0 : s32 deviceLogicId = 0;
691 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
692 0 : HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].",
693 : __func__, clusterInfo, rank, deviceLogicId);
694 : // 入参合法性校验
695 0 : CHK_PTR_NULL(clusterInfo);
696 0 : CHK_PTR_NULL(comm);
697 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
698 0 : HCCLV2_FUNC_RUN(
699 : [&]() -> HcclResult {
700 : void *commV2 = nullptr;
701 : CHK_RET(HcclCommInitClusterInfoV2(clusterInfo, rank, &commV2));
702 : constexpr HcclCommConfig *config = nullptr; // 未配置为默认加速模式
703 : HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
704 : if (ret != HCCL_SUCCESS) {
705 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
706 : CHK_RET(HcclCommDestroyV2(commV2));
707 : commV2 = nullptr;
708 : *comm = nullptr;
709 : return ret;
710 : }
711 : return HCCL_SUCCESS;
712 : }());
713 : #endif
714 0 : HcclResult ret = InitExternalInput();
715 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
716 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
717 0 : ret = InitEnvConfig();
718 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
719 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
720 :
721 0 : std::string identifier = HCCL_WORLD_GROUP;
722 0 : CommConfig commConfig(identifier);
723 0 : std::string rankTableM;
724 0 : std::string realFilePath;
725 0 : ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
726 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
727 : HCCL_ERROR("[Init][HcclCommInitClusterInfoWrapper]errNo[0x%016llx], clusterInfo[%s], rank[%u], "
728 : "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
729 :
730 0 : HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
731 :
732 0 : HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
733 0 : CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
734 :
735 0 : CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
736 :
737 : /* 关键状态记录 */
738 0 : HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].",
739 : __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
740 0 : return HCCL_SUCCESS;
741 0 : }
742 :
743 236 : HcclResult HcclCommInitClusterInfo(const char *clusterInfo, uint32_t rank, HcclComm *comm)
744 : {
745 236 : if(hcclGroupDepth > 0){
746 0 : HcclResult ret = HCCL_SUCCESS;
747 0 : std::shared_ptr<struct hcclCommInitRankTableAsyncJob> job;
748 0 : EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitRankTableAsyncJob>()), return HCCL_E_PARA);
749 0 : job->clusterInfo = clusterInfo;
750 0 : job->rank = rank;
751 0 : job->initComm = comm;
752 0 : s32 devId = 0;
753 0 : CHK_RET(HcclDeviceRefresh(devId));
754 0 : job->devId = devId;
755 0 : ret = commInitTaskAppend(job, HcclCommInitClusterInfoWrapper, comm);
756 0 : return ret;
757 0 : }
758 236 : HcclUs startut = TIME_NOW();
759 236 : s32 deviceLogicId = 0;
760 236 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
761 235 : HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].",
762 : __func__, clusterInfo, rank, deviceLogicId);
763 : // 入参合法性校验
764 235 : CHK_PTR_NULL(clusterInfo);
765 234 : CHK_PTR_NULL(comm);
766 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
767 233 : HCCLV2_FUNC_RUN(
768 : [&]() -> HcclResult {
769 : void *commV2 = nullptr;
770 : CHK_RET(HcclCommInitClusterInfoV2(clusterInfo, rank, &commV2));
771 : constexpr HcclCommConfig *config = nullptr; // 未配置为默认加速模式
772 : HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
773 : if (ret != HCCL_SUCCESS) {
774 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
775 : CHK_RET(HcclCommDestroyV2(commV2));
776 : commV2 = nullptr;
777 : *comm = nullptr;
778 : return ret;
779 : }
780 : return HCCL_SUCCESS;
781 : }());
782 : #endif
783 233 : HcclResult ret = InitExternalInput();
784 233 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
785 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
786 233 : ret = InitEnvConfig();
787 233 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
788 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
789 :
790 233 : std::string identifier = HCCL_WORLD_GROUP;
791 233 : CommConfig commConfig(identifier);
792 233 : std::string rankTableM;
793 233 : std::string realFilePath;
794 233 : ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
795 233 : CHK_PRT_RET(ret != HCCL_SUCCESS,
796 : HCCL_ERROR("[Init][HcclCommInitClusterInfo]errNo[0x%016llx], clusterInfo[%s], rank[%u], "
797 : "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
798 :
799 231 : HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
800 :
801 231 : HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
802 231 : CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
803 :
804 230 : CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
805 :
806 : /* 关键状态记录 */
807 229 : HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].",
808 : __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
809 229 : return HCCL_SUCCESS;
810 233 : }
811 :
812 0 : HcclResult HcclCommInitClusterInfoMemConfig(const char *rankTableString, uint32_t rank,
813 : HcclCommConfig *config, HcclComm *comm)
814 : {
815 0 : HcclUs startut = TIME_NOW();
816 0 : s32 deviceLogicId = 0;
817 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
818 :
819 : // 入参合法性校验
820 0 : CHK_PTR_NULL(rankTableString);
821 0 : CHK_PTR_NULL(config);
822 0 : CHK_PTR_NULL(config->hcclCommName);
823 0 : CHK_PTR_NULL(comm);
824 :
825 0 : HCCL_RUN_INFO("Entry-%s: rankTableString[%s], rank[%u], deviceLogicId[%d].",
826 : __func__, rankTableString, rank, deviceLogicId);
827 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
828 0 : HCCLV2_FUNC_RUN(
829 : [&]() -> HcclResult {
830 : void *commV2 = nullptr;
831 : CHK_RET(HcclCommInitClusterInfoMemConfigV2(rankTableString, rank, config, &commV2));
832 : HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
833 : if (ret != HCCL_SUCCESS) {
834 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
835 : CHK_RET(HcclCommDestroyV2(commV2));
836 : commV2 = nullptr;
837 : *comm = nullptr;
838 : return ret;
839 : }
840 : return HCCL_SUCCESS;
841 : }());
842 : #endif
843 0 : HcclResult ret = InitExternalInput();
844 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
845 : HCCL_ERROR("[%s]errNo[0x%016llx] init external input error", __func__, HCCL_ERROR_CODE(ret)),
846 : HCCL_E_PARA);
847 0 : ret = InitEnvConfig();
848 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
849 : HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.", __func__, HCCL_ERROR_CODE(ret)),
850 : HCCL_E_PARA);
851 :
852 0 : CHK_PRT_RET(strlen(config->hcclCommName) == 0,
853 : HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] hcclCommName is error."),
854 : HCCL_E_PARA);
855 :
856 0 : std::string rankTableM(rankTableString);
857 0 : std::string identifier = config->hcclCommName;
858 0 : CommConfig commConfig(identifier);
859 0 : HCCL_RUN_INFO("Entry-%s: %s", "hcclCommName", identifier.c_str());
860 :
861 : /* 读取用户配置 */
862 0 : ret = commConfig.Load(config);
863 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
864 : HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig]errNo[0x%016llx] load comm config failed.",
865 : HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
866 :
867 0 : CHK_PRT_RET(deviceLogicId == INVALID_INT,
868 : HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] deviceLogicId is error."),
869 : HCCL_E_PARA);
870 :
871 0 : bool isCommNameExist = IsCommNameExistInOneSidedComms(deviceLogicId, identifier);
872 0 : CHK_PRT_RET(isCommNameExist, HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] comm Name exist."), HCCL_E_PARA);
873 :
874 0 : CHK_RET(InitOneSidedHcomInfo(deviceLogicId, identifier));
875 :
876 0 : const std::string commIdentifier = commConfig.GetConfigCommName();
877 0 : HcclOpInfoCtx &oneSidedHCom = GetOneSidedOpInfoCtx(deviceLogicId, commIdentifier);
878 :
879 0 : AddOneSidedIdentifier(identifier);
880 :
881 0 : ret = InitCommClusterInfo(rankTableM, rank, commConfig, oneSidedHCom, comm);
882 0 : if (ret != HCCL_SUCCESS) {
883 0 : HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] InitCommClusterInfo failed");
884 0 : DeleteOneSidedIdentifier(identifier);
885 0 : DeInitOneSidedHcomInfo(deviceLogicId, identifier);
886 0 : return ret;
887 : }
888 :
889 0 : g_oneSidedCommSet.insert(*comm);
890 :
891 : /* 关键状态记录 */
892 0 : HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, rankTableString[%s], rank[%u], deviceLogicId[%d].",
893 : __func__, DURATION_US(TIME_NOW() - startut), rankTableString, rank, deviceLogicId);
894 0 : return HCCL_SUCCESS;
895 0 : }
896 :
897 0 : HcclResult HcclCommInitClusterInfoConfigWrapper(struct hcclAsyncJob* job_){
898 0 : struct hcclCommInitRankTableConfigAsyncJob* job = static_cast<hcclCommInitRankTableConfigAsyncJob*>(job_);
899 0 : uint32_t rank = job->rank;
900 0 : HcclComm* comm = job->initComm;
901 0 : const char *clusterInfo = job->clusterInfo;
902 0 : HcclCommConfig *config = job->config;
903 0 : s32 devId = job->devId;
904 0 : HCCL_DEBUG("[HcclCommInitClusterInfoConfigWrapper] Set device devId: %d", devId);
905 0 : CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
906 : HCCL_ERROR("[HcclCommInitClusterInfoConfigWrapper] set fail device[%d]", devId), HCCL_E_INTERNAL);
907 0 : HCCL_DEBUG("[HcclCommInitClusterInfoConfigWrapper] Done Set device devId: %d", devId);
908 :
909 0 : HcclUs startut = TIME_NOW();
910 0 : s32 deviceLogicId = 0;
911 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
912 0 : HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].",
913 : __func__, clusterInfo, rank, deviceLogicId);
914 : // 入参合法性校验
915 0 : CHK_PTR_NULL(clusterInfo);
916 0 : CHK_PTR_NULL(comm);
917 :
918 : // 检查配置参数是否为空
919 0 : RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
920 : std::vector<std::string>({"HcclCommInitClusterInfoConfigWrapper", "nullptr", "config", "non-null pointer"}));
921 0 : CHK_SMART_PTR_NULL(config);
922 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
923 0 : const char *socNamePtr = aclrtGetSocName();
924 0 : CHK_PTR_NULL(socNamePtr);
925 0 : HCCLV2_FUNC_RUN(
926 : [&]() -> HcclResult {
927 : void *commV2 = nullptr;
928 : CHK_RET(HcclCommInitClusterInfoConfigV2(clusterInfo, rank, config, &commV2));
929 : HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
930 : if (ret != HCCL_SUCCESS) {
931 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
932 : CHK_RET(HcclCommDestroyV2(commV2));
933 : commV2 = nullptr;
934 : *comm = nullptr;
935 : return ret;
936 : }
937 : return HCCL_SUCCESS;
938 : }(),
939 : socNamePtr);
940 : #endif
941 0 : HcclResult ret = InitExternalInput();
942 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
943 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
944 0 : ret = InitEnvConfig();
945 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
946 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
947 :
948 0 : std::string identifier = HCCL_WORLD_GROUP;
949 0 : CommConfig commConfig(identifier);
950 0 : ret = commConfig.Load(config);
951 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
952 : HCCL_ERROR("[%s]errNo[0x%016llx] load comm config failed.",
953 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
954 :
955 0 : std::string rankTableM;
956 0 : std::string realFilePath;
957 0 : ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
958 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
959 : HCCL_ERROR("[Init][HcclCommInitClusterInfoConfigWrapper]errNo[0x%016llx] clusterInfo[%s] rank[%u] "
960 : "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
961 :
962 0 : HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
963 :
964 0 : HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
965 0 : CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
966 :
967 0 : CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
968 :
969 : // 记录groupName和UDI的映射
970 0 : HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
971 :
972 : /* 关键状态记录 */
973 0 : HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].",
974 : __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
975 0 : return HCCL_SUCCESS;
976 0 : }
977 :
978 10 : HcclResult HcclCommInitClusterInfoConfig(const char *clusterInfo, uint32_t rank, HcclCommConfig *config,
979 : HcclComm *comm)
980 : {
981 10 : if(hcclGroupDepth > 0){
982 0 : HcclResult ret = HCCL_SUCCESS;
983 0 : std::shared_ptr<struct hcclCommInitRankTableConfigAsyncJob> job;
984 0 : EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitRankTableConfigAsyncJob>()), return HCCL_E_PARA);
985 0 : job->clusterInfo = clusterInfo;
986 0 : job->rank = rank;
987 0 : job->config = config;
988 0 : job->initComm = comm;
989 0 : s32 devId = 0;
990 0 : CHK_RET(HcclDeviceRefresh(devId));
991 0 : job->devId = devId;
992 0 : ret = commInitTaskAppend(job, HcclCommInitClusterInfoConfigWrapper, comm);
993 0 : return ret;
994 0 : }
995 10 : HcclUs startut = TIME_NOW();
996 10 : s32 deviceLogicId = 0;
997 10 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
998 9 : HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].",
999 : __func__, clusterInfo, rank, deviceLogicId);
1000 : // 入参合法性校验
1001 9 : CHK_PTR_NULL(clusterInfo);
1002 8 : CHK_PTR_NULL(comm);
1003 :
1004 : // 检查配置参数是否为空
1005 7 : RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
1006 : std::vector<std::string>({"HcclCommInitClusterInfoConfig", "nullptr", "config", "non-null pointer"}));
1007 7 : CHK_SMART_PTR_NULL(config);
1008 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
1009 7 : HCCLV2_FUNC_RUN(
1010 : [&]() -> HcclResult {
1011 : void *commV2 = nullptr;
1012 : CHK_RET(HcclCommInitClusterInfoConfigV2(clusterInfo, rank, config, &commV2));
1013 : HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
1014 : if (ret != HCCL_SUCCESS) {
1015 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
1016 : CHK_RET(HcclCommDestroyV2(commV2));
1017 : commV2 = nullptr;
1018 : *comm = nullptr;
1019 : return ret;
1020 : }
1021 : return HCCL_SUCCESS;
1022 : }());
1023 : #endif
1024 7 : HcclResult ret = InitExternalInput();
1025 7 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
1026 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1027 7 : ret = InitEnvConfig();
1028 7 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
1029 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1030 :
1031 7 : std::string identifier = HCCL_WORLD_GROUP;
1032 7 : CommConfig commConfig(identifier);
1033 7 : ret = commConfig.Load(config);
1034 7 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1035 : HCCL_ERROR("[%s]errNo[0x%016llx] load comm config failed.",
1036 : __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1037 :
1038 6 : std::string rankTableM;
1039 6 : std::string realFilePath;
1040 6 : ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
1041 6 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1042 : HCCL_ERROR("[Init][HcclCommInitClusterInfoConfig]errNo[0x%016llx] clusterInfo[%s] rank[%u] "
1043 : "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
1044 :
1045 5 : HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
1046 :
1047 5 : HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
1048 5 : CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
1049 :
1050 4 : CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
1051 :
1052 : // 记录groupName和UDI的映射
1053 4 : HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
1054 :
1055 : /* 关键状态记录 */
1056 4 : HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].",
1057 : __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
1058 4 : return HCCL_SUCCESS;
1059 7 : }
1060 :
1061 1 : HcclResult HcclCreateSubCommConfigInner(hccl::hcclComm *globalComm, uint32_t rankNum, uint32_t *rankIds,
1062 : uint32_t subCommRankId, CommConfig &commConfig, HcclComm *subComm)
1063 : {
1064 1 : HcclResult ret = HCCL_SUCCESS;
1065 1 : HcclCommParams globalParams{};
1066 1 : RankTable_t globalRankTable{};
1067 1 : CHK_RET(globalComm->GetCommParams(globalParams));
1068 1 : CHK_RET(globalComm->GetCommRankTable(globalRankTable));
1069 :
1070 1 : HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
1071 :
1072 1 : const std::string commIdentifier = commConfig.GetConfigCommName();
1073 1 : auto iter = opBaseHcom.opGroup2CommMap.find(commIdentifier);
1074 1 : CHK_PRT_RET(iter != opBaseHcom.opGroup2CommMap.end(),
1075 : HCCL_ERROR("[%s]errNo[0x%016llx]The comm name[%s] already exists in Group2Comm map.",
1076 : __func__, HCCL_ERROR_CODE(HCCL_E_PARA), commIdentifier.c_str()),
1077 : HCCL_E_PARA);
1078 :
1079 1 : std::shared_ptr<hccl::hcclComm> pComm;
1080 1 : pComm.reset(new (std::nothrow) hccl::hcclComm(
1081 2 : commConfig.GetConfigBufferSize(), commConfig.GetConfigBufferSize(), commIdentifier, commConfig.GetConfigBufferName()));
1082 1 : CHK_PTR_NULL(pComm);
1083 :
1084 1 : bool errorFlag = false;
1085 1 : hccl::HcclCommParams subParams{};
1086 1 : hccl::RankTable_t subRankTable{};
1087 : do {
1088 1 : RankConsistentcyChecker::GetInstance().SetCheckCannVersionSwitch(true); // 打开CANN软件版本校验开关
1089 :
1090 1 : std::unique_ptr<TopoinfoRanktablePartition> pTopoPartition;
1091 1 : pTopoPartition.reset(new (std::nothrow) hccl::TopoinfoRanktablePartition(globalParams, globalRankTable));
1092 1 : CHK_SMART_PTR_NULL(pTopoPartition);
1093 1 : CHK_RET(pTopoPartition->GenerateSubRankTable(rankNum, rankIds, subRankTable));
1094 1 : CHK_RET(pTopoPartition->GenerateSubParams(subRankTable, subCommRankId, subParams));
1095 :
1096 1 : std::string rankTableM = "";
1097 1 : CHK_RET(pTopoPartition->GetRankTableStr(subRankTable, rankTableM));
1098 :
1099 1 : ret = InitOtherInfo(subParams, rankTableM.c_str());
1100 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init other Info.",
1101 : __func__, HCCL_ERROR_CODE(ret)), errorFlag = true);
1102 1 : ret = pComm->init(subParams, commConfig, subRankTable);
1103 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] hcclComm init error.",
1104 : __func__, HCCL_ERROR_CODE(ret)), errorFlag = true);
1105 1 : HCCL_INFO("[HcclCreateSubCommConfigInner]comm id[%s]", subParams.id.internal);
1106 :
1107 : /* 设置确定性计算配置 */
1108 1 : ret = pComm->SetDeterministicConfig(commConfig.GetConfigDeterministic());
1109 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1110 : HCCL_ERROR("[%s]errNo[0x%016llx] set deterministic error.", __func__, HCCL_ERROR_CODE(ret)),
1111 : errorFlag = true);
1112 :
1113 : // 设置TC/SL配置
1114 1 : ret = pComm->SetQpQosAttr(commConfig.GetConfigTrafficClass(), commConfig.GetConfigServiceLevel());
1115 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] set TC and SL error",
1116 : __func__, HCCL_ERROR_CODE(ret)), errorFlag = true);
1117 1 : if (commConfig.GetConfigJobID() != 0) {
1118 0 : HCCL_RUN_INFO("[NSLBDP]GetConfigJobID = %llu,GetConfigWorldRankID = %u.",
1119 : commConfig.GetConfigJobID(), commConfig.GetConfigWorldRankID());
1120 0 : hcclNslbDp::GetInstance().SetGlobalCommTaskId(commConfig.GetConfigJobID());
1121 0 : hcclNslbDp::GetInstance().SetGlobalCommNodeId(commConfig.GetConfigWorldRankID());
1122 : }
1123 : /* 设置AIV模式 */
1124 1 : ret = pComm->SetAivModeConfig(commConfig.GetConfigAivMode());
1125 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1126 : HCCL_ERROR("[%s]errNo[0x%016llx] set aivMode error.", __func__, HCCL_ERROR_CODE(ret)),
1127 : errorFlag = true);
1128 :
1129 : /* 设置only AIV模式 */
1130 1 : ret = pComm->SetOnlyAivModeConfig(commConfig.GetConfigIsOnlyAivMode());
1131 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1132 : HCCL_ERROR("[%s]errNo[0x%016llx] set only aivMode error.", __func__, HCCL_ERROR_CODE(ret)),
1133 : errorFlag = true);
1134 :
1135 : /* 设置AICPU */
1136 1 : ret = pComm->SetAicpuUnfoldConfig(commConfig.GetConfigAicpuUnfold());
1137 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1138 : HCCL_ERROR("[%s]errNo[0x%016llx] set aicpu error.", __func__, HCCL_ERROR_CODE(ret)),
1139 : errorFlag = true);
1140 :
1141 : /* 设置HcclExecTimeOut */
1142 1 : ret = pComm->SetExecTimeOutConfig(commConfig.GetConfigExecTimeOut());
1143 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1144 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set execTimeOut error.", HCCL_ERROR_CODE(ret)),
1145 : errorFlag = true);
1146 :
1147 : /* 设置HcclAlgo */
1148 1 : ret = pComm->SetAlgoConfig(commConfig.GetConfigHcclAlgoMap());
1149 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1150 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set hcclAlgo error.", HCCL_ERROR_CODE(ret)),
1151 : errorFlag = true);
1152 :
1153 1 : ret = InitWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
1154 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1155 : HCCL_ERROR("[%s]errNo[0x%016llx] init workflow mode error.", __func__, HCCL_ERROR_CODE(ret)),
1156 : errorFlag = true);
1157 :
1158 1 : ret = DisplayRanktableInfo(subRankTable);
1159 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1160 : HCCL_ERROR("[%s]errNo[0x%016llx] print ranktable info error.", __func__, HCCL_ERROR_CODE(ret)),
1161 : errorFlag = true);
1162 :
1163 : /* 设置独立算子参数 */
1164 1 : ret = pComm->SetIndependentOpConfig(commConfig, subRankTable);
1165 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1166 : HCCL_ERROR("[%s] errNo[0x%016llx] set SetIndependentOpConfig error.", __func__, HCCL_ERROR_CODE(ret)),
1167 : errorFlag = true);
1168 : // 初始化完成的comm指针赋给出参
1169 1 : *subComm = pComm.get();
1170 1 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
1171 1 : opBaseHcom.opGroup2CommMap[pComm->GetIdentifier()] = pComm;
1172 1 : lock.unlock();
1173 :
1174 1 : ret = HcomSetGroupTopoInfo(pComm->GetIdentifier().c_str(), rankNum);
1175 1 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1176 : HCCL_ERROR("[%s]errNo[0x%016llx] set group topo info error.", __func__, HCCL_ERROR_CODE(ret)),
1177 : errorFlag = true);
1178 1 : ret = pComm->InitHccpChannel();
1179 1 : if (ret != HCCL_SUCCESS) {
1180 0 : HCCL_WARNING("InitHccp channel unsuccessful ret:[%u].", ret);
1181 : }
1182 1 : } while(0);
1183 :
1184 1 : if (errorFlag) {
1185 0 : HCCL_ERROR("[%s]Create sub communication failed, return[0x%016llx], " \
1186 : "rankNum[%u], subCommRankId[%u], sub commm identifier[%s], server[%s], logicDevId[%d]",
1187 : __func__, HCCL_ERROR_CODE(ret), rankNum, subCommRankId, commIdentifier.c_str(),
1188 : GetLocalServerId(subParams.serverId).c_str(), subParams.logicDevId);
1189 0 : (void)HcclCommDestroy(pComm.get());
1190 0 : return ret;
1191 : }
1192 1 : std::string identifier = pComm->GetIdentifier();
1193 :
1194 : /* NSLB 填充 表1 */
1195 1 : CHK_RET(hcclNslbDp::GetInstance().SetCommInfo_NoRankTable(subRankTable, identifier));
1196 1 : hcclNslbDp::GetInstance().SendTableFir(subCommRankId);
1197 :
1198 1 : HCCL_RUN_INFO("%s success, sub commm identifier[%s], rankNum[%u], rank[%u], server[%s], device[%d].",
1199 : __func__, commIdentifier.c_str(), subRankTable.rankNum, subCommRankId,
1200 : subParams.serverId.c_str(), subParams.logicDevId);
1201 1 : return HCCL_SUCCESS;
1202 1 : }
1203 :
1204 1 : HcclResult SubCommIsOneSidedComm(HcclComm *comm)
1205 : {
1206 1 : if (IsOneSidedComm(*comm)) {
1207 0 : HCCL_ERROR("[%s]errNo[0x%016llx] oneSidedComm does not support create sub comm.",
1208 : __func__, HCCL_ERROR_CODE(HCCL_E_NOT_SUPPORT));
1209 0 : return HCCL_E_NOT_SUPPORT;
1210 : }
1211 1 : return HCCL_SUCCESS;
1212 : }
1213 :
1214 9 : HcclResult HcclCreateSubCommConfig(HcclComm *comm, uint32_t rankNum, uint32_t *rankIds,
1215 : uint64_t subCommId, uint32_t subCommRankId, HcclCommConfig *config, HcclComm *subComm)
1216 : {
1217 9 : HcclUs startut = TIME_NOW();
1218 9 : s32 deviceLogicId = 0;
1219 9 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
1220 8 : HCCL_RUN_INFO("Entry-%s: rankNum[%u], rank[%u], deviceLogicId[%d]",
1221 : __func__, rankNum, subCommRankId, deviceLogicId);
1222 8 : CHK_SMART_PTR_NULL(subComm);
1223 7 : if (*subComm != nullptr) {
1224 0 : HCCL_WARNING("[%s]The value pointed by output param subComm is not nullptr. " \
1225 : "Please be ware of possible memory leak.", __func__);
1226 : }
1227 7 : CHK_PRT_RET(rankIds == nullptr && subCommId == INVALID_SUBCOMM_ID,
1228 : HCCL_RUN_INFO("[HCCL_TRACE]HcclCreateSubCommConfig return, rankIds is nullptr and subCommId is 0xFFFFFFFF, " \
1229 : "this device is not in the sub comm, deviceLogicId[%u].", deviceLogicId), HCCL_SUCCESS);
1230 6 : CHK_PRT_RET(rankIds == nullptr || subCommId == INVALID_SUBCOMM_ID,
1231 : HCCL_ERROR("[%s]errNo[0x%016llx] " \
1232 : "rankIds[%p] is nullptr xor subCommId[%llu] is invalid. " \
1233 : "The two parameters should only be both valid or both invalid.",
1234 : __func__, HCCL_ERROR_CODE(HCCL_E_PARA), rankIds, subCommId), HCCL_E_PARA);
1235 :
1236 4 : HcclResult ret = HCCL_SUCCESS;
1237 : // 入参合法性校验
1238 4 : CHK_PRT_RET((rankNum == 0), HCCL_ERROR("[%s]errNo[0x%016llx] Rank num cannot be zero.",
1239 : __func__, HCCL_ERROR_CODE(HCCL_E_PARA)), HCCL_E_PARA);
1240 3 : CHK_PRT_RET((subCommRankId >= rankNum), HCCL_ERROR("[%s]errNo[0x%016llx] subCommRankId[%u] should be less " \
1241 : "than rankNum[%u].", __func__, HCCL_ERROR_CODE(HCCL_E_PARA), subCommRankId, rankNum), HCCL_E_PARA);
1242 :
1243 22 : RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
1244 : std::vector<std::string>({"HcclCreateSubCommConfig", "nullptr", "config", "non-null pointer"}));
1245 2 : CHK_SMART_PTR_NULL(config);
1246 1 : CHK_SMART_PTR_NULL(comm);
1247 1 : CHK_RET(SubCommIsOneSidedComm(comm));
1248 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
1249 1 : HCCLV2_FUNC_RUN(
1250 : [&]() -> HcclResult {
1251 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(*comm);
1252 : CHK_PTR_NULL(hcclComm);
1253 : void* commV2 = hcclComm->GetCommunicatorV2();
1254 : CHK_PTR_NULL(commV2);
1255 : void* subCommV2 = nullptr;
1256 : CHK_RET(HcclCreateSubCommConfigV2(&commV2, rankNum, rankIds, subCommId, subCommRankId, config, &subCommV2));
1257 : HcclResult ret = HcclCommInitCollComm(subCommRankId, &subCommV2, config, subComm);
1258 : if (ret != HCCL_SUCCESS) {
1259 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed. Destroy subCommV2");
1260 : CHK_RET(HcclCommDestroyV2(subCommV2));
1261 : subCommV2 = nullptr;
1262 : *subComm = nullptr;
1263 : return ret;
1264 : }
1265 : return HCCL_SUCCESS;
1266 : }());
1267 : #endif
1268 1 : ret = InitExternalInput();
1269 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1270 : HCCL_ERROR("[%s]errNo[0x%016llx] init external input error", __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1271 1 : ret = InitEnvConfig();
1272 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1273 : HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.", __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1274 :
1275 1 : hccl::hcclComm *globalComm = static_cast<hccl::hcclComm*>(*comm);
1276 1 : CHK_PTR_NULL(globalComm);
1277 :
1278 1 : std::string identifier = globalComm->GetIdentifier() + "_sub_" + to_string(subCommId);
1279 1 : CommConfig commConfig(identifier);
1280 1 : ret = commConfig.Load(config);
1281 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1282 : HCCL_ERROR("[%s]errNo[0x%016llx] load comm config failed.", __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1283 :
1284 1 : CHK_RET(HcclCreateSubCommConfigInner(globalComm, rankNum, rankIds, subCommRankId, commConfig, subComm));
1285 :
1286 : // 记录groupName和UDI的映射
1287 1 : HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
1288 :
1289 : /* 关键状态记录 */
1290 1 : HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, " \
1291 : "sub commm identifier[%s], rankNum[%u], rank[%u], deviceLogicId[%d]",
1292 : __func__, DURATION_US(TIME_NOW() - startut), commConfig.GetConfigCommName().c_str(),
1293 : rankNum, subCommRankId, deviceLogicId);
1294 1 : return HCCL_SUCCESS;
1295 1 : }
1296 :
1297 16 : HcclResult HcclGetRootInfo(HcclRootInfo *rootInfo)
1298 : {
1299 16 : HcclUs startut = TIME_NOW();
1300 16 : s32 deviceLogicId = 0;
1301 16 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
1302 :
1303 : // input check
1304 16 : CHK_PTR_NULL(rootInfo);
1305 15 : HCCL_RUN_INFO("Entry-HcclGetRootInfo:rootInfo[%p], deviceLogicId[%d] ", rootInfo, deviceLogicId);
1306 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
1307 15 : HCCLV2_FUNC_RUN(HcclGetRootInfoV2(rootInfo));
1308 : #endif
1309 : // get commId from env
1310 15 : CHK_RET(InitExternalInput());
1311 15 : CHK_RET(InitEnvConfig());
1312 :
1313 : HcclRootHandle rootHandle;
1314 15 : std::shared_ptr<TopoInfoDetect> topoDetectServer;
1315 15 : EXCEPTION_CATCH((topoDetectServer = std::make_shared<TopoInfoDetect>()),
1316 : return HCCL_E_MEMORY);
1317 15 : HcclResult ret = topoDetectServer->SetupServer(rootHandle);
1318 15 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s][%s]%s failed, ret[%u]",
1319 : LOG_KEYWORDS_INIT_GROUP.c_str(), LOG_KEYWORDS_RANKTABLE_DETECT.c_str(), __func__, ret), ret);
1320 :
1321 : if (sizeof(HcclRootHandle) > HCCL_ROOT_INFO_BYTES) {
1322 : HCCL_ERROR("[Get][RootInfo]hccl root info overflow. max length: %u, actual:%zu, identifier[%s]",
1323 : HCCL_ROOT_INFO_BYTES, sizeof(HcclRootHandle), rootHandle.identifier);
1324 : return HCCL_E_INTERNAL;
1325 : } else {
1326 13 : s32 sRet = memcpy_s(rootInfo->internal, HCCL_ROOT_INFO_BYTES, &rootHandle, sizeof(HcclRootHandle));
1327 13 : CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Get][RootInfo]memcpy root info fail. errorno[%d] "\
1328 : "params:destMaxSize[%u], count[%u]", sRet, HCCL_ROOT_INFO_BYTES,
1329 : sizeof(HcclRootHandle)), HCCL_E_MEMORY);
1330 : }
1331 :
1332 13 : HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
1333 13 : EXCEPTION_CATCH(opBaseInfo.hcclCommTopoInfoDetectServer.insert({rootHandle.identifier, topoDetectServer}),
1334 : return HCCL_E_MEMORY);
1335 : /* 首节点诊断信息记录 */
1336 13 : HCCL_RUN_INFO("[HCCL_TRACE]HcclGetRootInfo success, take time [%lld]us, identifier[%s]",
1337 : DURATION_US(TIME_NOW() - startut), rootHandle.identifier);
1338 13 : return HCCL_SUCCESS;
1339 15 : }
1340 :
1341 0 : HcclResult GetSelfClusterInfo(const HcclBasicRankInfo &rankInfo, HcclCommParams ¶ms)
1342 : {
1343 0 : params.deviceType = rankInfo.deviceType;
1344 0 : params.rank = rankInfo.rank;
1345 0 : params.userRank = rankInfo.rank;
1346 0 : params.logicDevId = rankInfo.deviceLogicID;
1347 0 : params.totalRanks = rankInfo.rankSize;
1348 0 : params.serverId = rankInfo.hostIP.GetReadableAddress();
1349 :
1350 0 : return HCCL_SUCCESS;
1351 : }
1352 :
1353 5 : HcclResult HcclGetCommName(HcclComm commHandle, char *commName)
1354 : {
1355 5 : CHK_PTR_NULL(commHandle);
1356 4 : CHK_PTR_NULL(commName);
1357 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
1358 3 : HCCLV2_FUNC_RUN(
1359 : [&]() -> HcclResult {
1360 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(commHandle);
1361 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
1362 : CHK_PTR_NULL(commV2);
1363 : CHK_RET(HcclGetCommNameV2(commV2, commName));
1364 : return HCCL_SUCCESS;
1365 : }());
1366 : #endif
1367 3 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(commHandle);
1368 3 : s32 ret = strncpy_s(commName, ROOTINFO_INDENTIFIER_MAX_LENGTH, hcclComm->GetIdentifier().c_str(),
1369 6 : hcclComm->GetIdentifier().size());
1370 3 : CHK_PRT_RET(ret != EOK, HCCL_ERROR("HcclGetCommName str copy fail. return[%d]", ret), HCCL_E_INTERNAL);
1371 3 : HCCL_INFO("HcclGetCommName input handle=%p commName=%s", commHandle, commName);
1372 3 : return HCCL_SUCCESS;
1373 : }
1374 :
1375 5 : HcclResult HcclGetCommHandle(const char *commName, std::shared_ptr<hccl::hcclComm> &comm)
1376 : {
1377 5 : CHK_PTR_NULL(commName);
1378 3 : std::string group(commName);
1379 :
1380 3 : s32 deviceLogicId = 0;
1381 3 : HcclResult ret = HCCL_SUCCESS;
1382 3 : ret = hrtGetDevice(&deviceLogicId);
1383 9 : if (ret == HCCL_SUCCESS && IsCommNameExistInOneSidedComms(deviceLogicId, commName)) {
1384 0 : HcclOpInfoCtx &oneSidedHcom = GetOneSidedOpInfoCtx(deviceLogicId, commName);
1385 0 : comm = oneSidedHcom.pComm;
1386 0 : return HCCL_SUCCESS;
1387 : }
1388 :
1389 3 : HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
1390 3 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
1391 3 : auto iter = opBaseHcom.opGroup2CommMap.find(group);
1392 3 : if (iter == opBaseHcom.opGroup2CommMap.end()) {
1393 3 : HCCL_WARNING("please check the group name is correct, group=%s", commName);
1394 3 : return HCCL_E_PARA;
1395 : } else {
1396 0 : comm = iter->second;
1397 : }
1398 0 : return HCCL_SUCCESS;
1399 3 : }
1400 :
1401 3 : HcclResult HcclCommGetHandleWithName(const char* commName, HcclComm* comm)
1402 : {
1403 3 : CHK_PTR_NULL(commName);
1404 2 : CHK_PTR_NULL(comm);
1405 1 : std::string group(commName);
1406 :
1407 1 : s32 deviceLogicId = 0;
1408 1 : HcclResult ret = HCCL_SUCCESS;
1409 1 : ret = hrtGetDevice(&deviceLogicId);
1410 3 : if (ret == HCCL_SUCCESS && IsCommNameExistInOneSidedComms(deviceLogicId, commName)) {
1411 0 : HcclOpInfoCtx &oneSidedHcom = GetOneSidedOpInfoCtx(deviceLogicId, commName);
1412 0 : *comm = static_cast<HcclComm>(oneSidedHcom.pComm.get());
1413 0 : return HCCL_SUCCESS;
1414 : }
1415 :
1416 1 : HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
1417 1 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
1418 1 : auto iter = opBaseHcom.opGroup2CommMap.find(group);
1419 1 : if (iter == opBaseHcom.opGroup2CommMap.end()) {
1420 1 : HCCL_ERROR("please check the group name is correct, group=%s", commName);
1421 1 : return HCCL_E_PARA;
1422 : } else {
1423 0 : *comm = static_cast<HcclComm>(iter->second.get());
1424 : }
1425 0 : return HCCL_SUCCESS;
1426 1 : }
1427 :
1428 0 : HcclResult HcclGetCommConnections(const HcclRootHandle &rootHandle, const std::string &identifier,
1429 : HcclCommConnections &commConnections)
1430 : {
1431 0 : HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
1432 0 : auto iterServer = opBaseInfo.hcclCommTopoInfoDetectServer.find(rootHandle.identifier);
1433 0 : if (iterServer == opBaseInfo.hcclCommTopoInfoDetectServer.end()) {
1434 0 : commConnections.isRoot = false;
1435 : } else {
1436 0 : commConnections.isRoot = true;
1437 0 : CHK_RET(iterServer->second->GetServerConnections(commConnections.serverConnections));
1438 : }
1439 :
1440 0 : auto iterAgent = opBaseInfo.hcclCommTopoInfoDetectAgent.find(identifier);
1441 0 : if (iterAgent == opBaseInfo.hcclCommTopoInfoDetectAgent.end()) {
1442 0 : HCCL_ERROR("hccl get agent connections failed, identifier=%s", identifier.c_str());
1443 0 : return HCCL_E_PARA;
1444 : } else {
1445 0 : CHK_RET(iterAgent->second->GetAgentConnection(commConnections.agentConnection));
1446 : }
1447 0 : return HCCL_SUCCESS;
1448 : }
1449 :
1450 467 : void HcclCloseCommConnections(const std::string &identifier)
1451 : {
1452 467 : HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
1453 467 : EXCEPTION_CATCH(opBaseInfo.hcclCommTopoInfoDetectServer.erase(identifier), return);
1454 467 : EXCEPTION_CATCH(opBaseInfo.hcclCommTopoInfoDetectAgent.erase(identifier), return);
1455 467 : return;
1456 : }
1457 :
1458 0 : HcclResult SetupHierarchical(const u32 nRanks, const u32 rank, const HcclRootHandle &rootHandle,
1459 : std::shared_ptr<TopoInfoDetect> &topoDetectAgent, std::shared_ptr<TopoInfoDetect> &topoDetectMember,
1460 : HcclRankHandle& groupLeader)
1461 : {
1462 : HcclResult ret;
1463 : HcclRankHandle rankHandle;
1464 0 : std::vector<HcclIpAddress> whitelist;
1465 0 : std::shared_ptr<TopoInfoDetect> topoDetectGroupLeader;
1466 0 : EXCEPTION_CATCH((topoDetectGroupLeader = std::make_shared<TopoInfoDetect>()), return HCCL_E_MEMORY);
1467 :
1468 0 : CHK_PTR_NULL(topoDetectAgent);
1469 :
1470 0 : ret = topoDetectAgent->PrepareHandle(rankHandle, whitelist);
1471 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1472 : "prepare rank handle error", HCCL_ERROR_CODE(ret)), ret);
1473 :
1474 0 : CommConfig commConfig;
1475 0 : ret = topoDetectAgent->SetupAgent(nRanks, rank, rootHandle, rankHandle, commConfig); // member connect to root
1476 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1477 : "setup topo detect error", HCCL_ERROR_CODE(ret)), ret);
1478 :
1479 0 : ret = topoDetectAgent->GetGroupLeader(groupLeader); // get group leader 此时group leader未监听
1480 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1481 : "get group leader info error", HCCL_ERROR_CODE(ret)), ret);
1482 :
1483 0 : std::shared_ptr<HcclSocket> agentConnRoot;
1484 0 : ret = topoDetectAgent->GetAgentConnection(agentConnRoot);
1485 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1486 : "get agent connection ptr error", HCCL_ERROR_CODE(ret)), ret);
1487 : // 判读当前rank是否被选为GroupLeader
1488 0 : if (std::strcmp(groupLeader.ip, rankHandle.ip) == 0 && (groupLeader.rankId == rank)) {
1489 0 : HCCL_RUN_INFO("[Init][CommRootInfo][SetupHierarchical]rank[%u] is group leader", rank);
1490 0 : CHK_PTR_NULL(topoDetectGroupLeader);
1491 0 : std::shared_ptr<HcclSocket> groupLeaderConnRoot;
1492 :
1493 : //保留下Agent->Server的Socket
1494 0 : ret = topoDetectAgent->GetAgentConnection(groupLeaderConnRoot);
1495 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1496 : "get group leader connection ptr error", HCCL_ERROR_CODE(ret)), ret);
1497 :
1498 : // 开启GroupLeader监听
1499 0 : ret = topoDetectGroupLeader->GroupLeaderListen(rankHandle, whitelist); // rank bind one local port
1500 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1501 : "rank bind port error", HCCL_ERROR_CODE(ret)), ret);
1502 :
1503 : //传给root 监听的端口
1504 0 : ret = topoDetectAgent ->SendGroupLeaderPort(groupLeaderConnRoot, rankHandle);
1505 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1506 : "setup group leader error", HCCL_ERROR_CODE(ret)), ret);
1507 :
1508 0 : HCCL_RUN_INFO("rankHandle.port[%u]", rankHandle.port);
1509 :
1510 0 : ret = topoDetectGroupLeader->GroupLeaderAccept(rankHandle, whitelist, groupLeaderConnRoot);
1511 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1512 : "setup group leader error", HCCL_ERROR_CODE(ret)), ret);
1513 0 : }
1514 0 : ret = topoDetectAgent->SetupRank(agentConnRoot);
1515 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1516 : "set up rank to get newest grpleader error", HCCL_ERROR_CODE(ret)), ret);
1517 0 : ret = topoDetectAgent->GetGroupLeader(groupLeader); // get group leader 此时group leader已监听 更新groupLeader 准备连接groupLeader
1518 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1519 : "get group leader info error", HCCL_ERROR_CODE(ret)), ret);
1520 0 : CHK_PTR_NULL(topoDetectMember);
1521 0 : ret = topoDetectMember->SetupGroupMember(nRanks, rank, groupLeader); // group member connect to group leader
1522 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
1523 : "setup group member error", HCCL_ERROR_CODE(ret)), ret);
1524 :
1525 0 : return HCCL_SUCCESS;
1526 0 : }
1527 :
1528 0 : HcclResult GetTopoDetectInfo(hccl::HcclCommParams ¶ms, RankTable_t &rankTable,
1529 : HcclBasicRankInfo &localRankInfo, const HcclRootHandle &rootHandle,
1530 : std::shared_ptr<TopoInfoDetect> &topoDetectAgent, std::shared_ptr<TopoInfoDetect> &topoDetectMember)
1531 : {
1532 0 : HcclResult ret = HCCL_SUCCESS;
1533 0 : ret = topoDetectMember->GetCluterInfo(rankTable);
1534 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] " \
1535 : "GetCluterInfo error", HCCL_ERROR_CODE(ret)), ret);
1536 :
1537 0 : ret = topoDetectMember->GetLocalRankInfo(localRankInfo);
1538 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] "\
1539 : "GetLocalRankInfo error.", HCCL_ERROR_CODE(ret)), ret);
1540 :
1541 0 : ret = GetSelfClusterInfo(localRankInfo, params);
1542 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] "\
1543 : "GetRankInfo error.", HCCL_ERROR_CODE(ret)), ret);
1544 :
1545 0 : ret = topoDetectMember->WaitComplete(rootHandle);
1546 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] "\
1547 : "wait complete topo detect error", HCCL_ERROR_CODE(ret)), ret);
1548 :
1549 0 : ret = topoDetectAgent->GetAgentListenSocket(params.commPortConfig);
1550 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1551 : HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]HcclGetCommListenSockets failed."), ret);
1552 :
1553 0 : return HCCL_SUCCESS;
1554 : }
1555 :
1556 0 : HcclResult InitCommRootInfo(const u32 nRanks, const u32 rank, const HcclRootHandle &rootHandle,
1557 : const CommConfig &commConfig, HcclComm *comm)
1558 : {
1559 0 : HcclResult ret = HCCL_SUCCESS;
1560 0 : bool errorFlag = false;
1561 0 : std::shared_ptr<hccl::hcclComm> pComm;
1562 0 : HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
1563 0 : const std::string commIdentifier = commConfig.GetConfigCommName();
1564 0 : auto iter = opBaseHcom.opGroup2CommMap.find(commIdentifier);
1565 0 : CHK_PRT_RET(
1566 : iter != opBaseHcom.opGroup2CommMap.end(),
1567 : HCCL_ERROR("[Init][InitCommRootInfo]errNo[0x%016llx] The comm name[%s] already exists in Group2Comm map.",
1568 : HCCL_ERROR_CODE(HCCL_E_PARA), commIdentifier.c_str()),
1569 : HCCL_E_PARA
1570 : );
1571 0 : hccl::HcclCommParams params;
1572 0 : RankTable_t rankTable;
1573 0 : HcclBasicRankInfo localRankInfo;
1574 :
1575 : DevType devType;
1576 0 : CHK_RET(hrtGetDeviceType(devType));
1577 0 : bool retryEnable = devType == DevType::DEV_TYPE_910_93 && !commConfig.GetConfigAivMode() && (
1578 0 : commConfig.GetConfigInterServerRetryEnable() || commConfig.GetConfigInterSuperPodRetryEnable());
1579 0 : HCCL_INFO("[InitCommRootInfo] retryEnable is [%d]", retryEnable);
1580 :
1581 : do {
1582 0 : RankConsistentcyChecker::GetInstance().SetCheckCannVersionSwitch(true); // 打开CANN软件版本校验开关
1583 0 : pComm.reset(new hccl::hcclComm(commConfig.GetConfigBufferSize(), commConfig.GetConfigBufferSize(),
1584 0 : commIdentifier, commConfig.GetConfigBufferName()));
1585 0 : CHK_SMART_PTR_NULL(pComm);
1586 :
1587 0 : std::shared_ptr<TopoInfoDetect> topoDetectAgent;
1588 0 : EXCEPTION_CATCH((topoDetectAgent = std::make_shared<TopoInfoDetect>()), return HCCL_E_MEMORY);
1589 0 : topoDetectAgent->SetIsInterSuperPodRetryEnable(commConfig.GetConfigInterSuperPodRetryEnable());
1590 : // 32k 作为agent开启阈值
1591 0 : if (nRanks > TOPO_HIERARCHICAL_ENABLE_THRESHOLD ) {
1592 0 : HCCL_RUN_INFO("[Init][CommRootInfo][Hierarchical]nRanks[%u] entry hierarchical topo detect.", nRanks);
1593 :
1594 0 : std::shared_ptr<TopoInfoDetect> topoDetectMember;
1595 0 : EXCEPTION_CATCH((topoDetectMember = std::make_shared<TopoInfoDetect>()), return HCCL_E_MEMORY);
1596 0 : topoDetectMember->SetIsInterSuperPodRetryEnable(commConfig.GetConfigInterSuperPodRetryEnable());
1597 :
1598 : HcclRankHandle groupLeader;
1599 0 : ret = SetupHierarchical(nRanks, rank, rootHandle, topoDetectAgent, topoDetectMember, groupLeader);
1600 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo]errNo[0x%016llx] setup " \
1601 : "hierarchical error", HCCL_ERROR_CODE(ret)), errorFlag = true);
1602 :
1603 0 : ret = GetTopoDetectInfo(params, rankTable, localRankInfo, groupLeader, topoDetectAgent, topoDetectMember);
1604 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][Hierarchical]errNo[0x%016llx] setup " \
1605 : "GetTopoDetectInfo error", HCCL_ERROR_CODE(ret)), errorFlag = true);
1606 0 : } else {
1607 0 : HCCL_RUN_INFO("[Init][CommRootInfo][Flat]nRanks[%u] entry flat topo detect.", nRanks);
1608 :
1609 0 : ret = topoDetectAgent->SetupAgent(nRanks, rank, rootHandle, rootHandle, commConfig);
1610 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][Flat]errNo[0x%016llx] " \
1611 : "setup flat topo detect error", HCCL_ERROR_CODE(ret)), errorFlag = true);
1612 0 : ret = GetTopoDetectInfo(params, rankTable, localRankInfo, rootHandle, topoDetectAgent, topoDetectAgent);
1613 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][Flat]errNo[0x%016llx] setup " \
1614 : "GetTopoDetectInfo error", HCCL_ERROR_CODE(ret)), errorFlag = true);
1615 : }
1616 :
1617 : /* 初始化hccl comm */
1618 :
1619 0 : CHK_RET(DisplayRanktableInfo(rankTable));
1620 :
1621 0 : if (retryEnable) {
1622 0 : EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectAgent.insert({ commIdentifier, topoDetectAgent }),
1623 : return HCCL_E_MEMORY);
1624 0 : ret = HcclGetCommConnections(rootHandle, commIdentifier, params.commConnections);
1625 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][RootInfo]HcclGetCommConnections failed."),
1626 : errorFlag = true);
1627 : } else {
1628 0 : ret = topoDetectAgent->Teardown();
1629 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1630 : HCCL_ERROR("[Init][RootInfo]errNo[0x%016llx] Teardown topo detect error", HCCL_ERROR_CODE(ret)),
1631 : errorFlag = true);
1632 : }
1633 :
1634 0 : ret = InitWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
1635 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1636 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] init work flow mode error", HCCL_ERROR_CODE(ret)),
1637 : errorFlag = true);
1638 :
1639 0 : ret = InitOtherInfo(params, nullptr);
1640 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1641 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] init other Info", HCCL_ERROR_CODE(ret)),
1642 : errorFlag = true);
1643 :
1644 0 : HCCL_INFO("rootInfo[%s], params.logiceDevice[%d]", params.id.internal, params.logicDevId);
1645 0 : ret = pComm->init(params, commConfig, rankTable);
1646 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1647 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] hcclComm init error", HCCL_ERROR_CODE(ret)),
1648 : errorFlag = true);
1649 :
1650 : /* 设置确定性计算配置 */
1651 0 : ret = pComm->SetDeterministicConfig(commConfig.GetConfigDeterministic());
1652 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1653 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set deterministic error", HCCL_ERROR_CODE(ret)),
1654 : errorFlag = true);
1655 :
1656 : // 设置TC/SL配置
1657 0 : ret = pComm->SetQpQosAttr(commConfig.GetConfigTrafficClass(), commConfig.GetConfigServiceLevel());
1658 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1659 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set TC and SL error or Invalid configuration parameter.",
1660 : HCCL_ERROR_CODE(ret)), errorFlag = true);
1661 0 : if (commConfig.GetConfigJobID() != 0) {
1662 0 : HCCL_RUN_INFO("[NSLBDP]GetConfigJobID = %llu,GetConfigWorldRankID = %u.",
1663 : commConfig.GetConfigJobID(), commConfig.GetConfigWorldRankID());
1664 0 : hcclNslbDp::GetInstance().SetGlobalCommTaskId(commConfig.GetConfigJobID());
1665 0 : hcclNslbDp::GetInstance().SetGlobalCommNodeId(commConfig.GetConfigWorldRankID());
1666 : }
1667 :
1668 : // 设置HCCL QOS配置
1669 0 : ret = pComm->SetHcclQos(commConfig.GetConfigHcclQos());
1670 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1671 : HCCL_ERROR("[%s]errNo[0x%016llx] set hccl qos error.", __func__, HCCL_ERROR_CODE(ret)),
1672 : errorFlag = true);
1673 :
1674 : /* 设置AIV模式 */
1675 0 : ret = pComm->SetAivModeConfig(commConfig.GetConfigAivMode());
1676 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1677 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set aivMode error.", HCCL_ERROR_CODE(ret)),
1678 : errorFlag = true);
1679 :
1680 : /* 设置only AIV模式 */
1681 0 : ret = pComm->SetOnlyAivModeConfig(commConfig.GetConfigIsOnlyAivMode());
1682 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1683 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set only aivMode error.", HCCL_ERROR_CODE(ret)),
1684 : errorFlag = true);
1685 :
1686 : /* 设置AICPU */
1687 0 : ret = pComm->SetAicpuUnfoldConfig(commConfig.GetConfigAicpuUnfold());
1688 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1689 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set aicpu error.", HCCL_ERROR_CODE(ret)),
1690 : errorFlag = true);
1691 :
1692 : /* 设置独立算子参数 */
1693 0 : ret = pComm->SetIndependentOpConfig(commConfig, rankTable);
1694 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1695 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set SetIndependentOpConfig error.", HCCL_ERROR_CODE(ret)),
1696 : errorFlag = true);
1697 :
1698 : /* 设置HcclExecTimeOut */
1699 0 : ret = pComm->SetExecTimeOutConfig(commConfig.GetConfigExecTimeOut());
1700 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1701 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set execTimeOut error.", HCCL_ERROR_CODE(ret)),
1702 : errorFlag = true);
1703 :
1704 : /* 设置HcclAlgo */
1705 0 : ret = pComm->SetAlgoConfig(commConfig.GetConfigHcclAlgoMap());
1706 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1707 : HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set hcclAlgo error.", HCCL_ERROR_CODE(ret)),
1708 : errorFlag = true);
1709 :
1710 : // 初始化完成的comm指针赋给出参
1711 0 : *comm = pComm.get();
1712 0 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
1713 0 : opBaseHcom.opGroup2CommMap[pComm->GetIdentifier()] = pComm;
1714 0 : lock.unlock();
1715 :
1716 : // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将pComm赋值到hcomInfo.pComm
1717 0 : if (pComm->GetIdentifier() == HCCL_WORLD_GROUP) {
1718 0 : HcomGetCtxHomInfo().pComm = pComm;
1719 : }
1720 :
1721 0 : ret = HcomSetGroupTopoInfo(pComm->GetIdentifier().c_str(), nRanks);
1722 0 : CHK_PRT_BREAK(ret != HCCL_SUCCESS,
1723 : HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] setGroupTopoInfo error", HCCL_ERROR_CODE(ret)),
1724 : errorFlag = true);
1725 :
1726 0 : ret = pComm->InitHccpChannel();
1727 0 : if (ret != HCCL_SUCCESS) {
1728 0 : HCCL_WARNING("InitHccp channel unsuccessful ret:[%u].", ret);
1729 : }
1730 0 : if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
1731 : DevType nslb_devType;
1732 0 : CHK_RET(hrtGetDeviceType(nslb_devType));
1733 0 : if (nslb_devType == DevType::DEV_TYPE_910_93) {
1734 0 : hcclNslbDp::GetInstance().SetDeviceType();
1735 : }
1736 0 : if (hcclNslbDp::GetInstance().InitNetCo() == HCCL_SUCCESS) {
1737 0 : std::string identifier_nslb = commIdentifier;
1738 0 : hcclNslbDp::GetInstance().InitCmmDesc(identifier_nslb);
1739 0 : HCCL_INFO("nslb_InitCommRootInfo rankTable.rankList.size:[%zu], identifier_nslb[%s].",
1740 : rankTable.rankList.size(), identifier_nslb.c_str());
1741 0 : hcclNslbDp::GetInstance().SetGlobalCommRankTable_RootInfo(rankTable, localRankInfo, pComm->GetRankLists(), identifier_nslb, nRanks, rank);
1742 0 : hcclNslbDp::GetInstance().SetGlobalDisRankTable(localRankInfo);
1743 0 : } else {
1744 0 : HCCL_WARNING("nslbdp try to init hccp failed.");
1745 : }
1746 : }
1747 0 : } while (0);
1748 :
1749 0 : std::string defaultIdentifier = rootHandle.identifier;
1750 0 : bool serverExist = opBaseHcom.hcclCommTopoInfoDetectServer.find(defaultIdentifier)
1751 0 : != opBaseHcom.hcclCommTopoInfoDetectServer.end();
1752 0 : if (defaultIdentifier.compare(commIdentifier) != 0 && retryEnable && serverExist) {
1753 0 : EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectServer.insert({commIdentifier,
1754 : opBaseHcom.hcclCommTopoInfoDetectServer[defaultIdentifier]}), return HCCL_E_MEMORY);
1755 0 : EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectServer.erase(defaultIdentifier), return HCCL_E_MEMORY);
1756 0 : HCCL_INFO("[InitCommRootInfo] replace key of topoDetectServer from [%s] to [%s]",
1757 : defaultIdentifier.c_str(), commIdentifier.c_str());
1758 0 : } else if (!retryEnable && serverExist) {
1759 0 : EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectServer.erase(defaultIdentifier), return HCCL_E_MEMORY);
1760 0 : HCCL_INFO("[InitCommRootInfo] close topoDetectServer identifier[%s]", commIdentifier.c_str());
1761 : }
1762 :
1763 0 : if (errorFlag) {
1764 0 : HCCL_ERROR("[InitCommRootInfo]Init failed, return[0x%016llx], rankNum[%u], rank[%u], "\
1765 : "rootInfo identifier[%s], server[%s], logicDevId[%d]", HCCL_ERROR_CODE(ret), nRanks, rank,
1766 : commIdentifier.c_str(), GetLocalServerId(params.serverId).c_str(), params.logicDevId);
1767 0 : (void)HcclCommDestroy(pComm.get());
1768 0 : return ret;
1769 : }
1770 :
1771 0 : HCCL_INFO("[InitCommRootInfo]Init success, rankNum[%u], rank[%u], rootInfo identifier[%s], server[%s], "
1772 : "logicDevId[%d]",
1773 : nRanks, rank, commIdentifier.c_str(), params.serverId.c_str(), params.logicDevId);
1774 :
1775 0 : return HCCL_SUCCESS;
1776 0 : }
1777 :
1778 4 : HcclResult HcclCommInitRootInfoInner(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank, HcclComm *comm)
1779 : {
1780 4 : HcclUs startut = TIME_NOW();
1781 4 : s32 deviceLogicId = 0;
1782 4 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
1783 :
1784 4 : CHK_PRT_RET((nRanks == 0), HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] nRanks[%u] should "\
1785 : "be greater than 0.", HCCL_ERROR_CODE(HCCL_E_PARA), nRanks), HCCL_E_PARA);
1786 :
1787 3 : CHK_PRT_RET((rank >= nRanks), HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] rank[%u] should "\
1788 : "be less than nRanks[%u].", HCCL_ERROR_CODE(HCCL_E_PARA), rank, nRanks), HCCL_E_PARA);
1789 :
1790 2 : CHK_SMART_PTR_NULL(comm);
1791 1 : CHK_SMART_PTR_NULL(rootInfo);
1792 :
1793 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
1794 0 : HCCLV2_FUNC_RUN(
1795 : [&]() -> HcclResult {
1796 : void *commV2 = nullptr;
1797 : std::string fooidentifier;
1798 : CHK_RET(HcclCommInitRootInfoV2(nRanks, rootInfo, rank, &commV2, fooidentifier));
1799 : constexpr HcclCommConfig *config = nullptr; // 未配置为默认加速模式
1800 : HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
1801 : if (ret != HCCL_SUCCESS) {
1802 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
1803 : CHK_RET(HcclCommDestroyV2(commV2));
1804 : commV2 = nullptr;
1805 : *comm = nullptr;
1806 : return ret;
1807 : }
1808 : return HCCL_SUCCESS;
1809 : }());
1810 : #endif
1811 :
1812 0 : HcclResult ret = InitExternalInput();
1813 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] init "\
1814 : "external input error", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1815 0 : ret = InitEnvConfig();
1816 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1817 : HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] init environment config error.",
1818 : HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1819 :
1820 : HcclRootHandle rootHandle;
1821 0 : s32 sRet = memcpy_s(&rootHandle, sizeof(HcclRootHandle), rootInfo->internal, sizeof(HcclRootHandle));
1822 0 : CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Init][RootInfoInner]memcpy root info fail. errorno[%d] "\
1823 : "params:destMaxSize[%u], count[%u]", sRet, sizeof(HcclRootHandle),
1824 : sizeof(HcclRootHandle)), HCCL_E_MEMORY);
1825 0 : rootHandle.identifier[ROOTINFO_INDENTIFIER_MAX_LENGTH - 1] = '\0';
1826 :
1827 : /* 接口交互信息日志 */
1828 0 : HCCL_RUN_INFO("Entry-HcclCommInitRootInfoInner:ranks[%u], rank[%u], rootinfo: host ip[%s] port[%u] "\
1829 : "nicDeploy[%d] identifier[%s], deviceLogicId[%d]", nRanks, rank, rootHandle.ip, rootHandle.port,
1830 : rootHandle.nicDeploy, rootHandle.identifier, deviceLogicId);
1831 :
1832 0 : CommConfig commConfig(rootHandle.identifier);
1833 :
1834 : /* --------------初始化------------------------- */
1835 0 : HCCL_INFO("HCCL nslbdp entry InitCommRootInfo.");
1836 0 : ret = InitCommRootInfo(nRanks, rank, rootHandle, commConfig, comm);
1837 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1838 : HCCL_ERROR("[Init][CommRootInfoConfig]errNo[0x%016llx]HcclCommInitRootInfo failed.",
1839 : HCCL_ERROR_CODE(ret)),
1840 : ret);
1841 :
1842 : // 记录groupName和UDI的映射
1843 0 : HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
1844 0 : if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
1845 : /* NSLB 发送 */
1846 0 : HCCL_INFO("hcclNslbDp entry Table FIVE rank[%u]", rank);
1847 0 : hcclNslbDp::GetInstance().SendGlobalDisRankTable();
1848 : }
1849 :
1850 : /* 关键状态记录 */
1851 0 : HCCL_RUN_INFO("[HCCL_TRACE]HcclCommInitRootInfoInner success, take time [%lld]us, rankNum[%u], rank[%u]",
1852 : DURATION_US(TIME_NOW() - startut), nRanks, rank);
1853 0 : return HCCL_SUCCESS;
1854 0 : }
1855 :
1856 0 : HcclResult HcclCommInitRootInfoInnerWrapper(struct hcclAsyncJob* job_)
1857 : {
1858 0 : struct hcclCommInitAsyncJob* job = static_cast<hcclCommInitAsyncJob*>(job_);
1859 0 : uint32_t nRanks = job->nRanks;
1860 0 : const HcclRootInfo* rootInfo = job->rootInfo;
1861 0 : uint32_t rank = job->rank;
1862 0 : HcclComm* comm = job->initComm;
1863 0 : s32 devId = job->devId;
1864 0 : HCCL_DEBUG("[HcclCommInitRootInfoInnerWrapper] Set device devId: %d", devId);
1865 0 : CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
1866 : HCCL_ERROR("[HcclCommInitRootInfo] set fail device[%d]", devId), HCCL_E_INTERNAL);
1867 :
1868 0 : HcclResult ret = HCCL_SUCCESS;
1869 0 : ret = HcclCommInitRootInfoInner(nRanks, rootInfo, rank, comm);
1870 0 : return ret;
1871 : }
1872 :
1873 4 : HcclResult HcclCommInitRootInfo(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank, HcclComm *comm)
1874 : {
1875 4 : HCCL_INFO("hcclGroupDepth=[%d]", hcclGroupDepth);
1876 4 : HcclResult ret = HCCL_SUCCESS;
1877 4 : if(hcclGroupDepth > 0){
1878 0 : std::shared_ptr<struct hcclCommInitAsyncJob> job;
1879 0 : EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitAsyncJob>()), return HCCL_E_PARA);
1880 0 : job->nRanks = nRanks;
1881 0 : job->rootInfo = rootInfo;
1882 0 : job->rank = rank;
1883 0 : job->initComm = comm;
1884 0 : s32 devId = 0;
1885 0 : CHK_RET(HcclDeviceRefresh(devId));
1886 0 : job->devId = devId;
1887 0 : ret = commInitTaskAppend(job, HcclCommInitRootInfoInnerWrapper, comm);
1888 0 : return ret;
1889 0 : }
1890 4 : ret = HcclCommInitRootInfoInner(nRanks, rootInfo, rank, comm);
1891 4 : return ret;
1892 : }
1893 :
1894 5 : HcclResult HcclCommInitRootInfoConfigInner(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank,
1895 : const HcclCommConfig *config, HcclComm *comm)
1896 : {
1897 5 : HcclUs startut = TIME_NOW();
1898 5 : s32 deviceLogicId = 0;
1899 5 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
1900 :
1901 : // 检查配置参数是否为空
1902 25 : RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
1903 : std::vector<std::string>({"HcclCommInitRootInfoConfigInner", "nullptr", "config", "non-null pointer"}));
1904 :
1905 5 : CHK_PRT_RET((nRanks == 0),
1906 : HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] nRanks[%u] should be greater than 0.",
1907 : HCCL_ERROR_CODE(HCCL_E_PARA), nRanks),
1908 : HCCL_E_PARA);
1909 :
1910 4 : CHK_PRT_RET((rank >= nRanks),
1911 : HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] rank[%u] should be less than nRanks[%u].",
1912 : HCCL_ERROR_CODE(HCCL_E_PARA), rank, nRanks),
1913 : HCCL_E_PARA);
1914 :
1915 3 : CHK_PTR_NULL(comm);
1916 2 : CHK_SMART_PTR_NULL(rootInfo);
1917 :
1918 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
1919 1 : HCCLV2_FUNC_RUN(
1920 : [&]() -> HcclResult {
1921 : void *commV2 = nullptr;
1922 : CHK_RET(HcclCommInitRootInfoConfigV2(nRanks, rootInfo, rank, config, &commV2));
1923 : HcclResult ret = HcclCommInitCollComm(rank, &commV2, const_cast<HcclCommConfig *>(config), comm);
1924 : if (ret != HCCL_SUCCESS) {
1925 : HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
1926 : CHK_RET(HcclCommDestroyV2(commV2));
1927 : commV2 = nullptr;
1928 : *comm = nullptr;
1929 : return ret;
1930 : }
1931 : return HCCL_SUCCESS;
1932 : }());
1933 : #endif
1934 :
1935 1 : HcclResult ret = InitExternalInput();
1936 1 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] init "\
1937 : "external input error", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1938 1 : ret = InitEnvConfig();
1939 1 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] init "\
1940 : "environment config error", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1941 :
1942 : HcclRootHandle rootHandle;
1943 1 : s32 sRet = memcpy_s(&rootHandle, sizeof(HcclRootHandle), rootInfo->internal, sizeof(HcclRootHandle));
1944 1 : CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Init][RootInfo]memcpy root info fail. errorno[%d] "\
1945 : "params:destMaxSize[%u], count[%u]", sRet, sizeof(HcclRootHandle),
1946 : sizeof(HcclRootHandle)), HCCL_E_MEMORY);
1947 1 : rootHandle.identifier[ROOTINFO_INDENTIFIER_MAX_LENGTH - 1] = '\0';
1948 :
1949 : /* 读取用户配置 */
1950 1 : CommConfig commConfig(rootHandle.identifier);
1951 1 : ret = commConfig.Load(config);
1952 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1953 : HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] load comm config failed.",
1954 : HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
1955 :
1956 : /* 接口交互信息日志 */
1957 0 : HCCL_RUN_INFO("Entry-HcclCommInitRootInfoConfigInner:ranks[%u], rank[%u], rootinfo: host ip[%s] "\
1958 : "port[%u] nicDeploy[%d] identifier[%s], deviceLogicId[%d]", nRanks, rank, rootHandle.ip,
1959 : rootHandle.port, rootHandle.nicDeploy, commConfig.GetConfigCommName().c_str(), deviceLogicId);
1960 :
1961 : /* --------------初始化------------------------- */
1962 0 : ret = InitCommRootInfo(nRanks, rank, rootHandle, commConfig, comm);
1963 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
1964 : HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx]HcclCommInitRootInfoConfigInner failed.",
1965 : HCCL_ERROR_CODE(ret)),
1966 : ret);
1967 :
1968 0 : if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
1969 : /* NSLB 发送 */
1970 0 : HCCL_INFO("hcclNslbDp-sendTable 5 rank[%u]", rank);
1971 0 : hcclNslbDp::GetInstance().SendGlobalDisRankTable();
1972 : }
1973 :
1974 : // 记录groupName和UDI的映射
1975 0 : HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
1976 :
1977 0 : HCCL_RUN_INFO("[HCCL_TRACE]HcclCommInitRootInfoConfigInner success, take time [%lld]us, "\
1978 : "rankNum[%u], rank[%u]", DURATION_US(TIME_NOW() - startut), nRanks, rank);
1979 :
1980 0 : return HCCL_SUCCESS;
1981 1 : }
1982 :
1983 0 : HcclResult HcclCommInitRootInfoConfigInnerWrapper(struct hcclAsyncJob* job_){
1984 0 : struct hcclCommInitConfigAsyncJob* job = static_cast<hcclCommInitConfigAsyncJob*>(job_);
1985 0 : uint32_t nRanks = job->nRanks;
1986 0 : const HcclRootInfo* rootInfo = job->rootInfo;
1987 0 : uint32_t rank = job->rank;
1988 0 : HcclComm* comm = job->initComm;
1989 0 : const HcclCommConfig* config = job->config;
1990 0 : s32 devId = job->devId;
1991 0 : HCCL_DEBUG("[HcclCommInitRootInfoConfigInnerWrapper] Set device devId: %d", devId);
1992 0 : CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
1993 : HCCL_ERROR("[HcclCommInitRootInfoConfigInnerWrapper] set fail device[%d]", devId), HCCL_E_INTERNAL);
1994 :
1995 0 : HcclResult ret = HCCL_SUCCESS;
1996 0 : ret = HcclCommInitRootInfoConfigInner(nRanks, rootInfo, rank, config, comm);
1997 0 : return ret;
1998 : }
1999 :
2000 5 : HcclResult HcclCommInitRootInfoConfig(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank,
2001 : const HcclCommConfig *config, HcclComm *comm)
2002 : {
2003 5 : HcclResult ret = HCCL_SUCCESS;
2004 5 : HCCL_INFO("hcclGroupDepth=[%d]", hcclGroupDepth);
2005 5 : if(hcclGroupDepth > 0){
2006 0 : std::shared_ptr<struct hcclCommInitConfigAsyncJob> job;
2007 0 : EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitConfigAsyncJob>()), return HCCL_E_PARA);
2008 0 : job->nRanks = nRanks;
2009 0 : job->rootInfo = rootInfo;
2010 0 : job->rank = rank;
2011 0 : job->initComm = comm;
2012 0 : job->config = config;
2013 0 : s32 devId = 0;
2014 0 : CHK_RET(HcclDeviceRefresh(devId));
2015 0 : job->devId = devId;
2016 0 : ret = commInitTaskAppend(job, HcclCommInitRootInfoConfigInnerWrapper, comm);
2017 0 : return ret;
2018 0 : }
2019 5 : ret = HcclCommInitRootInfoConfigInner(nRanks, rootInfo, rank, config, comm);
2020 5 : return ret;
2021 : }
2022 :
2023 3 : HcclResult HcclSetConfig(HcclConfig config, HcclConfigValue configValue)
2024 : {
2025 3 : if (config == HCCL_DETERMINISTIC) {
2026 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2027 3 : HCCLV2_FUNC_RUN(HcclSetConfigV2(config, configValue));
2028 : #endif
2029 3 : char* mmSysGetEnvValue = nullptr;
2030 3 : MM_SYS_GET_ENV(MM_ENV_HCCL_DETERMINISTIC, mmSysGetEnvValue);
2031 3 : std::string hcclDeterministicEnv = (mmSysGetEnvValue != nullptr) ? mmSysGetEnvValue : "EmptyString";
2032 3 : if (hcclDeterministicEnv == "EmptyString") {
2033 3 : if (configValue.value != DETERMINISTIC_STRICT && configValue.value != DETERMINISTIC_ENABLE &&
2034 1 : configValue.value != DETERMINISTIC_DISABLE) {
2035 0 : HCCL_ERROR("[HcclSetConfig] HCCL_DETERMINISTIC is only support 0, 1 or 2");
2036 0 : return HCCL_E_PARA;
2037 : } else {
2038 : DevType devType;
2039 4 : CHK_RET(hrtGetDeviceType(devType));
2040 3 : if (configValue.value == DETERMINISTIC_STRICT && devType != DevType::DEV_TYPE_910B) {
2041 1 : HCCL_ERROR("[HcclSetConfig] configValue[%d], reduce order preservation is not supported for"
2042 : " devType[%d]", configValue.value, devType);
2043 1 : return HCCL_E_NOT_SUPPORT;
2044 : }
2045 2 : CHK_RET(SetDeterministic(configValue.value));
2046 2 : HCCL_INFO("[HcclSetConfig] Set HCCL_DETERMINISTIC to %u", configValue.value);
2047 : }
2048 : } else {
2049 0 : HCCL_WARNING("[HcclSetConfig] HCCL_DETERMINISTIC has been set by Env, so will not be reset again");
2050 0 : return HCCL_SUCCESS;
2051 : }
2052 2 : HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
2053 : // 遍历所有的通信域设置其确定性计算配置参数
2054 2 : for (auto it = opBaseInfo.opGroup2CommMap.begin(); it != opBaseInfo.opGroup2CommMap.end(); it++) {
2055 0 : CHK_RET(it->second->SetDeterministicConfig(configValue.value));
2056 : }
2057 3 : }
2058 2 : return HCCL_SUCCESS;
2059 : }
2060 :
2061 4 : HcclResult HcclGetConfig(HcclConfig config, HcclConfigValue *configValue)
2062 : {
2063 4 : CHK_PTR_NULL(configValue);
2064 3 : if (config == HCCL_DETERMINISTIC) {
2065 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2066 3 : HCCLV2_FUNC_RUN(HcclGetConfigV2(config, configValue));
2067 : #endif
2068 3 : configValue->value = static_cast<int32_t>(GetExternalInputHcclDeterministicV2());
2069 3 : HCCL_INFO("[HcclGetConfig] HCCL_DETERMINISTIC is [%d]", configValue->value);
2070 : }
2071 3 : return HCCL_SUCCESS;
2072 : }
2073 :
2074 317 : HcclResult HcclSetIfProfile()
2075 : {
2076 317 : bool ifOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
2077 317 : bool state = ProfilingManagerPub::GetAllState();
2078 317 : SetIfProfile((!ifOpbase) || (!state));
2079 317 : return HCCL_SUCCESS;
2080 : }
2081 :
2082 289 : void HcclResetIfProfile()
2083 : {
2084 289 : SetIfProfile(true);
2085 289 : }
2086 :
2087 28 : HcclResult HcclBroadcastInner(void *buf, uint64_t count, HcclDataType dataType, uint32_t root, HcclComm comm,
2088 : aclrtStream stream)
2089 : {
2090 : // 入参合法性校验
2091 28 : CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return broadcast success"), HCCL_SUCCESS);
2092 27 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2093 : std::vector<std::string>({"HcclBroadcastInner", "nullptr", "stream", "non-null pointer"}));
2094 27 : CHK_PTR_NULL(stream);
2095 47 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2096 : std::vector<std::string>({"HcclBroadcastInner", "nullptr", "comm", "non-null pointer"}));
2097 27 : CHK_PTR_NULL(comm);
2098 46 : RPT_INPUT_ERR(buf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2099 : std::vector<std::string>({"HcclBroadcastInner", "nullptr", "buf", "non-null pointer"}));
2100 26 : CHK_PTR_NULL(buf);
2101 :
2102 : // Group特性
2103 25 : if (hcclGroupDepth > 0) {
2104 : struct hcclOpInfo info;
2105 1 : info.coll = HcclCMDType::HCCL_CMD_BROADCAST;
2106 1 : info.sendbuff = buf;
2107 1 : info.sendCount = count;
2108 1 : info.sendType = dataType;
2109 1 : info.recvType = dataType;
2110 1 : info.op = HCCL_REDUCE_SUM;
2111 1 : info.root = root;
2112 1 : info.comm = comm;
2113 1 : info.stream = stream;
2114 1 : CHK_RET(taskAppend(comm, info));
2115 1 : HCCL_INFO("[HcclBroadcast] Finish taskAppend, count [%d] dataType [%s] root [%u]", count, GetDataTypeEnumStr(dataType).c_str(), root);
2116 1 : return HCCL_SUCCESS;
2117 : }
2118 :
2119 24 : HcclUs startut = TIME_NOW();
2120 : bool isCapture;
2121 24 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
2122 24 : uint64_t modelId = 0xFFFFFFFF;
2123 24 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
2124 24 : if (!isCapture) {
2125 23 : HcclSetIfProfile();
2126 : }
2127 24 : uint64_t beginTime = hrtMsprofSysCycleTime();
2128 :
2129 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2130 24 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
2131 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2132 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
2133 : CHK_PTR_NULL(commV2);
2134 : CHK_RET(HcclBroadcastV2(buf, count, dataType, root, commV2, stream));
2135 : return HCCL_SUCCESS;
2136 : }());
2137 : #endif
2138 24 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2139 24 : const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
2140 24 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
2141 24 : s32 threadID = SalGetTid();
2142 24 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
2143 : // 同通信域同算子复用tag
2144 24 : const string tag = "Broadcast_" + hcclComm->GetIdentifier();
2145 :
2146 24 : CHK_RET(HcomCheckOpParam(tag.c_str(), count, dataType, stream));
2147 :
2148 24 : HcomCollOpInfo opInfo = {"", buf, buf, count, dataType, root, HCCL_REDUCE_RESERVED};
2149 :
2150 24 : u32 rankSize = INVALID_VALUE_RANKSIZE;
2151 24 : CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
2152 :
2153 24 : CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, root), tag.c_str());
2154 :
2155 : /* 接口交互信息日志 */
2156 : char stackLogBuffer[LOG_TMPBUF_SIZE];
2157 23 : if (GetExternalInputHcclEnableEntryLog()) {
2158 23 : s32 deviceLogicId = 0;
2159 23 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
2160 :
2161 23 : u32 localRank = INVALID_VALUE_RANKID;
2162 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
2163 :
2164 23 : s32 streamId = 0;
2165 23 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
2166 :
2167 23 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
2168 : "tag[%s], buf[%p], count[%llu], dataType[%s], root[%u], localRank[%u], streamId[%d], deviceLogicId[%d]",
2169 46 : tag.c_str(), buf, count, GetDataTypeEnumStr(dataType).c_str(), root, localRank, streamId, deviceLogicId);
2170 :
2171 23 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
2172 46 : std::string logInfo = "Entry-HcclBroadcastInner:" + std::string(stackLogBuffer) +
2173 69 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
2174 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
2175 23 : }
2176 :
2177 23 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
2178 :
2179 23 : CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_BROADCAST, tag, opInfo), tag.c_str());
2180 :
2181 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(buf), tag.c_str());
2182 :
2183 23 : CHK_RET_AND_PRINT_IDE(hcclComm->BroadcastOutPlace(tag, buf, count, dataType, root, stream), tag.c_str());
2184 :
2185 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_BROADCAST, beginTime, count, dataType, tag));
2186 23 : if (!isCapture) {
2187 22 : HcclResetIfProfile();
2188 : }
2189 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
2190 :
2191 23 : if (GetExternalInputHcclEnableEntryLog()) {
2192 23 : HcclUs endut = TIME_NOW();
2193 : /* 关键状态记录 */
2194 23 : std::string endInfo = "HcclBroadcastInner:success,take time: " +
2195 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
2196 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
2197 23 : }
2198 23 : std::string identifier = hcclComm->GetIdentifier();
2199 23 : AlgType nslbAlgType;
2200 23 : CHK_RET(hcclComm->GetAlgType(nslbAlgType, HcclCMDType::HCCL_CMD_BROADCAST));
2201 :
2202 23 : if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
2203 0 : AlgTypeLevel1 algValue = nslbAlgType.algoLevel1;
2204 0 : uint8_t nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel1AlgType(algValue);
2205 : DevType devType;
2206 0 : CHK_RET(hrtGetDeviceType(devType));
2207 0 : if (devType == DevType::DEV_TYPE_910_93) {
2208 0 : AlgTypeLevel2 algValue2 = nslbAlgType.algoLevel2;
2209 0 : nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel2AlgType(algValue2);
2210 : }
2211 : // NSLB 填充 表6
2212 0 : hcclNslbDp::GetInstance().SetNslbDpRootRank(HcclCMDType::HCCL_CMD_BROADCAST, root, identifier, nslbAlg);
2213 : }
2214 23 : return HCCL_SUCCESS;
2215 24 : }
2216 :
2217 30 : HcclResult HcclReduceScatterInner(void *sendBuf, void *recvBuf, uint64_t recvCount, HcclDataType dataType,
2218 : HcclReduceOp op, HcclComm comm, aclrtStream stream)
2219 : {
2220 : // 入参合法性校验
2221 30 : CHK_PRT_RET(recvCount == 0, HCCL_WARNING("input recvCount is 0, return ReduceScatter success"), HCCL_SUCCESS);
2222 29 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2223 : std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "stream", "non-null pointer"}));
2224 29 : CHK_PTR_NULL(stream);
2225 49 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2226 : std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "comm", "non-null pointer"}));
2227 29 : CHK_PTR_NULL(comm);
2228 48 : RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2229 : std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "sendBuf", "non-null pointer"}));
2230 28 : CHK_PTR_NULL(sendBuf);
2231 47 : RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2232 : std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "recvBuf", "non-null pointer"}));
2233 27 : CHK_PTR_NULL(recvBuf);
2234 :
2235 : // Group特性
2236 26 : if (hcclGroupDepth > 0) {
2237 : struct hcclOpInfo info;
2238 1 : info.coll = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
2239 1 : info.sendbuff = sendBuf;
2240 1 : info.recvbuff = recvBuf;
2241 1 : info.recvCount = recvCount;
2242 1 : info.sendType = dataType;
2243 1 : info.recvType = dataType;
2244 1 : info.op = op;
2245 1 : info.comm = comm;
2246 1 : info.stream = stream;
2247 1 : CHK_RET(taskAppend(comm, info));
2248 1 : HCCL_INFO("[HcclReduceScatter] Finish taskAppend, count [%d] dataType [%s]", recvCount, GetDataTypeEnumStr(dataType).c_str());
2249 1 : return HCCL_SUCCESS;
2250 : }
2251 :
2252 25 : HcclUs startut = TIME_NOW();
2253 : bool isCapture;
2254 25 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
2255 25 : uint64_t modelId = 0xFFFFFFFF;
2256 25 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
2257 25 : if (!isCapture) {
2258 24 : HcclSetIfProfile();
2259 : }
2260 25 : uint64_t beginTime = hrtMsprofSysCycleTime();
2261 :
2262 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2263 25 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
2264 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2265 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
2266 : CHK_PTR_NULL(commV2);
2267 : CHK_RET(HcclReduceScatterV2(sendBuf, recvBuf, recvCount, dataType, op, commV2, stream));
2268 : return HCCL_SUCCESS;
2269 : }());
2270 : #endif
2271 25 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2272 25 : const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
2273 25 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
2274 25 : s32 threadID = SalGetTid();
2275 25 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
2276 : // 同通信域同算子复用tag
2277 25 : const string tag = "ReduceScatter_" + hcclComm->GetIdentifier();
2278 :
2279 25 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), recvCount, dataType, stream), tag.c_str());
2280 :
2281 72 : CHK_RET_AND_PRINT_IDE(HcomCheckReductionOp("HcclReduceScatterInner", op), tag.c_str());
2282 : DevType devType;
2283 24 : CHK_RET(hrtGetDeviceType(devType));
2284 24 : CHK_RET_AND_PRINT_IDE(HcomCheckReduceDataType(dataType, op, devType), tag.c_str());
2285 :
2286 : /* 接口交互信息日志 */
2287 : char stackLogBuffer[LOG_TMPBUF_SIZE];
2288 23 : if (GetExternalInputHcclEnableEntryLog()) {
2289 23 : s32 deviceLogicId = 0;
2290 23 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
2291 :
2292 23 : u32 localRank = INVALID_VALUE_RANKID;
2293 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
2294 :
2295 23 : s32 streamId = 0;
2296 23 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
2297 :
2298 46 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
2299 : "tag[%s], sendBuf[%p], recvBuf[%p], recvCount[%llu], dataType[%s], op[%s], "
2300 : "localRank[%u], streamId[%d], deviceLogicId[%d]",
2301 69 : tag.c_str(), sendBuf, recvBuf, recvCount, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
2302 : localRank, streamId, deviceLogicId);
2303 :
2304 23 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
2305 46 : std::string logInfo = "Entry-HcclReduceScatterInner:" + std::string(stackLogBuffer) +
2306 69 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
2307 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
2308 23 : }
2309 :
2310 23 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
2311 :
2312 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
2313 :
2314 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
2315 :
2316 23 : CHK_RET_AND_PRINT_IDE(SetOverFlowAddr(hcclComm), tag.c_str());
2317 :
2318 23 : CHK_RET_AND_PRINT_IDE(hcclComm->ReduceScatterOutPlace(tag, sendBuf, recvBuf, recvCount, dataType, op, stream),
2319 : tag.c_str());
2320 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE_SCATTER, beginTime, recvCount,
2321 : dataType, tag));
2322 23 : if (!isCapture) {
2323 22 : HcclResetIfProfile();
2324 : }
2325 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
2326 :
2327 23 : if (GetExternalInputHcclEnableEntryLog()) {
2328 23 : HcclUs endut = TIME_NOW();
2329 : /* 关键状态记录 */
2330 23 : std::string endInfo = "HcclReduceScatterInner:success,take time: " +
2331 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
2332 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
2333 23 : }
2334 :
2335 23 : return HCCL_SUCCESS;
2336 25 : }
2337 :
2338 34 : HcclResult HcclReduceScatterVInner(void *sendBuf, const void *sendCounts, const void *sendDispls,
2339 : void *recvBuf, uint64_t recvCount, HcclDataType dataType, HcclReduceOp op, HcclComm comm, aclrtStream stream)
2340 : {
2341 : // 入参合法性校验
2342 34 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2343 : std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "stream", "non-null pointer"}));
2344 34 : CHK_PTR_NULL(stream);
2345 54 : RPT_INPUT_ERR(sendCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2346 : std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "sendCounts", "non-null pointer"}));
2347 34 : CHK_PTR_NULL(sendCounts);
2348 53 : RPT_INPUT_ERR(sendDispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2349 : std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "sendDispls", "non-null pointer"}));
2350 33 : CHK_PTR_NULL(sendDispls);
2351 52 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2352 : std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "comm", "non-null pointer"}));
2353 32 : CHK_PTR_NULL(comm);
2354 31 : if (UNLIKELY(recvCount > 0 && recvBuf == nullptr)) {
2355 21 : RPT_INPUT_ERR(true, "EI0003",\
2356 : std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2357 : std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "recvBuf", "non-null pointer"}));
2358 1 : CHK_PTR_NULL(recvBuf);
2359 : }
2360 :
2361 : // Group特性
2362 30 : if (hcclGroupDepth > 0) {
2363 : struct hcclOpInfo info;
2364 1 : info.coll = HcclCMDType::HCCL_CMD_REDUCE_SCATTER_V;
2365 1 : info.sendbuff = sendBuf;
2366 1 : info.recvbuff = recvBuf;
2367 1 : info.sendCounts = sendCounts;
2368 1 : info.sdispls = sendDispls;
2369 1 : info.recvCount = recvCount;
2370 1 : info.sendType = dataType;
2371 1 : info.recvType = dataType;
2372 1 : info.op = op;
2373 1 : info.comm = comm;
2374 1 : info.stream = stream;
2375 1 : CHK_RET(taskAppend(comm, info));
2376 1 : HCCL_INFO("[HcclReduceScatterV] Finish taskAppend, recvCount [%d] dataType [%s]", recvCount, GetDataTypeEnumStr(dataType).c_str());
2377 1 : return HCCL_SUCCESS;
2378 : }
2379 :
2380 29 : HcclUs startut = TIME_NOW();
2381 : bool isCapture;
2382 29 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
2383 29 : uint64_t modelId = 0xFFFFFFFF;
2384 29 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
2385 29 : if (!isCapture) {
2386 28 : HcclSetIfProfile();
2387 : }
2388 29 : s32 threadID = SalGetTid();
2389 29 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
2390 29 : uint64_t beginTime = hrtMsprofSysCycleTime();
2391 :
2392 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2393 29 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
2394 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2395 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
2396 : CHK_PTR_NULL(commV2);
2397 : CHK_RET(HcclReduceScatterVV2(sendBuf, const_cast<void*>(sendCounts), const_cast<void*>(sendDispls), recvBuf, recvCount, dataType, op, commV2, stream));
2398 : return HCCL_SUCCESS;
2399 : }());
2400 : #endif
2401 29 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2402 29 : const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
2403 : // 同通信域同算子复用tag
2404 29 : const string tag = "ReduceScatterV_" + hcclComm->GetIdentifier();
2405 :
2406 29 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), recvCount, dataType, stream), tag.c_str());
2407 :
2408 84 : CHK_RET_AND_PRINT_IDE(HcomCheckReductionOp("HcclReduceScatterVInner", op), tag.c_str());
2409 : DevType devType;
2410 28 : CHK_RET(hrtGetDeviceType(devType));
2411 28 : CHK_RET_AND_PRINT_IDE(HcomCheckReduceDataType(dataType, op, devType), tag.c_str());
2412 :
2413 27 : u32 rankSize = INVALID_VALUE_RANKSIZE;
2414 27 : CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
2415 27 : u32 userRank = INVALID_VALUE_RANKID;
2416 27 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(userRank), tag.c_str());
2417 27 : CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, userRank), tag.c_str());
2418 :
2419 27 : u64 maxCount = 0;
2420 27 : u64 inputCount = 0;
2421 27 : u64* counts = static_cast<u64 *>(const_cast<void*>(sendCounts));
2422 61 : for (u32 i = 0; i < rankSize; i++) {
2423 34 : CHK_PRT_RET(counts[i] > SYS_MAX_COUNT,
2424 : HCCL_ERROR("HcclReduceScatterVInner sendCounts[%u][%llu] is invalid.(bigger than MAX count[%llu])",
2425 : i, counts[i], SYS_MAX_COUNT),
2426 : HCCL_E_PARA);
2427 34 : inputCount += counts[i];
2428 34 : maxCount = std::max(maxCount, counts[i]);
2429 : }
2430 27 : CHK_PRT_RET(inputCount == 0, HCCL_WARNING("The inputCount is 0, this ReduceScatter v has no task to execute, "
2431 : "returning success."), HCCL_SUCCESS);
2432 46 : RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
2433 : std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "sendBuf", "non-null pointer"}));
2434 26 : CHK_PTR_NULL(sendBuf);
2435 :
2436 : /* 接口交互信息日志 */
2437 : char stackLogBuffer[LOG_TMPBUF_SIZE];
2438 25 : if (GetExternalInputHcclEnableEntryLog()) {
2439 25 : s32 deviceLogicId = 0;
2440 25 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
2441 :
2442 25 : u32 localRank = INVALID_VALUE_RANKID;
2443 25 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
2444 :
2445 25 : s32 streamId = 0;
2446 25 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
2447 :
2448 50 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
2449 : "tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], sendDispls[%p], recvCount[%llu], dataType[%s], op[%s], "
2450 : "localRank[%u], streamId[%d], deviceLogicId[%d]",
2451 : tag.c_str(), sendBuf, recvBuf, sendCounts, sendDispls, recvCount,
2452 75 : GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(), localRank, streamId, deviceLogicId);
2453 :
2454 25 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
2455 50 : std::string logInfo = "Entry-HcclReduceScatterVInner:" + std::string(stackLogBuffer) +
2456 75 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
2457 25 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
2458 25 : }
2459 :
2460 50 : PrintCountsAndDispls(rankSize, sendCounts, sendDispls, tag.c_str());
2461 :
2462 25 : CheckCountsAndDispls(rankSize, sendCounts, sendDispls, tag.c_str());
2463 :
2464 25 : const u64 countOfThisRank = static_cast<const u64 *>(sendCounts)[userRank];
2465 25 : CHK_PRT_RET(recvCount != countOfThisRank,
2466 : HCCL_ERROR("[HcclReduceScatterVInner] input recvCount[%llu] is not equal to sendCounts[%u][%llu]", recvCount,
2467 : userRank, countOfThisRank),
2468 : HCCL_E_PARA);
2469 :
2470 23 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
2471 :
2472 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
2473 :
2474 23 : if (recvBuf != nullptr) {
2475 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
2476 : }
2477 :
2478 23 : CHK_RET_AND_PRINT_IDE(SetOverFlowAddr(hcclComm), tag.c_str());
2479 :
2480 23 : CHK_RET_AND_PRINT_IDE(hcclComm->ReduceScatterVOutPlace(tag, sendBuf, recvBuf, sendCounts, sendDispls, recvCount,
2481 : dataType, op, stream), tag.c_str());
2482 :
2483 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE_SCATTER_V, beginTime, maxCount,
2484 : dataType, tag));
2485 23 : if (!isCapture) {
2486 22 : HcclResetIfProfile();
2487 : }
2488 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
2489 :
2490 23 : if (GetExternalInputHcclEnableEntryLog()) {
2491 23 : HcclUs endut = TIME_NOW();
2492 : /* 关键状态记录 */
2493 23 : std::string endInfo = "HcclReduceScatterVInner:success,take time: " +
2494 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
2495 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
2496 23 : }
2497 :
2498 23 : return HCCL_SUCCESS;
2499 29 : }
2500 :
2501 29 : HcclResult CheckScatterInputPara(HcclComm comm, void *recvBuf)
2502 : {
2503 : // 入参合法性校验
2504 49 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
2505 : std::vector<std::string>({"HcclScatterInner", "nullptr", "comm", "non-null pointer"}));
2506 29 : CHK_PTR_NULL(comm);
2507 48 : RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
2508 : std::vector<std::string>({"HcclScatterInner", "nullptr", "recvBuf", "non-null pointer"}));
2509 28 : CHK_PTR_NULL(recvBuf);
2510 :
2511 27 : return HCCL_SUCCESS;
2512 : }
2513 :
2514 30 : HcclResult HcclScatterInner(void *sendBuf, void *recvBuf, uint64_t recvCount, HcclDataType dataType, uint32_t root,
2515 : HcclComm comm, aclrtStream stream)
2516 : {
2517 : // 入参合法性校验
2518 30 : CHK_PRT_RET(recvCount == 0, HCCL_WARNING("input recvCount is 0, return scatter success"), HCCL_SUCCESS);
2519 29 : CHK_RET(CheckScatterInputPara(comm, recvBuf));
2520 27 : CHK_PTR_NULL(stream);
2521 :
2522 : // Group特性
2523 27 : if (hcclGroupDepth > 0) {
2524 : struct hcclOpInfo info;
2525 1 : info.coll = HcclCMDType::HCCL_CMD_SCATTER;
2526 1 : info.sendbuff = sendBuf;
2527 1 : info.recvbuff = recvBuf;
2528 1 : info.recvCount = recvCount;
2529 1 : info.sendType = dataType;
2530 1 : info.recvType = dataType;
2531 1 : info.root = root;
2532 1 : info.comm = comm;
2533 1 : info.stream = stream;
2534 1 : CHK_RET(taskAppend(comm, info));
2535 1 : HCCL_INFO("[HcclScatter] Finish taskAppend, recvCount [%d] dataType [%s]", recvCount, GetDataTypeEnumStr(dataType).c_str());
2536 1 : return HCCL_SUCCESS;
2537 : }
2538 :
2539 26 : HcclUs startut = TIME_NOW();
2540 : bool isCapture;
2541 26 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
2542 26 : uint64_t modelId = 0xFFFFFFFF;
2543 26 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
2544 26 : if (!isCapture) {
2545 25 : HcclSetIfProfile();
2546 : }
2547 26 : uint64_t beginTime = hrtMsprofSysCycleTime();
2548 :
2549 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2550 26 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
2551 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2552 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
2553 : CHK_PTR_NULL(commV2);
2554 : CHK_RET(HcclScatterV2(sendBuf, recvBuf, recvCount, dataType, root, commV2, stream));
2555 : return HCCL_SUCCESS;
2556 : }());
2557 : #endif
2558 26 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2559 26 : const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
2560 26 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
2561 26 : s32 threadID = SalGetTid();
2562 26 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
2563 26 : u32 commRank = INVALID_VALUE_RANKID;
2564 26 : CHK_RET(hcclComm->GetUserRank(commRank));
2565 26 : if (commRank == root) { // 本rank为root节点,send_buff不为空
2566 45 : RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
2567 : std::vector<std::string>({"HcclScatterInner", "nullptr", "sendBuf", "non-null pointer"}));
2568 25 : CHK_PTR_NULL(sendBuf);
2569 : }
2570 :
2571 : // 同通信域同算子复用tag
2572 25 : const string tag = "Scatter_" + hcclComm->GetIdentifier();
2573 :
2574 25 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), recvCount, dataType, stream), tag.c_str());
2575 :
2576 24 : HcomCollOpInfo opInfo = {"", sendBuf, recvBuf, recvCount, dataType, root};
2577 :
2578 24 : u32 rankSize = INVALID_VALUE_RANKSIZE;
2579 24 : CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
2580 :
2581 24 : CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, root), tag.c_str());
2582 :
2583 : /* 接口交互信息日志 */
2584 : char stackLogBuffer[LOG_TMPBUF_SIZE];
2585 24 : if (GetExternalInputHcclEnableEntryLog()) {
2586 24 : s32 deviceLogicId = 0;
2587 24 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
2588 :
2589 24 : u32 localRank = INVALID_VALUE_RANKID;
2590 24 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
2591 :
2592 24 : s32 streamId = 0;
2593 24 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
2594 :
2595 24 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
2596 : "tag[%s], sendBuf[%p], recvBuf[%p], recvCount[%llu], dataType[%s], root[%u], localRank[%u], streamId[%d], deviceLogicId[%d]",
2597 48 : tag.c_str(), sendBuf, recvBuf, recvCount, GetDataTypeEnumStr(dataType).c_str(), root, localRank, streamId, deviceLogicId);
2598 :
2599 24 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
2600 48 : std::string logInfo = "Entry-HcclScatterInner:" + std::string(stackLogBuffer) +
2601 72 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
2602 24 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
2603 24 : }
2604 :
2605 24 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
2606 :
2607 24 : CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_SCATTER, tag, opInfo), tag.c_str());
2608 :
2609 24 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
2610 :
2611 24 : CHK_RET_AND_PRINT_IDE(hcclComm->ScatterOutPlace(tag, sendBuf, recvBuf, recvCount, dataType, root, stream),
2612 : tag.c_str());
2613 :
2614 24 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_SCATTER, beginTime, recvCount, dataType,
2615 : tag));
2616 24 : if (!isCapture) {
2617 23 : HcclResetIfProfile();
2618 : }
2619 24 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
2620 :
2621 24 : if (GetExternalInputHcclEnableEntryLog()) {
2622 24 : HcclUs endut = TIME_NOW();
2623 : /* 关键状态记录 */
2624 24 : std::string endInfo = "HcclScatterInner:success,take time: " +
2625 48 : std::to_string(DURATION_US(endut - startut).count()) + " us, tag: " + tag;
2626 24 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
2627 24 : }
2628 24 : std::string identifier = hcclComm->GetIdentifier();
2629 24 : AlgType algType;
2630 24 : CHK_RET(hcclComm->GetAlgType(algType, HcclCMDType::HCCL_CMD_SCATTER));
2631 :
2632 24 : if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
2633 : DevType nslb_devType;
2634 0 : CHK_RET(hrtGetDeviceType(nslb_devType));
2635 0 : AlgTypeLevel1 algValue = algType.algoLevel1;
2636 0 : uint8_t nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel1AlgType(algValue);
2637 0 : if (nslb_devType == DevType::DEV_TYPE_910_93) {
2638 0 : AlgTypeLevel2 algValue2 = algType.algoLevel2;
2639 0 : nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel2AlgType(algValue2);
2640 : }
2641 : // NSLB 填充 表6
2642 0 : hcclNslbDp::GetInstance().SetNslbDpRootRank(HcclCMDType::HCCL_CMD_SCATTER, root, identifier, nslbAlg);
2643 : }
2644 24 : return HCCL_SUCCESS;
2645 26 : }
2646 :
2647 29 : HcclResult HcclAllGatherInner(void *sendBuf, void *recvBuf, uint64_t sendCount, HcclDataType dataType,
2648 : HcclComm comm, aclrtStream stream)
2649 : {
2650 : // 入参合法性校验
2651 29 : CHK_PRT_RET(sendCount == 0, HCCL_WARNING("input sendCount is 0, return HcclAllGatherInner success"), HCCL_SUCCESS);
2652 48 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2653 : std::vector<std::string>({"HcclAllGatherInner", "nullptr", "comm", "non-null pointer"}));
2654 28 : CHK_PTR_NULL(comm);
2655 47 : RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2656 : std::vector<std::string>({"HcclAllGatherInner", "nullptr", "sendBuf", "non-null pointer"}));
2657 27 : CHK_PTR_NULL(sendBuf);
2658 46 : RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2659 : std::vector<std::string>({"HcclAllGatherInner", "nullptr", "recvBuf", "non-null pointer"}));
2660 26 : CHK_PTR_NULL(recvBuf);
2661 25 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2662 : std::vector<std::string>({"HcclAllGatherInner", "nullptr", "stream", "non-null pointer"}));
2663 25 : CHK_PTR_NULL(stream);
2664 :
2665 : // Group特性
2666 25 : if (hcclGroupDepth > 0) {
2667 : struct hcclOpInfo info;
2668 1 : info.coll = HcclCMDType::HCCL_CMD_ALLGATHER;
2669 1 : info.sendbuff = sendBuf;
2670 1 : info.recvbuff = recvBuf;
2671 1 : info.sendCount = sendCount;
2672 1 : info.sendType = dataType;
2673 1 : info.recvType = dataType;
2674 1 : info.comm = comm;
2675 1 : info.stream = stream;
2676 1 : CHK_RET(taskAppend(comm, info));
2677 1 : HCCL_INFO("[HcclAllGather] Finish taskAppend, sendCount [%d] dataType [%s]", sendCount, GetDataTypeEnumStr(dataType).c_str());
2678 1 : return HCCL_SUCCESS;
2679 : }
2680 :
2681 24 : HcclUs startut = TIME_NOW();
2682 : bool isCapture;
2683 24 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
2684 24 : uint64_t modelId = 0xFFFFFFFF;
2685 24 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
2686 24 : if (!isCapture) {
2687 23 : HcclSetIfProfile();
2688 : }
2689 24 : uint64_t beginTime = hrtMsprofSysCycleTime();
2690 :
2691 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2692 24 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
2693 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2694 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
2695 : CHK_PTR_NULL(commV2);
2696 : CHK_RET(HcclAllGatherV2(sendBuf, recvBuf, sendCount, dataType, commV2, stream));
2697 : return HCCL_SUCCESS;
2698 : }());
2699 : #endif
2700 24 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2701 24 : const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
2702 24 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
2703 24 : s32 threadID = SalGetTid();
2704 24 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
2705 : // 同通信域同算子复用tag
2706 24 : const std::string tag = "AllGather_" + hcclComm->GetIdentifier();
2707 24 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), sendCount, dataType, stream), tag.c_str());
2708 :
2709 : /* 接口交互信息日志 */
2710 : char stackLogBuffer[LOG_TMPBUF_SIZE];
2711 23 : if (GetExternalInputHcclEnableEntryLog()) {
2712 23 : s32 deviceLogicId = 0;
2713 23 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
2714 :
2715 23 : u32 localRank = INVALID_VALUE_RANKID;
2716 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
2717 :
2718 23 : s32 streamId = 0;
2719 23 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
2720 :
2721 23 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
2722 : "tag[%s], sendBuf[%p], recvBuf[%p], sendCount[%llu], dataType[%s], localRank[%u], streamId[%d], "
2723 : "deviceLogicId[%d]",
2724 46 : tag.c_str(), sendBuf, recvBuf, sendCount, GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
2725 :
2726 23 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
2727 46 : std::string logInfo = "Entry-HcclAllGatherInner:" + std::string(stackLogBuffer) +
2728 69 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
2729 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
2730 23 : }
2731 :
2732 23 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
2733 :
2734 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
2735 :
2736 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
2737 :
2738 23 : CHK_RET_AND_PRINT_IDE(hcclComm->AllGatherOutPlace(tag, sendBuf, recvBuf, sendCount, dataType, stream), tag.c_str());
2739 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLGATHER, beginTime, sendCount, dataType,
2740 : tag));
2741 23 : if (!isCapture) {
2742 22 : HcclResetIfProfile();
2743 : }
2744 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
2745 :
2746 23 : if (GetExternalInputHcclEnableEntryLog()) {
2747 23 : HcclUs endut = TIME_NOW();
2748 : /* 关键状态记录 */
2749 23 : std::string endInfo = "HcclAllGatherInner:success,take time: " +
2750 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
2751 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
2752 23 : }
2753 :
2754 23 : return HCCL_SUCCESS;
2755 24 : }
2756 :
2757 33 : HcclResult HcclAllGatherVInner(void *sendBuf, uint64_t sendCount, void *recvBuf,
2758 : const void *recvCounts, const void *recvDispls, HcclDataType dataType, HcclComm comm, aclrtStream stream)
2759 : {
2760 : // 入参合法性校验
2761 53 : RPT_INPUT_ERR(recvCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2762 : std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "recvCounts", "non-null pointer"}));
2763 33 : CHK_PTR_NULL(recvCounts);
2764 52 : RPT_INPUT_ERR(recvDispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2765 : std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "recvDispls", "non-null pointer"}));
2766 32 : CHK_PTR_NULL(recvDispls);
2767 51 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2768 : std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "comm", "non-null pointer"}));
2769 31 : CHK_PTR_NULL(comm);
2770 30 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2771 : std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "stream", "non-null pointer"}));
2772 30 : CHK_PTR_NULL(stream);
2773 30 : if (UNLIKELY(sendCount > 0 && sendBuf == nullptr)) {
2774 21 : RPT_INPUT_ERR(true, "EI0003",\
2775 : std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
2776 : std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "sendBuf", "non-null pointer"}));
2777 1 : CHK_PTR_NULL(sendBuf);
2778 : }
2779 :
2780 : // Group特性
2781 29 : if (hcclGroupDepth > 0) {
2782 : struct hcclOpInfo info;
2783 1 : info.coll = HcclCMDType::HCCL_CMD_ALLGATHER_V;
2784 1 : info.sendbuff = sendBuf;
2785 1 : info.recvbuff = recvBuf;
2786 1 : info.sendCount = sendCount;
2787 1 : info.recvCounts = recvCounts;
2788 1 : info.rdispls = recvDispls;
2789 1 : info.sendType = dataType;
2790 1 : info.recvType = dataType;
2791 1 : info.comm = comm;
2792 1 : info.stream = stream;
2793 1 : CHK_RET(taskAppend(comm, info));
2794 1 : HCCL_INFO("[HcclAllGatherV] Finish taskAppend, sendCount [%d] dataType [%s]", sendCount, GetDataTypeEnumStr(dataType).c_str());
2795 1 : return HCCL_SUCCESS;
2796 : }
2797 :
2798 28 : HcclUs startut = TIME_NOW();
2799 : bool isCapture;
2800 28 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
2801 28 : uint64_t modelId = 0xFFFFFFFF;
2802 28 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
2803 28 : if (!isCapture) {
2804 27 : HcclSetIfProfile();
2805 : }
2806 28 : s32 threadID = SalGetTid();
2807 28 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
2808 28 : uint64_t beginTime = hrtMsprofSysCycleTime();
2809 :
2810 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2811 28 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
2812 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2813 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
2814 : CHK_PTR_NULL(commV2);
2815 : CHK_RET(HcclAllGatherVV2(sendBuf, sendCount, recvBuf, const_cast<void*>(recvCounts), const_cast<void*>(recvDispls), dataType, commV2, stream));
2816 : return HCCL_SUCCESS;
2817 : }());
2818 : #endif
2819 28 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2820 28 : const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
2821 : // 同通信域同算子复用tag
2822 28 : const std::string tag = "AllGatherV_" + hcclComm->GetIdentifier();
2823 28 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), sendCount, dataType, stream), tag.c_str());
2824 :
2825 27 : u32 rankSize = INVALID_VALUE_RANKSIZE;
2826 27 : CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
2827 27 : u32 userRank = INVALID_VALUE_RANKID;
2828 27 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(userRank), tag.c_str());
2829 27 : CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, userRank), tag.c_str());
2830 :
2831 27 : u64 maxCount = 0;
2832 27 : u64 outputCount = 0;
2833 27 : u64* counts = static_cast<u64 *>(const_cast<void*>(recvCounts));
2834 61 : for (u32 i = 0; i < rankSize; i++) {
2835 34 : CHK_PRT_RET(counts[i] > SYS_MAX_COUNT,
2836 : HCCL_ERROR("HcclAllGatherVInner recvCounts[%u][%llu] is invalid.(bigger than MAX count[%llu])",
2837 : i, counts[i], SYS_MAX_COUNT),
2838 : HCCL_E_PARA);
2839 34 : outputCount += counts[i];
2840 34 : maxCount = std::max(maxCount, counts[i]);
2841 : }
2842 27 : CHK_PRT_RET(outputCount == 0, HCCL_WARNING("The outputCount is 0, this AllGatherV has no task to execute, "
2843 : "returning success."), HCCL_SUCCESS);
2844 46 : RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
2845 : std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "recvBuf", "non-null pointer"}));
2846 26 : CHK_PTR_NULL(recvBuf);
2847 :
2848 : /* 接口交互信息日志 */
2849 : char stackLogBuffer[LOG_TMPBUF_SIZE];
2850 25 : if (GetExternalInputHcclEnableEntryLog()) {
2851 25 : u32 localRank = INVALID_VALUE_RANKID;
2852 25 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
2853 :
2854 25 : s32 streamId = 0;
2855 25 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
2856 :
2857 25 : s32 deviceLogicId = 0;
2858 25 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
2859 :
2860 25 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
2861 : "tag[%s], sendBuf[%p], recvBuf[%p], sendCount[%llu], recvCounts[%u], recvDispls[%u], "
2862 : "dataType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
2863 : tag.c_str(), sendBuf, recvBuf, sendCount, recvCounts, recvDispls,
2864 50 : GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
2865 :
2866 25 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
2867 50 : std::string logInfo = "Entry-HcclAllGatherVInner:" + std::string(stackLogBuffer) +
2868 75 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
2869 25 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
2870 25 : }
2871 :
2872 50 : PrintCountsAndDispls(rankSize, recvCounts, recvDispls, tag.c_str());
2873 :
2874 25 : CheckCountsAndDispls(rankSize, recvCounts, recvDispls, tag.c_str());
2875 :
2876 25 : const u64 countOfThisRank = static_cast<const u64*>(recvCounts)[userRank];
2877 25 : CHK_PRT_RET(sendCount != countOfThisRank,
2878 : HCCL_ERROR("[HcclAllGatherVInner] input sendCount[%llu] is not equal to recvCounts[%u][%llu]", sendCount,
2879 : userRank, countOfThisRank),
2880 : HCCL_E_PARA);
2881 :
2882 23 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
2883 :
2884 23 : if(sendBuf != nullptr) {
2885 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
2886 : }
2887 :
2888 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
2889 :
2890 23 : CHK_RET_AND_PRINT_IDE(hcclComm->AllGatherVOutPlace(tag, sendBuf, recvBuf, sendCount, recvCounts, recvDispls,
2891 : dataType, stream), tag.c_str());
2892 :
2893 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLGATHER_V, beginTime, maxCount, dataType, tag));
2894 23 : if (!isCapture) {
2895 22 : HcclResetIfProfile();
2896 : }
2897 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
2898 :
2899 23 : if (GetExternalInputHcclEnableEntryLog()) {
2900 23 : HcclUs endut = TIME_NOW();
2901 : /* 关键状态记录 */
2902 23 : std::string endInfo = "HcclAllGatherVInner:success,take time: " +
2903 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
2904 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
2905 23 : }
2906 :
2907 23 : return HCCL_SUCCESS;
2908 28 : }
2909 :
2910 28 : HcclResult HcclSendInner(void* sendBuf, uint64_t count, HcclDataType dataType, uint32_t destRank,
2911 : HcclComm comm, aclrtStream stream)
2912 : {
2913 : // 入参合法性校验
2914 28 : CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return HcclSendInner success."), HCCL_SUCCESS);
2915 27 : CHK_PTR_NULL(comm);
2916 26 : CHK_PTR_NULL(sendBuf);
2917 25 : CHK_PTR_NULL(stream);
2918 25 : CHK_RET(HcomCheckCount(count));
2919 :
2920 : // Group特性
2921 25 : if (hcclGroupDepth > 0) {
2922 1 : HCCL_INFO("[HcclSendInner] groupDepth[%d]", hcclGroupDepth);
2923 : struct hcclOpInfo info;
2924 1 : info.coll = HcclCMDType::HCCL_CMD_SEND;
2925 1 : info.sendbuff = sendBuf;
2926 1 : info.sendCount = count;
2927 1 : info.sendType = dataType;
2928 1 : info.root = destRank;
2929 1 : info.comm = comm;
2930 1 : info.stream = stream;
2931 1 : CHK_RET(taskAppend(comm, info));
2932 1 : HCCL_INFO("[HcclSend] Finish taskAppend, count [%lld] dataType [%s] destRank [%u]", count, GetDataTypeEnumStr(dataType).c_str(), destRank);
2933 1 : return HCCL_SUCCESS;
2934 : }
2935 :
2936 24 : HcclUs startut = TIME_NOW();
2937 : bool isCapture;
2938 24 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
2939 24 : uint64_t modelId = 0xFFFFFFFF;
2940 24 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
2941 24 : if (!isCapture) {
2942 23 : HcclSetIfProfile();
2943 : }
2944 24 : uint64_t beginTime = hrtMsprofSysCycleTime();
2945 :
2946 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
2947 24 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
2948 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2949 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
2950 : CHK_PTR_NULL(commV2);
2951 : CHK_RET(HcclSendV2(sendBuf, count, dataType, destRank, commV2, stream));
2952 : return HCCL_SUCCESS;
2953 : }());
2954 : #endif
2955 24 : CHK_RET(HcomCheckDataType(dataType));
2956 24 : s32 streamId = 0;
2957 24 : CHK_RET(hrtGetStreamId(stream, streamId));
2958 :
2959 24 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
2960 24 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
2961 24 : s32 threadID = SalGetTid();
2962 24 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
2963 : // 同算子复用tag,为实现通信域复用,根据srRank和dstRank构造Tag
2964 24 : u32 localRank = INVALID_VALUE_RANKID;
2965 24 : CHK_RET(hcclComm->GetGroupRank(localRank));
2966 :
2967 48 : const string tag = "worldCommSendRecv_" + std::to_string(localRank) + "_" + std::to_string(destRank) + "_" +
2968 72 : hcclComm->GetIdentifier();
2969 :
2970 24 : HcomCollOpInfo opInfo = {"", sendBuf, sendBuf, count, dataType, 0, HCCL_REDUCE_RESERVED};
2971 : /* 接口交互信息日志 */
2972 : char stackLogBuffer[LOG_TMPBUF_SIZE];
2973 24 : if (GetExternalInputHcclEnableEntryLog()) {
2974 24 : s32 deviceLogicId = 0;
2975 24 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
2976 :
2977 24 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
2978 : "tag[%s], sendBuf[%p], count[%llu], dataType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
2979 48 : tag.c_str(), sendBuf, count, GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
2980 :
2981 24 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
2982 48 : std::string logInfo = "Entry-HcclSendInner:" + std::string(stackLogBuffer) +
2983 72 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
2984 24 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
2985 24 : }
2986 :
2987 24 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
2988 :
2989 24 : CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_SEND, tag, opInfo), tag.c_str());
2990 :
2991 24 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
2992 :
2993 24 : CHK_RET_AND_PRINT_IDE(hcclComm->SendOutPlace(tag, sendBuf, count, dataType, destRank, stream), tag.c_str());
2994 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_SEND, beginTime, count, dataType, tag));
2995 23 : if (!isCapture) {
2996 22 : HcclResetIfProfile();
2997 : }
2998 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
2999 :
3000 23 : if (GetExternalInputHcclEnableEntryLog()) {
3001 23 : HcclUs endut = TIME_NOW();
3002 : /* 关键状态记录 */
3003 23 : std::string endInfo = "HcclSendInner:success,take time: " +
3004 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
3005 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
3006 23 : }
3007 :
3008 23 : return HCCL_SUCCESS;
3009 24 : }
3010 :
3011 28 : HcclResult HcclRecvInner(void* recvBuf, uint64_t count, HcclDataType dataType, uint32_t srcRank,
3012 : HcclComm comm, aclrtStream stream)
3013 : {
3014 : // 入参合法性校验
3015 28 : CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return HcclRecvInner success."), HCCL_SUCCESS);
3016 27 : CHK_PTR_NULL(comm);
3017 26 : CHK_PTR_NULL(recvBuf);
3018 25 : CHK_PTR_NULL(stream);
3019 25 : CHK_RET(HcomCheckCount(count));
3020 :
3021 : // Group特性
3022 25 : if (hcclGroupDepth > 0) {
3023 1 : HCCL_INFO("[HcclRecvInner] groupDepth[%d]", hcclGroupDepth);
3024 : struct hcclOpInfo info;
3025 1 : info.coll = HcclCMDType::HCCL_CMD_RECEIVE;
3026 1 : info.recvbuff = recvBuf;
3027 1 : info.recvCount = count;
3028 1 : info.recvType = dataType;
3029 1 : info.root = srcRank;
3030 1 : info.comm = comm;
3031 1 : info.stream = stream;
3032 1 : CHK_RET(taskAppend(comm, info));
3033 1 : HCCL_INFO("[HcclRecv] Finish taskAppend, count [%d] dataType [%s] srcRank [%u]", count, GetDataTypeEnumStr(dataType).c_str(), srcRank);
3034 1 : return HCCL_SUCCESS;
3035 : }
3036 :
3037 24 : HcclUs startut = TIME_NOW();
3038 : bool isCapture;
3039 24 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
3040 24 : uint64_t modelId = 0xFFFFFFFF;
3041 24 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
3042 24 : if (!isCapture) {
3043 23 : HcclSetIfProfile();
3044 : }
3045 24 : uint64_t beginTime = hrtMsprofSysCycleTime();
3046 :
3047 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3048 24 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
3049 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3050 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
3051 : CHK_PTR_NULL(commV2);
3052 : CHK_RET(HcclRecvV2(recvBuf, count, dataType, srcRank, commV2, stream));
3053 : return HCCL_SUCCESS;
3054 : }());
3055 : #endif
3056 24 : CHK_RET(HcomCheckDataType(dataType));
3057 24 : s32 streamId = 0;
3058 24 : CHK_RET(hrtGetStreamId(stream, streamId));
3059 :
3060 24 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3061 24 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
3062 24 : s32 threadID = SalGetTid();
3063 24 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
3064 : // 同算子复用tag,为实现通信域复用,根据srRank和dstRank构造Tag
3065 24 : u32 localRank = INVALID_VALUE_RANKID;
3066 24 : CHK_RET(hcclComm->GetGroupRank(localRank));
3067 :
3068 48 : const string tag = "worldCommSendRecv_" + std::to_string(srcRank) + "_" + std::to_string(localRank) + "_" +
3069 72 : hcclComm->GetIdentifier();
3070 :
3071 24 : HcomCollOpInfo opInfo = {"", recvBuf, recvBuf, count, dataType, 0, HCCL_REDUCE_RESERVED};
3072 : /* 接口交互信息日志 */
3073 : char stackLogBuffer[LOG_TMPBUF_SIZE];
3074 24 : if (GetExternalInputHcclEnableEntryLog()) {
3075 24 : s32 deviceLogicId = 0;
3076 24 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
3077 :
3078 24 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
3079 : "tag[%s], recvBuf[%p], count[%llu], dataType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
3080 48 : tag.c_str(), recvBuf, count, GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
3081 :
3082 24 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
3083 48 : std::string logInfo = "Entry-HcclRecvInner:" + std::string(stackLogBuffer) +
3084 72 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
3085 24 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
3086 24 : }
3087 :
3088 24 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
3089 :
3090 24 : CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_RECEIVE, tag, opInfo), tag.c_str());
3091 :
3092 24 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
3093 :
3094 24 : CHK_RET_AND_PRINT_IDE(hcclComm->ReceiveOutPlace(tag, recvBuf, count, dataType, srcRank, stream), tag.c_str());
3095 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_RECEIVE, beginTime, count, dataType, tag));
3096 23 : if (!isCapture) {
3097 22 : HcclResetIfProfile();
3098 : }
3099 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
3100 :
3101 23 : if (GetExternalInputHcclEnableEntryLog()) {
3102 23 : HcclUs endut = TIME_NOW();
3103 : /* 关键状态记录 */
3104 23 : std::string endInfo = "HcclRecvInner:success,take time: " +
3105 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
3106 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
3107 23 : }
3108 :
3109 23 : return HCCL_SUCCESS;
3110 24 : }
3111 :
3112 0 : HcclResult HcclOneSidedCommDestroy(HcclComm comm, s32 deviceLogicId, HcclUs startut)
3113 : {
3114 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
3115 0 : std::string group = hcclComm->GetIdentifier();
3116 0 : CHK_PRT_RET(group.empty(),
3117 : HCCL_ERROR("[HcclCommDestroy][HcclOneSidedCommDestroy] commName is error."),
3118 : HCCL_E_PARA);
3119 0 : HCCL_RUN_INFO("Entry-%s: deviceLogicId[%d], commName[%s]",
3120 : __func__, deviceLogicId, group.c_str());
3121 :
3122 : #if (!defined(HCCD)) && (!defined(CCL_KERNEL_AICPU))
3123 0 : HcclResult ret = hcclComm->DeinitOneSidedService();
3124 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
3125 : HCCL_ERROR("[HcclCommDestroy][HcclOneSidedCommDestroy] Deinit one sided service"
3126 : " failed, commName[%s].", group.c_str()),
3127 : ret);
3128 : #endif
3129 :
3130 0 : HcclOpInfoCtx &opBaseHcom = GetOneSidedOpInfoCtx(deviceLogicId, hcclComm->GetIdentifier());
3131 :
3132 0 : g_oneSidedCommSet.erase(comm);
3133 0 : DeleteOneSidedIdentifier(group);
3134 :
3135 0 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
3136 0 : auto iter = opBaseHcom.opGroup2CommMap.find(group);
3137 0 : if (iter != opBaseHcom.opGroup2CommMap.end()) {
3138 0 : EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
3139 0 : HcclCloseCommConnections(group);
3140 : } else {
3141 0 : HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(),
3142 : deviceLogicId);
3143 0 : return HCCL_E_PARA;
3144 : }
3145 :
3146 0 : opBaseHcom.isUsed = false;
3147 0 : CHK_RET(DeInitOneSidedHcomInfo(deviceLogicId, group));
3148 :
3149 0 : HcclUs endut = TIME_NOW();
3150 : /* 关键状态记录 */
3151 0 : HCCL_USER_CRITICAL_LOG("op_base comm destroy complete, take time [%lld]us, group[%s], deviceLogicId[%d]",
3152 : DURATION_US(endut - startut), group.c_str(), deviceLogicId);
3153 :
3154 0 : return HCCL_SUCCESS;
3155 0 : }
3156 :
3157 235 : static HcclResult ResetDevice(hccl::hcclComm* hcclComm)
3158 : {
3159 235 : s32 logicDeviceId = 0;
3160 235 : CHK_RET(hcclComm->GetDeviceId(logicDeviceId));
3161 234 : g_hcclDeviceId = logicDeviceId;
3162 234 : if (hcclComm->IsNeedResetDevice()) {
3163 0 : HCCL_RUN_INFO("op_base com destroy, com is not global com");
3164 0 : HCCL_RUN_INFO("[HcclCommDestroy] reset logicDeviceId[%d]", logicDeviceId);
3165 0 : CHK_PRT_RET(hrtResetDevice(logicDeviceId) != HCCL_SUCCESS,
3166 : HCCL_ERROR("[HcclCommDestroy] reset fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
3167 : }
3168 234 : return HCCL_SUCCESS;
3169 : }
3170 :
3171 0 : HcclResult HcclCommDestroyWrapper(struct hcclAsyncJob* job_){
3172 0 : struct hcclCommDestroyAsyncJob* job = static_cast<hcclCommDestroyAsyncJob*>(job_);
3173 0 : HcclComm comm = job->initComm;
3174 0 : s32 devId = job->devId;
3175 0 : HCCL_DEBUG("[HcclCommDestroyWrapper] Set device devId: %d", devId);
3176 0 : CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
3177 : HCCL_ERROR("[HcclCommDestroyWrapper] set fail"), HCCL_E_INTERNAL);
3178 0 : HCCL_DEBUG("[HcclCommDestroyWrapper] Done Set device devId: %d", devId);
3179 :
3180 0 : HCCL_RUN_INFO("Entry-%s: op_base comm destroy begin", __func__);
3181 :
3182 0 : HcclUs startut = TIME_NOW();
3183 0 : s32 deviceLogicId = 0;
3184 0 : HcclResult ret = HcclDeviceRefresh(deviceLogicId);
3185 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclCommDestroy] Get device fail, comm=%p", comm), ret);
3186 0 : CHK_PRT_RET(comm == nullptr, HCCL_WARNING("[Destroy][HcclComm]An empty comm given, skip destroy."), HCCL_SUCCESS);
3187 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3188 0 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
3189 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3190 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
3191 : CHK_PTR_NULL(commV2);
3192 : CHK_RET(HcclCommDestroyV2(commV2)); // 临时处理,dpustream的销毁要在其他资源销毁前完成。待新方案CpuThread上库后,原dpuStream删除可以恢复顺序
3193 : string group = hcclComm->GetIdentifier();
3194 : HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
3195 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
3196 : auto iter = opBaseHcom.opGroup2CommMap.find(group);
3197 : if (iter != opBaseHcom.opGroup2CommMap.end()) {
3198 : EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
3199 : } else {
3200 : HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
3201 : return HCCL_E_PARA;
3202 : }
3203 : return HCCL_SUCCESS;
3204 : }());
3205 : #endif
3206 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3207 0 : HcclCommState state = hcclComm->GetState();
3208 0 : if (state == HcclCommState::INUSE) {
3209 0 : HCCL_WARNING("[HcclCommDestroy] comm is in use, please try again later");
3210 0 : return HCCL_E_AGAIN;
3211 : }
3212 0 : hcclComm->DeinitZeroCopyMemoryAgent();
3213 0 : HCCL_RUN_INFO("[HcclCommDestroy] comm state is %s", HcclCommStateToString(state));
3214 :
3215 0 : CHK_RET(hcclComm->SetStopFlag(true));
3216 0 : CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
3217 0 : CHK_RET(ResetDevice(hcclComm));
3218 :
3219 0 : if (IsOneSidedComm(comm)) {
3220 0 : return HcclOneSidedCommDestroy(comm, deviceLogicId, startut);
3221 : }
3222 :
3223 0 : HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
3224 0 : string group;
3225 0 : if (comm == opBaseHcom.pComm.get()) {
3226 0 : group = opBaseHcom.pComm->GetIdentifier();
3227 0 : opBaseHcom.pComm = nullptr;
3228 0 : HcclCloseCommConnections(group);
3229 : } else {
3230 0 : HCCL_RUN_INFO("com is not global com");
3231 0 : group = hcclComm->GetIdentifier();
3232 : }
3233 :
3234 : // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将hcomInfo.pComm设为nullptr
3235 0 : if (hcclComm->GetIdentifier() == HCCL_WORLD_GROUP) {
3236 0 : HcomGetCtxHomInfo().pComm = nullptr;
3237 : }
3238 :
3239 0 : HcomUnSetGroupTopoInfo(group.c_str());
3240 :
3241 0 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
3242 0 : auto iter = opBaseHcom.opGroup2CommMap.find(group);
3243 0 : if (iter != opBaseHcom.opGroup2CommMap.end()) {
3244 0 : EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
3245 0 : HcclCloseCommConnections(group);
3246 : } else {
3247 0 : HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
3248 0 : return HCCL_E_PARA;
3249 : }
3250 :
3251 0 : if (ProfilingManagerPub::GetAllState()) {
3252 0 : ProfilingManagerPub::ClearStoragedProfilingInfo();
3253 : }
3254 :
3255 0 : HcclUs endut = TIME_NOW();
3256 :
3257 : // 删除groupName和UDI的映射
3258 0 : HCCL_PROFILER_DEL_GROUP_UDI(group);
3259 :
3260 : /* 关键状态记录 */
3261 0 : HCCL_RUN_INFO("op_base comm destroy complete, take time [%lld]us, group[%s], deviceLogicId[%d].",
3262 : DURATION_US(endut - startut), group.c_str(), deviceLogicId);
3263 0 : return HCCL_SUCCESS;
3264 0 : }
3265 :
3266 303 : HcclResult HcclCommDestroy(HcclComm comm)
3267 : {
3268 303 : if(hcclGroupDepth > 0){
3269 0 : std::shared_ptr<struct hcclCommDestroyAsyncJob> job;
3270 0 : EXCEPTION_CATCH((job = std::make_shared<struct hcclCommDestroyAsyncJob>()), return HCCL_E_PARA);
3271 0 : job->initComm = comm;
3272 0 : s32 devId = 0;
3273 0 : HcclResult ret = HcclDeviceRefresh(devId);
3274 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Group][HcclCommDestroy] Get device fail, comm=%p", comm), ret);
3275 0 : job->devId = devId;
3276 0 : ret = commInitTaskAppend(job, HcclCommDestroyWrapper, &comm);
3277 0 : return ret;
3278 0 : }
3279 303 : HCCL_RUN_INFO("Entry-%s: op_base comm destroy begin", __func__);
3280 :
3281 303 : HcclUs startut = TIME_NOW();
3282 303 : s32 deviceLogicId = 0;
3283 303 : HcclResult ret = HcclDeviceRefresh(deviceLogicId);
3284 303 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclCommDestroy] Get device fail, comm=%p", comm), ret);
3285 302 : CHK_PRT_RET(comm == nullptr, HCCL_WARNING("[Destroy][HcclComm]An empty comm given, skip destroy."), HCCL_SUCCESS);
3286 :
3287 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3288 235 : HCCLV2_FUNC_RUN(
3289 : [&]() -> HcclResult {
3290 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3291 : // 先拷贝orion通信域地址,避免coll comm销毁后无法获取
3292 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
3293 : CHK_RET(HcclCommDestroyV2(commV2)); // 临时处理,dpustream的销毁要在其他资源销毁前完成。待新方案CpuThread上库后,原dpuStream删除可以恢复顺序
3294 : string group = hcclComm->GetIdentifier();
3295 : HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
3296 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
3297 : auto iter = opBaseHcom.opGroup2CommMap.find(group);
3298 : if (iter != opBaseHcom.opGroup2CommMap.end()) {
3299 : EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
3300 : } else {
3301 : HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
3302 : return HCCL_E_PARA;
3303 : }
3304 : return HCCL_SUCCESS;
3305 : }());
3306 : #endif
3307 235 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3308 235 : HcclCommState state = hcclComm->GetState();
3309 235 : if (state == HcclCommState::INUSE) {
3310 0 : HCCL_WARNING("[HcclCommDestroy] comm is in use, please try again later");
3311 0 : return HCCL_E_AGAIN;
3312 : }
3313 235 : hcclComm->DeinitZeroCopyMemoryAgent();
3314 235 : HCCL_RUN_INFO("[HcclCommDestroy] comm state is %s", HcclCommStateToString(state));
3315 235 : CHK_RET(hcclComm->RealeaseShareCCLbuffer());
3316 235 : CHK_RET(hcclComm->SetStopFlag(true));
3317 235 : CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
3318 235 : CHK_RET(ResetDevice(hcclComm));
3319 :
3320 234 : std::unique_lock<std::mutex> oneSideLock(g_opHcomOneSideMutex);
3321 234 : if (IsOneSidedComm(comm)) {
3322 0 : return HcclOneSidedCommDestroy(comm, deviceLogicId, startut);
3323 : }
3324 234 : oneSideLock.unlock();
3325 :
3326 234 : HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
3327 234 : string group;
3328 234 : if (comm == opBaseHcom.pComm.get()) {
3329 233 : group = opBaseHcom.pComm->GetIdentifier();
3330 233 : opBaseHcom.pComm = nullptr;
3331 233 : HcclCloseCommConnections(group);
3332 : } else {
3333 1 : HCCL_RUN_INFO("com is not global com");
3334 1 : group = hcclComm->GetIdentifier();
3335 : }
3336 :
3337 : // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将hcomInfo.pComm设为nullptr
3338 234 : if (hcclComm->GetIdentifier() == HCCL_WORLD_GROUP) {
3339 233 : HcomGetCtxHomInfo().pComm = nullptr;
3340 : }
3341 :
3342 234 : HcomUnSetGroupTopoInfo(group.c_str());
3343 :
3344 234 : std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
3345 234 : auto iter = opBaseHcom.opGroup2CommMap.find(group);
3346 234 : if (iter != opBaseHcom.opGroup2CommMap.end()) {
3347 234 : EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
3348 234 : HcclCloseCommConnections(group);
3349 : } else {
3350 0 : HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
3351 0 : return HCCL_E_PARA;
3352 : }
3353 :
3354 234 : if (ProfilingManagerPub::GetAllState()) {
3355 234 : ProfilingManagerPub::ClearStoragedProfilingInfo();
3356 : }
3357 :
3358 234 : HcclUs endut = TIME_NOW();
3359 :
3360 : // 删除groupName和UDI的映射
3361 234 : HCCL_PROFILER_DEL_GROUP_UDI(group);
3362 :
3363 : /* 关键状态记录 */
3364 234 : HCCL_RUN_INFO("op_base comm destroy complete, take time [%lld]us, group[%s], deviceLogicId[%d].",
3365 : DURATION_US(endut - startut), group.c_str(), deviceLogicId);
3366 :
3367 234 : return HCCL_SUCCESS;
3368 234 : }
3369 :
3370 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3371 0 : static HcclConfigTypeOpExpansionMode OpExpansionModeValueToModeEnum(const uint32_t value)
3372 : {
3373 0 : constexpr uint32_t defaultMode = 0;
3374 0 : constexpr uint32_t hostTsMode = 1;
3375 0 : constexpr uint32_t aicpuTsMode = 2;
3376 0 : constexpr uint32_t aivMode = 3;
3377 0 : constexpr uint32_t aivOnlyMode = 4;
3378 0 : constexpr uint32_t ccuMsMode = 5;
3379 0 : constexpr uint32_t ccuSchedMode = 6;
3380 0 : constexpr uint32_t aicpuMode = 7;
3381 :
3382 0 : switch(value) {
3383 0 : case defaultMode:
3384 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_CCU_SCHED;
3385 0 : case hostTsMode:
3386 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_HOST_TS;
3387 0 : case aicpuTsMode:
3388 : case aicpuMode:
3389 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_AI_CPU;
3390 0 : case ccuMsMode:
3391 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_CCU_MS;
3392 0 : case ccuSchedMode:
3393 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_CCU_SCHED;
3394 0 : case aivMode:
3395 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_AIV;
3396 0 : case aivOnlyMode:
3397 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_AIV_ONLY;
3398 0 : default:
3399 0 : break;
3400 : }
3401 :
3402 0 : return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_INVALID;
3403 : }
3404 : #endif
3405 :
3406 1 : HcclResult HcclConfigGetInfo(HcclComm comm, HcclConfigType cfgType,
3407 : uint32_t infoLen, void *info)
3408 : {
3409 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3410 1 : CHK_PTR_NULL(comm);
3411 1 : CHK_PTR_NULL(info);
3412 :
3413 1 : if (cfgType != HcclConfigType::HCCL_CONFIG_TYPE_OP_EXPANSION_MODE) {
3414 0 : HCCL_ERROR("[%s] cfgType[%d] is invalid.", __func__, cfgType);
3415 0 : return HcclResult::HCCL_E_PARA;
3416 : }
3417 :
3418 1 : constexpr size_t infoExpectedLen = sizeof(HcclConfigTypeOpExpansionMode);
3419 1 : if (static_cast<size_t>(infoLen) != infoExpectedLen) {
3420 0 : HCCL_ERROR("[%s] cfgType[%d] infoLen[%u] is not equal to expected[%zu].",
3421 : __func__, cfgType, infoLen, infoExpectedLen);
3422 0 : return HcclResult::HCCL_E_PARA;
3423 : }
3424 :
3425 1 : auto *hcclComm = static_cast<hccl::hcclComm *>(comm);
3426 1 : auto *collComm = hcclComm->GetCollComm();
3427 1 : CHK_PTR_NULL(collComm);
3428 0 : auto *myRank = collComm->GetMyRank();
3429 0 : CHK_PTR_NULL(myRank);
3430 0 : const uint32_t opExpansionModeValue = myRank->GetOpExpansionMode();
3431 0 : const auto opExpansionMode = OpExpansionModeValueToModeEnum(opExpansionModeValue);
3432 0 : if (opExpansionMode == HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_INVALID) {
3433 0 : HCCL_ERROR("[%s] unknown expansion mode[%d].", __func__, opExpansionMode);
3434 0 : return HcclResult::HCCL_E_INTERNAL;
3435 : }
3436 :
3437 0 : auto *modeInfo = static_cast<HcclConfigTypeOpExpansionMode *>(info);
3438 0 : *modeInfo = opExpansionMode;
3439 0 : return HcclResult::HCCL_SUCCESS;
3440 : #endif
3441 :
3442 : HCCL_ERROR("[%s] is not support for hccd or kernel.", __func__);
3443 : return HcclResult::HCCL_E_NOT_SUPPORT;
3444 : }
3445 :
3446 235 : HcclResult HcclGenerateCommId(hccl::HcclCommParams ¶ms)
3447 : {
3448 235 : s32 sRet = memset_s(params.id.internal, HCCL_ROOT_INFO_BYTES, 0, sizeof(params.id.internal));
3449 235 : CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[GenerateCommId]memory set error. return[%d].", sRet), HCCL_E_PARA);
3450 :
3451 : HcclRootInfo uniqueId;
3452 235 : std::string group;
3453 235 : CHK_RET(hcclComm::GetUniqueId(&uniqueId));
3454 :
3455 235 : if (!params.isHeterogComm) {
3456 235 : group = "hccl_world_group";
3457 : } else {
3458 0 : group = "hccl_heterog_group";
3459 : }
3460 :
3461 235 : sRet = snprintf_s(params.id.internal, HCCL_ROOT_INFO_BYTES, HCCL_ROOT_INFO_BYTES - 1, "%s%s%s",
3462 : uniqueId.internal, "-", group.c_str());
3463 235 : CHK_PRT_RET(sRet == -1, HCCL_ERROR("[GenerateCommId]errNo[0x%016llx] sal snprintf_s error",
3464 : HCCL_ERROR_CODE(HCCL_E_INTERNAL)), HCCL_E_INTERNAL);
3465 235 : HCCL_INFO("params.id.internal [%s]", params.id.internal);
3466 235 : return HCCL_SUCCESS;
3467 235 : }
3468 :
3469 235 : HcclResult InitOtherInfo(hccl::HcclCommParams ¶ms, const char *rankTable)
3470 : {
3471 : // 记录版本信息
3472 235 : std::string curVersion = GetExternalInputCannVersion();
3473 235 : CHK_RET(RankConsistentcyChecker::GetInstance().RecordVerInfo(curVersion));
3474 :
3475 : // ranktableCRC计算
3476 235 : if (rankTable == nullptr) {
3477 0 : HCCL_INFO("rank table is null, rankTableCrc is 0.");
3478 : } else {
3479 235 : HcclResult ret = HcomCalcCRC(params, rankTable);
3480 235 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][OtherInfo]errNo[0x%016llx] calc ranktable crc error",
3481 : HCCL_ERROR_CODE(HCCL_E_INTERNAL)), HCCL_E_INTERNAL);
3482 : }
3483 :
3484 : // 生成通信域标识符
3485 235 : HcclResult ret = HcclGenerateCommId(params);
3486 235 : CHK_PRT_RET(ret != HCCL_SUCCESS,
3487 : HCCL_ERROR("[Init][OtherInfo]errNo[0x%016llx] generate CommId error, params: dest[%p]",
3488 : HCCL_ERROR_CODE(HCCL_E_INTERNAL), params.id.internal), HCCL_E_INTERNAL);
3489 235 : return HCCL_SUCCESS;
3490 235 : }
3491 :
3492 0 : HcclResult ReduceScatterLoop(const std::string &tag, void *inputPtr, void *outputPtr, const u64 &count,
3493 : HcclDataType dataType, HcclReduceOp op, hccl::hcclComm *hcclComm, rtStream_t stream)
3494 : {
3495 : HcclResult ret;
3496 0 : void *commInputPtr = nullptr;
3497 0 : void *commOutputPtr = nullptr;
3498 : u64 commInputSize, commOutputSize;
3499 :
3500 0 : CHK_RET(hcclComm->GetInCCLbuffer(commInputPtr, commInputSize));
3501 :
3502 0 : CHK_RET(hcclComm->GetOutCCLbuffer(commOutputPtr, commOutputSize));
3503 :
3504 : u32 unitSize;
3505 0 : CHK_RET(SalGetDataTypeSize(dataType, unitSize));
3506 :
3507 0 : char *curInputPtr = static_cast<char *>(inputPtr);
3508 0 : char *curOutputPtr = static_cast<char *>(outputPtr);
3509 0 : u32 rankSize = INVALID_VALUE_RANKSIZE;
3510 0 : CHK_RET(hcclComm->GetRankSize(rankSize));
3511 :
3512 0 : CHK_PRT_RET(rankSize * unitSize == 0, HCCL_ERROR("The result of rankSize * unitSize is 0"), HCCL_E_PARA);
3513 0 : u64 maxCountPerLoop = commInputSize / (rankSize * unitSize); // 中转内存单次最多能够接受的output count
3514 0 : u64 curCount = 0;
3515 :
3516 0 : for (u64 countLeft = count, inputOffset = 0, outputOffset = 0; countLeft > 0; countLeft -= curCount) {
3517 0 : curInputPtr += inputOffset;
3518 0 : curOutputPtr += outputOffset;
3519 0 : HCCL_INFO("-OP_BASE-ReduceScatterLoop:inputOffset[%llu], outputOffset[%llu]", inputOffset, outputOffset);
3520 : // 判断剩余数据量对应的input size是否大于中转input size
3521 0 : curCount = ((countLeft * unitSize * rankSize) > commInputSize) ? maxCountPerLoop : countLeft;
3522 0 : u64 curSize = curCount * unitSize; // 单位:字节
3523 :
3524 0 : for (u32 i = 0; i < rankSize; i++) {
3525 : // 拷贝input上每个slice的数据到中转内存,源端每个slice的size固定为output的size
3526 0 : ret = hrtMemAsyncCopy(static_cast<char *>(commInputPtr) + curSize * i, curSize,
3527 0 : curInputPtr + count * unitSize * i, curSize, HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE,
3528 : stream);
3529 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
3530 : HCCL_ERROR("[Loop][ReduceScatter]In OP_BASE inputbuffer transit,[%u]slice memcopy "\
3531 : "failed", i), HCCL_E_MEMORY);
3532 : }
3533 :
3534 0 : ret = hcclComm->ReduceScatter(tag, commInputPtr, commOutputPtr, curCount, dataType, op, stream);
3535 :
3536 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
3537 : HCCL_ERROR("[Loop][ReduceScatter]errNo[0x%016llx] op_base hcclComm ReduceScatter error, "\
3538 : "tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s]",
3539 : HCCL_ERROR_CODE(ret), tag.c_str(), commInputPtr, commOutputPtr, curCount,
3540 : GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str()), ret);
3541 :
3542 0 : CHK_RET(hrtMemAsyncCopy(curOutputPtr, curSize, commOutputPtr, curSize,
3543 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE, stream));
3544 :
3545 0 : CHK_PRT_RET((curCount == 0), HCCL_ERROR("[Loop][ReduceScatter]In OP_BASE curCount is zero"), HCCL_E_PARA);
3546 0 : inputOffset = curSize;
3547 0 : outputOffset = curSize;
3548 : }
3549 :
3550 0 : return HCCL_SUCCESS;
3551 : }
3552 :
3553 : // 获取算子所需workspace memory大小[byte]
3554 0 : HcclResult HcclGetOpBasedMemSize(const HcclCMDType &opType, u64 &size,
3555 : const HcomCollOpInfo &opInfo)
3556 : {
3557 0 : u64 opMemSize = 0;
3558 :
3559 0 : if (opType == HcclCMDType::HCCL_CMD_REDUCE_SCATTER) {
3560 : // ReduceScatter 算子所需memory大小为 GetExternalInputCCLBuffSize()
3561 : DevType devType;
3562 0 : CHK_RET(hrtGetDeviceType(devType));
3563 0 : if (IsSupportSDMAReduce(opInfo.inputAddr, opInfo.outputAddr, opInfo.dataType, opInfo.reduceOp) &&
3564 0 : IsSupportRDMAReduce(opInfo.dataType, opInfo.reduceOp) && devType == DevType::DEV_TYPE_910B) {
3565 0 : opMemSize = 0;
3566 : } else {
3567 0 : opMemSize = GetExternalInputCCLBuffSize();
3568 : }
3569 : } else {
3570 0 : opMemSize = 0;
3571 : }
3572 0 : size = HCCL_WORKSPACE_MEM_32_KB + opMemSize;
3573 0 : HCCL_INFO("workspace memory size: op[%d], memory size[%llu]", opType, size);
3574 0 : return HCCL_SUCCESS;
3575 : }
3576 :
3577 30 : HcclResult HcclAlltoAllInner(const void *sendBuf, uint64_t sendCount, HcclDataType sendType, const void *recvBuf,
3578 : uint64_t recvCount, HcclDataType recvType, HcclComm comm, aclrtStream stream)
3579 : {
3580 : // 入参校验
3581 30 : CHK_PRT_RET(sendCount == 0 && recvCount == 0,
3582 : HCCL_WARNING("sendCount and recvCount are both 0, return AllToAll success"), HCCL_SUCCESS);
3583 49 : RPT_INPUT_ERR(sendBuf == nullptr, "EI0003",\
3584 : std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
3585 : std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "sendBuf", "non-null pointer"}));
3586 29 : CHK_PTR_NULL(sendBuf);
3587 48 : RPT_INPUT_ERR(recvBuf == nullptr, "EI0003",\
3588 : std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
3589 : std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "recvBuf", "non-null pointer"}));
3590 28 : CHK_PTR_NULL(recvBuf);
3591 27 : CHK_PRT_RET(sendCount != recvCount,
3592 : HCCL_ERROR("sendCount[%lu] and recvCount[%lu] are not equal, please check params",
3593 : sendCount, recvCount), HCCL_E_PARA);
3594 26 : CHK_PRT_RET(sendType != recvType,
3595 : HCCL_ERROR("sendType[%s] and recvType[%s] are not equal, please check params",
3596 : GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str()), HCCL_E_PARA);
3597 :
3598 25 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
3599 : std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "stream", "non-null pointer"}));
3600 25 : CHK_PTR_NULL(stream);
3601 45 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
3602 : std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "comm", "non-null pointer"}));
3603 25 : CHK_PTR_NULL(comm);
3604 24 : CHK_PRT_RET(sendBuf == recvBuf,
3605 : HCCL_ERROR("[HcclAlltoAllInner] sendBuf and recvBuf cannot be same."), HCCL_E_PARA);
3606 :
3607 : // Group特性
3608 24 : if (hcclGroupDepth > 0) {
3609 : struct hcclOpInfo info;
3610 1 : info.coll = HcclCMDType::HCCL_CMD_ALLTOALL;
3611 1 : info.sendbuff = const_cast<void *>(sendBuf);
3612 1 : info.recvbuff = const_cast<void *>(recvBuf);
3613 1 : info.sendCount = sendCount;
3614 1 : info.recvCount = recvCount;
3615 1 : info.comm = comm;
3616 1 : info.stream = stream;
3617 1 : CHK_RET(taskAppend(comm, info));
3618 1 : HCCL_INFO("[HcclAlltoAll] Finish taskAppend, sendCount [%d] sendType [%s] recvCount [%d] recvType [%s]", sendCount, GetDataTypeEnumStr(sendType).c_str(), recvCount, GetDataTypeEnumStr(recvType).c_str());
3619 1 : return HCCL_SUCCESS;
3620 : }
3621 :
3622 23 : HcclUs startut = TIME_NOW();
3623 : bool isCapture;
3624 23 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
3625 23 : uint64_t modelId = 0xFFFFFFFF;
3626 23 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
3627 23 : if (!isCapture) {
3628 22 : HcclSetIfProfile();
3629 : }
3630 :
3631 23 : uint64_t beginTime = hrtMsprofSysCycleTime();
3632 :
3633 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3634 23 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
3635 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3636 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
3637 : CHK_PTR_NULL(commV2);
3638 : CHK_RET(HcclAlltoAllV2(sendBuf, sendCount, sendType, recvBuf, recvCount, recvType, commV2, stream));
3639 : return HCCL_SUCCESS;
3640 : }());
3641 : #endif
3642 23 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3643 23 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
3644 23 : s32 threadID = SalGetTid();
3645 23 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
3646 23 : const std::string tag = HCCL_ALLTOALL + "_" + hcclComm->GetIdentifier();
3647 23 : CHK_RET(HcomCheckOpParam(tag.c_str(), 0, sendType, stream));
3648 23 : CHK_RET(HcomCheckDataType(recvType));
3649 : // 接口交互信息日志
3650 : char stackLogBuffer[LOG_TMPBUF_SIZE];
3651 23 : if (GetExternalInputHcclEnableEntryLog()) {
3652 23 : s32 deviceLogicId = 0;
3653 23 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
3654 :
3655 23 : u32 localRank = INVALID_VALUE_RANKID;
3656 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
3657 :
3658 23 : s32 streamId = 0;
3659 23 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
3660 :
3661 46 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
3662 : "tag[%s], sendCount[%llu], recvCount[%llu], sendType[%s], recvType[%s], localRank[%u], streamId[%d], "
3663 : "deviceLogicId[%d]",
3664 69 : tag.c_str(), sendCount, recvCount, GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str(),
3665 : localRank, streamId, deviceLogicId);
3666 :
3667 23 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
3668 46 : std::string logInfo = "Entry-HcclAlltoAllInner:" + std::string(stackLogBuffer) +
3669 69 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
3670 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
3671 23 : }
3672 :
3673 23 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
3674 :
3675 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
3676 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
3677 :
3678 23 : CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAll(sendBuf, sendCount, sendType, recvBuf, recvCount, recvType, stream, tag),
3679 : tag.c_str());
3680 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALL, beginTime, sendCount, sendType,
3681 : tag));
3682 23 : if (!isCapture) {
3683 22 : HcclResetIfProfile();
3684 : }
3685 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
3686 :
3687 23 : if (GetExternalInputHcclEnableEntryLog()) {
3688 23 : HcclUs endut = TIME_NOW();
3689 23 : std::string endInfo = "HcclAlltoAllInner:success,take time: " +
3690 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
3691 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
3692 23 : }
3693 :
3694 23 : return HCCL_SUCCESS;
3695 23 : }
3696 :
3697 : // sendBuf & recvBuf为device mem, 其它为host mem
3698 34 : HcclResult HcclAlltoAllVInner(const void *sendBuf, const void *sendCounts, const void *sdispls, HcclDataType sendType,
3699 : const void *recvBuf, const void *recvCounts, const void *rdispls, HcclDataType recvType,
3700 : HcclComm comm, aclrtStream stream)
3701 : {
3702 : // 入参校验
3703 54 : RPT_INPUT_ERR(sendCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3704 : std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "sendCounts", "non-null pointer"}));
3705 34 : CHK_PTR_NULL(sendCounts);
3706 53 : RPT_INPUT_ERR(sdispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3707 : std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "sdispls", "non-null pointer"}));
3708 33 : CHK_PTR_NULL(sdispls);
3709 52 : RPT_INPUT_ERR(recvCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3710 : std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "recvCounts", "non-null pointer"}));
3711 32 : CHK_PTR_NULL(recvCounts);
3712 51 : RPT_INPUT_ERR(rdispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3713 : std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "rdispls", "non-null pointer"}));
3714 31 : CHK_PTR_NULL(rdispls);
3715 30 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3716 : std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "stream", "non-null pointer"}));
3717 30 : CHK_PTR_NULL(stream);
3718 50 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3719 : std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "comm", "non-null pointer"}));
3720 30 : CHK_PTR_NULL(comm);
3721 :
3722 : // Group特性
3723 29 : if (hcclGroupDepth > 0) {
3724 : struct hcclOpInfo info;
3725 1 : info.coll = HcclCMDType::HCCL_CMD_ALLTOALLV;
3726 1 : info.sendbuff = const_cast<void *>(sendBuf);
3727 1 : info.recvbuff = const_cast<void *>(recvBuf);
3728 1 : info.sendCounts = sendCounts;
3729 1 : info.recvCounts = recvCounts;
3730 1 : info.sdispls = sdispls;
3731 1 : info.rdispls = rdispls;
3732 1 : info.sendType = sendType;
3733 1 : info.recvType = recvType;
3734 1 : info.comm = comm;
3735 1 : info.stream = stream;
3736 1 : CHK_RET(taskAppend(comm, info));
3737 1 : HCCL_INFO("[HcclAlltoAllV] Finish taskAppend, sendType [%s] recvType [%s]", GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str());
3738 1 : return HCCL_SUCCESS;
3739 : }
3740 :
3741 28 : HcclUs startut = TIME_NOW();
3742 : bool isCapture;
3743 28 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
3744 28 : uint64_t modelId = 0xFFFFFFFF;
3745 28 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
3746 28 : if (!isCapture) {
3747 27 : HcclSetIfProfile();
3748 : }
3749 28 : uint64_t beginTime = hrtMsprofSysCycleTime();
3750 :
3751 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3752 28 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
3753 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3754 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
3755 : CHK_PTR_NULL(commV2);
3756 : CHK_RET(HcclAlltoAllVV2(sendBuf, sendCounts, sdispls, sendType, recvBuf, recvCounts, rdispls, recvType, commV2, stream));
3757 : return HCCL_SUCCESS;
3758 : }());
3759 : #endif
3760 28 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3761 28 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
3762 28 : s32 threadID = SalGetTid();
3763 28 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
3764 28 : u32 rankSize = 0;
3765 28 : CHK_RET(hcclComm->GetRankSize(rankSize));
3766 28 : CHK_RET(HcomCheckAlltoAllVExternalMem(sendBuf, sendCounts, recvBuf, recvCounts, rankSize));
3767 :
3768 25 : const std::string tag = HCCL_ALLTOALLV + "_" + hcclComm->GetIdentifier();
3769 25 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), 0, sendType, stream), tag.c_str());
3770 25 : CHK_RET_AND_PRINT_IDE(HcomCheckDataType(recvType), tag.c_str());
3771 : /* 接口交互信息日志 */
3772 : char stackLogBuffer[LOG_TMPBUF_SIZE];
3773 25 : if (GetExternalInputHcclEnableEntryLog()) {
3774 25 : s32 deviceLogicId = 0;
3775 25 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
3776 :
3777 25 : u32 localRank = INVALID_VALUE_RANKID;
3778 25 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
3779 :
3780 25 : s32 streamId = 0;
3781 25 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
3782 :
3783 50 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
3784 : "tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], recvCounts[%p], sendType[%s], "
3785 : "recvType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
3786 50 : tag.c_str(), sendBuf, recvBuf, sendCounts, recvCounts, GetDataTypeEnumStr(sendType).c_str(),
3787 50 : GetDataTypeEnumStr(recvType).c_str(), localRank, streamId, deviceLogicId);
3788 :
3789 25 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
3790 50 : std::string logInfo = "Entry-HcclAlltoAllVInner:" + std::string(stackLogBuffer) +
3791 75 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
3792 25 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
3793 25 : }
3794 :
3795 25 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
3796 :
3797 25 : if (sendBuf != nullptr) {
3798 25 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
3799 : }
3800 25 : if (recvBuf != nullptr) {
3801 25 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
3802 : }
3803 :
3804 25 : if (!GetExternalInputHcclEnableFfts()) {
3805 24 : CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllV(sendBuf, sendCounts, sdispls, sendType, recvBuf,
3806 : recvCounts, rdispls, recvType, stream, tag), tag.c_str());
3807 : } else {
3808 1 : CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllVOutPlace(sendBuf, sendCounts, sdispls, sendType, recvBuf,
3809 : recvCounts, rdispls, recvType, stream, tag), tag.c_str());
3810 : }
3811 :
3812 25 : u64 sendCount = 0;
3813 57 : for (u32 i = 0; i < rankSize; i++) {
3814 32 : sendCount += *(static_cast<const u64 *>(sendCounts) + i);
3815 : }
3816 25 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALLV, beginTime, sendCount, sendType, tag));
3817 25 : if (!isCapture) {
3818 24 : HcclResetIfProfile();
3819 : }
3820 25 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
3821 :
3822 25 : if (GetExternalInputHcclEnableEntryLog()) {
3823 25 : HcclUs endut = TIME_NOW();
3824 : /* 关键状态记录 */
3825 25 : std::string endInfo = "HcclAlltoAllVInner:success,take time: " +
3826 50 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
3827 25 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
3828 25 : }
3829 :
3830 25 : return HCCL_SUCCESS;
3831 28 : }
3832 :
3833 1 : HcclResult HcclAlltoAllVCInner(const void *sendBuf, const void *sendCountMatrix,
3834 : HcclDataType sendType, const void *recvBuf, HcclDataType recvType,
3835 : HcclComm comm, rtStream_t stream)
3836 : {
3837 : // 参数校验
3838 1 : RPT_INPUT_ERR(sendCountMatrix == nullptr, "EI0003",\
3839 : std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3840 : std::vector<std::string>({"HcclAlltoAllVCInner", "nullptr", "sendCountMatrix", "non-null pointer"}));
3841 1 : CHK_PTR_NULL(sendCountMatrix);
3842 1 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3843 : std::vector<std::string>({"HcclAlltoAllVCInner", "nullptr", "comm", "non-null pointer"}));
3844 1 : CHK_PTR_NULL(comm);
3845 1 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3846 : std::vector<std::string>({"HcclAlltoAllVCInner", "nullptr", "stream", "non-null pointer"}));
3847 1 : CHK_PTR_NULL(stream);
3848 :
3849 : // Group特性
3850 1 : if (hcclGroupDepth > 0) {
3851 : struct hcclOpInfo info;
3852 1 : info.coll = HcclCMDType::HCCL_CMD_ALLTOALLVC;
3853 1 : info.sendbuff = const_cast<void *>(sendBuf);
3854 1 : info.recvbuff = const_cast<void *>(recvBuf);
3855 1 : info.sendCounts = sendCountMatrix;
3856 1 : info.sendType = sendType;
3857 1 : info.recvType = recvType;
3858 1 : info.comm = comm;
3859 1 : info.stream = stream;
3860 1 : CHK_RET(taskAppend(comm, info));
3861 1 : HCCL_INFO("[HcclAlltoAllVC] Finish taskAppend, sendType [%s] recvType [%s]", GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str());
3862 1 : return HCCL_SUCCESS;
3863 : }
3864 :
3865 0 : HcclUs startut = TIME_NOW();
3866 : bool isCapture;
3867 0 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
3868 0 : uint64_t modelId = 0xFFFFFFFF;
3869 0 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
3870 0 : if (!isCapture) {
3871 0 : HcclSetIfProfile();
3872 : }
3873 0 : s32 threadID = SalGetTid();
3874 0 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
3875 0 : uint64_t beginTime = hrtMsprofSysCycleTime();
3876 :
3877 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
3878 0 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
3879 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3880 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
3881 : CHK_PTR_NULL(commV2);
3882 : CHK_RET(HcclAlltoAllVCV2(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, commV2, stream));
3883 : return HCCL_SUCCESS;
3884 : }());
3885 : #endif
3886 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
3887 0 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
3888 :
3889 0 : u32 rankSize = 0;
3890 0 : CHK_RET(hcclComm->GetRankSize(rankSize));
3891 0 : u32 rank = 0;
3892 0 : hcclComm->GetUserRank(rank);
3893 0 : u32 userRank = 0;
3894 0 : hcclComm->GetGroupRank(userRank);
3895 :
3896 0 : CHK_RET(HcomCheckAlltoAllVCExternalMem(sendBuf, sendCountMatrix, recvBuf, rankSize, rank));
3897 0 : const std::string tag = HCCL_ALLTOALLVC + "_" + hcclComm->GetIdentifier();
3898 0 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), 0, sendType, stream), tag.c_str());
3899 0 : CHK_RET_AND_PRINT_IDE(HcomCheckDataType(recvType), tag.c_str());
3900 :
3901 : /* 接口交互信息日志 */
3902 : char stackLogBuffer[LOG_TMPBUF_SIZE];
3903 0 : if (GetExternalInputHcclEnableEntryLog()) {
3904 : u64 sendCountMatrixHash;
3905 0 : HcomGetHashFromSendCountMatrix(sendCountMatrixHash, sendCountMatrix, rankSize, tag);
3906 :
3907 0 : s32 deviceLogicId = 0;
3908 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
3909 :
3910 0 : u32 localRank = INVALID_VALUE_RANKID;
3911 0 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
3912 :
3913 0 : s32 streamId = 0;
3914 0 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
3915 :
3916 0 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
3917 : "tag[%s], sendBuf[%p], sendCountMatrixHash[%llu], sendType[%s], recvBuf[%p], "
3918 : "recvType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
3919 0 : tag.c_str(), sendBuf, sendCountMatrixHash, GetDataTypeEnumStr(sendType).c_str(), recvBuf,
3920 0 : GetDataTypeEnumStr(recvType).c_str(), localRank, streamId, deviceLogicId);
3921 :
3922 0 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
3923 0 : std::string logInfo = "Entry-HcclAlltoAllVCInner:" + std::string(stackLogBuffer) +
3924 0 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
3925 0 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
3926 0 : }
3927 :
3928 0 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
3929 :
3930 0 : if (sendBuf != nullptr) {
3931 0 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
3932 : }
3933 0 : if (recvBuf != nullptr) {
3934 0 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
3935 : }
3936 :
3937 0 : if (!GetExternalInputHcclEnableFfts()) {
3938 0 : CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllVC(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, stream, tag),
3939 : tag.c_str());
3940 : } else {
3941 0 : CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllVCOutPlace(sendBuf, sendCountMatrix, sendType, recvBuf,
3942 : recvType, stream, tag), tag.c_str());
3943 : }
3944 0 : u64 sendCount = 0;
3945 0 : for (u32 i = 0; i < rankSize; i++) {
3946 0 : sendCount += *(static_cast<const u64 *>(sendCountMatrix) + userRank * rankSize + i);
3947 : }
3948 0 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALLVC, beginTime, sendCount, sendType,
3949 : tag));
3950 0 : if (!isCapture) {
3951 0 : HcclResetIfProfile();
3952 : }
3953 0 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
3954 :
3955 0 : if (GetExternalInputHcclEnableEntryLog()) {
3956 0 : HcclUs endut = TIME_NOW();
3957 : /* 关键状态记录 */
3958 0 : std::string endInfo = "HcclAlltoAllVCInner:success,take time: " +
3959 0 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
3960 0 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
3961 0 : }
3962 :
3963 0 : return HCCL_SUCCESS;
3964 0 : }
3965 :
3966 29 : HcclResult HcclReduceInner(void *sendBuf, void *recvBuf, uint64_t count, HcclDataType dataType, HcclReduceOp op,
3967 : uint32_t root, HcclComm comm, aclrtStream stream)
3968 : {
3969 : // 入参合法性校验
3970 29 : CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return reduce success"), HCCL_SUCCESS);
3971 48 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3972 : std::vector<std::string>({"HcclReduceInner", "nullptr", "comm", "non-null pointer"}));
3973 28 : CHK_PTR_NULL(comm);
3974 47 : RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3975 : std::vector<std::string>({"HcclReduceInner", "nullptr", "sendBuf", "non-null pointer"}));
3976 27 : CHK_PTR_NULL(sendBuf);
3977 46 : RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3978 : std::vector<std::string>({"HcclReduceInner", "nullptr", "recvBuf", "non-null pointer"}));
3979 26 : CHK_PTR_NULL(recvBuf);
3980 25 : RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
3981 : std::vector<std::string>({"HcclReduceInner", "nullptr", "stream", "non-null pointer"}));
3982 25 : CHK_PTR_NULL(stream);
3983 :
3984 : // Group特性
3985 25 : if (hcclGroupDepth > 0) {
3986 : struct hcclOpInfo info;
3987 1 : info.coll = HcclCMDType::HCCL_CMD_REDUCE;
3988 1 : info.sendbuff = sendBuf;
3989 1 : info.recvbuff = recvBuf;
3990 1 : info.sendCount = count;
3991 1 : info.sendType = dataType;
3992 1 : info.recvType = dataType;
3993 1 : info.comm = comm;
3994 1 : info.stream = stream;
3995 1 : CHK_RET(taskAppend(comm, info));
3996 1 : HCCL_INFO("[HcclReduce] Finish taskAppend, count [%d] dataType [%s]", count, GetDataTypeEnumStr(dataType).c_str());
3997 1 : return HCCL_SUCCESS;
3998 : }
3999 :
4000 24 : HcclUs startut = TIME_NOW();
4001 : bool isCapture;
4002 24 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
4003 24 : uint64_t modelId = 0xFFFFFFFF;
4004 24 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
4005 24 : if (!isCapture) {
4006 23 : HcclSetIfProfile();
4007 : }
4008 24 : uint64_t beginTime = hrtMsprofSysCycleTime();
4009 :
4010 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4011 24 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
4012 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4013 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
4014 : CHK_PTR_NULL(commV2);
4015 : CHK_RET(HcclReduceV2(sendBuf, recvBuf, count, dataType, op, root, commV2, stream));
4016 : return HCCL_SUCCESS;
4017 : }());
4018 : #endif
4019 24 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4020 24 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
4021 24 : s32 threadID = SalGetTid();
4022 24 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
4023 : // 同通信域同算子复用tag
4024 24 : const string tag = "Reduce_" + hcclComm->GetIdentifier();
4025 24 : CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), count, dataType, stream), tag.c_str());
4026 :
4027 69 : CHK_RET_AND_PRINT_IDE(HcomCheckReductionOp("HcclReduceInner", op), tag.c_str());
4028 : DevType devType;
4029 23 : CHK_RET(hrtGetDeviceType(devType));
4030 23 : CHK_RET_AND_PRINT_IDE(HcomCheckReduceDataType(dataType, op, devType), tag.c_str());
4031 :
4032 23 : u32 rankSize = INVALID_VALUE_RANKSIZE;
4033 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
4034 23 : CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, root), tag.c_str());
4035 :
4036 : /* 接口交互信息日志 */
4037 : char stackLogBuffer[LOG_TMPBUF_SIZE];
4038 23 : if (GetExternalInputHcclEnableEntryLog()) {
4039 23 : s32 deviceLogicId = 0;
4040 23 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
4041 :
4042 23 : u32 localRank = INVALID_VALUE_RANKID;
4043 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
4044 :
4045 23 : s32 streamId = 0;
4046 23 : CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
4047 :
4048 46 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
4049 : "tag[%s], sendBuf[%p], recvBuf[%p], count[%llu], dataType[%s], op[%s], root[%u], "
4050 : "localRank[%u], streamId[%d], deviceLogicId[%d]",
4051 69 : tag.c_str(), sendBuf, recvBuf, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
4052 : root, localRank, streamId, deviceLogicId);
4053 :
4054 23 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
4055 46 : std::string logInfo = "Entry-HcclReduceInner:" + std::string(stackLogBuffer) +
4056 69 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
4057 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
4058 23 : }
4059 :
4060 23 : CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
4061 :
4062 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
4063 :
4064 23 : CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
4065 :
4066 23 : CHK_RET_AND_PRINT_IDE(SetOverFlowAddr(hcclComm), tag.c_str());
4067 :
4068 23 : CHK_RET_AND_PRINT_IDE(hcclComm->ReduceOutPlace(tag, sendBuf, recvBuf, count, dataType, op, root, stream),
4069 : tag.c_str());
4070 :
4071 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE, beginTime, count, dataType, tag));
4072 23 : if (!isCapture) {
4073 22 : HcclResetIfProfile();
4074 : }
4075 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
4076 :
4077 23 : if (GetExternalInputHcclEnableEntryLog()) {
4078 23 : HcclUs endut = TIME_NOW();
4079 : /* 关键状态记录 */
4080 23 : std::string endInfo = "HcclReduceInner:success,take time: " +
4081 46 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
4082 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
4083 23 : }
4084 23 : std::string identifier = hcclComm->GetIdentifier();
4085 23 : AlgType algType;
4086 23 : CHK_RET(hcclComm->GetAlgType(algType, HcclCMDType::HCCL_CMD_REDUCE));
4087 :
4088 23 : if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
4089 0 : AlgTypeLevel1 algValue = algType.algoLevel1;
4090 0 : uint8_t nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel1AlgType(algValue);
4091 0 : if (devType == DevType::DEV_TYPE_910_93) {
4092 0 : AlgTypeLevel2 algValue2 = algType.algoLevel2;
4093 0 : nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel2AlgType(algValue2);
4094 : }
4095 : // NSLB 填充 表6
4096 0 : hcclNslbDp::GetInstance().SetNslbDpRootRank(HcclCMDType::HCCL_CMD_REDUCE, root, identifier, nslbAlg);
4097 : }
4098 23 : return HCCL_SUCCESS;
4099 24 : }
4100 :
4101 0 : HcclResult ReduceLoop(const std::string &tag, void *inputPtr, void *outputPtr, const u64 count,
4102 : HcclDataType dataType, HcclReduceOp op, const u32 root, hccl::hcclComm *hcclComm, rtStream_t stream)
4103 : {
4104 0 : HcclSetIfProfile();
4105 :
4106 0 : void *commInputPtr = nullptr;
4107 0 : void *commOutputPtr = nullptr;
4108 : u64 commInputSize, commOutputSize;
4109 :
4110 : HcclResult ret;
4111 0 : CHK_RET(hcclComm->GetInCCLbuffer(commInputPtr, commInputSize));
4112 0 : CHK_PTR_NULL(commInputPtr);
4113 :
4114 0 : CHK_RET(hcclComm->GetOutCCLbuffer(commOutputPtr, commOutputSize));
4115 0 : CHK_PTR_NULL(commOutputPtr);
4116 :
4117 : u32 unitSize;
4118 0 : CHK_RET(SalGetDataTypeSize(dataType, unitSize));
4119 :
4120 0 : char *curInputPtr = static_cast<char *>(inputPtr);
4121 0 : char *curOutputPtr = static_cast<char *>(outputPtr);
4122 0 : u64 inputOffset = 0;
4123 0 : u64 outputOffset = 0;
4124 0 : u64 countLeft = count;
4125 :
4126 0 : while (countLeft > 0) {
4127 0 : curInputPtr += inputOffset;
4128 0 : curOutputPtr += outputOffset;
4129 0 : HCCL_DEBUG("-OP_BASE-ReduceLoop:inputOffset[%llu], outputOffset[%llu]", inputOffset, outputOffset);
4130 0 : u64 curCount = ((countLeft * unitSize) > commInputSize) ? (commInputSize / unitSize) : countLeft; // 单次执行操作的数据量
4131 0 : u64 curSize = curCount * unitSize; // 单位 byte
4132 :
4133 0 : HCCL_DEBUG("-OP_BASE-ReduceLoop:curInputPtr[%p], curOutputPtr[%p], curCount[%llu], curSize[%llu]",
4134 : curInputPtr, curOutputPtr, curCount, curSize);
4135 :
4136 0 : u32 commRank = INVALID_VALUE_RANKID;
4137 0 : CHK_RET(hcclComm->GetUserRank(commRank));
4138 :
4139 0 : CHK_RET(hrtMemAsyncCopy(commInputPtr, curSize, curInputPtr, curSize,
4140 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE, stream));
4141 :
4142 : /* 入参的正确性由HCCL确保 */
4143 0 : ret = hcclComm->Reduce(tag, commInputPtr, commOutputPtr, curCount, dataType, op, root, stream);
4144 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
4145 : HCCL_ERROR("[Loop][Reduce]errNo[0x%016llx] op_base hcclComm reduce error, tag[%s], "\
4146 : "input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s], root[%u]",
4147 : HCCL_ERROR_CODE(ret), tag.c_str(), commInputPtr, commOutputPtr, curCount,
4148 : GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(), root), ret);
4149 :
4150 0 : if (commRank == root) { // 只root rank需要把数据从中转内存拷贝出去
4151 0 : CHK_RET(hrtMemAsyncCopy(curOutputPtr, curSize, commOutputPtr, curSize,
4152 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE, stream));
4153 : }
4154 :
4155 0 : countLeft -= curCount;
4156 0 : inputOffset = curSize;
4157 0 : outputOffset = curSize;
4158 : }
4159 :
4160 0 : return HCCL_SUCCESS;
4161 : }
4162 :
4163 : /*
4164 : * **********************************************************************
4165 : * 单算子GatherAllToAllV的函数接口,目前不对外开放,仅图模式动态shape使用
4166 : * **********************************************************************
4167 : */
4168 0 : HcclResult HcclGatherAlltoAllV(HcomGatherAllToAllVParams params, HcclComm comm, aclrtStream stream)
4169 : {
4170 0 : HcclUs startut = TIME_NOW();
4171 0 : CHK_PTR_NULL(comm);
4172 0 : CHK_PTR_NULL(params.addrInfoCountPerRank);
4173 0 : CHK_PTR_NULL(params.recvcounts);
4174 0 : CHK_PTR_NULL(params.gatheredbuf);
4175 0 : CHK_PTR_NULL(params.rdispls);
4176 :
4177 0 : const u32 NUM_TWO = 2;
4178 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4179 0 : u32 rankSize = 0;
4180 0 : CHK_RET(hcclComm->GetRankSize(rankSize));
4181 :
4182 : // 同通信域同算子复用tag
4183 0 : const string tag = "Reduce_" + hcclComm->GetIdentifier();
4184 :
4185 0 : std::vector<u64> addrInfoCountPerRank(rankSize, 0);
4186 0 : CHK_RET_AND_PRINT_IDE(hrtMemSyncCopy(addrInfoCountPerRank.data(), rankSize * sizeof(u64),
4187 : params.addrInfoCountPerRank, rankSize * sizeof(u64),
4188 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_HOST), tag.c_str());
4189 0 : u64 blockNum = 0;
4190 0 : for (u32 index = 0; index < rankSize; index++) {
4191 0 : blockNum += addrInfoCountPerRank[index];
4192 : }
4193 0 : if (blockNum != 0) {
4194 0 : CHK_PTR_NULL(params.addrInfo);
4195 : }
4196 0 : std::vector<u64> addrInfo(blockNum * NUM_TWO, 0);
4197 0 : CHK_RET_AND_PRINT_IDE(hrtMemSyncCopy(addrInfo.data(), addrInfo.size() * sizeof(u64), params.addrInfo,
4198 : addrInfo.size() * sizeof(u64), HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_HOST), tag.c_str());
4199 :
4200 : char stackLogBuffer[LOG_TMPBUF_SIZE];
4201 0 : if (GetExternalInputHcclEnableEntryLog()) {
4202 0 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
4203 : "tag[%s]", tag.c_str());
4204 :
4205 0 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
4206 0 : std::string logInfo = "Entry-HcclGatherAlltoAllV:" + std::string(stackLogBuffer);
4207 0 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
4208 0 : }
4209 :
4210 : // 执行gather
4211 0 : u64 sendCounts = static_cast<u64>(rankSize);
4212 0 : u64 sdispls = static_cast<u64>(rankSize);
4213 :
4214 : // step1 gather
4215 0 : GatherPara gatherPara;
4216 0 : gatherPara.addrInfo = addrInfo;
4217 0 : gatherPara.rankSize = rankSize;
4218 0 : gatherPara.addrInfoCountPerRank = addrInfoCountPerRank;
4219 0 : gatherPara.addrLength = params.addrLength;
4220 0 : CHK_RET_AND_PRINT_IDE(RunGather(&sendCounts, &sdispls, params.gatheredbuf, gatherPara), tag.c_str());
4221 :
4222 : // step2 alltoallv
4223 0 : CHK_RET_AND_PRINT_IDE(HcclAlltoAllVInner(params.gatheredbuf, &sendCounts, &sdispls, params.recvtype, params.recvbuf,
4224 : params.recvcounts, params.rdispls, params.recvtype, comm, stream), tag.c_str());
4225 :
4226 0 : if (GetExternalInputHcclEnableEntryLog()) {
4227 0 : HcclUs endut = TIME_NOW();
4228 0 : std::string endInfo = "HcclGatherAlltoAllV:success,take time: " +
4229 0 : std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
4230 0 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
4231 0 : }
4232 :
4233 0 : return HCCL_SUCCESS;
4234 0 : }
4235 :
4236 : /*
4237 : * **********************************************************************
4238 : * 单算子GatherAllToAllV step1 执行gather,出参作为step2的入参
4239 : * **********************************************************************
4240 : */
4241 0 : HcclResult RunGather(u64 *sendCounts, u64 *sdispls, void *sendDevBuf, GatherPara &gatherPara)
4242 : {
4243 0 : u64 memSize = 0;
4244 0 : const u32 GATHER_THREAD_NUM = 16;
4245 0 : const u32 NUM_TWO = 2;
4246 0 : u64 perThreadCount = gatherPara.addrInfo.size() / NUM_TWO / GATHER_THREAD_NUM;
4247 0 : std::vector<u64> perThreadCounts(GATHER_THREAD_NUM, perThreadCount);
4248 0 : perThreadCounts[GATHER_THREAD_NUM - 1] =
4249 0 : gatherPara.addrInfo.size() / NUM_TWO - perThreadCount * (GATHER_THREAD_NUM - 1);
4250 0 : std::vector<u64> offset(GATHER_THREAD_NUM, 0);
4251 0 : if (gatherPara.addrLength == -1) { // 数据包长度不一样的情况
4252 0 : u32 offsetIndex = 0;
4253 0 : for (u32 index = 1; index < gatherPara.addrInfo.size(); index += NUM_TWO) { // 由于是二元组,单数为数据包的长度,每个循环+2
4254 : /* 如果数据包数量小于线程数量则offset全置为0 */
4255 0 : if (perThreadCount != 0 && index / NUM_TWO % perThreadCount == 0 && offsetIndex < GATHER_THREAD_NUM) {
4256 : /* 条件1:当累加的数量达到perThreadCount时往offset中填入累加值,即可计算出前面thread产生的offset值 */
4257 : /* 条件2:由于第0个thread的offset为0,后面的线程的offset为前面线程处理数据量的累加,因此对最后一个值弃之不用 */
4258 0 : offset[offsetIndex] = memSize;
4259 0 : offsetIndex++;
4260 : }
4261 0 : memSize += gatherPara.addrInfo[index];
4262 : }
4263 : } else {
4264 0 : memSize = gatherPara.addrInfo.size() / NUM_TWO * gatherPara.addrInfo[1];
4265 0 : for (u32 index = 0; index < GATHER_THREAD_NUM; index++) {
4266 0 : offset[index] = index * perThreadCount * gatherPara.addrInfo[1];
4267 : }
4268 : }
4269 :
4270 : // 多线程拷贝
4271 0 : HostMem tmpHostMem = HostMem::alloc(memSize);
4272 0 : CHK_PTR_NULL(tmpHostMem.ptr());
4273 0 : std::vector<std::unique_ptr<std::thread>> threads(GATHER_THREAD_NUM);
4274 0 : for (u32 num = 0; num < GATHER_THREAD_NUM; num++) {
4275 : OpBaseMemPara memPara;
4276 0 : memPara.beginIndex = num * perThreadCount * NUM_TWO;
4277 0 : memPara.count = perThreadCounts[num];
4278 0 : memPara.tmpMemSize = memSize;
4279 0 : threads[num].reset(new (std::nothrow) std::thread(&GatherMemCopyThread, tmpHostMem.ptr(),
4280 0 : offset[num], std::ref(gatherPara.addrInfo), memPara));
4281 0 : CHK_PRT_RET(!threads[num], HCCL_ERROR("[Exec][EnqueueGatherAlltoAllV]threads[%u] reset "\
4282 : "failed ", num), HCCL_E_INTERNAL);
4283 : }
4284 :
4285 : // 构造入参
4286 0 : auto ret = memset_s(sendCounts, gatherPara.rankSize * sizeof(u64), 0, gatherPara.rankSize * sizeof(u64));
4287 0 : CHK_PRT_RET(ret != EOK, HCCL_ERROR("[Exec][EnqueueGatherAlltoAllV] mem set failed, count[%lld]",
4288 : gatherPara.rankSize * sizeof(u64)), HCCL_E_SYSCALL);
4289 0 : u64 prevNum = 0;
4290 0 : u64 nextNum = 0;
4291 0 : for (u32 index = 0; index < gatherPara.addrInfoCountPerRank.size(); index++) {
4292 0 : nextNum += gatherPara.addrInfoCountPerRank[index];
4293 0 : for (u64 i = NUM_TWO * prevNum; i < NUM_TWO * nextNum; i += NUM_TWO) {
4294 0 : *(sendCounts + index) += gatherPara.addrInfo[i + 1];
4295 : }
4296 0 : prevNum = nextNum;
4297 : }
4298 :
4299 0 : ret = memset_s(sdispls, gatherPara.rankSize * sizeof(u64), 0, gatherPara.rankSize * sizeof(u64));
4300 0 : CHK_PRT_RET(ret != EOK, HCCL_ERROR("[Exec][EnqueueGatherAlltoAllV] mem set failed, count[%lld]",
4301 : gatherPara.rankSize * sizeof(u64)), HCCL_E_SYSCALL);
4302 0 : u64 displ = 0;
4303 0 : for (u32 i = 0; i < gatherPara.rankSize; i++) {
4304 0 : *(sdispls + i) = displ;
4305 0 : displ += *(sendCounts + i);
4306 : }
4307 :
4308 : // 等待线程执行完毕
4309 0 : for (u32 num = 0; num < GATHER_THREAD_NUM; num++) {
4310 0 : threads[num]->join();
4311 : }
4312 :
4313 0 : CHK_RET(hrtMemSyncCopy(sendDevBuf, memSize, tmpHostMem.ptr(), memSize,
4314 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
4315 0 : return HCCL_SUCCESS;
4316 0 : }
4317 :
4318 : /*
4319 : * **********************************************************************
4320 : * 单算子GatherAllToAllV gather多线程拷贝
4321 : * **********************************************************************
4322 : */
4323 0 : void GatherMemCopyThread(void *baseAddr, u64 offset, std::vector<u64> &addrInfo, OpBaseMemPara memCpyPara)
4324 : {
4325 : //给当前线程添加名字
4326 0 : SetThreadName("Hccl_GatherCopy");
4327 :
4328 0 : void *addr = nullptr;
4329 0 : const u32 NUM_TWO = 2;
4330 0 : u64 length = 0;
4331 0 : auto destMax = [&]()-> u64 {
4332 0 : return memCpyPara.tmpMemSize < offset ? 0 : memCpyPara.tmpMemSize - offset;
4333 0 : };
4334 :
4335 0 : for (u32 index = 0; index < memCpyPara.count; index++) {
4336 0 : addr = reinterpret_cast<void *>(addrInfo[memCpyPara.beginIndex + NUM_TWO * index]);
4337 0 : length = addrInfo[memCpyPara.beginIndex + index * NUM_TWO + 1];
4338 0 : if (memcpy_s(static_cast<s8 *>(baseAddr) + offset, destMax(), addr, length) != EOK) {
4339 0 : HCCL_ERROR("[MemCopy][GatherAlltoAllV] mem copy failed, destMax[%llu], count[%llu]",
4340 : memCpyPara.tmpMemSize - offset, length);
4341 0 : return;
4342 : }
4343 0 : offset += length;
4344 : }
4345 : }
4346 :
4347 : /*
4348 : * **********************************************************************
4349 : * 获取HCCL错误
4350 : * **********************************************************************
4351 : */
4352 1 : HcclResult HcclGetCommAsyncError(HcclComm comm, HcclResult *asyncError)
4353 : {
4354 21 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4355 : std::vector<std::string>({"HcclCommGetAsyncError", "nullptr", "comm", "non-null pointer"}));
4356 1 : CHK_PTR_NULL(comm);
4357 0 : CHK_PTR_NULL(asyncError);
4358 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4359 0 : HCCLV2_FUNC_RUN(HcclGetCommAsyncErrorV2());
4360 : #endif
4361 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4362 0 : CHK_RET(hcclComm->CommCheckErrorCqe(*asyncError));
4363 0 : if (*asyncError == HCCL_SUCCESS) {
4364 0 : CHK_RET(hcclComm->CommCheckOpInconsistentError(*asyncError));
4365 : }
4366 0 : return HCCL_SUCCESS;
4367 : }
4368 :
4369 : /*
4370 : * **********************************************************************
4371 : * HCCL提供错误码到字符串的转换
4372 : * **********************************************************************
4373 : */
4374 22 : const char *HcclGetErrorString(HcclResult code)
4375 : {
4376 22 : if (code < HcclResult::HCCL_SUCCESS || code >= HcclResult::HCCL_E_RESERVED) {
4377 0 : return "unknown error";
4378 : }
4379 0 : static const std::map<HcclResult, std::string> errorMap = {{HCCL_SUCCESS, "no error"},
4380 0 : {HCCL_E_PARA, "parameter error"}, {HCCL_E_PTR, "empty pointer"},
4381 0 : {HCCL_E_MEMORY, "memory error"}, {HCCL_E_INTERNAL, "internal error"},
4382 0 : {HCCL_E_NOT_SUPPORT, "not support feature"}, {HCCL_E_NOT_FOUND, "not found specific resource"},
4383 0 : {HCCL_E_UNAVAIL, "resource unavailable"}, {HCCL_E_SYSCALL, "call system interface error"},
4384 0 : {HCCL_E_TIMEOUT, "timeout"}, {HCCL_E_OPEN_FILE_FAILURE, "open file fail"},
4385 0 : {HCCL_E_TCP_CONNECT, "tcp connect fail"}, {HCCL_E_ROCE_CONNECT, "roce connect fail"},
4386 0 : {HCCL_E_TCP_TRANSFER, "tcp transfer fail"}, {HCCL_E_ROCE_TRANSFER, "roce transfer fail"},
4387 0 : {HCCL_E_RUNTIME, "call runtime api fail"}, {HCCL_E_DRV, "call driver api fail"},
4388 0 : {HCCL_E_PROFILING, "call profiling api fail"}, {HCCL_E_CCE, "call cce api fail"},
4389 0 : {HCCL_E_NETWORK, "call network api fail"}, {HCCL_E_AGAIN, "try again"},
4390 0 : {HCCL_E_REMOTE, "error cqe"}, {HCCL_E_SUSPENDING, "error communicator suspending"},
4391 49 : {HCCL_E_OPRETRY_FAIL, "retry constraint"}, {HCCL_E_OOM, "out of memory"}};
4392 :
4393 22 : auto it = errorMap.find(code);
4394 22 : if (it != errorMap.end()) {
4395 22 : return it->second.c_str();
4396 : } else {
4397 0 : return "unknown err";
4398 : }
4399 1 : }
4400 :
4401 : /*
4402 : * 配置溢出检测地址
4403 : */
4404 92 : HcclResult SetOverFlowAddr(hccl::hcclComm *hcclComm)
4405 : {
4406 92 : std::vector<void *> globalWorkSpaceAddr;
4407 92 : CHK_RET(hcclComm->SetGlobalWorkSpace(globalWorkSpaceAddr));
4408 92 : return HCCL_SUCCESS;
4409 92 : }
4410 :
4411 : #ifdef __cplusplus
4412 : extern "C" {
4413 : #endif // __cplusplus
4414 0 : HcclResult HcclCreateComResource(const char *commName, u32 streamMode, void** commContext)
4415 : {
4416 0 : RPT_INPUT_ERR(commName == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4417 : std::vector<std::string>({"HcclCreateComResource", "nullptr", "commName", "non-null pointer"}));
4418 :
4419 0 : RPT_INPUT_ERR(commContext == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4420 : std::vector<std::string>({"HcclCreateComResource", "nullptr", "commContext", "non-null pointer"}));
4421 : // 切换线程后获取不到hcom上下文,需重新刷新一次线程操作的deviceid
4422 0 : s32 deviceLogicId = 0;
4423 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
4424 0 : std::shared_ptr<hccl::hcclComm> hcclComm;
4425 0 : CHK_RET(HcomGetCommByGroup(commName, hcclComm));
4426 0 : HcclComm comm = hcclComm.get();
4427 0 : CHK_RET(HcclCreateComResourceByComm(comm, streamMode, true, commContext));
4428 0 : return HCCL_SUCCESS;
4429 0 : }
4430 :
4431 : #ifdef __cplusplus
4432 : }
4433 : #endif // __cplusplus
4434 :
4435 0 : HcclResult HcclCreateComResourceByComm(HcclComm comm, u32 streamMode, bool isOpbaseMode,
4436 : void** commContext, bool isMC2, void* mc2Tiling)
4437 : {
4438 0 : HcclUs startut = TIME_NOW();
4439 0 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4440 : std::vector<std::string>({"HcclCreateComResource", "nullptr", "comm", "non-null pointer"}));
4441 :
4442 0 : RPT_INPUT_ERR(commContext == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4443 : std::vector<std::string>({"HcclCreateComResource", "nullptr", "commContext", "non-null pointer"}));
4444 :
4445 : // 同通信域同算子复用tag
4446 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4447 0 : u32 moduleNum = hcclComm->GetModuleNum();
4448 : // mc2算子更改tag
4449 : DevType devType;
4450 0 : CHK_RET(hrtGetDeviceType(devType));
4451 0 : string commIdentifier = hcclComm->GetIdentifier();
4452 0 : string tag = "CreatecomResource_" + commIdentifier;
4453 0 : std::string algConfigMc2 = "";
4454 0 : if (isMC2 && devType == DevType::DEV_TYPE_910B &&
4455 : (moduleNum > HCCL_DEVICE_NUM_ONE)) {
4456 0 : tag += HCCL_MC2_MULTISERVER_SUFFIX;
4457 : const void *tilingList[MAX_HCOM_NUM];
4458 : uint32_t tilingNum;
4459 0 : CHK_RET(HcclGetInitTilingList(mc2Tiling, tilingList, tilingNum));
4460 0 : const Mc2HcommCfg *tiling = static_cast<const Mc2HcommCfg *>(tilingList[0]);
4461 0 : if (tiling != nullptr && string(tiling->groupName) == commIdentifier) {
4462 0 : algConfigMc2 = string(tiling->algConfig);
4463 : }
4464 : }
4465 :
4466 : // A2 MC2引擎默认为AICPU
4467 0 : if (isMC2) {
4468 0 : CHK_RET(hcclComm->SetAicpuCommEngine(true));
4469 : }
4470 :
4471 0 : if (LIKELY(hcclComm->GetCommResource(tag, commContext))) {
4472 0 : return HCCL_SUCCESS;
4473 : }
4474 :
4475 : char stackLogBuffer[LOG_TMPBUF_SIZE];
4476 0 : if (GetExternalInputHcclEnableEntryLog()) {
4477 0 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U, "tag[%s], commContext[%p]", tag.c_str(),
4478 : commContext);
4479 0 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
4480 : }
4481 0 : const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
4482 :
4483 0 : u32 localRank = INVALID_VALUE_RANKID;
4484 0 : CHK_RET(hcclComm->GetUserRank(localRank));
4485 :
4486 0 : if (GetExternalInputHcclEnableEntryLog()) {
4487 : /* 接口交互信息日志 */
4488 0 : std::string logInfo = "Entry-HcclCreateComResource:localRank[" + std::to_string(localRank)
4489 0 : + "]" + std::string(stackLogBuffer);
4490 0 : CHK_RET(hcclComm->SaveTraceInfo(logInfo));
4491 0 : }
4492 :
4493 : // SetWorkflowMode性能开销hrtGetDevice,0.11us
4494 0 : HcclUs middleut0 = TIME_NOW();
4495 0 : CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
4496 0 : HcclUs middleut1 = TIME_NOW();
4497 : rtStream_t stream;
4498 0 : CHK_RET(hcclComm->Mc2AiCpuStreamAllocAndGet(streamMode, stream));
4499 0 : CHK_RET(hcclComm->CreateCommResource(tag, stream, isOpbaseMode, commContext, algConfigMc2));
4500 :
4501 0 : if (GetExternalInputHcclEnableEntryLog()) {
4502 0 : HcclUs endut = TIME_NOW();
4503 : /* 关键状态记录 */
4504 : std::string endInfo = "HcclCreateComResource success, HcclCreateComResource take time ["
4505 0 : + std::to_string(DURATION_US(endut - startut).count()) + "]us, CreateComResource take time ["
4506 0 : + std::to_string(DURATION_US(endut - middleut1).count()) + "]us, SetWorkflowMode take time ["
4507 0 : + std::to_string(DURATION_US(middleut1 - middleut0).count()) + "]us, localRank["
4508 0 : + std::to_string(localRank) + "] " + std::string(stackLogBuffer);
4509 0 : CHK_RET(hcclComm->SaveTraceInfo(endInfo));
4510 0 : }
4511 :
4512 0 : return HCCL_SUCCESS;
4513 0 : }
4514 :
4515 50 : void PrintCountsAndDispls(const u32 length, const void *counts, const void *displs, const std::string &tag)
4516 : {
4517 : // 打印counts和displs
4518 50 : const u64 *countsPtr = static_cast<const u64 *>(counts);
4519 50 : const u64 *displsPtr = static_cast<const u64 *>(displs);
4520 50 : if (HcclCheckLogLevel(DLOG_DEBUG)) {
4521 50 : std::ostringstream countsStream;
4522 50 : std::ostringstream displsStream;
4523 50 : countsStream << "[ ";
4524 50 : displsStream << "[ ";
4525 114 : for (u32 i = 0; i < length; ++i) {
4526 64 : countsStream << countsPtr[i] << " ";
4527 64 : displsStream << displsPtr[i] << " ";
4528 : }
4529 50 : countsStream << "]";
4530 50 : displsStream << "]";
4531 50 : HCCL_DEBUG("[PrintCountsAndDispls]tag[%s], counts%s", tag.c_str(), countsStream.str().c_str());
4532 50 : HCCL_DEBUG("[PrintCountsAndDispls]tag[%s], displs%s", tag.c_str(), displsStream.str().c_str());
4533 50 : }
4534 50 : }
4535 :
4536 50 : void CheckCountsAndDispls(const u32 length, const void *counts, const void *displs, const std::string &tag)
4537 : {
4538 : // 校验counts和displs是否匹配
4539 50 : const u64 *countsPtr = static_cast<const u64 *>(counts);
4540 50 : const u64 *displsPtr = static_cast<const u64 *>(displs);
4541 50 : u64 displsCal = 0;
4542 :
4543 114 : for (u32 i = 0; i < length; i++) {
4544 64 : if (displsCal != displsPtr[i]) {
4545 0 : HCCL_WARNING("[CheckCountsAndDispls]tag[%s], displs[%u]: [%llu] memory is discontinuous.",
4546 : tag.c_str(), i, displsPtr[i]);
4547 : }
4548 :
4549 64 : displsCal = displsCal + countsPtr[i];
4550 : }
4551 50 : }
4552 :
4553 : #ifdef __cplusplus
4554 : extern "C" {
4555 : #endif // __cplusplus
4556 0 : HcclResult HcclGetAicpuOpStreamNotify(const char *commName, rtStream_t* opstream, void** aicpuNotify)
4557 : {
4558 0 : RPT_INPUT_ERR(commName == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4559 : std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "commName", "non-null pointer"}));
4560 :
4561 0 : RPT_INPUT_ERR(opstream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4562 : std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "opstream", "non-null pointer"}));
4563 :
4564 0 : RPT_INPUT_ERR(aicpuNotify == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4565 : std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "aicpuNotify", "non-null pointer"}));
4566 : // 切换线程后获取不到hcom上下文,需重新刷新一次线程操作的deviceid
4567 0 : s32 deviceLogicId = 0;
4568 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
4569 0 : std::shared_ptr<hccl::hcclComm> hcclComm;
4570 0 : CHK_RET(HcomGetCommByGroup(commName, hcclComm));
4571 :
4572 0 : CHK_RET(hcclComm->GetAicpuOpStreamNotify(opstream, 1, aicpuNotify));
4573 0 : return HCCL_SUCCESS;
4574 0 : }
4575 :
4576 0 : HcclResult HcclGetAicpuOpStreamAndNotify(HcclComm comm, rtStream_t* opstream, u8 aicpuNotifyNum, void** aicpuNotify)
4577 : {
4578 0 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4579 : std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "comm", "non-null pointer"}));
4580 :
4581 0 : RPT_INPUT_ERR(opstream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4582 : std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "opstream", "non-null pointer"}));
4583 :
4584 0 : RPT_INPUT_ERR(aicpuNotify == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4585 : std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "aicpuNotify", "non-null pointer"}));
4586 : // 切换线程后获取不到hcom上下文,需重新刷新一次线程操作的deviceid
4587 0 : s32 deviceLogicId = 0;
4588 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
4589 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4590 0 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
4591 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4592 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
4593 : CHK_PTR_NULL(commV2);
4594 : CHK_RET(HcclGetAicpuOpStreamAndNotifyV2(commV2, opstream, aicpuNotifyNum, aicpuNotify));
4595 : return HCCL_SUCCESS;
4596 : }());
4597 : #endif
4598 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4599 :
4600 0 : CHK_RET(hcclComm->GetAicpuOpStreamNotify(opstream, aicpuNotifyNum, aicpuNotify));
4601 0 : return HCCL_SUCCESS;
4602 : }
4603 : #ifdef __cplusplus
4604 : }
4605 : #endif // __cplusplus
4606 :
4607 0 : HcclResult HcclBatchSendRecvGroup(HcclSendRecvItem* sendRecvInfo, uint32_t itemNum, HcclComm comm, aclrtStream stream)
4608 : {
4609 0 : HcclUs startut = TIME_NOW();
4610 : bool isCapture;
4611 0 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
4612 0 : uint64_t modelId = 0xFFFFFFFF;
4613 0 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
4614 0 : if (!isCapture) {
4615 0 : HcclSetIfProfile();
4616 : }
4617 0 : s32 threadID = SalGetTid();
4618 0 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
4619 0 : uint64_t beginTime = hrtMsprofSysCycleTime();
4620 :
4621 : // 入参校验
4622 0 : CHK_PTR_NULL(comm);
4623 0 : CHK_PTR_NULL(stream);
4624 :
4625 0 : CHK_PTR_NULL(sendRecvInfo);
4626 0 : CHK_PRT_RET((itemNum == 0), HCCL_WARNING("[BatchSendRecvGroup] taskList itemNum is zero."), HCCL_SUCCESS);
4627 :
4628 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4629 0 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
4630 : // 若任务不同,也复用tag
4631 0 : const string tag = "worldBatchSendRecvGroup_" + hcclComm->GetIdentifier();
4632 0 : u32 rankSize = INVALID_VALUE_RANKSIZE;
4633 0 : CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
4634 0 : u32 rankId = INVALID_VALUE_RANKID;
4635 0 : CHK_RET_AND_PRINT_IDE(hcclComm->GetGroupRank(rankId), tag.c_str());
4636 :
4637 : /* 记录接口交互信息日志 */
4638 : char stackLogBuffer[LOG_TMPBUF_SIZE];
4639 0 : if (GetExternalInputHcclEnableEntryLog()) {
4640 0 : s32 deviceLogicId = 0;
4641 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
4642 :
4643 0 : u32 localRank = INVALID_VALUE_RANKID;
4644 0 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
4645 :
4646 0 : s32 streamId = 0;
4647 0 : CHK_RET(hrtGetStreamId(stream, streamId));
4648 :
4649 0 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
4650 : "tag[%s], itemNum[%u], localRank[%u], streamId[%d], deviceLogicId[%d]", tag.c_str(), itemNum, localRank, streamId, deviceLogicId);
4651 :
4652 0 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
4653 0 : std::string logInfo = "Entry-HcclBatchSendRecvGroup:" + std::string(stackLogBuffer) +
4654 0 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
4655 0 : CHK_RET(hcclComm->SaveTraceInfo(logInfo));
4656 0 : }
4657 :
4658 0 : for (u32 i = 0; i < itemNum; i++) {
4659 0 : CHK_PTR_NULL((sendRecvInfo + i)->buf);
4660 0 : CHK_RET(HcomCheckDataType((sendRecvInfo + i)->dataType));
4661 0 : CHK_RET(HcomCheckCount((sendRecvInfo + i)->count));
4662 0 : CHK_RET(HcomCheckUserRank(rankSize, (sendRecvInfo + i)->remoteRank));
4663 0 : if (GetExternalInputHcclEnableEntryLog()) {
4664 : char stackLogBuffer[LOG_TMPBUF_SIZE];
4665 0 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
4666 : "SendRecvItem : SendRecvType[%d], remoteRank[%u], count[%llu], dataType[%d], buf[%p].",
4667 0 : (sendRecvInfo + i)->sendRecvType, (sendRecvInfo + i)->remoteRank, (sendRecvInfo + i)->count,
4668 0 : (sendRecvInfo + i)->dataType, (sendRecvInfo + i)->buf);
4669 0 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
4670 0 : std::string logInfo = "[HcclBatchSendRecvGroup]" + std::string(stackLogBuffer);
4671 0 : CHK_RET(hcclComm->SaveTraceInfo(logInfo));
4672 0 : }
4673 : }
4674 :
4675 0 : CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
4676 0 : HCCL_INFO("About to enter BatchSendRecv, itemNum[%u]", itemNum);
4677 0 : CHK_RET_AND_PRINT_IDE(hcclComm->BatchSendRecv(tag, sendRecvInfo, itemNum, stream), tag.c_str());
4678 0 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_BATCH_SEND_RECV, beginTime, sendRecvInfo->count,
4679 : sendRecvInfo->dataType, tag));
4680 0 : if (!isCapture) {
4681 0 : HcclResetIfProfile();
4682 : }
4683 0 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
4684 :
4685 0 : if (GetExternalInputHcclEnableEntryLog()) {
4686 0 : HcclUs endut = TIME_NOW();
4687 : /* 关键状态记录 */
4688 0 : std::string endInfo = "HcclBatchSendRecvGroup:success,take time: " +
4689 0 : std::to_string(DURATION_US(endut - startut).count()) + " us, tag: " + tag;
4690 0 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
4691 0 : }
4692 :
4693 0 : return HCCL_SUCCESS;
4694 0 : }
4695 :
4696 26 : HcclResult HcclBatchSendRecvInner(HcclSendRecvItem* sendRecvInfo, uint32_t itemNum, HcclComm comm, aclrtStream stream)
4697 : {
4698 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4699 26 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
4700 : CHK_PTR_NULL(comm);
4701 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4702 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
4703 : CHK_PTR_NULL(commV2);
4704 : CHK_RET(HcclBatchSendRecvV2(sendRecvInfo, itemNum, commV2, stream));
4705 : return HCCL_SUCCESS;
4706 : }());
4707 : #endif
4708 26 : HcclUs startut = TIME_NOW();
4709 : bool isCapture;
4710 26 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
4711 26 : uint64_t modelId = 0xFFFFFFFF;
4712 26 : CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
4713 26 : if (!isCapture) {
4714 25 : HcclSetIfProfile();
4715 : }
4716 26 : s32 threadID = SalGetTid();
4717 26 : ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
4718 26 : uint64_t beginTime = hrtMsprofSysCycleTime();
4719 :
4720 : // 入参校验
4721 26 : CHK_PTR_NULL(comm);
4722 25 : CHK_PTR_NULL(stream);
4723 :
4724 25 : CHK_PTR_NULL(sendRecvInfo);
4725 24 : CHK_PRT_RET((itemNum == 0), HCCL_WARNING("[BatchSendRecv] taskList itemNum is zero."), HCCL_SUCCESS);
4726 :
4727 23 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4728 23 : StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
4729 : // 若任务不同,也复用tag
4730 23 : const string tag = "worldBatchSendRecv_" + hcclComm->GetIdentifier();
4731 23 : u32 rankSize = INVALID_VALUE_RANKSIZE;
4732 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
4733 23 : u32 rankId = INVALID_VALUE_RANKID;
4734 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetGroupRank(rankId), tag.c_str());
4735 :
4736 : /* 记录接口交互信息日志 */
4737 : char stackLogBuffer[LOG_TMPBUF_SIZE];
4738 23 : if (GetExternalInputHcclEnableEntryLog()) {
4739 23 : s32 deviceLogicId = 0;
4740 23 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
4741 :
4742 23 : u32 localRank = INVALID_VALUE_RANKID;
4743 23 : CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
4744 :
4745 23 : s32 streamId = 0;
4746 23 : CHK_RET(hrtGetStreamId(stream, streamId));
4747 :
4748 23 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
4749 : "tag[%s], itemNum[%u], localRank[%u], streamId[%d], deviceLogicId[%d]", tag.c_str(), itemNum, localRank, streamId, deviceLogicId);
4750 :
4751 23 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
4752 46 : std::string logInfo = "Entry-HcclBatchSendRecvInner:" + std::string(stackLogBuffer) +
4753 69 : ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
4754 23 : CHK_RET(hcclComm->SaveTraceInfo(logInfo));
4755 23 : }
4756 :
4757 46 : for (u32 i = 0; i < itemNum; i++) {
4758 : // 支持数据量为0的场景,buf为空的item跳过
4759 23 : if ((sendRecvInfo + i)->buf == nullptr) {
4760 0 : continue;
4761 : }
4762 23 : CHK_RET(HcomCheckDataType((sendRecvInfo + i)->dataType));
4763 23 : CHK_RET(HcomCheckCount((sendRecvInfo + i)->count));
4764 23 : CHK_RET(HcomCheckUserRank(rankSize, (sendRecvInfo + i)->remoteRank));
4765 23 : if (GetExternalInputHcclEnableEntryLog()) {
4766 : char stackLogBuffer[LOG_TMPBUF_SIZE];
4767 46 : s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
4768 : "SendRecvItem : SendRecvType[%d], remoteRank[%u], count[%llu], dataType[%d], buf[%p].",
4769 23 : (sendRecvInfo + i)->sendRecvType, (sendRecvInfo + i)->remoteRank, (sendRecvInfo + i)->count,
4770 23 : (sendRecvInfo + i)->dataType, (sendRecvInfo + i)->buf);
4771 23 : CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
4772 23 : std::string logInfo = "[HcclBatchSendRecvInner]" + std::string(stackLogBuffer);
4773 23 : CHK_RET(hcclComm->SaveTraceInfo(logInfo));
4774 23 : }
4775 : }
4776 :
4777 23 : CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
4778 23 : CHK_RET_AND_PRINT_IDE(hcclComm->BatchSendRecv(tag, sendRecvInfo, itemNum, stream), tag.c_str());
4779 23 : CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_BATCH_SEND_RECV, beginTime, sendRecvInfo->count,
4780 : sendRecvInfo->dataType, tag));
4781 23 : if (!isCapture) {
4782 22 : HcclResetIfProfile();
4783 : }
4784 23 : ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
4785 :
4786 23 : if (GetExternalInputHcclEnableEntryLog()) {
4787 23 : HcclUs endut = TIME_NOW();
4788 : /* 关键状态记录 */
4789 23 : std::string endInfo = "HcclBatchSendRecvInner:success,take time: " +
4790 46 : std::to_string(DURATION_US(endut - startut).count()) + " us, tag: " + tag;
4791 23 : CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
4792 23 : }
4793 :
4794 23 : return HCCL_SUCCESS;
4795 23 : }
4796 :
4797 875 : HcclResult HcclDeviceRefresh(s32 &deviceLogicId)
4798 : {
4799 875 : HcclResult ret = hrtGetDeviceRefresh(&g_hcclDeviceId);
4800 875 : CHK_PRT_RET(ret != HCCL_SUCCESS,
4801 : HCCL_ERROR("[Get][DeviceRefresh]errNo[0x%016llx] g_hcclDeviceId[%d]"
4802 : "get device refresh error.", ret, g_hcclDeviceId), ret);
4803 871 : deviceLogicId = g_hcclDeviceId;
4804 871 : return HCCL_SUCCESS;
4805 : }
4806 :
4807 : #ifdef __cplusplus
4808 : extern "C" {
4809 : #endif // __cplusplus
4810 0 : int32_t HcclTaskRegister(HcclComm comm, const char *msgTag, Callback cb)
4811 : {
4812 0 : HCCL_INFO("[HcclTaskRegister] start to register task");
4813 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4814 0 : CHK_PTR_NULL(comm);
4815 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4816 0 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
4817 : HcclResult ret;
4818 0 : if (commV2 != nullptr) {
4819 0 : ret = HcclTaskRegisterV2(commV2, msgTag, cb);
4820 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] TaskRegisterV2 failed, ret[0x%016llx]",
4821 : HCCL_ERROR_CODE(ret)), ret);
4822 : } else {
4823 0 : std::string commId = hcclComm->GetIdentifier();
4824 0 : CHK_RET(HcclCheckTaskServiceExist(commId, g_hcclDeviceId));
4825 0 : ret = g_taskServiceMap[commId][g_hcclDeviceId]->TaskRegister(msgTag, cb);
4826 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] TaskRegister failed, ret[0x%016llx]",
4827 : HCCL_ERROR_CODE(ret)), ret);
4828 0 : return HCCL_SUCCESS;
4829 0 : }
4830 : uint32_t dpuStreamId;
4831 0 : CHK_PTR_NULL(commV2);
4832 0 : ret = HcclGetDpuSteamIdV2(commV2, dpuStreamId);
4833 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] GetDpuSteamIdV2 failed, ret[0x%016llx]",
4834 : HCCL_ERROR_CODE(ret)), ret);
4835 0 : hccl::CollComm *collComm = hcclComm->GetCollComm();
4836 0 : CHK_PTR_NULL(collComm);
4837 0 : collComm->GetHcclCommDfx()->SetDpuStreamId(dpuStreamId);
4838 0 : auto profCallback = collComm->GetHcclCommDfx()->GetDpuCallback();
4839 0 : CHK_PTR_NULL(profCallback);
4840 0 : ret = HcclTaskRegisterProfV2(commV2, profCallback);
4841 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] TaskProfRegister failed, ret[0x%016llx]",
4842 : HCCL_ERROR_CODE(ret)), ret);
4843 0 : return ret;
4844 :
4845 : #endif
4846 : return HCCL_E_NOT_SUPPORT;
4847 0 : }
4848 :
4849 0 : int32_t HcclTaskUnRegister(HcclComm comm, const char *msgTag)
4850 : {
4851 0 : HCCL_INFO("[HcclTaskUnRegister] start to register task");
4852 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4853 0 : CHK_PTR_NULL(comm);
4854 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4855 0 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
4856 0 : if (commV2 != nullptr) {
4857 0 : return HcclTaskUnRegisterV2(commV2, msgTag);
4858 : } else {
4859 0 : std::string commId = hcclComm->GetIdentifier();
4860 0 : CHK_RET(HcclCheckTaskServiceExist(commId, g_hcclDeviceId));
4861 0 : return g_taskServiceMap[commId][g_hcclDeviceId]->TaskUnRegister(msgTag);
4862 0 : }
4863 : #endif
4864 : return HCCL_E_NOT_SUPPORT;
4865 : }
4866 :
4867 0 : HcclResult HcclGetTopoDesc(HcclComm comm, HcclTopoDescs *topoDescs, uint32_t topoSize)
4868 : {
4869 : // 入参合法性校验
4870 0 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4871 : std::vector<std::string>({"HcclGetTopoDesc", "nullptr", "comm", "non-null pointer"}));
4872 :
4873 0 : RPT_INPUT_ERR(topoDescs == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
4874 : std::vector<std::string>({"HcclGetTopoDesc", "nullptr", "topoDescs", "non-null pointer"}));
4875 :
4876 0 : s32 deviceLogicId = 0;
4877 0 : CHK_RET(HcclDeviceRefresh(deviceLogicId));
4878 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4879 0 : HCCLV2_FUNC_RUN(HcclGetTopoDescV2());
4880 : #endif
4881 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4882 0 : CHK_RET(hcclComm->GetTopoDesc(topoDescs, topoSize));
4883 :
4884 0 : return HCCL_SUCCESS;
4885 : }
4886 :
4887 2 : HcclResult HcclCommSuspend(HcclComm comm)
4888 : {
4889 : // 入参校验
4890 2 : CHK_PTR_NULL(comm);
4891 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4892 1 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
4893 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4894 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
4895 : CHK_PTR_NULL(commV2);
4896 : CHK_RET(HcclCommSuspendV2(commV2));
4897 : return HCCL_SUCCESS;
4898 : }());
4899 : #endif
4900 1 : HcclUs startut = TIME_NOW();
4901 1 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
4902 1 : CHK_RET(hcclComm->Suspend());
4903 1 : HcclUs endut = TIME_NOW();
4904 1 : HCCL_RUN_INFO("HcclCommSuspend:success, take time:[%lld]us, comm[%s]",
4905 : DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str());
4906 1 : return HCCL_SUCCESS;
4907 : }
4908 :
4909 : static std::unordered_map<std::string, pair<HcclCommStateCallback, void*>> g_resumeCallBack;
4910 : static std::mutex g_callBackMtx; // 保护 g_resumeCallBack
4911 5 : HcclResult HcclCommRegCommStateCallback(const char *regName, HcclCommStateCallback cb, void *args)
4912 : {
4913 5 : CHK_PTR_NULL(regName);
4914 4 : CHK_PTR_NULL(cb);
4915 3 : CHK_PTR_NULL(args);
4916 :
4917 2 : constexpr uint32_t MAX_REG_NAME_LEN = 160;
4918 2 : const uint32_t nameLen = strlen(regName);
4919 2 : CHK_PRT_RET((nameLen == 0 || nameLen >= MAX_REG_NAME_LEN),
4920 : HCCL_ERROR("[%s]Invalid regName, valid length is (0, %u)", __func__, MAX_REG_NAME_LEN), HCCL_E_PARA);
4921 : {
4922 2 : std::lock_guard<std::mutex> lock(g_callBackMtx);
4923 4 : g_resumeCallBack[regName] = std::make_pair(cb, args);
4924 2 : }
4925 2 : HCCL_RUN_INFO("[%s]Register commStateCallBack success, regName[%s], args[%p].", __func__, regName, args);
4926 2 : return HCCL_SUCCESS;
4927 : }
4928 :
4929 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4930 2 : HcclResult HcclCommResumePostCallback(HcclComm comm) {
4931 2 : std::lock_guard<std::mutex> lock(g_callBackMtx);
4932 4 : for(const auto& [regName, cbPair] : g_resumeCallBack) {
4933 2 : HcclCommStateCallback cb = cbPair.first;
4934 2 : void* args = cbPair.second;
4935 2 : CHK_RET(cb(comm, HcclCommStatePhase::HCCL_COMM_STATE_PHASE_RESUME_POST, args));
4936 2 : HCCL_RUN_INFO("[%s]COMM_STATE_RESUME_POST, regName[%s], args[%p] callback success.", __func__, regName, args);
4937 : }
4938 2 : return HCCL_SUCCESS;
4939 2 : }
4940 : #endif
4941 :
4942 2 : HcclResult HcclCommResume(HcclComm comm)
4943 : {
4944 : // 入参校验
4945 2 : CHK_PTR_NULL(comm);
4946 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4947 1 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
4948 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
4949 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
4950 : CHK_PTR_NULL(commV2);
4951 : CHK_RET(HcclCommResumeV2(commV2));
4952 :
4953 : CHK_RET(hcclComm->Resume());
4954 : CHK_RET(HcclCommResumePostCallback(comm));
4955 :
4956 : return HCCL_SUCCESS;
4957 : }());
4958 : #endif
4959 1 : HcclUs startut = TIME_NOW();
4960 1 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
4961 1 : CHK_RET(hcclComm->Resume());
4962 1 : HcclUs endut = TIME_NOW();
4963 1 : HCCL_RUN_INFO("HcclCommResume:success, take time:[%lld]us, comm[%s]",
4964 : DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str());
4965 1 : return HCCL_SUCCESS;
4966 : }
4967 :
4968 1 : uint32_t HcclGetCommConfigCapability()
4969 : {
4970 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4971 1 : HCCLV2_FUNC_RUN(HcclGetCommConfigCapabilityV2());
4972 : #endif
4973 : // RESERVED在枚举中是最后一个,返回RESERVED说明它前面所有的配置项都支持
4974 1 : return static_cast<uint32_t>(HCCL_COMM_CONFIG_RESERVED);
4975 : }
4976 :
4977 3 : HcclResult HcclCommSetMemoryRange(HcclComm comm, void *baseVirPtr, size_t size, size_t alignment, uint64_t flags)
4978 : {
4979 : // 入参校验
4980 3 : CHK_PTR_NULL(comm);
4981 2 : CHK_PTR_NULL(baseVirPtr);
4982 :
4983 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
4984 1 : HCCLV2_FUNC_RUN(HcclCommSetMemoryRangeV2(comm, baseVirPtr, size, alignment, flags));
4985 :
4986 : #endif
4987 :
4988 1 : HcclUs startut = TIME_NOW();
4989 1 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
4990 1 : CHK_RET(hcclComm->SetMemoryRange(baseVirPtr, size, alignment, flags));
4991 1 : HcclUs endut = TIME_NOW();
4992 1 : HCCL_RUN_INFO("HcclCommSetMemoryRange:success, take time:[%lld]us, comm[%s] basePtr[%p] size[%lu] alignment[%lu] flags[%lu]",
4993 : DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), baseVirPtr, size, alignment, flags);
4994 1 : return HCCL_SUCCESS;
4995 : }
4996 :
4997 3 : HcclResult HcclCommUnsetMemoryRange(HcclComm comm, void *baseVirPtr)
4998 : {
4999 : // 入参校验
5000 3 : CHK_PTR_NULL(comm);
5001 2 : CHK_PTR_NULL(baseVirPtr);
5002 :
5003 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5004 1 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
5005 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
5006 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
5007 : CHK_PTR_NULL(commV2);
5008 : CHK_RET(HcclCommUnsetMemoryRangeV2(commV2, baseVirPtr));
5009 : return HCCL_SUCCESS;
5010 : }());
5011 : #endif
5012 :
5013 1 : HcclUs startut = TIME_NOW();
5014 1 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5015 1 : CHK_RET(hcclComm->UnsetMemoryRange(baseVirPtr));
5016 1 : HcclUs endut = TIME_NOW();
5017 1 : HCCL_RUN_INFO("HcclCommUnsetMemoryRange:success, take time:[%lld]us, comm[%s] basePtr[%p]",
5018 : DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), baseVirPtr);
5019 1 : return HCCL_SUCCESS;
5020 : }
5021 :
5022 4 : HcclResult HcclCommActivateCommMemory(HcclComm comm, void *virPtr, size_t size, size_t offset, void* handle, uint64_t flags)
5023 : {
5024 : // 入参校验
5025 4 : CHK_PTR_NULL(comm);
5026 3 : CHK_PTR_NULL(virPtr);
5027 2 : CHK_PTR_NULL(handle);
5028 :
5029 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5030 1 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
5031 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
5032 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
5033 : CHK_PTR_NULL(commV2);
5034 : CHK_RET(HcclCommActivateCommMemoryV2(commV2, virPtr, size, offset, handle, flags));
5035 : return HCCL_SUCCESS;
5036 : }());
5037 : #endif
5038 :
5039 1 : HcclUs startut = TIME_NOW();
5040 1 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5041 1 : CHK_RET(hcclComm->ActivateCommMemory(virPtr, size, offset, handle, flags));
5042 1 : HcclUs endut = TIME_NOW();
5043 1 : HCCL_RUN_INFO("HcclCommActivateCommMemory:success, take time:[%lld]us, comm[%s] virPtr[%p] size[%lu] offset[%lu] "
5044 : "handle[%p] flags[%lu]", DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), virPtr, size,
5045 : offset, handle, flags);
5046 1 : return HCCL_SUCCESS;
5047 : }
5048 :
5049 3 : HcclResult HcclCommDeactivateCommMemory(HcclComm comm, void *virPtr)
5050 : {
5051 : // 入参校验
5052 3 : CHK_PTR_NULL(comm);
5053 2 : CHK_PTR_NULL(virPtr);
5054 :
5055 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5056 1 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
5057 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
5058 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
5059 : CHK_PTR_NULL(commV2);
5060 : CHK_RET(HcclCommDeactivateCommMemoryV2(commV2, virPtr));
5061 : return HCCL_SUCCESS;
5062 : }());
5063 : #endif
5064 :
5065 1 : HcclUs startut = TIME_NOW();
5066 1 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5067 1 : CHK_RET(hcclComm->DeactivateCommMemory(virPtr));
5068 1 : HcclUs endut = TIME_NOW();
5069 1 : HCCL_RUN_INFO("HcclCommDeactivateCommMemory:success, take time:[%lld]us, comm[%s] virPtr[%p]",
5070 : DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), virPtr);
5071 1 : return HCCL_SUCCESS;
5072 : }
5073 :
5074 4 : HcclResult HcclCommWorkingDevNicSet(HcclComm comm, uint32_t *ranks, bool *useBackup, uint32_t nRanks)
5075 : {
5076 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5077 4 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
5078 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
5079 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
5080 : CHK_PTR_NULL(commV2);
5081 : CHK_RET(HcclCommWorkingDevNicSetV2(commV2, ranks, useBackup, nRanks));
5082 : return HCCL_SUCCESS;
5083 : }());
5084 : #endif
5085 24 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5086 : std::vector<std::string>({"HcclCommWorkingDevNicSet", "nullptr", "comm", "non-null pointer"}));
5087 4 : CHK_PTR_NULL(comm);
5088 3 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5089 3 : u32 localRank = INVALID_VALUE_RANKID;
5090 3 : (void) hcclComm->GetUserRank(localRank);
5091 3 : HCCL_RUN_INFO("Entry-HcclCommWorkingDevNicSet, comm[%s], rank[%u], nRanks[%u] need to switch nic",
5092 : hcclComm->GetIdentifier().c_str(), localRank, nRanks);
5093 :
5094 23 : RPT_INPUT_ERR(ranks == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5095 : std::vector<std::string>({"HcclCommWorkingDevNicSet", "nullptr", "ranks", "non-null pointer"}));
5096 3 : CHK_PTR_NULL(ranks);
5097 22 : RPT_INPUT_ERR(useBackup == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5098 : std::vector<std::string>({"HcclCommWorkingDevNicSet", "nullptr", "useBackup", "non-null pointer"}));
5099 2 : CHK_PTR_NULL(useBackup);
5100 1 : HcclResult ret = hcclComm->SwitchNic(nRanks, ranks, useBackup);
5101 1 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("HcclCommWorkingDevNicSet fail, comm[%s], rank[%u], ret[%u]",
5102 : hcclComm->GetIdentifier().c_str(), localRank, ret), ret);
5103 :
5104 1 : HCCL_RUN_INFO("HcclCommWorkingDevNicSet success, comm[%s], rank[%u], nRanks[%u] switch nic success.",
5105 : hcclComm->GetIdentifier().c_str(), localRank, nRanks);
5106 1 : return HCCL_SUCCESS;
5107 : }
5108 :
5109 0 : HcclResult HcclCommRegister(HcclComm comm, void* addr, uint64_t size, void **handle, uint32_t flag)
5110 : {
5111 : // 入参校验
5112 0 : CHK_PTR_NULL(comm);
5113 0 : CHK_PTR_NULL(addr);
5114 0 : CHK_PTR_NULL(handle);
5115 0 : CHK_PRT_RET(size == 0, HCCL_ERROR("[%s] size is 0, please check size value", __func__), HCCL_E_PARA);
5116 :
5117 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5118 0 : CHK_RET(hcclComm->RegisterCommUserMem(addr, size, handle));
5119 0 : u32 rankSize = INVALID_VALUE_RANKSIZE;
5120 0 : CHK_RET(hcclComm->GetRankSize(rankSize));
5121 0 : CHK_RET(HcomSetGroupTopoInfo(hcclComm->GetIdentifier().c_str(), rankSize));
5122 0 : HCCL_RUN_INFO("[%s]Register mem success, group[%s], handle ptr[%p], size[%llu]", __func__,
5123 : hcclComm->GetIdentifier().c_str(), *handle, size);
5124 0 : return HCCL_SUCCESS;
5125 : }
5126 :
5127 0 : HcclResult HcclCommDeregister(HcclComm comm, void* handle)
5128 : {
5129 : // 入参校验
5130 0 : CHK_PTR_NULL(comm);
5131 0 : CHK_PTR_NULL(handle);
5132 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5133 0 : CHK_RET(hcclComm->DeregisterCommUserMem(handle));
5134 0 : u32 rankSize = INVALID_VALUE_RANKSIZE;
5135 0 : CHK_RET(hcclComm->GetRankSize(rankSize));
5136 0 : CHK_RET(HcomSetGroupTopoInfo(hcclComm->GetIdentifier().c_str(), rankSize));
5137 0 : HCCL_RUN_INFO("[%s]Deregister mem success, group[%s], handle ptr[%p]", __func__,
5138 : hcclComm->GetIdentifier().c_str(), handle);
5139 0 : return HCCL_SUCCESS;
5140 : }
5141 :
5142 0 : HcclResult HcclCommExchangeMem(HcclComm comm, void* handle, uint32_t* peerRanks, uint32_t peerRankNum)
5143 : {
5144 0 : HcclUs startut = TIME_NOW();
5145 : // 入参校验
5146 0 : CHK_PTR_NULL(comm);
5147 0 : CHK_PTR_NULL(handle);
5148 0 : CHK_PTR_NULL(peerRanks);
5149 0 : CHK_PRT_RET((peerRankNum == 0 || peerRankNum > MAX_RANK_NUM_A3),
5150 : HCCL_ERROR("[%s]Invalid peerRankNum, valid range is (0, %u], peerRankNum[%u]",
5151 : __func__, MAX_RANK_NUM_A3, peerRankNum), HCCL_E_PARA);
5152 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5153 0 : std::vector<u32> peerRanksVec(peerRanks, peerRanks + peerRankNum);
5154 0 : CHK_RET(hcclComm->ExchangeCommUserMem(handle, peerRanksVec));
5155 0 : HCCL_RUN_INFO("[%s] success, take time [%lld]us, group[%s]", __func__, DURATION_US(TIME_NOW() - startut),
5156 : hcclComm->GetIdentifier().c_str());
5157 0 : return HCCL_SUCCESS;
5158 0 : }
5159 :
5160 0 : HcclResult CommGetLocalCCLBuf(HcclComm comm, void **addr, uint64_t *size)
5161 : {
5162 0 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5163 : std::vector<std::string>({"CommGetLocalCCLBuf", "nullptr", "comm", "non-null pointer"}));
5164 0 : CHK_PTR_NULL(comm);
5165 0 : RPT_INPUT_ERR(addr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5166 : std::vector<std::string>({"CommGetLocalCCLBuf", "nullptr", "addr", "non-null pointer"}));
5167 0 : CHK_PTR_NULL(addr);
5168 0 : RPT_INPUT_ERR(size == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5169 : std::vector<std::string>({"CommGetLocalCCLBuf", "nullptr", "size", "non-null pointer"}));
5170 0 : CHK_PTR_NULL(size);
5171 :
5172 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5173 0 : HcclResult ret = hcclComm->GetLocalCCLBuf(addr, size);
5174 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("CommGetLocalCCLBuf fail, comm[%s]",
5175 : hcclComm->GetIdentifier().c_str()), ret);
5176 :
5177 0 : HCCL_RUN_INFO("CommGetLocalCCLBuf success, comm[%s]", hcclComm->GetIdentifier().c_str());
5178 0 : return HCCL_SUCCESS;
5179 : }
5180 :
5181 0 : HcclResult CommGetRemoteCCLBuf(HcclComm comm, uint32_t remoteRank, void **addr, uint64_t *size)
5182 : {
5183 0 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5184 : std::vector<std::string>({"CommGetRemoteCCLBuf", "nullptr", "comm", "non-null pointer"}));
5185 0 : CHK_PTR_NULL(comm);
5186 0 : RPT_INPUT_ERR(addr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5187 : std::vector<std::string>({"CommGetRemoteCCLBuf", "nullptr", "addr", "non-null pointer"}));
5188 0 : CHK_PTR_NULL(addr);
5189 0 : RPT_INPUT_ERR(size == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5190 : std::vector<std::string>({"CommGetRemoteCCLBuf", "nullptr", "size", "non-null pointer"}));
5191 0 : CHK_PTR_NULL(size);
5192 :
5193 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5194 0 : HcclResult ret = hcclComm->GetRemoteCCLBuf(remoteRank, addr, size);
5195 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("CommGetRemoteCCLBuf fail, comm[%s], remoteRank[%u]",
5196 : hcclComm->GetIdentifier().c_str(), remoteRank), ret);
5197 :
5198 0 : HCCL_RUN_INFO("CommGetRemoteCCLBuf success, comm[%s], remoteRank[%u]", hcclComm->GetIdentifier().c_str(), remoteRank);
5199 0 : return HCCL_SUCCESS;
5200 : }
5201 0 : HcclResult CommGetKFCWorkSpace(HcclComm comm, void **addr, uint64_t *size)
5202 : {
5203 0 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5204 : std::vector<std::string>({"CommGetKFCWorkSpace", "nullptr", "comm", "non-null pointer"}));
5205 0 : CHK_PTR_NULL(comm);
5206 0 : RPT_INPUT_ERR(addr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5207 : std::vector<std::string>({"CommGetKFCWorkSpace", "nullptr", "addr", "non-null pointer"}));
5208 0 : CHK_PTR_NULL(addr);
5209 0 : RPT_INPUT_ERR(size == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5210 : std::vector<std::string>({"CommGetKFCWorkSpace", "nullptr", "size", "non-null pointer"}));
5211 0 : CHK_PTR_NULL(size);
5212 :
5213 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5214 0 : HcclResult ret = hcclComm->GetKFCWorkSpace(addr, size);
5215 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("CommGetKFCWorkSpace fail, comm[%s]",
5216 : hcclComm->GetIdentifier().c_str()), ret);
5217 :
5218 0 : HCCL_RUN_INFO("CommGetKFCWorkSpace success, comm[%s]", hcclComm->GetIdentifier().c_str());
5219 0 : return HCCL_SUCCESS;
5220 : }
5221 0 : HcclResult CommGetCCLBufSizeCfg(HcclComm comm, uint64_t *cclBufSize)
5222 : {
5223 0 : RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5224 : std::vector<std::string>({"CommGetCCLBufSizeCfg", "nullptr", "comm", "non-null pointer"}));
5225 0 : CHK_PTR_NULL(comm);
5226 0 : RPT_INPUT_ERR(cclBufSize == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
5227 : std::vector<std::string>({"CommGetCCLBufSizeCfg", "nullptr", "cclBufSize", "non-null pointer"}));
5228 0 : CHK_PTR_NULL(cclBufSize);
5229 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5230 0 : const char *socNamePtr = aclrtGetSocName();
5231 0 : CHK_PTR_NULL(socNamePtr);
5232 0 : HCCLV2_FUNC_RUN([&]() -> HcclResult {
5233 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
5234 : HcclComm commV2 = hcclComm->GetCommunicatorV2();
5235 : CHK_PTR_NULL(commV2);
5236 : CHK_RET(CommGetCCLBufSizeCfgV2(commV2, cclBufSize));
5237 : return HCCL_SUCCESS;
5238 : }());
5239 : #endif
5240 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5241 0 : uint64_t buffSize = 0;
5242 0 : if (0 == hcclComm->GetConfigInCCLbufferSize()) {
5243 0 : buffSize = GetExternalInputCCLBuffSize();
5244 : }else {
5245 0 : buffSize = hcclComm->GetConfigInCCLbufferSize();
5246 : }
5247 0 : *cclBufSize = buffSize;
5248 0 : HCCL_RUN_INFO("CommGetCCLBufSizeCfg success, comm[%s], size[%u]", hcclComm->GetIdentifier().c_str(), buffSize);
5249 0 : return HCCL_SUCCESS;
5250 : }
5251 :
5252 : enum HcclCommSymWindowInnerFlag {
5253 : HCCL_COMM_SYM_WINDOW_FLAG_DEFAULT = 0,
5254 : HCCL_COMM_SYM_WINDOW_FLAG_COLL_SYMMETRIC = 1
5255 : };
5256 :
5257 : std::unordered_map<HcclCommSymWindow, HcclComm> winHandle2comm;
5258 : std::mutex g_winHandleMtx; // 保护 winHandle2comm
5259 :
5260 0 : HcclResult HcclCommSymWinRegister(HcclComm comm, void* addr, uint64_t size, HcclCommSymWindow *winHandle, uint32_t flag)
5261 : {
5262 : // 入参校验
5263 0 : CHK_PTR_NULL(comm);
5264 0 : CHK_PTR_NULL(addr);
5265 0 : CHK_PTR_NULL(winHandle);
5266 0 : CHK_PRT_RET(size == 0, HCCL_ERROR("[%s] size is 0, please check size value", __func__), HCCL_E_PARA);
5267 0 : if (flag == HCCL_COMM_SYM_WINDOW_FLAG_COLL_SYMMETRIC) {
5268 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5269 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5270 0 : if (hcclComm->IsCommunicatorV2()) {
5271 0 : hccl::CollComm *collComm = hcclComm->GetCollComm();
5272 0 : CHK_PTR_NULL(collComm);
5273 0 : CHK_RET(collComm->RegisterWindow(addr, size, winHandle));
5274 : } else {
5275 : #endif
5276 0 : CHK_RET(hcclComm->RegisterWindow(addr, size, winHandle));
5277 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5278 : }
5279 : #endif
5280 0 : HCCL_RUN_INFO("[%s]WindowRegister mem success, group[%s], handle ptr[%p], size[%llu]", __func__,
5281 : hcclComm->GetIdentifier().c_str(), *winHandle, size);
5282 : {
5283 0 : std::lock_guard<std::mutex> lock(g_winHandleMtx);
5284 0 : winHandle2comm[*winHandle] = comm;
5285 0 : }
5286 0 : } else if (flag == HCCL_COMM_SYM_WINDOW_FLAG_DEFAULT) {
5287 0 : HCCL_ERROR("[HcclCommSymWinRegister]flag: 0 is not supported yet.");
5288 0 : return HCCL_E_PARA;
5289 : }else {
5290 0 : HCCL_ERROR("[HcclCommSymWinRegister]Invalid flag[%u], must be 0 or 1", flag);
5291 0 : return HCCL_E_PARA;
5292 : }
5293 0 : return HCCL_SUCCESS;
5294 : }
5295 :
5296 0 : HcclResult HcclCommSymWinDeregister(HcclCommSymWindow winHandle)
5297 : {
5298 : // 入参校验
5299 0 : CHK_PTR_NULL(winHandle);
5300 0 : HcclComm comm = nullptr;
5301 0 : std::lock_guard<std::mutex> lock(g_winHandleMtx);
5302 0 : auto it = winHandle2comm.find(winHandle);
5303 0 : if (it == winHandle2comm.end()) {
5304 0 : HCCL_ERROR("[HcclCommSymWinDeregister]Window handle[%p] is not registered.", winHandle);
5305 0 : return HCCL_E_PARA;
5306 : }
5307 0 : comm = it->second;
5308 0 : CHK_PTR_NULL(comm);
5309 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5310 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5311 0 : if (hcclComm->IsCommunicatorV2()) {
5312 0 : hccl::CollComm *collComm = hcclComm->GetCollComm();
5313 0 : CHK_PTR_NULL(collComm);
5314 0 : CHK_RET(collComm->DeregisterWindow(winHandle));
5315 : } else {
5316 : #endif
5317 0 : CHK_RET(hcclComm->DeregisterWindow(winHandle));
5318 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5319 : }
5320 : #endif
5321 0 : winHandle2comm.erase(it);
5322 0 : HCCL_RUN_INFO("[%s]WindowDeregister mem success, group[%s]", __func__, hcclComm->GetIdentifier().c_str());
5323 0 : return HCCL_SUCCESS;
5324 0 : }
5325 :
5326 1 : HcclResult HcclCommSymWinGet(HcclComm comm, void *ptr, size_t size, HcclCommSymWindow *winHandle, size_t *offset)
5327 : {
5328 : // 入参校验
5329 1 : CHK_PTR_NULL(comm);
5330 1 : CHK_PTR_NULL(ptr);
5331 1 : CHK_PTR_NULL(winHandle);
5332 1 : CHK_PTR_NULL(offset);
5333 1 : CHK_PRT_RET(size == 0, HCCL_ERROR("[%s] size is 0, please check size value", __func__), HCCL_E_PARA);
5334 :
5335 1 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
5336 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5337 1 : if (hcclComm->IsCommunicatorV2()) {
5338 0 : hccl::CollComm *collComm = hcclComm->GetCollComm();
5339 0 : CHK_PTR_NULL(collComm);
5340 0 : CHK_RET(collComm->GetCommSymWin(ptr, size, winHandle, offset));
5341 : } else {
5342 : #endif
5343 1 : CHK_RET(hcclComm->GetCommSymWin(ptr, size, winHandle, offset));
5344 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5345 : }
5346 : #endif
5347 1 : HCCL_DEBUG("[%s]GetCommSymWin success, group[%s], handle ptr[%p], offset[%llu], size[%llu]", __func__,
5348 : hcclComm->GetIdentifier().c_str(), *winHandle, *offset, size);
5349 1 : return HCCL_SUCCESS;
5350 : }
5351 :
5352 0 : HcclResult HcclGetCcuTaskInfo(HcclComm comm, void *tilingData, void *ccuTaskGroup)
5353 : {
5354 0 : CHK_PTR_NULL(comm);
5355 0 : CHK_PTR_NULL(tilingData);
5356 0 : CHK_PTR_NULL(ccuTaskGroup);
5357 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
5358 0 : hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
5359 0 : comm = hcclComm->GetCommunicatorV2();
5360 0 : CHK_PTR_NULL(comm);
5361 0 : CHK_RET(HcclGetCcuTaskInfoLegacy(comm, tilingData, ccuTaskGroup));
5362 : #endif
5363 0 : return HCCL_SUCCESS;
5364 : }
5365 :
5366 : #ifdef __cplusplus
5367 : }
5368 : #endif // __cplusplus
|