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_ring_transport_req.h"
12 : #include "calc_ahc_template_register.h"
13 :
14 : constexpr u32 HCCL_RANK_OFFSET = 1;
15 :
16 : namespace hccl {
17 62 : CalcRingTransportReq::CalcRingTransportReq(std::vector<std::vector<u32>> &subCommPlaneVector,
18 62 : std::vector<bool> &isBridgeVector, u32 userRank)
19 62 : : CalcTransportReqBase(subCommPlaneVector, isBridgeVector, userRank)
20 : {
21 62 : }
22 :
23 124 : CalcRingTransportReq::~CalcRingTransportReq()
24 : {
25 124 : }
26 :
27 61 : HcclResult CalcRingTransportReq::CalcTransportRequest(const std::string &tag, TransportMemType inputMemType,
28 : TransportMemType outputMemType, const CommParaInfo &commParaInfo,
29 : std::vector<SingleSubCommTransport> &commTransport, u32 subUserRankRoot)
30 : {
31 61 : u32 ringSize = subCommPlaneVector_.size();
32 61 : commTransport.resize(ringSize);
33 :
34 122 : for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
35 55 : if ((commParaInfo.commPlane == COMM_LEVEL1 || commParaInfo.commPlane == COMM_LEVEL1_ANYPATH_SDMA ||
36 158 : commParaInfo.commPlane == COMM_LEVEL1_ANYPATH_RDMA)&&
37 22 : !isBridgeVector_[ringIndex]) {
38 13 : continue; // 跳出本次循环
39 : }
40 :
41 68 : u32 rank = GetSubCollectiveRank(subCommPlaneVector_[ringIndex]);
42 68 : if (rank == INVALID_VALUE_RANKID) {
43 0 : continue;
44 : }
45 :
46 68 : u32 rankSize = subCommPlaneVector_[ringIndex].size();
47 68 : SingleSubCommTransport &subCommTransport = commTransport[ringIndex];
48 68 : subCommTransport.transportRequests.resize(rankSize);
49 : // 只有一张卡时不需要建链
50 68 : if (rankSize == HCCL_RANK_SIZE_EQ_ONE) {
51 18 : HCCL_INFO("comm base needn't to create links, rankSize_[%u].", rankSize);
52 18 : return HCCL_SUCCESS;
53 : }
54 :
55 238 : for (u32 rankIndex = 0; rankIndex < rankSize; rankIndex++) {
56 188 : TransportRequest &tmpTransport = subCommTransport.transportRequests[rankIndex];
57 188 : if (rankIndex == (rank + rankSize + HCCL_RANK_OFFSET) % rankSize ||
58 138 : rankIndex == (rank + rankSize - HCCL_RANK_OFFSET) % rankSize) {
59 74 : tmpTransport.isValid = true;
60 74 : tmpTransport.localUserRank = userRank_;
61 74 : tmpTransport.remoteUserRank = subCommPlaneVector_[ringIndex][rankIndex];
62 74 : tmpTransport.inputMemType = inputMemType;
63 74 : tmpTransport.outputMemType = outputMemType;
64 74 : HCCL_INFO("[CommFactory][CalcRingCommInfo] param_.tag[%s] ringIndex[%u], localRank[%u], "\
65 : "remoteRank[%u], inputMemType[%d], outputMemType[%d]", tag.c_str(), ringIndex, userRank_,
66 : tmpTransport.remoteUserRank, inputMemType, outputMemType);
67 : } else {
68 114 : tmpTransport.isValid = false;
69 : }
70 : }
71 50 : const u32 rdmaTaskNumRatio = 4;
72 50 : if (GetWorkflowMode() != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
73 26 : subCommTransport.taskNum = rankSize * rdmaTaskNumRatio;
74 : }
75 : }
76 :
77 44 : return HCCL_SUCCESS;
78 : }
79 :
80 0 : HcclResult CalcRingTransportReq::CalcDstRanks(const u32 rank, const std::vector<u32> commGroups, std::set<u32> &dstRanks)
81 : {
82 0 : CHK_PRT_RET(rank >= commGroups.size(),
83 : HCCL_ERROR("[CalcRingTransportReq][CalcDstRanks] rank [%u] exceed commGroups Size [%u] error",
84 : rank, commGroups.size() ), HCCL_E_INTERNAL);
85 :
86 : // 正方向下一个节点的rank号
87 0 : const u32 targetRankPos = static_cast<u32>(rank + 1) % commGroups.size();
88 0 : dstRanks.insert(commGroups[targetRankPos]);
89 :
90 : // 反方向下一个节点的rank号
91 0 : const u32 targetRankNeg = static_cast<u32>(rank + commGroups.size() - 1) % commGroups.size();
92 :
93 0 : HCCL_DEBUG("[CalcRingTransportReq][CalcDstRanks] local rank[%u], remote rank[%u]", commGroups[rank], commGroups[targetRankNeg]);
94 :
95 0 : dstRanks.insert(commGroups[targetRankNeg]);
96 :
97 0 : return HCCL_SUCCESS;
98 : }
99 : REGISTER_AHC_COMM_CALC_FUNC(AHCTemplateType::AHC_TEMPLATE_RING, CalcRingTransportReq, CalcRingTransportReq::CalcDstRanks);
100 : } // namespace hccl
|