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 ALL_GATHER_MESH_MIX_PUB_H
12 : #define ALL_GATHER_MESH_MIX_PUB_H
13 :
14 : #include "alg_template_base_pub.h"
15 :
16 : namespace hccl {
17 : class AllgatherMeshMix : public AlgTemplateBase {
18 : public:
19 : explicit AllgatherMeshMix(const HcclDispatcher dispatcher);
20 :
21 : ~AllgatherMeshMix() override;
22 :
23 : // should be called soon after template AllGatherMeshMix instance created
24 : HcclResult Prepare(std::vector<Stream> &meshStreams, std::vector<std::shared_ptr<LocalNotify>> &meshSignal,
25 : std::vector<std::shared_ptr<LocalNotify>> &meshSignalAux, u32 userRank = INVALID_VALUE_RANKID,
26 : HcomCollOpInfo *opInfo = nullptr, u32 interRank = INVALID_VALUE_RANKID, u32 interRankSize = 0) override;
27 :
28 : HcclResult RunAsync(const u32 rank, const u32 rankSize, const std::vector<LINK> &links) override;
29 :
30 : protected:
31 : // 获取向该rank往前的第i个rank
32 0 : inline u32 BackwardRank(u32 rank, u32 rankSize, u32 step) const
33 : {
34 0 : if (rankSize == 0) {
35 0 : return 0;
36 : }
37 0 : return (rank + rankSize - step) % rankSize;
38 : }
39 :
40 : inline u32 ForwardRank(u32 rank, u32 rankSize, u32 step) const
41 : {
42 : if (rankSize == 0) {
43 : return 0;
44 : }
45 : return (rank + step) % rankSize;
46 : }
47 : std::vector<Stream> meshStreams_; /** 多steam**/
48 :
49 : std::vector<std::shared_ptr<LocalNotify>> *meshSignal_{nullptr}; /* 每个ring创建一个signal */
50 : std::vector<std::shared_ptr<LocalNotify>> *meshSignalAux_{nullptr}; /* 从stream wait,主steam record */
51 : u32 interRank_; // 在所有rank环上的rankid
52 : u32 interRankSize_;
53 : HcomCollOpInfo *opInfo_{nullptr};
54 :
55 : private:
56 : HcclResult MainRecordSub();
57 : HcclResult SubWaitMain();
58 : HcclResult MainWaitSub();
59 : HcclResult SubRecordMain();
60 : };
61 : } // namespace hccl
62 :
63 : #endif /* ALL_GATHER_MESH_PUB_H */
|