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 NONUNIFORM_HIERARCHICAL_RING_BASE_PUB_H
12 : #define NONUNIFORM_HIERARCHICAL_RING_BASE_PUB_H
13 :
14 : #include <cmath>
15 : #include "alg_template_base_pub.h"
16 :
17 : namespace hccl {
18 :
19 : using InterServerAlgoStep = struct InterServerAlgoStepDef {
20 : u32 step = 0;
21 : u32 myRank = 0;
22 :
23 : u32 nSlices;
24 : u32 toRank = 0;
25 : u32 fromRank = 0;
26 : std::vector<u32> txSliceIdxs;
27 : std::vector<u32> rxSliceIdxs;
28 :
29 18 : InterServerAlgoStepDef() : nSlices(0)
30 : {
31 18 : }
32 : };
33 :
34 : class NHRBase : public AlgTemplateBase {
35 : public:
36 : explicit NHRBase(const HcclDispatcher dispatcher);
37 : ~NHRBase() override;
38 :
39 : void GetRankMapping(const u32 rankSize, bool keepOrder = false);
40 :
41 : void FetchRankMapping(std::vector<u32> &sliceMap);
42 :
43 : void MergeSlices(std::vector<Slice> &slices);
44 :
45 : protected:
46 : void ReorderSequence(u32 start, u32 end, u32 len, std::vector<u32> &tree, std::vector<u32> &tmp);
47 :
48 : u32 GetStepNumInterServer(u32 rankSize);
49 :
50 : virtual HcclResult GetStepInfo(u32 step, u32 nSteps, u32 rank, u32 rankSize, InterServerAlgoStep &stepInfo);
51 :
52 : HcclResult ExecuteBarrier(const std::shared_ptr<Transport> &preLink, const std::shared_ptr<Transport> &aftLink);
53 :
54 : std::vector<u32> sliceMap_;
55 :
56 : bool isNeedMerge = false;
57 :
58 : private:
59 : };
60 : } // hccl
61 :
62 : #endif /* NONUNIFORM_HIERARCHICAL_RING_BASE_PUB_H */
|