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_mesh_transport_req.h"
12 :
13 :
14 : namespace hccl {
15 58 : CalcMeshTransportReq::CalcMeshTransportReq(std::vector<std::vector<u32>> &subCommPlaneVector,
16 58 : std::vector<bool> &isBridgeVector, u32 userRank)
17 58 : : CalcTransportReqBase(subCommPlaneVector, isBridgeVector, userRank)
18 : {
19 61 : }
20 :
21 122 : CalcMeshTransportReq::~CalcMeshTransportReq()
22 : {
23 122 : }
24 :
25 56 : HcclResult CalcMeshTransportReq::CalcTransportRequest(const std::string &tag, TransportMemType inputMemType,
26 : TransportMemType outputMemType, const CommParaInfo &commParaInfo,
27 : std::vector<SingleSubCommTransport> &commTransport, u32 subUserRankRoot)
28 : {
29 56 : u32 ringSize = subCommPlaneVector_.size();
30 : // 910B非确定性计算场景,server内MESH组网只需要创建一个commbase平面
31 56 : if (commParaInfo.meshSinglePlane == true) {
32 39 : ringSize = 1;
33 : }
34 56 : commTransport.resize(ringSize);
35 :
36 137 : for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
37 89 : if (commParaInfo.commPlane == COMM_LEVEL1 && !isBridgeVector_[ringIndex]) {
38 0 : continue; // 跳出本次循环
39 : }
40 :
41 89 : u32 rank = GetSubCollectiveRank(subCommPlaneVector_[ringIndex]);
42 83 : if (rank == INVALID_VALUE_RANKID) {
43 0 : continue;
44 : }
45 :
46 83 : u32 rankSize = subCommPlaneVector_[ringIndex].size();
47 83 : SingleSubCommTransport &subCommTransport = commTransport[ringIndex];
48 86 : subCommTransport.transportRequests.resize(rankSize);
49 : // 只有一张卡时不需要建链
50 86 : HCCL_DEBUG("[CalcMeshTransportReq]Calc for transportRequest");
51 93 : if (rankSize == HCCL_RANK_SIZE_EQ_ONE) {
52 13 : HCCL_INFO("comm base needn't to create links, rankSize_[%u].", rankSize);
53 13 : return HCCL_SUCCESS;
54 : }
55 :
56 396 : for (u32 rankIndex = 0; rankIndex < rankSize; rankIndex++) {
57 316 : TransportRequest &tmpTransport = subCommTransport.transportRequests[rankIndex];
58 310 : if (rankIndex != rank) {
59 231 : tmpTransport.isValid = true;
60 231 : tmpTransport.localUserRank = userRank_;
61 231 : tmpTransport.remoteUserRank = subCommPlaneVector_[ringIndex][rankIndex];
62 228 : tmpTransport.inputMemType = inputMemType;
63 228 : tmpTransport.outputMemType = outputMemType;
64 228 : HCCL_INFO("[CommFactory][CalcMeshCommInfo] 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 79 : tmpTransport.isValid = false;
69 : }
70 : }
71 : }
72 48 : return HCCL_SUCCESS;
73 : }
74 :
75 : } // namespace hccl
|