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 "calc_ahc_transport_req_base.h"
12 :
13 : namespace hccl {
14 0 : CalcAHCTransportReqBase::CalcAHCTransportReqBase(std::vector<std::vector<u32>> &subCommPlaneVector,
15 : std::vector<bool> &isBridgeVector, u32 userRank, std::vector<std::vector<std::vector<u32>>> &globalSubGroups,
16 0 : std::map<AHCConcOpType, TemplateType> &ahcAlgOption, std::unordered_map<u32, bool> &isUsedRdmaMap)
17 : : CalcTransportReqBase(subCommPlaneVector, isBridgeVector, userRank),
18 0 : globalSubGroups_(globalSubGroups), ahcAlgOption_(ahcAlgOption),
19 0 : isUsedRdmaMap_(isUsedRdmaMap)
20 : {
21 0 : }
22 :
23 0 : CalcAHCTransportReqBase::~CalcAHCTransportReqBase()
24 : {
25 0 : }
26 :
27 0 : HcclResult CalcAHCTransportReqBase::DisposeSubGroups(u32 rank)
28 : {
29 : (void)rank;
30 0 : return HCCL_SUCCESS;
31 : }
32 :
33 0 : HcclResult CalcAHCTransportReqBase::CalcDstRanks(u32 rank, std::set<u32> &dstRanks, u32 ringIndex)
34 : {
35 : (void)rank;
36 : (void)dstRanks;
37 : (void)ringIndex;
38 0 : return HCCL_SUCCESS;
39 : }
40 :
41 0 : HcclResult CalcAHCTransportReqBase::CommAHCInfoInit(std::vector<std::vector<u32>> &subGroups)
42 : {
43 : (void) subGroups;
44 0 : return HCCL_SUCCESS;
45 : }
46 :
47 0 : HcclResult CalcAHCTransportReqBase::CalcTransportRequest(const std::string &tag, TransportMemType inputMemType,
48 : TransportMemType outputMemType, const CommParaInfo &commParaInfo,
49 : std::vector<SingleSubCommTransport> &commTransport, u32 subUserRankRoot)
50 : {
51 : (void)subUserRankRoot;
52 0 : u32 ringSize = subCommPlaneVector_.size();
53 0 : commTransport.resize(ringSize);
54 0 : if (tag.find("AllReduce", 0) != std::string::npos) {
55 0 : opType_ = AHCOpType::AHC_OP_TYPE_ALLREDUCE;
56 0 : } else if(tag.find("ReduceScatter", 0) != std::string::npos) {
57 0 : opType_ = AHCOpType::AHC_OP_TYPE_REDUCE_SCATTER;
58 0 : } else if (tag.find("AllGather", 0) != std::string::npos) {
59 0 : opType_ = AHCOpType::AHC_OP_TYPE_ALLGATHER;
60 : }
61 :
62 0 : for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
63 0 : if (commParaInfo.commPlane == COMM_LEVEL1_AHC && !isBridgeVector_[ringIndex]) {
64 0 : continue; // 跳出本次循环
65 : }
66 :
67 0 : u32 rank = GetSubCollectiveRank(subCommPlaneVector_[ringIndex]);
68 0 : if (rank == INVALID_VALUE_RANKID) {
69 0 : continue;
70 : }
71 :
72 0 : u32 rankSize = subCommPlaneVector_[ringIndex].size();
73 0 : SingleSubCommTransport &subCommTransport = commTransport[ringIndex];
74 0 : subCommTransport.transportRequests.resize(rankSize);
75 : // 只有一张卡时不需要建链
76 0 : if (rankSize == HCCL_RANK_SIZE_EQ_ONE) {
77 0 : HCCL_INFO("[CalcAHCTransportReqBase] comm base needn't to create links, rankSize_[%u].", rankSize);
78 0 : return HCCL_SUCCESS;
79 : }
80 :
81 0 : std::set<u32> dstRanks;
82 0 : CHK_RET(CalcDstRanks(rank, dstRanks, ringIndex));
83 :
84 : // 建链
85 0 : for (u32 dstRank : dstRanks) {
86 0 : CHK_PRT_RET(dstRank >= rankSize,
87 : HCCL_ERROR("[CalcAHCTransportReqBase][CalcTransportRequest] dstRank [%u] exceed rankSize [%u] error",
88 : dstRank, rankSize ), HCCL_E_INTERNAL);
89 :
90 0 : if (dstRank != rank) {
91 0 : TransportRequest &tmpTransport = subCommTransport.transportRequests[dstRank];
92 0 : tmpTransport.isValid = true;
93 0 : tmpTransport.localUserRank = userRank_;
94 0 : tmpTransport.remoteUserRank = subCommPlaneVector_[ringIndex][dstRank];
95 0 : tmpTransport.inputMemType = inputMemType;
96 0 : tmpTransport.outputMemType = outputMemType;
97 0 : HCCL_INFO("[CalcAHCTransportReqBase] param_.tag[%s] ringIndex[%u], localRank[%u], " \
98 : "remoteRank[%u], inputMemType[%d], outputMemType[%d]", tag.c_str(), ringIndex, userRank_,
99 : tmpTransport.remoteUserRank, inputMemType, outputMemType);
100 : }
101 : }
102 :
103 : //刷新RDMA建链标记
104 0 : RefreshTransportIsUsedRdma(rank, ringIndex, commTransport);
105 0 : }
106 0 : return HCCL_SUCCESS;
107 : }
108 :
109 0 : void CalcAHCTransportReqBase::RefreshTransportIsUsedRdma(u32 rank, u32 ringIndex, std::vector<SingleSubCommTransport> &commTransport)
110 : {
111 : //组内和组间通信域计算
112 0 : std::vector<u32> intraCommGroup;
113 0 : std::vector<std::vector<u32>> interCommGroupList;
114 :
115 0 : commAHCBaseInfo_->GetIntraCommGroup(rank, intraCommGroup);
116 0 : commAHCBaseInfo_->GetInterCommGroupList(rank, interCommGroupList);
117 :
118 0 : SingleSubCommTransport &subCommTransport = commTransport[ringIndex];
119 :
120 : //组内子通信域粒度刷新
121 0 : bool isUsedRdma = false;
122 0 : for (u32 i = 0; i < intraCommGroup.size(); i++) {
123 0 : u32 dstRank = intraCommGroup[i];
124 0 : HCCL_DEBUG("[CalcAHCTransportReqBase][RefreshTransportIsUsedRdma] intraCommGroup localRank[%u], dstRank [%u] ", rank, dstRank);
125 0 : if (isUsedRdmaMap_[subCommPlaneVector_[ringIndex][dstRank]]) {
126 0 : isUsedRdma = true;
127 0 : HCCL_DEBUG("[CalcAHCTransportReqBase][RefreshTransportIsUsedRdma] intraCommGroup userrank[%u] rdma map is true", subCommPlaneVector_[ringIndex][dstRank]);
128 0 : break;
129 : }
130 : }
131 0 : for (u32 i = 0; i < intraCommGroup.size(); i++) {
132 0 : u32 dstRank = intraCommGroup[i];
133 0 : TransportRequest &tmpTransport = subCommTransport.transportRequests[dstRank];
134 0 : tmpTransport.isUsedRdma = isUsedRdma;
135 : }
136 :
137 : //组间子通信域粒度刷新
138 0 : for (u32 i = 0; i < interCommGroupList.size(); i++) {
139 0 : isUsedRdma = false;
140 0 : for (u32 j = 0; j < interCommGroupList[i].size(); j++) {
141 0 : u32 dstRank = interCommGroupList[i][j];
142 0 : HCCL_DEBUG("[CalcAHCTransportReqBase][RefreshTransportIsUsedRdma] interCommGroupList index[%u] localRank[%u], dstRank [%u] ", i, rank, dstRank);
143 0 : if (isUsedRdmaMap_[subCommPlaneVector_[ringIndex][dstRank]]) {
144 0 : isUsedRdma = true;
145 0 : HCCL_DEBUG("[CalcAHCTransportReqBase][RefreshTransportIsUsedRdma] interCommGroupList userrank[%u] rdma map is true", subCommPlaneVector_[ringIndex][dstRank]);
146 0 : break;
147 : }
148 : }
149 0 : for (u32 j = 0; j < interCommGroupList[i].size(); j++) {
150 0 : u32 dstRank = interCommGroupList[i][j];
151 0 : TransportRequest &tmpTransport = subCommTransport.transportRequests[dstRank];
152 0 : tmpTransport.isUsedRdma = isUsedRdma;
153 : }
154 : }
155 0 : }
156 : } // namespace hccl
|