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_RING_PUB_H
12 : #define ALL_GATHER_RING_PUB_H
13 :
14 : #include "alg_template_base_pub.h"
15 :
16 : namespace hccl {
17 : class AllGatherRing : public AlgTemplateBase {
18 : public:
19 : explicit AllGatherRing(const HcclDispatcher dispatcher);
20 :
21 : ~AllGatherRing() override;
22 :
23 : HcclResult RunAsync(const u32 rank, const u32 rankSize, const std::vector<LINK> &links) override;
24 : HcclResult GetNslbAdjInfo(const u32 rank, const u32 rankSize,
25 : const std::vector<LINK> &links, AdjInfo& nslbAdjInfo) override;
26 : protected:
27 : private:
28 : // 获取向该rank往前的第i个rank
29 0 : inline u32 ForwordRank(u32 rank, u32 rankSize, u32 preNum) const
30 : {
31 0 : return (rank + rankSize - preNum) % rankSize;
32 : }
33 : HcclResult RunAllGather(u32 rank, u32 rankSize, const std::vector<Slice> &outputSlices);
34 :
35 : HcclResult TxVector(const LINK &link, const std::vector<Slice> &txSlices);
36 : HcclResult RxVector(const LINK &link, const std::vector<Slice> &rxSlices);
37 : HcclResult Tx(const LINK &link, const Slice &txSlice);
38 : HcclResult Rx(const LINK &link, const Slice &rxSlice);
39 :
40 : // allgather ring chunk实现相关函数
41 : HcclResult RunAllGatherChunk(const u32 rank, const u32 rankSize, const std::vector<Slice> &outputSlices);
42 : HcclResult HeadAllGatherChunk(u32 rank, u32 rankSize, const std::vector<Slice> &outputSlices);
43 : HcclResult MidAllGatherChunk(u32 rank, u32 rankSize, u32 sliceIdx, const std::vector<Slice> &outputSlices);
44 : HcclResult TailAllGatherChunk(u32 rank, u32 rankSize, u32 sliceIdx, const std::vector<Slice> &outputSlices);
45 : HcclResult AllGatherSlicesPrep(u32 rankSize, u32 nicSize);
46 :
47 : // 迭代6新增加
48 : std::shared_ptr<Transport> linkLeft_;
49 : std::shared_ptr<Transport> linkRight_;
50 : };
51 : } // namespace hccl
52 :
53 : #endif /* ALL_GATHER_RING_PUB_H */
|