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 "comm_mesh.h"
12 :
13 : namespace hccl {
14 4 : CommMesh::CommMesh(
15 : const std::string& collectiveId, const u32 userRank, const u32 userRankSize, const u32 rank, const u32 rankSize,
16 : const TopoType topoFlag, const HcclDispatcher dispatcher, const std::unique_ptr<NotifyPool>& notifyPool,
17 : std::map<HcclIpAddress, HcclNetDevCtx>& netDevCtxMap, const IntraExchanger& exchanger,
18 : const std::vector<RankInfo> paraVector, const DeviceMem& inputMem, const DeviceMem& outputMem,
19 : const bool isUsedRdmaLevel0, const std::string& tag, bool isAlltoAllCommMesh, const NICDeployment nicDeployInner,
20 : const bool useOneDoorbell, const bool isAicpuModeEn, const bool isHaveCpuRank, const bool useSuperPodMode,
21 4 : DeviceMem expMem)
22 : : CommBase(
23 : collectiveId, userRank, userRankSize, rank, rankSize, paraVector, topoFlag, dispatcher, notifyPool,
24 : netDevCtxMap, exchanger, inputMem, outputMem, isUsedRdmaLevel0, tag, nicDeployInner, isAlltoAllCommMesh,
25 4 : useOneDoorbell, isAicpuModeEn, INVALID_UINT, isHaveCpuRank, useSuperPodMode, expMem)
26 4 : {}
27 :
28 8 : CommMesh::~CommMesh() {}
29 :
30 0 : HcclResult CommMesh::CalcLink()
31 : {
32 : // 原则:创建本rank与rank+n时的link,本rank为server端;创建本rank与rank-n时的link,本rank为client端;
33 0 : u32 dstClientRank = INVALID_VALUE_RANKID;
34 0 : u32 dstServerRank = INVALID_VALUE_RANKID;
35 :
36 0 : u32 backwardDst = rankSize_ - rank_ - HCCL_RANK_OFFSET;
37 :
38 0 : HcclResult ret = HCCL_SUCCESS;
39 : // 先创建dst_rank < rank_
40 0 : for (u32 clientIndex = 0; clientIndex < rank_; clientIndex++) {
41 : // rank 作为client
42 0 : dstServerRank = rank_ - clientIndex - HCCL_RANK_OFFSET;
43 0 : ret = CalcLinksNum(MachineType::MACHINE_CLIENT_TYPE, dstServerRank);
44 0 : CHK_PRT_RET(
45 : ret != HCCL_SUCCESS,
46 : HCCL_ERROR(
47 : "[Calc][Link]comm mesh calc links num failed, type[%d], dstServerRank[%u]",
48 : static_cast<int32_t>(MachineType::MACHINE_CLIENT_TYPE), dstServerRank),
49 : ret);
50 : }
51 :
52 : // 再创建dst_rank > rank_
53 0 : for (u32 serverIndex = 0; serverIndex < backwardDst; serverIndex++) {
54 : // rank 作为server
55 0 : dstClientRank = rank_ + serverIndex + HCCL_RANK_OFFSET;
56 0 : ret = CalcLinksNum(MachineType::MACHINE_SERVER_TYPE, dstClientRank);
57 0 : CHK_PRT_RET(
58 : ret != HCCL_SUCCESS,
59 : HCCL_ERROR(
60 : "[Calc][Link]comm mesh calc links num failed, type[%d], dstClientRank[%u]",
61 : static_cast<int32_t>(MachineType::MACHINE_SERVER_TYPE), dstClientRank),
62 : ret);
63 : }
64 :
65 0 : return HCCL_SUCCESS;
66 : }
67 : } // namespace hccl
|