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