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