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