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 : #ifndef HCCLV2_TOPO_MATCH_CONCURR_MESH_NHR
12 : #define HCCLV2_TOPO_MATCH_CONCURR_MESH_NHR
13 :
14 : #include "topo_match_base.h"
15 :
16 : namespace Hccl {
17 :
18 : class TopoMatchConcurrMeshNHR : public TopoMatchBase {
19 : public:
20 : explicit TopoMatchConcurrMeshNHR(
21 : const RankId vRank, const u32 rankSize, const RankGraph* rankGraph, const DevType devType);
22 : ~TopoMatchConcurrMeshNHR() override;
23 :
24 0 : std::string Describe() const override
25 : {
26 0 : return "Topo Match for Multi-dimensional Concurrent Mesh Algorithm (CURRENTLY only 2-D Concurr Mesh is "
27 0 : "supported).";
28 : }
29 : using TopoMatchBase::MatchTopo;
30 : HcclResult MatchTopo(
31 : std::vector<std::vector<std::vector<RankId>>>& vTopo, std::vector<std::vector<RankId>>& virtRanks,
32 : std::vector<std::map<RankId, u32>>& virtRankMap) override;
33 :
34 : private:
35 : std::vector<RankId> rankOnSameBoard_; // ranks with same boardIds in rack
36 : std::vector<RankId> rankOnSameSlot_; // ranks with same slotIds in rack
37 : std::vector<std::vector<RankId>> rankOnSameBoardVector_; // ranks vector with same boardIds in rack
38 : std::vector<std::vector<RankId>> rankOnSameSlotVector_; // ranks vector with same slotIds in rack
39 : std::vector<u32> numRanksPerBoard_; // ranks num with same boardIds in rack
40 :
41 : HcclResult GenerateLevel0(
42 : const std::set<RankId>& rankSetLevel0, u32 gcdInstSize, RankId rankId,
43 : std::vector<std::vector<std::vector<RankId>>>& vTopo, std::vector<std::vector<RankId>>& virtRanks);
44 :
45 : // 当 level0 子通信域为矩形时, 计算 myRank 所在 level0 子通信域的具体信息
46 : HcclResult FindLevel0Block(
47 : const Matrix<RankId>& podTopo, u32 subDim0Size, u32 subDim1Size, u32 myRank, std::vector<RankId>& subRankList,
48 : Matrix<RankId>& subRankTopo) const;
49 :
50 : // FindLevel0Bloc 的辅助函数
51 : HcclResult FindMyRankLocation(const Matrix<RankId>& podTopo, u32 myRank, u32& row, u32& col) const;
52 : HcclResult ExtractLevel0Block(
53 : const Matrix<RankId>& podTopo, u32 startRow, u32 startCol, u32 targetRow, u32 targetCol, u32 subDim0Size,
54 : u32 subDim1Size, std::vector<RankId>& subRankList, Matrix<RankId>& subRankTopo) const;
55 :
56 : // 对称判断依据: instSizeList 中每个元素相等
57 : bool CheckSymmetric(std::vector<u32>& values) const;
58 : };
59 : } // namespace Hccl
60 :
61 : #endif // !HCCLV2_TOPO_MATCH_CONCURR_MESH_NHR
|