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