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 <atomic>
12 : #include <algorithm>
13 : #include <arpa/inet.h>
14 : #include <fstream>
15 : #include <fcntl.h>
16 : #include <unistd.h>
17 : #include <hccl/hccl_types.h>
18 : #include "hccl_communicator.h"
19 : #include "hccl_comm_pub.h"
20 : #if !defined(CCL_KERNEL_AICPU) && !defined(HCCD)
21 : #include "coll_comm_mgr.h"
22 : #endif
23 : #include "coll_alg_utils.h"
24 : #include "env_config.h"
25 : #include "comm_configer.h"
26 : #include "hccl_group_utils.h"
27 : #include "hccl_dispatcher_ctx.h"
28 :
29 : namespace hccl {
30 : RankTable_t g_hcclDefaultRankTable;
31 :
32 687 : hcclComm::hcclComm(u64 inCCLbufferSize, u64 outCCLbufferSize, std::string identifier, std::string cclBuffName)
33 687 : : barrierSendBuf(nullptr),
34 687 : barrierRecvBuf(nullptr),
35 687 : inCCLbufferSize_(inCCLbufferSize),
36 687 : outCCLbufferSize_(outCCLbufferSize),
37 687 : deviceType_(DevType::DEV_TYPE_COUNT),
38 687 : isFirstBarrier_(true),
39 687 : identifier_(identifier),
40 687 : cclBuffName_(cclBuffName),
41 687 : isHeterogComm_(false),
42 687 : isResetDevice_(false),
43 687 : isSpecialType_(false),
44 1374 : communicator_(nullptr)
45 : {
46 687 : indirectInCCLbuffer_ = DeviceMem();
47 687 : indirectOutCCLbuffer_ = DeviceMem();
48 686 : barrierInMemory_ = DeviceMem();
49 686 : barrierOutMemory_ = DeviceMem();
50 686 : planner = std::make_shared<hcclKernelPlanner>();
51 686 : }
52 :
53 2059 : hcclComm::~hcclComm()
54 : {
55 : #if !defined(CCL_KERNEL_AICPU) && !defined(HCCD)
56 : // collComm_ 为 fullMode 时由 owner(hcclComm) 负责注销,避免在 ~CollComm 中反向依赖 CollCommMgr;
57 : // 此时 collComm_ 尚未析构(成员析构发生在函数体之后),指针有效
58 685 : if (collComm_ != nullptr && collComm_->IsFullMode()) {
59 176 : CollCommMgr::GetInstance().UnRegisteCollComm(collComm_.get());
60 : }
61 : #endif
62 687 : RealeaseBarrierMemory();
63 687 : (void)UnRegistTaskAbortHandler();
64 687 : BinaryUnLoad();
65 687 : communicator_ = nullptr;
66 686 : }
67 :
68 0 : HcclResult hcclComm::ReleaseSubComms() const
69 : {
70 0 : CHK_SMART_PTR_NULL(communicator_);
71 :
72 0 : CHK_RET(communicator_->ReleaseCommInfos());
73 :
74 0 : return HCCL_SUCCESS;
75 : }
76 :
77 0 : void hcclComm::ReleaseCommCCLbuffer() const
78 : {
79 0 : if (!communicator_) {
80 0 : return;
81 : }
82 0 : communicator_->ReleaseCommCCLbuffer();
83 : }
84 :
85 687 : void hcclComm::RealeaseBarrierMemory()
86 : {
87 687 : barrierInMemory_.free();
88 687 : barrierOutMemory_.free();
89 687 : }
90 :
91 236 : HcclResult hcclComm::RealeaseShareCCLbuffer()
92 : {
93 236 : CHK_RET(ShareCCLbufferMgr::GetInstance().FreeShareCCLbuffer(cclBuffName_));
94 236 : return HCCL_SUCCESS;
95 : }
96 :
97 410 : void hcclComm::UpdateIsHaveCpuRank(const RankTable_t& rankTable)
98 : {
99 1583 : for (u32 i = 0; i < rankTable.rankList.size(); i++) {
100 : // 同一server的标识IP 是一样的,所以可以以此推算出平均dev个数
101 1173 : if (rankTable.rankList[i].deviceInfo.devicePhyId == HOST_DEVICE_ID) {
102 0 : isHaveCpuRank_ = true;
103 : }
104 : }
105 410 : }
106 :
107 2 : void hcclComm::UpdateIsHaveCpuRank(const std::vector<RankInfo>& rankList)
108 : {
109 2 : for (u32 i = 0; i < rankList.size(); i++) {
110 : // 同一server的标识IP 是一样的,所以可以以此推算出平均dev个数
111 0 : if (rankList[i].devicePhyId == HOST_DEVICE_ID) {
112 0 : isHaveCpuRank_ = true;
113 : }
114 : }
115 2 : }
116 :
117 410 : HcclResult hcclComm::init(HcclCommParams& params, const CommConfig& commConfig, const RankTable_t& rankTable)
118 : {
119 410 : UpdateIsHaveCpuRank(rankTable);
120 410 : isHeterogComm_ = params.isHeterogComm;
121 :
122 410 : HCCL_INFO("hcclComm init workmode [%d]", params.commWorkMode);
123 410 : if (params.commWorkMode == WorkMode::HCCL_MODE_AI_CPU) {
124 0 : isSpecialType_ = true;
125 : }
126 410 : CHK_RET(InitImpl(params.deviceType, commConfig));
127 :
128 : /* 强行将最后一个字符置0, 确保其可以做字符串操作 */
129 410 : params.id.internal[HCCL_ROOT_INFO_BYTES - 1] = '\0';
130 :
131 : /* 入参判断 */
132 410 : if (params.rank >= params.totalRanks) {
133 2 : HCCL_ERROR(
134 : "[HcclComm][Init]errNo[0x%016llx] rank[%u] out of range[0, %u]", HCCL_ERROR_CODE(HCCL_E_PARA), params.rank,
135 : params.totalRanks - 1);
136 2 : return HCCL_E_PARA;
137 : }
138 408 : params.identifier = identifier_;
139 408 : params.cclBuffName = cclBuffName_;
140 :
141 : /* 设置commConfig单例 */
142 408 : HcclResult ret = CommConfiger::GetInstance().SetCommConfig(commConfig, identifier_);
143 408 : CHK_PRT_RET(
144 : ret != HCCL_SUCCESS,
145 : HCCL_ERROR("[hcclComm][init]errNo[0x%016llx] set commConfiger failed.", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
146 :
147 408 : CHK_RET(communicator_->AtomicInitSet()); /* 初始化竞争, 只允许被初始化一次 */
148 408 : ret = communicator_->Init(params, rankTable); /* 初始化实例, 失败则重新开放初始化竞争 */
149 408 : if (ret != HCCL_SUCCESS) {
150 4 : HCCL_ERROR("[HcclComm][Init]errNo[0x%016llx] hccl initialize failed", HCCL_ERROR_CODE(ret));
151 4 : communicator_->AtomicInitClear();
152 4 : return ret;
153 : }
154 404 : CHK_RET(ShareCCLbufferMgr::GetInstance().RecordShareCCLbuffer(cclBuffName_));
155 404 : if (params.totalRanks != 1) {
156 206 : CHK_RET(communicator_->InitCCLbuffer(inCCLbufferSize_, outCCLbufferSize_));
157 : }
158 :
159 404 : HCCL_USER_CRITICAL_LOG(
160 : "hcclCommInitInfo:commId[%s], rank[%u], totalRanks[%u], serverId[%s], deviceType[%d],"
161 : "logicDevId[%d], identifier[%s]",
162 : params.id.internal, params.rank, params.totalRanks, params.serverId.c_str(), params.deviceType,
163 : params.logicDevId, params.identifier.c_str());
164 :
165 404 : InitIndependentOp();
166 :
167 404 : return HCCL_SUCCESS;
168 : }
169 :
170 2 : HcclResult hcclComm::init(
171 : HcclCommParams& params, const CommConfig& commConfig, const std::vector<RankInfo>& rankList,
172 : WorldGroupInfo& groupCommonData)
173 : {
174 2 : UpdateIsHaveCpuRank(rankList);
175 : /* 强行将最后一个字符置0, 确保其可以做字符串操作 */
176 2 : params.id.internal[HCCL_ROOT_INFO_BYTES - 1] = '\0';
177 :
178 2 : HCCL_USER_CRITICAL_LOG(
179 : "rootInfo[%s], rank[%u], totalRanks[%u], chip[%d], logicDevId[%d]", params.id.internal, params.rank,
180 : params.totalRanks, params.deviceType, params.logicDevId);
181 :
182 2 : HCCL_INFO("rootInfo init group workmode[%d]", params.commWorkMode);
183 2 : if (params.commWorkMode == WorkMode::HCCL_MODE_AI_CPU) {
184 0 : isSpecialType_ = true;
185 : }
186 2 : CHK_RET(InitImpl(params.deviceType, commConfig));
187 :
188 : /* 入参判断 */
189 2 : if (params.rank >= params.totalRanks) {
190 1 : HCCL_ERROR(
191 : "[HcclComm][Init]errNo[0x%016llx] rank[%u] out of range[0, %u]", HCCL_ERROR_CODE(HCCL_E_PARA), params.rank,
192 : params.totalRanks - 1);
193 1 : return HCCL_E_PARA;
194 : }
195 :
196 1 : params.identifier = identifier_;
197 :
198 : /* 设置commConfig单例 */
199 1 : HcclResult ret = CommConfiger::GetInstance().SetCommConfig(commConfig, identifier_);
200 1 : CHK_PRT_RET(
201 : ret != HCCL_SUCCESS,
202 : HCCL_ERROR("[hcclComm][init]errNo[0x%016llx] set commConfiger failed.", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
203 :
204 1 : CHK_RET(communicator_->CheckDeviceType(params.deviceType)); /* 芯片类型检查 */
205 0 : CHK_RET(communicator_->AtomicInitSet()); /* 初始化竞争, 只允许被初始化一次 */
206 0 : ret = communicator_->Init(params, rankList, groupCommonData); /* 初始化实例, 失败则重新开放初始化竞争 */
207 0 : if (ret != HCCL_SUCCESS) {
208 0 : communicator_->AtomicInitClear();
209 0 : HCCL_ERROR("[HcclComm][Init]errNo[0x%016llx] hccl initialize failed", HCCL_ERROR_CODE(ret));
210 0 : return ret;
211 : }
212 0 : return ret;
213 : }
214 :
215 235 : HcclResult hcclComm::SetQpQosAttr(u32 trafficClass, u32 serviceLevel)
216 : {
217 : // 校验config中TC的合法性
218 235 : if (trafficClass == HCCL_COMM_TRAFFIC_CLASS_CONFIG_NOT_SET
219 235 : && serviceLevel == HCCL_COMM_SERVICE_LEVEL_CONFIG_NOT_SET) {
220 235 : HCCL_INFO(
221 : "[SetQpQosAttr]The TC and SL do not use the config configuration. "
222 : "It will use environment variables to configure. TC[%u], SL[%u]",
223 : EnvConfig::GetExternalInputRdmaTrafficClass(), EnvConfig::GetExternalInputRdmaServerLevel());
224 235 : return HCCL_SUCCESS;
225 0 : } else if (
226 : trafficClass != HCCL_COMM_TRAFFIC_CLASS_CONFIG_NOT_SET
227 0 : && serviceLevel == HCCL_COMM_SERVICE_LEVEL_CONFIG_NOT_SET) {
228 0 : serviceLevel = EnvConfig::GetExternalInputRdmaServerLevel();
229 0 : HCCL_INFO("[SetQpQosAttr]The SL is not configured. It will use the environment value[%u]", serviceLevel);
230 0 : } else if (
231 : trafficClass == HCCL_COMM_TRAFFIC_CLASS_CONFIG_NOT_SET
232 0 : && serviceLevel != HCCL_COMM_SERVICE_LEVEL_CONFIG_NOT_SET) {
233 0 : trafficClass = EnvConfig::GetExternalInputRdmaTrafficClass();
234 0 : HCCL_INFO("[SetQpQosAttr]The TC is not configured. It will use the environment value[%u]", trafficClass);
235 : }
236 :
237 : // 若转换出错或者设置的RDMATrafficClass不在有效范围内,则报错
238 0 : if (trafficClass > EnvConfig::HCCL_RDMA_TC_MAX) {
239 0 : HCCL_ERROR(
240 : "[SetQpQosAttr]rdmaTrafficClass is invalid. except:[%u, %u], actual:[%u]", EnvConfig::HCCL_RDMA_TC_MIN,
241 : EnvConfig::HCCL_RDMA_TC_MAX, trafficClass);
242 0 : return HCCL_E_PARA;
243 : }
244 : // 若设置的RDMATrafficClass不是4的整数倍,则报错
245 0 : if (trafficClass % EnvConfig::HCCL_RDMA_TC_BASE != 0) {
246 0 : HCCL_ERROR(
247 : "[SetQpQosAttr]rdmaTrafficClass[%u] is not a multiple of [%u]", trafficClass, EnvConfig::HCCL_RDMA_TC_BASE);
248 0 : return HCCL_E_PARA;
249 : }
250 :
251 : // 校验config中SL是否合法
252 0 : if (serviceLevel > EnvConfig::HCCL_RDMA_SL_MAX) {
253 0 : HCCL_ERROR(
254 : "[SetQpQosAttr]rdmaServiceLevel is invalid. except:[%u, %u], actual:[%u]", EnvConfig::HCCL_RDMA_SL_MIN,
255 : EnvConfig::HCCL_RDMA_SL_MAX, serviceLevel);
256 0 : return HCCL_E_PARA;
257 : }
258 :
259 0 : HCCL_INFO("[SetQpQosAttr] rdmaTrafficClass[%u], rdmaServiceLevel[%u]", trafficClass, serviceLevel);
260 0 : communicator_->SetQpQosAttr(trafficClass, serviceLevel);
261 :
262 0 : return HCCL_SUCCESS;
263 : }
264 :
265 0 : HcclResult hcclComm::CreateGroup(
266 : const std::string& group, const u32& groupRank, const u32& userRank, const std::vector<u32>& groupRanks,
267 : std::shared_ptr<hcclComm>& groupComm)
268 : {
269 : // 增加输出日志关键字
270 0 : HCCL_INFO(
271 : "HCCL_KEY_INFO: group[%s], groupRank[%u], userRank[%u], groupComm[%p]", group.c_str(), groupRank, userRank,
272 : groupComm.get());
273 :
274 : // 入参有消息校验
275 0 : if (group.length() == 0) {
276 0 : HCCL_ERROR("[Create][Group]errNo[0x%016llx] group name length is 0", HCCL_ERROR_CODE(HCCL_E_PARA));
277 0 : return HCCL_E_PARA;
278 : }
279 :
280 0 : if (groupRank >= groupRanks.size()) {
281 0 : HCCL_ERROR(
282 : "[Create][Group]errNo[0x%016llx] group rank[%u] out of range [0,%llu])", HCCL_ERROR_CODE(HCCL_E_PARA),
283 : groupRank, groupRanks.size() - 1);
284 0 : return HCCL_E_PARA;
285 : }
286 :
287 : HcclRootInfo id;
288 0 : CHK_RET(GetUniqueId(&id));
289 :
290 0 : HcclCommParams params;
291 0 : params.rank = groupRank;
292 0 : params.userRank = userRank;
293 0 : params.totalRanks = groupRanks.size();
294 0 : params.isHeterogComm = isHeterogComm_;
295 0 : s32 iret = snprintf_s(
296 : params.id.internal, HCCL_ROOT_INFO_BYTES, HCCL_ROOT_INFO_BYTES - 1, "%s%s%s", id.internal, "-", group.c_str());
297 :
298 0 : CHK_PRT_RET(
299 : (iret == -1),
300 : HCCL_ERROR("[Create][Group]errNo[0x%016llx] get group unique id failed", HCCL_ERROR_CODE(HCCL_E_INTERNAL)),
301 : HCCL_E_INTERNAL);
302 :
303 0 : WorldGroupInfo groupCommonData;
304 :
305 0 : CHK_RET(communicator_->GetGroupCommonData(groupCommonData));
306 0 : params.logicDevId = groupCommonData.deviceLogicId;
307 0 : params.profilingInitiated = groupCommonData.profilingInitiated;
308 0 : params.deviceType = deviceType_;
309 0 : params.hcomGroupNicInit = communicator_->GetNicInitialized();
310 0 : std::vector<RankInfo> rankList;
311 :
312 0 : CHK_RET(communicator_->GetGroupRanksInfo(groupRanks, rankList));
313 :
314 0 : groupComm.reset(new (std::nothrow) hccl::hcclComm(0, 0, group));
315 0 : CHK_SMART_PTR_NULL(groupComm);
316 0 : CommConfig commConfig(group);
317 0 : CHK_RET(groupComm->init(params, commConfig, rankList, groupCommonData));
318 :
319 0 : return HCCL_SUCCESS;
320 0 : }
321 :
322 0 : HcclResult hcclComm::DestroyGroup(const std::string& group) const
323 : {
324 : /* 增加输出日志关键字 */
325 0 : HCCL_DEBUG("start destroy group: group[%s]", group.c_str());
326 0 : return HCCL_SUCCESS;
327 : }
328 :
329 80 : HcclResult hcclComm::GetAlgType(AlgType& algType, HcclCMDType opType)
330 : {
331 : /* 增加输出日志关键字 */
332 80 : HCCL_DEBUG("algType[%s]", AlgTypeToStr(algType).c_str());
333 80 : return communicator_->GetAlgType(algType, opType);
334 : }
335 :
336 29 : void hcclComm::PrintSubmittedOpCnt(const std::string& tag, HcclResult ret)
337 : {
338 29 : u32 index = 0;
339 29 : ProfilerBase::GetSubmittedOpCnt(index);
340 29 : HCCL_ERROR("[HcclComm][%s]errNo[0x%016llx] index[%u]", tag.c_str(), ret, index);
341 29 : }
342 :
343 2 : HcclResult hcclComm::AllGather(
344 : const std::string& tag, void* inputPtr, void* outputPtr, u64 inputCount, HcclDataType dataType, HcclRtStream stream,
345 : HcomCollOpInfo* opInfo)
346 : {
347 : /* 增加输出日志关键字 */
348 2 : HCCL_INFO(
349 : "HCCL_KEY_INFO: tag[%s], count[%llu], data_type[%s]", tag.c_str(), inputCount,
350 : GetDataTypeEnumStr(dataType).c_str());
351 :
352 : /* * 入参检查 */
353 2 : CHK_PTR_NULL(inputPtr);
354 2 : CHK_PTR_NULL(outputPtr);
355 2 : CHK_PTR_NULL(stream);
356 :
357 2 : CHK_PRT_RET(
358 : tag.empty(),
359 : HCCL_ERROR("[HcclComm][AllGather]errNo[0x%016llx] AllGather tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA)),
360 : HCCL_E_PARA);
361 :
362 2 : CHK_RET(communicator_->CheckCount(inputCount));
363 2 : CHK_RET(communicator_->CheckDataType(dataType, false));
364 2 : HcclResult ret = communicator_->AllGather(tag, inputPtr, outputPtr, inputCount, dataType, stream, opInfo);
365 2 : if (ret != HCCL_SUCCESS) {
366 1 : PrintSubmittedOpCnt(tag, ret);
367 1 : return ret;
368 : }
369 :
370 1 : return HCCL_SUCCESS;
371 : }
372 :
373 0 : HcclResult hcclComm::AllGatherV(
374 : const std::string& tag, const void* sendBuf, u64 sendCount, const void* recvBuf, const void* recvCounts,
375 : const void* rdispls, HcclDataType dataType, HcclRtStream stream)
376 : {
377 : /* 增加输出日志关键字 */
378 0 : HCCL_INFO(
379 : "HCCL_KEY_INFO: tag[%s], count[%llu], data_type[%s]", tag.c_str(), sendCount,
380 : GetDataTypeEnumStr(dataType).c_str());
381 :
382 : /* * 入参检查 */
383 0 : CHK_PTR_NULL(stream);
384 0 : CHK_PTR_NULL(sendBuf);
385 0 : CHK_PTR_NULL(recvBuf);
386 0 : CHK_PTR_NULL(recvCounts);
387 0 : CHK_PTR_NULL(rdispls);
388 :
389 0 : CHK_PRT_RET(
390 : tag.empty(),
391 : HCCL_ERROR("[HcclComm][AllGatherV]errNo[0x%016llx] AllGather tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA)),
392 : HCCL_E_PARA);
393 :
394 0 : CHK_RET(communicator_->CheckDataType(dataType, false));
395 0 : HcclResult ret = communicator_->AllGatherV(tag, sendBuf, sendCount, recvBuf, recvCounts, rdispls, dataType, stream);
396 0 : if (ret != HCCL_SUCCESS) {
397 0 : PrintSubmittedOpCnt(tag, ret);
398 0 : return ret;
399 : }
400 :
401 0 : return HCCL_SUCCESS;
402 : }
403 :
404 23 : HcclResult hcclComm::AllGatherOutPlace(
405 : const std::string& tag, void* inputPtr, void* outputPtr, u64 inputCount, HcclDataType dataType, HcclRtStream stream)
406 : {
407 : /* 增加输出日志关键字 */
408 23 : HCCL_INFO(
409 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s]", tag.c_str(), inputPtr,
410 : outputPtr, inputCount, GetDataTypeEnumStr(dataType).c_str());
411 :
412 : /* * 入参检查 */
413 23 : CHK_RET(communicator_->CheckDataType(dataType, false));
414 23 : HcclResult ret = communicator_->AllGatherOutPlace(tag, inputPtr, outputPtr, inputCount, dataType, stream);
415 23 : if (ret != HCCL_SUCCESS) {
416 0 : PrintSubmittedOpCnt(tag, ret);
417 0 : return ret;
418 : }
419 :
420 23 : return HCCL_SUCCESS;
421 : }
422 :
423 23 : HcclResult hcclComm::AllGatherVOutPlace(
424 : const std::string& tag, void* inputPtr, void* outputPtr, u64 inputCount, const void* outputCounts,
425 : const void* outputDispls, HcclDataType dataType, HcclRtStream stream)
426 : {
427 : /* 增加输出日志关键字 */
428 23 : HCCL_INFO(
429 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], counts[%llu], data_type[%d]", tag.c_str(), inputPtr,
430 : outputPtr, outputCounts, dataType);
431 :
432 : /* * 入参检查 */
433 23 : CHK_RET(communicator_->CheckDataType(dataType, false));
434 23 : CHK_RET(communicator_->AllGatherVOutPlace(
435 : tag, inputPtr, outputPtr, inputCount, outputCounts, outputDispls, dataType, stream));
436 :
437 23 : return HCCL_SUCCESS;
438 : }
439 :
440 24 : HcclResult hcclComm::AlltoAllV(
441 : const void* sendBuf, const void* sendCounts, const void* sdispls, HcclDataType sendType, const void* recvBuf,
442 : const void* recvCounts, const void* rdispls, HcclDataType recvType, rtStream_t stream, const std::string& tag)
443 : {
444 : /* * 入参检查 */
445 24 : CHK_PTR_NULL(stream);
446 24 : CHK_PTR_NULL(sendCounts);
447 24 : CHK_PTR_NULL(sdispls);
448 24 : CHK_PTR_NULL(recvCounts);
449 24 : CHK_PTR_NULL(rdispls);
450 :
451 24 : CHK_PRT_RET(
452 : tag.empty(),
453 : HCCL_ERROR("[HcclComm][AlltoAllV]errNo[0x%016llx] AllToAllV tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA)),
454 : HCCL_E_PARA);
455 :
456 24 : CHK_RET(communicator_->CheckDataType(sendType, false));
457 :
458 24 : CHK_RET(communicator_->CheckDataType(recvType, false));
459 :
460 24 : HcclResult ret = communicator_->AlltoAllV(
461 : sendBuf, sendCounts, sdispls, sendType, recvBuf, recvCounts, rdispls, recvType, stream, tag);
462 24 : if (ret != HCCL_SUCCESS) {
463 0 : PrintSubmittedOpCnt(tag, ret);
464 0 : return ret;
465 : }
466 :
467 24 : return HCCL_SUCCESS;
468 : }
469 :
470 1 : HcclResult hcclComm::AlltoAllVOutPlace(
471 : const void* sendBuf, const void* sendCounts, const void* sdispls, HcclDataType sendType, const void* recvBuf,
472 : const void* recvCounts, const void* rdispls, HcclDataType recvType, rtStream_t stream, const std::string& tag)
473 : {
474 : /* * 入参检查 */
475 1 : CHK_RET(communicator_->CheckDataType(sendType, false));
476 1 : CHK_RET(communicator_->CheckDataType(recvType, false));
477 :
478 1 : HcclResult ret = communicator_->AlltoAllVOutPlace(
479 : sendBuf, sendCounts, sdispls, sendType, recvBuf, recvCounts, rdispls, recvType, stream, tag);
480 1 : if (ret != HCCL_SUCCESS) {
481 0 : PrintSubmittedOpCnt(tag, ret);
482 0 : return ret;
483 : }
484 :
485 1 : return HCCL_SUCCESS;
486 : }
487 :
488 0 : HcclResult hcclComm::AlltoAllVC(
489 : const void* sendBuf, const void* sendCountMatrix, HcclDataType sendType, const void* recvBuf, HcclDataType recvType,
490 : rtStream_t stream, const std::string& tag)
491 : {
492 : /* * 入参检查 */
493 0 : CHK_PTR_NULL(stream);
494 0 : CHK_PTR_NULL(sendCountMatrix);
495 :
496 0 : CHK_PRT_RET(
497 : tag.empty(),
498 : HCCL_ERROR("[HcclComm][AlltoAllVC]errNo[0x%016llx] AllToAllVC tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA)),
499 : HCCL_E_PARA);
500 :
501 0 : CHK_RET(communicator_->CheckDataType(sendType, false));
502 :
503 0 : CHK_RET(communicator_->CheckDataType(recvType, false));
504 :
505 0 : HcclResult ret = communicator_->AlltoAllVC(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, stream, tag);
506 0 : if (ret != HCCL_SUCCESS) {
507 0 : PrintSubmittedOpCnt(tag, ret);
508 0 : return ret;
509 : }
510 :
511 0 : return HCCL_SUCCESS;
512 : }
513 :
514 0 : HcclResult hcclComm::AlltoAllVCOutPlace(
515 : const void* sendBuf, const void* sendCountMatrix, HcclDataType sendType, const void* recvBuf, HcclDataType recvType,
516 : rtStream_t stream, const std::string& tag)
517 : {
518 : /* * 入参检查 */
519 0 : CHK_RET(communicator_->CheckDataType(sendType, false));
520 0 : CHK_RET(communicator_->CheckDataType(recvType, false));
521 :
522 : HcclResult ret
523 0 : = communicator_->AlltoAllVCOutPlace(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, stream, tag);
524 0 : if (ret != HCCL_SUCCESS) {
525 0 : PrintSubmittedOpCnt(tag, ret);
526 0 : return ret;
527 : }
528 :
529 0 : return HCCL_SUCCESS;
530 : }
531 :
532 23 : HcclResult hcclComm::AlltoAll(
533 : const void* sendBuf, u64 sendCount, HcclDataType sendType, const void* recvBuf, u64 recvCount,
534 : HcclDataType recvType, rtStream_t stream, const std::string& tag)
535 : {
536 : /* * 入参检查 */
537 23 : CHK_PTR_NULL(communicator_);
538 :
539 23 : CHK_PRT_RET(
540 : tag.empty(),
541 : HCCL_ERROR("[HcclComm][AlltoAll]errNo[0x%016llx] AllToAll tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA)),
542 : HCCL_E_PARA);
543 :
544 23 : CHK_RET(communicator_->CheckDataType(sendType, false));
545 :
546 23 : HcclResult ret = communicator_->AlltoAll(sendBuf, sendCount, sendType, recvBuf, recvCount, recvType, stream, tag);
547 23 : if (ret != HCCL_SUCCESS) {
548 0 : PrintSubmittedOpCnt(tag, ret);
549 0 : return ret;
550 : }
551 :
552 23 : return HCCL_SUCCESS;
553 : }
554 :
555 : HcclResult
556 3 : hcclComm::Broadcast(const std::string& tag, void* ptr, u64 count, HcclDataType dataType, u32 root, HcclRtStream stream)
557 : {
558 : /* 增加输出日志关键字 */
559 3 : HCCL_INFO(
560 : "HCCL_KEY_INFO:tag[%s], ptr[%p], count[%llu], data_type[%s], root[%u]", tag.c_str(), ptr, count,
561 : GetDataTypeEnumStr(dataType).c_str(), root);
562 :
563 : /* * 入参检查 */
564 3 : CHK_PTR_NULL(stream);
565 3 : CHK_PTR_NULL(ptr);
566 :
567 3 : if (tag.empty()) {
568 0 : HCCL_ERROR("[HcclComm][Broadcast]errNo[0x%016llx] broadcast tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA));
569 0 : return HCCL_E_PARA;
570 : }
571 :
572 : /* * 初始化检查 */
573 3 : CHK_SMART_PTR_NULL(communicator_);
574 3 : CHK_RET(communicator_->CheckCount(count));
575 3 : CHK_RET(communicator_->CheckDataType(dataType, false));
576 3 : CHK_RET(communicator_->CheckUserRank(root));
577 3 : HcclResult ret = communicator_->Broadcast(tag, ptr, count, dataType, root, stream);
578 3 : if (ret != HCCL_SUCCESS) {
579 1 : PrintSubmittedOpCnt(tag, ret);
580 1 : return ret;
581 : }
582 :
583 2 : return HCCL_SUCCESS;
584 : }
585 :
586 23 : HcclResult hcclComm::BroadcastOutPlace(
587 : const std::string& tag, void* ptr, u64 count, HcclDataType dataType, u32 root, HcclRtStream stream)
588 : {
589 : /* 增加输出日志关键字 */
590 23 : HCCL_INFO(
591 : "HCCL_KEY_INFO:tag[%s], ptr[%p], count[%llu], data_type[%s], root[%u]", tag.c_str(), ptr, count,
592 : GetDataTypeEnumStr(dataType).c_str(), root);
593 :
594 : /* * 入参检查 */
595 23 : CHK_RET(communicator_->CheckDataType(dataType, false));
596 23 : CHK_RET(communicator_->CheckUserRank(root));
597 23 : HcclResult ret = communicator_->BroadcastOutPlace(tag, ptr, count, dataType, root, stream);
598 23 : if (ret != HCCL_SUCCESS) {
599 0 : PrintSubmittedOpCnt(tag, ret);
600 0 : return ret;
601 : }
602 :
603 23 : return HCCL_SUCCESS;
604 : }
605 :
606 24 : HcclResult hcclComm::ScatterOutPlace(
607 : const std::string& tag, void* inputPtr, void* outputPtr, u64 recvCount, HcclDataType dataType, u32 root,
608 : HcclRtStream stream)
609 : {
610 : /* 增加输出日志关键字 */
611 24 : HCCL_INFO(
612 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], recvCount[%llu], data_type[%s], root[%u]", tag.c_str(),
613 : inputPtr, outputPtr, recvCount, GetDataTypeEnumStr(dataType).c_str(), root);
614 :
615 24 : if (tag.empty()) {
616 0 : HCCL_ERROR("[HcclComm][Scatter]errNo[0x%016llx] scatter tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA));
617 0 : return HCCL_E_PARA;
618 : }
619 :
620 24 : CHK_RET(communicator_->CheckCount(recvCount));
621 24 : CHK_RET(communicator_->CheckDataType(dataType, false));
622 24 : CHK_RET(communicator_->CheckUserRank(root));
623 24 : HcclResult ret = communicator_->ScatterOutPlace(tag, inputPtr, outputPtr, recvCount, dataType, root, stream);
624 24 : if (ret != HCCL_SUCCESS) {
625 0 : PrintSubmittedOpCnt(tag, ret);
626 0 : return ret;
627 : }
628 :
629 24 : return HCCL_SUCCESS;
630 : }
631 :
632 9 : HcclResult hcclComm::ReduceScatter(
633 : const std::string& tag, void* inputPtr, void* outputPtr, u64 recvCount, HcclDataType dataType, HcclReduceOp op,
634 : HcclRtStream stream)
635 : {
636 : /* 增加输出日志关键字 */
637 9 : HCCL_INFO(
638 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], recvCount[%llu], data_type[%s], "
639 : "op[%s]",
640 : tag.c_str(), inputPtr, outputPtr, recvCount, GetDataTypeEnumStr(dataType).c_str(),
641 : GetReduceOpEnumStr(op).c_str());
642 :
643 : /* * 入参检查 */
644 19 : CHK_PTR_NULL(stream);
645 19 : CHK_PTR_NULL(inputPtr);
646 19 : CHK_PTR_NULL(outputPtr);
647 :
648 19 : if (tag.empty()) {
649 0 : HCCL_ERROR(
650 : "[HcclComm][ReduceScatter]errNo[0x%016llx] reduceScatter tag length is"
651 : "0",
652 : HCCL_ERROR_CODE(HCCL_E_PARA));
653 0 : return HCCL_E_PARA;
654 : }
655 :
656 19 : CHK_RET(communicator_->CheckCount(recvCount));
657 16 : CHK_RET(communicator_->CheckDataType(dataType, true));
658 16 : CHK_RET(communicator_->CheckReduceDataType(dataType, op));
659 12 : CHK_RET(communicator_->CheckReductionOp(op));
660 11 : HcclResult ret = communicator_->ReduceScatter(tag, inputPtr, outputPtr, recvCount, dataType, op, stream);
661 16 : if (ret != HCCL_SUCCESS) {
662 9 : PrintSubmittedOpCnt(tag, ret);
663 9 : return ret;
664 : }
665 :
666 7 : return HCCL_SUCCESS;
667 : }
668 :
669 32 : HcclResult hcclComm::ReduceScatterOutPlace(
670 : const std::string& tag, void* inputPtr, void* outputPtr, u64 recvCount, HcclDataType dataType, HcclReduceOp op,
671 : HcclRtStream stream)
672 : {
673 : /* 增加输出日志关键字 */
674 32 : HCCL_INFO(
675 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], recvCount[%llu], data_type[%s], op[%s]", tag.c_str(),
676 : inputPtr, outputPtr, recvCount, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str());
677 :
678 : /* * 入参检查 */
679 35 : CHK_RET(communicator_->CheckDataType(dataType, true));
680 32 : CHK_RET(communicator_->CheckReduceDataType(dataType, op));
681 28 : HcclResult ret = communicator_->ReduceScatterOutPlace(tag, inputPtr, outputPtr, recvCount, dataType, op, stream);
682 35 : if (ret != HCCL_SUCCESS) {
683 8 : PrintSubmittedOpCnt(tag, ret);
684 8 : return ret;
685 : }
686 :
687 27 : return HCCL_SUCCESS;
688 : }
689 :
690 0 : HcclResult hcclComm::ReduceScatterV(
691 : const std::string& tag, void* inputPtr, const void* inputCounts, const void* inputDispls, void* outputPtr,
692 : u64 outputCount, HcclDataType dataType, HcclReduceOp op, HcclRtStream stream)
693 : {
694 : /* 增加输出日志关键字 */
695 0 : HCCL_INFO(
696 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], "
697 : "input_counts[%p], input_displs[%p], output_count[%llu], data_type[%s], op[%s]",
698 : tag.c_str(), inputPtr, outputPtr, inputCounts, inputDispls, outputCount, GetDataTypeEnumStr(dataType).c_str(),
699 : GetReduceOpEnumStr(op).c_str());
700 :
701 : /* * 入参检查 */
702 0 : CHK_PTR_NULL(stream);
703 0 : CHK_PTR_NULL(inputPtr);
704 0 : CHK_PTR_NULL(outputPtr);
705 :
706 0 : if (tag.empty()) {
707 0 : HCCL_ERROR(
708 : "[HcclComm][ReduceScatterV]errNo[0x%016llx] reduceScatterV tag length is"
709 : "0",
710 : HCCL_ERROR_CODE(HCCL_E_PARA));
711 0 : return HCCL_E_PARA;
712 : }
713 :
714 : // ReduceScatterV只支持inlinereduce,因此不支持int64类型
715 0 : if (dataType == HCCL_DATA_TYPE_INT64) {
716 0 : HCCL_ERROR(
717 : "[Check][DataType]errNo[0x%016llx] data type[%s] not supported.", HCCL_ERROR_CODE(HCCL_E_NOT_SUPPORT),
718 : GetDataTypeEnumStr(dataType).c_str());
719 0 : return HCCL_E_NOT_SUPPORT;
720 : }
721 :
722 0 : CHK_RET(communicator_->CheckDataType(dataType, true));
723 0 : CHK_RET(communicator_->CheckReduceDataType(dataType, op));
724 0 : CHK_RET(communicator_->CheckReductionOp(op));
725 0 : HcclResult ret = communicator_->ReduceScatterV(
726 : tag, inputPtr, inputCounts, inputDispls, outputPtr, outputCount, dataType, op, stream);
727 0 : if (ret != HCCL_SUCCESS) {
728 0 : PrintSubmittedOpCnt(tag, ret);
729 0 : return ret;
730 : }
731 :
732 0 : return HCCL_SUCCESS;
733 : }
734 :
735 23 : HcclResult hcclComm::ReduceScatterVOutPlace(
736 : const std::string& tag, void* inputPtr, void* outputPtr, const void* inputCounts, const void* inputDispls,
737 : u64 outputCount, HcclDataType dataType, HcclReduceOp op, HcclRtStream stream)
738 : {
739 : /* 增加输出日志关键字 */
740 23 : HCCL_INFO(
741 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], "
742 : "input_counts[%llu], input_displs[%llu], output_count[%llu], data_type[%s], op[%s]",
743 : tag.c_str(), inputPtr, outputPtr, inputCounts, inputDispls, outputCount, GetDataTypeEnumStr(dataType).c_str(),
744 : GetReduceOpEnumStr(op).c_str());
745 :
746 : /* * 入参检查 */
747 23 : CHK_RET(communicator_->CheckDataType(dataType, true));
748 23 : CHK_RET(communicator_->CheckReduceDataType(dataType, op));
749 23 : HcclResult ret = communicator_->ReduceScatterVOutPlace(
750 : tag, inputPtr, outputPtr, inputCounts, inputDispls, outputCount, dataType, op, stream);
751 23 : if (ret != HCCL_SUCCESS) {
752 0 : PrintSubmittedOpCnt(tag, ret);
753 0 : return ret;
754 : }
755 :
756 23 : return HCCL_SUCCESS;
757 : }
758 :
759 5 : HcclResult hcclComm::Reduce(
760 : const std::string& tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op,
761 : u32 root, HcclRtStream stream)
762 : {
763 : /* 增加输出日志关键字 */
764 5 : HCCL_INFO(
765 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s], root[%u]",
766 : tag.c_str(), inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
767 : root);
768 :
769 : /* * 入参检查 */
770 5 : CHK_PTR_NULL(stream);
771 5 : CHK_PTR_NULL(inputPtr);
772 5 : CHK_PTR_NULL(outputPtr);
773 :
774 5 : if (tag.empty()) {
775 0 : HCCL_ERROR("[HcclComm][Reduce]errNo[0x%016llx] reduce tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA));
776 0 : return HCCL_E_PARA;
777 : }
778 :
779 5 : CHK_RET(communicator_->CheckCount(count));
780 5 : CHK_RET(communicator_->CheckDataType(dataType, true));
781 5 : CHK_RET(communicator_->CheckReduceDataType(dataType, op));
782 5 : CHK_RET(communicator_->CheckReductionOp(op));
783 5 : CHK_RET(communicator_->CheckUserRank(root));
784 5 : HcclResult ret = communicator_->Reduce(tag, inputPtr, outputPtr, count, dataType, op, root, stream);
785 5 : if (ret != HCCL_SUCCESS) {
786 0 : PrintSubmittedOpCnt(tag, ret);
787 0 : return ret;
788 : }
789 :
790 5 : return HCCL_SUCCESS;
791 : }
792 :
793 27 : HcclResult hcclComm::ReduceOutPlace(
794 : const std::string& tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op,
795 : u32 root, HcclRtStream stream)
796 : {
797 : /* 增加输出日志关键字 */
798 27 : HCCL_INFO(
799 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s], root[%u]",
800 : tag.c_str(), inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
801 : root);
802 :
803 : /* * 入参检查 */
804 27 : CHK_RET(communicator_->CheckDataType(dataType, true));
805 25 : CHK_RET(communicator_->CheckReduceDataType(dataType, op));
806 25 : CHK_RET(communicator_->CheckUserRank(root));
807 24 : HcclResult ret = communicator_->ReduceOutPlace(tag, inputPtr, outputPtr, count, dataType, op, root, stream);
808 27 : if (ret != HCCL_SUCCESS) {
809 4 : PrintSubmittedOpCnt(tag, ret);
810 4 : return ret;
811 : }
812 :
813 23 : return HCCL_SUCCESS;
814 : }
815 :
816 23 : HcclResult hcclComm::BatchSendRecv(
817 : const std::string& tag, struct HcclSendRecvItemDef* sendRecvItemsPtr, u32 itemNum, rtStream_t stream)
818 : {
819 23 : HcclResult ret = communicator_->BatchSendRecv(tag, sendRecvItemsPtr, itemNum, stream);
820 23 : if (ret != HCCL_SUCCESS) {
821 0 : PrintSubmittedOpCnt(tag, ret);
822 0 : return ret;
823 : }
824 :
825 23 : return HCCL_SUCCESS;
826 : }
827 :
828 0 : HcclResult hcclComm::send(
829 : const std::string& tag, void* inputPtr, u64 count, HcclDataType dataType, u32 destRank, rtStream_t stream,
830 : u32 srTag, u32 localGroupRank)
831 : {
832 : /* 增加输出日志关键字 */
833 0 : HCCL_INFO(
834 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], count[%llu], data_type[%s], destRank[%u]", tag.c_str(), inputPtr, count,
835 : GetDataTypeEnumStr(dataType).c_str(), destRank);
836 :
837 : /* 入参检查 */
838 0 : CHK_PTR_NULL(inputPtr);
839 :
840 0 : if (tag.empty()) {
841 0 : HCCL_ERROR("[HcclComm][Send]errNo[0x%016llx] send tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA));
842 0 : return HCCL_E_PARA;
843 : }
844 :
845 0 : CHK_RET(communicator_->CheckCount(count));
846 0 : CHK_RET(communicator_->CheckDataType(dataType, false));
847 0 : CHK_RET(communicator_->CheckUserRank(destRank));
848 0 : HcclResult ret = communicator_->Send(tag, inputPtr, count, dataType, destRank, stream, srTag, localGroupRank);
849 0 : if (ret != HCCL_SUCCESS) {
850 0 : PrintSubmittedOpCnt(tag, ret);
851 0 : return ret;
852 : }
853 :
854 0 : return HCCL_SUCCESS;
855 : }
856 :
857 25 : HcclResult hcclComm::SendOutPlace(
858 : const std::string& tag, void* inputPtr, u64 count, HcclDataType dataType, u32 destRank, rtStream_t stream)
859 : {
860 : /* 增加输出日志关键字 */
861 25 : HCCL_INFO(
862 : "HCCL_KEY_INFO: tag[%s], input_ptr[%p], count[%llu], data_type[%s], destRank[%u],", tag.c_str(), inputPtr,
863 : count, GetDataTypeEnumStr(dataType).c_str(), destRank);
864 :
865 : /* 入参检查 */
866 25 : CHK_RET(communicator_->CheckDataType(dataType, false));
867 25 : CHK_RET(communicator_->CheckUserRank(destRank));
868 24 : HcclResult ret = communicator_->SendOutPlace(tag, inputPtr, count, dataType, destRank, stream);
869 24 : if (ret != HCCL_SUCCESS) {
870 1 : PrintSubmittedOpCnt(tag, ret);
871 1 : return ret;
872 : }
873 :
874 23 : return HCCL_SUCCESS;
875 : }
876 :
877 25 : HcclResult hcclComm::ReceiveOutPlace(
878 : const std::string& tag, void* outputPtr, u64 count, HcclDataType dataType, u32 srcRank, rtStream_t stream)
879 : {
880 : /* 增加输出日志关键字 */
881 25 : HCCL_INFO(
882 : "HCCL_KEY_INFO: tag[%s], output_ptr[%p], count[%llu], data_type[%s], srcRank[%u]", tag.c_str(), outputPtr,
883 : count, GetDataTypeEnumStr(dataType).c_str(), srcRank);
884 :
885 : /* * 入参检查 */
886 25 : CHK_RET(communicator_->CheckDataType(dataType, false));
887 25 : CHK_RET(communicator_->CheckUserRank(srcRank));
888 24 : HcclResult ret = communicator_->ReceiveOutPlace(tag, outputPtr, count, dataType, srcRank, stream);
889 24 : if (ret != HCCL_SUCCESS) {
890 1 : PrintSubmittedOpCnt(tag, ret);
891 1 : return ret;
892 : }
893 :
894 23 : return HCCL_SUCCESS;
895 : }
896 :
897 0 : HcclResult hcclComm::receive(
898 : const std::string& tag, void* outputPtr, u64 count, HcclDataType dataType, u32 srcRank, rtStream_t stream,
899 : u32 srTag, u32 localGroupRank)
900 : {
901 : /* 增加输出日志关键字 */
902 0 : HCCL_INFO(
903 : "HCCL_KEY_INFO: tag[%s], output_ptr[%p], count[%llu], data_type[%s], srcRank[%u]", tag.c_str(), outputPtr,
904 : count, GetDataTypeEnumStr(dataType).c_str(), srcRank);
905 :
906 : /* * 入参检查 */
907 0 : CHK_PTR_NULL(outputPtr);
908 :
909 0 : CHK_PRT_RET(
910 : tag.empty(),
911 : HCCL_ERROR("[HcclComm][Receive]errNo[0x%016llx] receive tag length is 0", HCCL_ERROR_CODE(HCCL_E_PARA)),
912 : HCCL_E_PARA);
913 :
914 0 : CHK_RET(communicator_->CheckCount(count));
915 0 : CHK_RET(communicator_->CheckDataType(dataType, false));
916 0 : CHK_RET(communicator_->CheckUserRank(srcRank));
917 0 : HcclResult ret = communicator_->Receive(tag, outputPtr, count, dataType, srcRank, stream, srTag, localGroupRank);
918 0 : if (ret != HCCL_SUCCESS) {
919 0 : PrintSubmittedOpCnt(tag, ret);
920 0 : return ret;
921 : }
922 :
923 0 : return HCCL_SUCCESS;
924 : }
925 :
926 : // 目前支持按tag对资源释放、解绑定
927 16 : HcclResult hcclComm::ClearOpResource(const std::string& tag)
928 : {
929 16 : CHK_RET(communicator_->ClearOpResource(tag));
930 :
931 16 : return HCCL_SUCCESS;
932 : }
933 :
934 0 : HcclResult hcclComm::SetClearAivSyncBuf(bool aivClearEnable)
935 : {
936 0 : CHK_RET(communicator_->SetClearAivSyncBuf(aivClearEnable));
937 :
938 0 : return HCCL_SUCCESS;
939 : }
940 :
941 292 : HcclResult hcclComm::GetUniqueId(HcclRootInfo* uniqueId)
942 : {
943 292 : CHK_PTR_NULL(uniqueId);
944 :
945 292 : std::string uniqueIdGot = HcclCommunicator::GetUniqueId();
946 292 : s32 ret = snprintf_s(
947 292 : uniqueId->internal, HCCL_ROOT_INFO_BYTES, HCCL_ROOT_INFO_BYTES - 1, "%s%s", "hccl-", uniqueIdGot.c_str());
948 292 : CHK_PRT_RET(
949 : (ret == -1),
950 : HCCL_ERROR("[Get][UniqueId]errNo[0x%016llx] get unique id failed,uniqueId[%p]", HCCL_ERROR_CODE(ret), uniqueId),
951 : HCCL_E_MEMORY);
952 :
953 292 : return HCCL_SUCCESS;
954 292 : }
955 :
956 1 : HcclResult hcclComm::CreateCommCCLbuffer() const
957 : {
958 1 : CHK_RET(communicator_->CreateCommCCLbuffer());
959 :
960 1 : return HCCL_SUCCESS;
961 : }
962 :
963 0 : HcclResult hcclComm::CreateIndirectCCLbuf()
964 : {
965 0 : CHK_RET(DeviceMem::alloc(indirectInCCLbuffer_, sizeof(uintptr_t), true));
966 0 : CHK_RET(DeviceMem::alloc(indirectOutCCLbuffer_, sizeof(uintptr_t), true));
967 :
968 0 : return HCCL_SUCCESS;
969 : }
970 :
971 0 : void hcclComm::ReleaseIndirectCCLbuf()
972 : {
973 0 : indirectInCCLbuffer_.free();
974 0 : indirectOutCCLbuffer_.free();
975 0 : }
976 :
977 0 : HcclResult hcclComm::GetIndirectInCCLbuf(void*& ptr, u64& size)
978 : {
979 0 : ptr = indirectInCCLbuffer_.ptr();
980 0 : size = sizeof(uintptr_t);
981 0 : return HCCL_SUCCESS;
982 : }
983 :
984 0 : HcclResult hcclComm::GetIndirectOutCCLbuf(void*& ptr, u64& size)
985 : {
986 0 : ptr = indirectOutCCLbuffer_.ptr();
987 0 : size = sizeof(uintptr_t);
988 0 : return HCCL_SUCCESS;
989 : }
990 1858 : std::string hcclComm::GetIdentifier() { return identifier_; }
991 :
992 2 : std::string hcclComm::GetCCLbufferName() { return cclBuffName_; }
993 :
994 1 : HcclResult hcclComm::CommCheckErrorCqe(HcclResult& result)
995 : {
996 1 : CHK_RET(communicator_->GetCqeError(result));
997 :
998 1 : return HCCL_SUCCESS;
999 : }
1000 :
1001 0 : HcclResult hcclComm::CommCheckOpInconsistentError(HcclResult& result)
1002 : {
1003 0 : CHK_RET(communicator_->GetOpInconsistentError(result));
1004 :
1005 0 : return HCCL_SUCCESS;
1006 : }
1007 :
1008 412 : HcclResult hcclComm::InitImpl(DevType deviceType, const CommConfig& commConfig)
1009 : {
1010 412 : HCCL_INFO(
1011 : "InitImpl Implementation isHeterogComm_[%d] isHaveCpuRank_[%d] deviceType[%d] isSpecialType_[%d]",
1012 : isHeterogComm_, isHaveCpuRank_, deviceType, isSpecialType_);
1013 :
1014 412 : communicator_.reset(new (std::nothrow) HcclCommunicator(commConfig));
1015 411 : CHK_SMART_PTR_NULL(communicator_);
1016 412 : deviceType_ = deviceType;
1017 412 : CHK_RET(RegistTaskAbortHandler());
1018 :
1019 412 : return HCCL_SUCCESS;
1020 : }
1021 :
1022 0 : HcclResult hcclComm::CreateBarrierMemory()
1023 : {
1024 0 : if (isFirstBarrier_) {
1025 : // 申请device内存
1026 0 : CHK_RET(DeviceMem::alloc(barrierInMemory_, HCCL_BARRIER_DEFAULT_COUNT * sizeof(float)));
1027 0 : CHK_RET(DeviceMem::alloc(barrierOutMemory_, HCCL_BARRIER_DEFAULT_COUNT * sizeof(float)));
1028 :
1029 0 : barrierSendBuf = static_cast<void*>(barrierInMemory_.ptr());
1030 0 : barrierRecvBuf = static_cast<void*>(barrierOutMemory_.ptr());
1031 :
1032 : // device内存清0
1033 : // 申请host内存,并将初始值设置为0
1034 0 : HostMem barrierHostMem = HostMem::alloc(HCCL_BARRIER_DEFAULT_COUNT * sizeof(float));
1035 0 : CHK_SMART_PTR_NULL(barrierHostMem);
1036 0 : s32 sRet = memset_s(barrierHostMem.ptr(), barrierHostMem.size(), 0, barrierHostMem.size());
1037 0 : CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Create][BarrierMemory]mem set failed.errorno[%d]", sRet), HCCL_E_MEMORY);
1038 :
1039 0 : CHK_RET(hrtMemSyncCopy(
1040 : barrierSendBuf, barrierInMemory_.size(), barrierHostMem.ptr(), barrierHostMem.size(),
1041 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
1042 :
1043 0 : CHK_RET(hrtMemSyncCopy(
1044 : barrierRecvBuf, barrierOutMemory_.size(), barrierHostMem.ptr(), barrierHostMem.size(),
1045 : HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
1046 :
1047 0 : isFirstBarrier_ = false;
1048 0 : }
1049 0 : return HCCL_SUCCESS;
1050 : }
1051 :
1052 0 : HcclResult hcclComm::GetInCCLbuffer(void*& buffer, u64& size)
1053 : {
1054 0 : CHK_RET(communicator_->GetInCCLbuffer(buffer, size));
1055 :
1056 0 : return HCCL_SUCCESS;
1057 : }
1058 0 : HcclResult hcclComm::GetOutCCLbuffer(void*& buffer, u64& size)
1059 : {
1060 0 : CHK_RET(communicator_->GetOutCCLbuffer(buffer, size));
1061 :
1062 0 : return HCCL_SUCCESS;
1063 : }
1064 :
1065 346 : HcclResult hcclComm::GetUserRank(u32& userRank)
1066 : {
1067 346 : userRank = communicator_->GetUserRank();
1068 :
1069 346 : return HCCL_SUCCESS;
1070 : }
1071 :
1072 71 : HcclResult hcclComm::GetGroupRank(u32& userRank)
1073 : {
1074 71 : userRank = communicator_->GetGroupRank();
1075 :
1076 71 : return HCCL_SUCCESS;
1077 : }
1078 :
1079 331 : HcclResult hcclComm::GetRankSize(u32& rankSize)
1080 : {
1081 331 : rankSize = communicator_->GetRankSize();
1082 :
1083 331 : return HCCL_SUCCESS;
1084 : }
1085 :
1086 0 : HcclResult hcclComm::HcclSelectAlg(
1087 : HcclCMDType opType, u64 count, void* counts, HcclDataType dataType, HcclReduceOp op, int32_t aivCoreLimit,
1088 : bool& ifAiv, std::string& algName)
1089 : {
1090 0 : return communicator_->HcclSelectAlg(opType, count, counts, dataType, op, aivCoreLimit, ifAiv, algName);
1091 : }
1092 :
1093 0 : HcclResult hcclComm::HcclCalcNumBlocks(
1094 : HcclCMDType opType, u64 count, void* counts, HcclDataType dataType, int32_t aivCoreLimit, std::string& algName,
1095 : u32& numBlocks)
1096 : {
1097 0 : return communicator_->HcclCalcNumBlocks(opType, count, counts, dataType, aivCoreLimit, algName, numBlocks);
1098 : }
1099 :
1100 0 : HcclResult hcclComm::HcclGetAlgExecParam(
1101 : const std::string& tag, u64 count, void* inputPtr, void* outputPtr, HcclCMDType opType, bool clearEnable,
1102 : HcclDataType dataType, HcclReduceOp op, void*& commContext, u64& len, u32 aivCoreLimit)
1103 : {
1104 0 : return communicator_->HcclGetAlgExecParam(
1105 0 : tag, opType, count, inputPtr, outputPtr, clearEnable, dataType, op, commContext, len, aivCoreLimit);
1106 : }
1107 :
1108 1 : HcclResult hcclComm::SetAicpuCommEngine(bool isAicpuCommEngine)
1109 : {
1110 1 : return communicator_->SetAicpuCommEngine(isAicpuCommEngine);
1111 : }
1112 :
1113 155 : HcclResult hcclComm::GetWorkspaceSubStreamNum(
1114 : u64 count, HcclDataType dataType, HcclReduceOp op, const std::string& algName, u64& streamNum, u64 dataSize,
1115 : bool ifAiv, HcclCMDType optype) const
1116 : {
1117 155 : return communicator_->GetWorkspaceSubStreamNum(count, dataType, op, algName, streamNum, dataSize, ifAiv, optype);
1118 : }
1119 : HcclResult
1120 91 : hcclComm::GetWorkspaceMemSize(const std::string& opType, u64 count, HcclDataType dataType, u32& rankSize, u64& size)
1121 : {
1122 91 : return communicator_->GetWorkspaceMemSize(opType, count, dataType, rankSize, size, deviceType_);
1123 : }
1124 :
1125 0 : HcclResult hcclComm::GetAllReduceScratchSize(const u64 count, const HcclDataType dataType, u64& scratchSize) const
1126 : {
1127 0 : return communicator_->GetAllReduceScratchSize(count, dataType, scratchSize);
1128 : }
1129 :
1130 : // 设定 workspace 资源
1131 : HcclResult
1132 155 : hcclComm::SetWorkspaceResource(const std::string& tag, void* memPtr, u64 maxSize, std::vector<rtStream_t>& stream)
1133 : {
1134 155 : return communicator_->SetWorkspaceResource(tag, memPtr, maxSize, stream);
1135 : }
1136 :
1137 : HcclResult
1138 95 : hcclComm::CreateOpBasedResources(const HcclCMDType& opType, const std::string& tag, const HcomCollOpInfo& opInfo)
1139 : {
1140 95 : return communicator_->CreateOpBasedResources(opType, tag, opInfo);
1141 : }
1142 :
1143 0 : HcclResult hcclComm::GetDeviceNumPerAggregation(u32& deviceNumPerAggregation)
1144 : {
1145 0 : return communicator_->GetDeviceNumPerAggregation(deviceNumPerAggregation);
1146 : }
1147 :
1148 0 : HcclResult hcclComm::GetBandWidthPerNPU(u32 level, float& bandWidth)
1149 : {
1150 0 : return communicator_->GetBandWidthPerNPU(level, bandWidth);
1151 : }
1152 :
1153 0 : HcclResult hcclComm::GetAlltoAllStagedWorkSpaceMemSize(
1154 : u64* sendCounts, u64* sdispls, HcclDataType sendType, u64* recvCounts, u64* rdispls, HcclDataType recvType,
1155 : u64& memSize) const
1156 : {
1157 0 : CHK_RET(communicator_->GetAlltoAllStagedWorkSpaceMemSize(
1158 : sendCounts, sdispls, sendType, recvCounts, rdispls, recvType, memSize));
1159 0 : return HCCL_SUCCESS;
1160 : }
1161 :
1162 0 : HcclResult hcclComm::GetAlltoAllStagedWorkSpaceMemSize(
1163 : std::vector<SendRecvInfo>& allMeshAggregationSendRecvInfo, u64& memSize) const
1164 : {
1165 0 : CHK_RET(communicator_->GetAlltoAllStagedWorkSpaceMemSize(allMeshAggregationSendRecvInfo, memSize));
1166 0 : return HCCL_SUCCESS;
1167 : }
1168 :
1169 92 : HcclResult hcclComm::SetGlobalWorkSpace(std::vector<void*>& globalWorkSpaceAddr)
1170 : {
1171 92 : CHK_RET(communicator_->SetGlobalWorkSpace(globalWorkSpaceAddr));
1172 :
1173 92 : return HCCL_SUCCESS;
1174 : }
1175 :
1176 0 : HcclResult hcclComm::SetAttachedStream(u32 graphId, const std::vector<rtStream_t>& streams)
1177 : {
1178 0 : CHK_RET(communicator_->SetAttachedStream(graphId, streams));
1179 0 : return HCCL_SUCCESS;
1180 : }
1181 :
1182 0 : HcclResult hcclComm::GetandClearOverFlowTasks(std::vector<HcclDumpInfo>& hcclDumpInfo)
1183 : {
1184 0 : CHK_RET(communicator_->GetandClearOverFlowTasks(hcclDumpInfo));
1185 :
1186 0 : return HCCL_SUCCESS;
1187 : }
1188 :
1189 0 : HcclResult hcclComm::SetCommDispatcherCtx()
1190 : {
1191 0 : DispatcherCtxPtr dispatherCtx = GetDispatcherCtx(identifier_.c_str());
1192 0 : CHK_PTR_NULL(dispatherCtx);
1193 0 : HCCL_INFO("[%s] dispatherCtx = [%p]", __func__, dispatherCtx);
1194 0 : CHK_RET(SetDispatcherCtx(dispatherCtx));
1195 0 : return HCCL_SUCCESS;
1196 : }
1197 :
1198 0 : HcclResult hcclComm::ReleaseCommDispatcherCtx() { return HCCL_SUCCESS; }
1199 :
1200 0 : HcclResult hcclComm::SupportDeterministicOptim(bool& isDeterministicOptim)
1201 : {
1202 0 : CHK_RET(communicator_->SupportDeterministicOptim(isDeterministicOptim));
1203 :
1204 0 : return HCCL_SUCCESS;
1205 : }
1206 :
1207 0 : HcclResult hcclComm::GetHccsLinkNum(u32& numHccsLink) { return communicator_->GetHccsLinkNum(numHccsLink); }
1208 :
1209 236 : HcclResult hcclComm::GetDeviceId(s32& deviceId)
1210 : {
1211 236 : CHK_SMART_PTR_NULL(communicator_);
1212 235 : CHK_RET(communicator_->GetDeviceId(deviceId));
1213 :
1214 235 : return HCCL_SUCCESS;
1215 : }
1216 :
1217 0 : HcclResult hcclComm::GetDevType(DevType& devType)
1218 : {
1219 0 : devType = deviceType_;
1220 0 : return HCCL_SUCCESS;
1221 : }
1222 :
1223 0 : HcclResult hcclComm::IsStandardCard(bool& isStandardCard)
1224 : {
1225 0 : isStandardCard = communicator_->IsStandardCard();
1226 :
1227 0 : return HCCL_SUCCESS;
1228 : }
1229 :
1230 0 : HcclResult hcclComm::Is310PDuoCard(bool& is310PDuoCard)
1231 : {
1232 0 : is310PDuoCard = communicator_->Is310PDuoCard();
1233 0 : return HCCL_SUCCESS;
1234 : }
1235 :
1236 235 : bool hcclComm::IsNeedResetDevice() const { return isResetDevice_; }
1237 :
1238 0 : HcclResult hcclComm::ResetDeviceEnable()
1239 : {
1240 0 : isResetDevice_ = true;
1241 0 : return HCCL_SUCCESS;
1242 : }
1243 :
1244 633 : HcclResult hcclComm::SaveTraceInfo(std::string& logInfo)
1245 : {
1246 633 : CHK_PRT(communicator_->SaveTraceInfo(logInfo));
1247 :
1248 633 : return HCCL_SUCCESS;
1249 : }
1250 :
1251 1 : bool hcclComm::GetCommResource(const std::string& tag, void** commContext)
1252 : {
1253 : /* 增加输出日志关键字 */
1254 1 : HCCL_INFO("HCCL_KEY_INFO: GetCommResource commContext[%p]", commContext);
1255 :
1256 1 : return (communicator_->GetCommResource(tag, commContext));
1257 : }
1258 :
1259 7 : bool hcclComm::GetCommResource(void*& commContext)
1260 : {
1261 7 : HCCL_INFO("HCCL_KEY_INFO: GetCommResource commContext[%p]", commContext);
1262 7 : return communicator_->GetCommResource(commContext);
1263 : }
1264 :
1265 236 : HcclResult hcclComm::SetStopFlag(bool value)
1266 : {
1267 236 : if (communicator_ != nullptr) {
1268 235 : return communicator_->SetStopFlag(value);
1269 : }
1270 1 : return HCCL_SUCCESS;
1271 : }
1272 :
1273 540 : HcclResult hcclComm::SetState(HcclCommState state)
1274 : {
1275 540 : if (communicator_ != nullptr) {
1276 540 : return communicator_->SetState(state);
1277 : }
1278 0 : return HCCL_SUCCESS;
1279 : }
1280 :
1281 506 : HcclCommState hcclComm::GetState()
1282 : {
1283 506 : if (communicator_ != nullptr) {
1284 505 : return communicator_->GetState();
1285 : }
1286 1 : return HcclCommState::IDLE;
1287 : }
1288 :
1289 1 : HcclResult hcclComm::AllocComResourceByTiling(const std::string& algConfig, void* param)
1290 : {
1291 1 : HCCL_INFO("HCCL_KEY_INFO: AllocComResourceByTiling algConfig[%s].", algConfig.c_str());
1292 1 : return communicator_->AllocComResourceByTiling(algConfig, param);
1293 : }
1294 :
1295 1 : HcclResult hcclComm::CreateCommResource(
1296 : const std::string& tag, rtStream_t aiCpuStream, bool isOpbaseMode, void** commContext, const std::string& algConfig)
1297 : {
1298 : /* 增加输出日志关键字 */
1299 1 : HCCL_INFO(
1300 : "HCCL_KEY_INFO: CreateCommResource commContext[%p], isOpbaseMode[%u], algConfig[%s].", commContext,
1301 : isOpbaseMode, algConfig.c_str());
1302 :
1303 1 : CHK_RET(communicator_->CreateCommResource(tag, aiCpuStream, isOpbaseMode, commContext, algConfig));
1304 :
1305 1 : return HCCL_SUCCESS;
1306 : }
1307 :
1308 0 : HcclResult hcclComm::GetAicpuOpStreamNotify(HcclRtStream* opStream, u8 aicpuNotifyNum, void** aicpuNotify)
1309 : {
1310 : /* 增加输出日志关键字 */
1311 0 : HCCL_INFO("HCCL_KEY_INFO: GetAicpuOpStreamNotify commContext[%p]", opStream);
1312 :
1313 0 : CHK_RET(communicator_->GetAicpuOpStreamNotify(opStream, aicpuNotifyNum, aicpuNotify));
1314 :
1315 0 : return HCCL_SUCCESS;
1316 : }
1317 :
1318 2 : HcclResult hcclComm::Mc2AiCpuStreamAllocAndGet(u32 streamMode, rtStream_t& aiCpuStream)
1319 : {
1320 : /* 增加输出日志关键字 */
1321 2 : HCCL_INFO("HCCL_KEY_INFO: Mc2AiCpuStreamAllocAndGet streamMode[%u]", streamMode);
1322 :
1323 2 : CHK_RET(communicator_->Mc2AiCpuStreamAllocAndGet(streamMode, aiCpuStream));
1324 2 : CHK_PTR_NULL(aiCpuStream);
1325 :
1326 2 : return HCCL_SUCCESS;
1327 : }
1328 :
1329 0 : HcclResult hcclComm::GetTopoDesc(HcclTopoDescs* topoDescs, uint32_t topoSize)
1330 : {
1331 0 : HCCL_INFO("HCCL_KEY_INFO: GetTopoDesc topoDescs[%p] topoSize[%u]", topoDescs, topoSize);
1332 :
1333 0 : CHK_RET(communicator_->GetTopoDesc(topoDescs, topoSize));
1334 :
1335 0 : return HCCL_SUCCESS;
1336 : }
1337 :
1338 0 : HcclResult hcclComm::GetCommUserMemSize(uint64_t& size)
1339 : {
1340 0 : HcclResult ret = communicator_->GetCommUserMemSize(size);
1341 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_INFO("[%s]call trace: hcclRet -> %d", __func__, ret), ret);
1342 0 : return HCCL_SUCCESS;
1343 : }
1344 235 : HcclResult hcclComm::SetDeterministicConfig(const u8 deterministic)
1345 : {
1346 235 : CHK_RET(communicator_->SetDeterministicConfig(deterministic));
1347 235 : return HCCL_SUCCESS;
1348 : }
1349 :
1350 235 : HcclResult hcclComm::SetAivModeConfig(const bool aivMode)
1351 : {
1352 235 : CHK_RET(communicator_->SetAivModeConfig(aivMode));
1353 235 : return HCCL_SUCCESS;
1354 : }
1355 :
1356 235 : HcclResult hcclComm::SetOnlyAivModeConfig(const bool isOnlyAiv)
1357 : {
1358 235 : CHK_RET(communicator_->SetOnlyAivModeConfig(isOnlyAiv));
1359 235 : return HCCL_SUCCESS;
1360 : }
1361 :
1362 0 : HcclResult hcclComm::GetOnlyAivModeConfig(bool& isOnlyAiv)
1363 : {
1364 0 : isOnlyAiv = communicator_->GetConfigIsOnlyAivMode();
1365 0 : return HCCL_SUCCESS;
1366 : }
1367 :
1368 235 : HcclResult hcclComm::SetAicpuUnfoldConfig(const bool aicpuUnfold)
1369 : {
1370 235 : CHK_RET(communicator_->SetAicpuUnfoldConfig(aicpuUnfold));
1371 235 : return HCCL_SUCCESS;
1372 : }
1373 :
1374 235 : HcclResult hcclComm::SetExecTimeOutConfig(const s32 execTimeOut)
1375 : {
1376 235 : CHK_RET(communicator_->SetExecTimeOutConfig(execTimeOut));
1377 235 : return HCCL_SUCCESS;
1378 : }
1379 :
1380 235 : HcclResult hcclComm::SetAlgoConfig(const std::map<HcclCMDType, std::vector<HcclAlgoType>>& algoMap)
1381 : {
1382 235 : CHK_RET(communicator_->SetAlgoConfig(algoMap));
1383 235 : return HCCL_SUCCESS;
1384 : }
1385 :
1386 0 : u64 hcclComm::GetConfigInCCLbufferSize() const { return inCCLbufferSize_; }
1387 :
1388 0 : u64 hcclComm::GetConfigOutCCLbufferSize() const { return outCCLbufferSize_; }
1389 :
1390 0 : u32 hcclComm::GetRankTableCrc() { return communicator_->GetRankTableCrc(); }
1391 :
1392 0 : u32 hcclComm::GetServerNum() { return communicator_->GetServerNum(); }
1393 :
1394 1 : u32 hcclComm::GetModuleNum() { return communicator_->GetModuleNum(); }
1395 :
1396 0 : u32 hcclComm::GetRealUserRank() const { return communicator_->GetRealUserRank(); }
1397 :
1398 1 : HcclResult hcclComm::GetCommParams(HcclCommParams& params)
1399 : {
1400 1 : CHK_RET(communicator_->GetCommParams(params));
1401 1 : params.deviceType = deviceType_;
1402 1 : params.isHeterogComm = isHeterogComm_;
1403 1 : params.identifier = identifier_;
1404 1 : return HCCL_SUCCESS;
1405 : }
1406 :
1407 1 : HcclResult hcclComm::GetCommRankTable(RankTable_t& rankTable)
1408 : {
1409 1 : CHK_RET(communicator_->GetCommRankTable(rankTable));
1410 1 : return HCCL_SUCCESS;
1411 : }
1412 :
1413 1 : HcclResult hcclComm::Suspend()
1414 : {
1415 1 : CHK_RET(communicator_->Suspend());
1416 1 : return HCCL_SUCCESS;
1417 : }
1418 :
1419 0 : HcclResult hcclComm::InitZeroCopyMemoryAgent()
1420 : {
1421 0 : CHK_SMART_PTR_NULL(communicator_);
1422 0 : CHK_RET(communicator_->InitZeroCopyMemoryAgent());
1423 0 : return HCCL_SUCCESS;
1424 : }
1425 :
1426 236 : HcclResult hcclComm::DeinitZeroCopyMemoryAgent()
1427 : {
1428 236 : CHK_SMART_PTR_NULL(communicator_);
1429 235 : CHK_RET(communicator_->DeinitZeroCopyMemoryAgent());
1430 235 : return HCCL_SUCCESS;
1431 : }
1432 :
1433 1 : HcclResult hcclComm::SetMemoryRange(void* baseVirPtr, size_t size, size_t alignment, uint64_t flags)
1434 : {
1435 1 : CHK_SMART_PTR_NULL(communicator_);
1436 1 : CHK_RET(communicator_->SetMemoryRange(baseVirPtr, size, alignment, flags));
1437 1 : return HCCL_SUCCESS;
1438 : }
1439 :
1440 1 : HcclResult hcclComm::UnsetMemoryRange(void* baseVirPtr)
1441 : {
1442 1 : CHK_SMART_PTR_NULL(communicator_);
1443 1 : CHK_RET(communicator_->UnsetMemoryRange(baseVirPtr));
1444 1 : return HCCL_SUCCESS;
1445 : }
1446 :
1447 1 : HcclResult hcclComm::ActivateCommMemory(void* virPtr, size_t size, size_t offset, void* handle, uint64_t flags)
1448 : {
1449 1 : CHK_SMART_PTR_NULL(communicator_);
1450 1 : CHK_RET(communicator_->ActivateCommMemory(virPtr, size, offset, handle, flags));
1451 1 : return HCCL_SUCCESS;
1452 : }
1453 :
1454 1 : HcclResult hcclComm::DeactivateCommMemory(void* virPtr)
1455 : {
1456 1 : CHK_SMART_PTR_NULL(communicator_);
1457 1 : CHK_RET(communicator_->DeactivateCommMemory(virPtr));
1458 1 : return HCCL_SUCCESS;
1459 : }
1460 :
1461 13 : HcclResult hcclComm::GetNumBlocks(u32& numBlocks) { return communicator_->GetNumBlocks(numBlocks); }
1462 :
1463 302 : HcclResult hcclComm::SetAivCoreLimit(u32 aivCoreLimit)
1464 : {
1465 302 : CHK_SMART_PTR_NULL(communicator_);
1466 302 : return communicator_->SetAivCoreLimit(aivCoreLimit);
1467 : }
1468 :
1469 1 : HcclResult hcclComm::SwitchNic(uint32_t nRanks, uint32_t* ranks, bool* useBackup)
1470 : {
1471 1 : CHK_SMART_PTR_NULL(communicator_);
1472 1 : CHK_RET(communicator_->SwitchNic(nRanks, ranks, useBackup));
1473 1 : return HCCL_SUCCESS;
1474 : }
1475 235 : HcclResult hcclComm::InitHccpChannel()
1476 : {
1477 : /* 增加输出日志关键字 */
1478 235 : HCCL_INFO("NslbDp try to init hccp ");
1479 235 : return communicator_->InitHccpChannel();
1480 : }
1481 :
1482 404 : std::vector<RankInfo> hcclComm::GetRankLists() { return communicator_->GetRankLists(); }
1483 :
1484 0 : HcclResult hcclComm::GetLocalCCLBuf(void** addr, uint64_t* size)
1485 : {
1486 0 : CHK_SMART_PTR_NULL(communicator_);
1487 0 : CHK_RET(communicator_->GetLocalCCLBuf(addr, size));
1488 0 : return HCCL_SUCCESS;
1489 : }
1490 :
1491 6 : HcclResult hcclComm::GetRemoteCCLBuf(uint32_t remoteRank, void** addr, uint64_t* size)
1492 : {
1493 6 : CHK_SMART_PTR_NULL(communicator_);
1494 6 : CHK_RET(communicator_->GetRemoteCCLBuf(remoteRank, addr, size));
1495 4 : return HCCL_SUCCESS;
1496 : }
1497 :
1498 0 : HcclResult hcclComm::SetGroupMode(bool isGroup)
1499 : {
1500 0 : isGroupMode_ = isGroup;
1501 0 : CHK_SMART_PTR_NULL(communicator_);
1502 0 : CHK_RET(communicator_->SetGroupMode(isGroup));
1503 0 : return HCCL_SUCCESS;
1504 : }
1505 :
1506 0 : bool hcclComm::GetGroupMode() const { return isGroupMode_; }
1507 :
1508 0 : HcclResult hcclComm::GetKFCWorkSpace(void** addr, uint64_t* size)
1509 : {
1510 0 : CHK_SMART_PTR_NULL(communicator_);
1511 0 : CHK_RET(communicator_->GetKFCWorkSpace(addr, size));
1512 0 : return HCCL_SUCCESS;
1513 : }
1514 :
1515 114 : bool hcclComm::IsCommunicatorV2()
1516 : {
1517 114 : if (devType_ == DevType::DEV_TYPE_950 || devType_ == DevType::DEV_TYPE_960) {
1518 92 : return true;
1519 : }
1520 22 : return false;
1521 : }
1522 :
1523 0 : HcclResult hcclComm::SetHcclQos(u32 hcclQos)
1524 : {
1525 : // 校验config中QoS的合法性
1526 0 : if (hcclQos == HCCL_COMM_QOS_CONFIG_NOT_SET) {
1527 0 : HCCL_INFO(
1528 : "[SetHcclQos]The QoS do not use the config configuration. "
1529 : "It will use environment variables to configure. QoS[%u]",
1530 : EnvConfig::HCCL_QOS_DEFAULT);
1531 0 : hcclQos_ = EnvConfig::HCCL_QOS_DEFAULT;
1532 0 : communicator_->SetHcclQos(EnvConfig::HCCL_QOS_DEFAULT);
1533 0 : return HCCL_SUCCESS;
1534 : }
1535 :
1536 : // 若设置的hcclQos不在有效范围内,则使用默认值
1537 0 : if (hcclQos > EnvConfig::HCCL_QOS_MAX) {
1538 0 : HCCL_INFO(
1539 : "[SetHcclQos]hcclQos is invalid, expect[%u, %u], actual[%u]. "
1540 : "It will use the default value. QoS[%u]",
1541 : EnvConfig::HCCL_QOS_MIN, EnvConfig::HCCL_QOS_MAX, hcclQos, EnvConfig::HCCL_QOS_DEFAULT);
1542 0 : hcclQos_ = EnvConfig::HCCL_QOS_DEFAULT;
1543 0 : communicator_->SetHcclQos(EnvConfig::HCCL_QOS_DEFAULT);
1544 0 : return HCCL_SUCCESS;
1545 : }
1546 :
1547 0 : HCCL_INFO("[SetHcclQos] hcclQos[%u]", hcclQos);
1548 0 : hcclQos_ = hcclQos;
1549 0 : communicator_->SetHcclQos(hcclQos);
1550 :
1551 0 : return HCCL_SUCCESS;
1552 : }
1553 :
1554 0 : u32 hcclComm::GetHcclQos() const { return hcclQos_; }
1555 :
1556 0 : HcclResult hcclComm::RegisterWindow(void* ptr, size_t size, HcclCommSymWindow* winHandle)
1557 : {
1558 0 : CHK_SMART_PTR_NULL(communicator_);
1559 0 : CHK_RET(communicator_->RegisterWindow(ptr, size, winHandle));
1560 0 : return HCCL_SUCCESS;
1561 : }
1562 :
1563 0 : HcclResult hcclComm::DeregisterWindow(HcclCommSymWindow winHandle)
1564 : {
1565 0 : CHK_SMART_PTR_NULL(communicator_);
1566 0 : CHK_RET(communicator_->DeregisterWindow(winHandle));
1567 0 : return HCCL_SUCCESS;
1568 : }
1569 :
1570 0 : HcclResult hcclComm::GetCommSymWin(void* ptr, size_t size, HcclCommSymWindow* winHandle, size_t* offset)
1571 : {
1572 0 : CHK_SMART_PTR_NULL(communicator_);
1573 0 : CHK_RET(communicator_->GetCommSymWin(ptr, size, winHandle, offset));
1574 0 : return HCCL_SUCCESS;
1575 : }
1576 :
1577 0 : aclrtBinHandle hcclComm::GetBinHandle() { return binHandle_; }
1578 :
1579 : } // namespace hccl
|