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