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 "comm_halving_doubling.h"
12 :
13 : namespace hccl {
14 0 : CommHalvingDoubling::CommHalvingDoubling(const std::string &collectiveId,
15 : const u32 userRank, const u32 userRankSize,
16 : const u32 rank, const u32 rankSize, const TopoType topoFlag,
17 : const HcclDispatcher dispatcher,
18 : const std::unique_ptr<NotifyPool> ¬ifyPool,
19 : std::map<HcclIpAddress, HcclNetDevCtx> &netDevCtxMap,
20 : const IntraExchanger &exchanger,
21 : const std::vector<RankInfo> paraVector,
22 : const DeviceMem& inputMem, const DeviceMem& outputMem,
23 : const bool isUsedRdmaLevel0,
24 : const std::string &tag, const NICDeployment nicDeployInner,
25 : const u32 subUserRankRoot, HalvingDoublingType halvingDoublingType,
26 0 : const bool isHaveCpuRank, const bool useSuperPodMode)
27 : : CommBase(collectiveId, userRank, userRankSize, rank, rankSize, paraVector, topoFlag,
28 : dispatcher, notifyPool, netDevCtxMap, exchanger, inputMem, outputMem, isUsedRdmaLevel0,
29 : tag, nicDeployInner, false, false, false,
30 : INVALID_UINT, isHaveCpuRank, useSuperPodMode),
31 0 : subUserRankRoot_(subUserRankRoot), halvingDoublingType_(halvingDoublingType)
32 : {
33 0 : }
34 :
35 0 : CommHalvingDoubling::~CommHalvingDoubling()
36 : {
37 0 : }
38 :
39 0 : HcclResult CommHalvingDoubling::CalcLink()
40 : {
41 0 : u32 subRoot = INVALID_VALUE_RANKID;
42 0 : HcclResult ret = HCCL_SUCCESS;
43 0 : if (subUserRankRoot_ != INVALID_VALUE_RANKID) {
44 0 : CHK_RET(GetRankByUserRank(subUserRankRoot_, subRoot));
45 : }
46 :
47 0 : std::vector<bool> linkRelation = AlgTemplateBase::CalcLinksRelation(rank_, rankSize_, subRoot,
48 0 : halvingDoublingType_);
49 0 : if (linkRelation.size() == 0) {
50 0 : HCCL_ERROR("[Calc][Link]comm halving doubling calculate link relation failed!");
51 0 : return HCCL_E_INTERNAL;
52 : }
53 :
54 0 : for (u32 dstRank = 0; dstRank < rankSize_; dstRank++) {
55 0 : if (!linkRelation[dstRank]) {
56 0 : HCCL_DEBUG("comm halving doubling rank[%u] don't need create link with dst_rank[%u]", rank_, dstRank);
57 0 : continue;
58 : }
59 :
60 0 : if (rank_ < dstRank) {
61 0 : ret = CalcLinksNum(MachineType::MACHINE_SERVER_TYPE, dstRank);
62 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
63 : HCCL_ERROR("[Calc][Link]comm halving doubling calc links num failed, type[%d], "\
64 : "dstRank[%u]", static_cast<int32_t>(MachineType::MACHINE_SERVER_TYPE), dstRank), ret);
65 : }
66 :
67 0 : if (rank_ > dstRank) {
68 0 : ret = CalcLinksNum(MachineType::MACHINE_CLIENT_TYPE, dstRank);
69 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
70 : HCCL_ERROR("[Calc][Link]comm halving doubling calc links num failed, type[%d], "\
71 : "dstRank[%u]", static_cast<int32_t>(MachineType::MACHINE_CLIENT_TYPE), dstRank), ret);
72 : }
73 : }
74 :
75 0 : return HCCL_SUCCESS;
76 0 : }
77 0 : bool CommHalvingDoubling::NeedDataReceivedAck()
78 : {
79 0 : HCCL_INFO("having-doubling need make a comm supporting DataReceivedAck");
80 0 : return true;
81 : }
82 : } // namespace hccl
|