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