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