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