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