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
25 : GetNslbAdjInfo(const u32 rank, const u32 rankSize, const std::vector<LINK>& links, AdjInfo& nslbAdjInfo) override;
26 :
27 : protected:
28 : private:
29 : // 获取向该rank往前的第i个rank
30 0 : inline u32 ForwordRank(u32 rank, u32 rankSize, u32 preNum) const { return (rank + rankSize - preNum) % rankSize; }
31 : HcclResult RunAllGather(u32 rank, u32 rankSize, const std::vector<Slice>& outputSlices);
32 :
33 : HcclResult TxVector(const LINK& link, const std::vector<Slice>& txSlices);
34 : HcclResult RxVector(const LINK& link, const std::vector<Slice>& rxSlices);
35 : HcclResult Tx(const LINK& link, const Slice& txSlice);
36 : HcclResult Rx(const LINK& link, const Slice& rxSlice);
37 :
38 : // allgather ring chunk实现相关函数
39 : HcclResult RunAllGatherChunk(const u32 rank, const u32 rankSize, const std::vector<Slice>& outputSlices);
40 : HcclResult HeadAllGatherChunk(u32 rank, u32 rankSize, const std::vector<Slice>& outputSlices);
41 : HcclResult MidAllGatherChunk(u32 rank, u32 rankSize, u32 sliceIdx, const std::vector<Slice>& outputSlices);
42 : HcclResult TailAllGatherChunk(u32 rank, u32 rankSize, u32 sliceIdx, const std::vector<Slice>& outputSlices);
43 : HcclResult AllGatherSlicesPrep(u32 rankSize, u32 nicSize);
44 :
45 : // 迭代6新增加
46 : std::shared_ptr<Transport> linkLeft_;
47 : std::shared_ptr<Transport> linkRight_;
48 : };
49 : } // namespace hccl
50 :
51 : #endif /* ALL_GATHER_RING_PUB_H */
|