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_HD_STAGE_PUB_H
12 : #define ALL_GATHER_HD_STAGE_PUB_H
13 :
14 : #include "alg_template_base_pub.h"
15 : #include "mem_host_pub.h"
16 : #include "mem_device_pub.h"
17 : #include "stream_pub.h"
18 : #include "alg_template_register.h"
19 :
20 : namespace hccl {
21 : class AllGatherHDStage : public AlgTemplateBase {
22 : public:
23 : explicit AllGatherHDStage(const HcclDispatcher dispatcher);
24 : ~AllGatherHDStage() override;
25 :
26 : HcclResult RunAsync(const u32 rank, const u32 rankSize, const std::vector<LINK>& links) override;
27 : HcclResult Prepare(PrepareData& param) override;
28 :
29 : protected:
30 : private:
31 : HcclResult MainRecordSub(u32 streamNum);
32 : HcclResult SubWaitMain(u32 streamNum);
33 : HcclResult MainWaitSub(u32 streamNum);
34 : HcclResult SubRecordMain(u32 streamNum);
35 : HcclResult ReverseId(u32 oriIdx, u32& revIdx);
36 : HcclResult PrepareSliceData(u32 subRank, u32 subRankSize, u32 size, u32 batchSize, std::vector<Slice>& slices);
37 : HcclResult RunPreCopy(u32 rank, u32 rankSize, const std::vector<LINK>& links);
38 : HcclResult RunAllGatherStage(u32 rank, u32 rankSize, const std::vector<LINK>& links);
39 : HcclResult RunAllGatherNoPower(u32 rank, u32 rankSize, const std::vector<LINK>& links);
40 : HcclResult RunBetweenStep(u32 rank, u32 neighCur, u32 neighNext, const std::vector<LINK>& links);
41 : HcclResult RunAllGatherPower(u32 rank, u32 rankSize, const std::vector<LINK>& links);
42 : HcclResult RunAllGatherLast(u32 rank, u32 rankSize, const std::vector<LINK>& links);
43 : HcclResult RunAllGatherLastOne(u32 rank, u32 rankSize, const std::vector<LINK>& links);
44 : HcclResult RunAllGatherLastTwo(u32 rank, u32 rankSize, const std::vector<LINK>& links);
45 0 : inline u32 BackwardRank(u32 rank, u32 rankSize, u32 step) const
46 : {
47 0 : if (rankSize == 0) {
48 0 : return 0;
49 : }
50 0 : return (rank + rankSize - step) % rankSize;
51 : }
52 : const u32 base = 2;
53 : u32 userRank_;
54 : std::vector<Stream> meshStreams_; /* * 多steam* */
55 : const std::vector<std::shared_ptr<LocalNotify>>* meshSignalPtr_; /* 每个ring创建一个signal */
56 : const std::vector<std::shared_ptr<LocalNotify>>* meshSignalAuxPtr_; /* 从stream wait,主steam record */
57 : const HcomCollOpInfo* opInfo_;
58 : std::vector<Slice> sliceNoPower_;
59 : std::vector<Slice> slicePower_;
60 : const std::vector<u32> resMap = {0, 2, 1, 3};
61 : u32 nSteps_ = 0;
62 : u32 powerSteps_ = 0;
63 : u32 finalSteps_ = 0;
64 : u32 noPower_ = 0;
65 : u32 totalSize_ = 0;
66 : };
67 : } // namespace hccl
68 : #endif /* ALL_GATHER_HD_STAGE_PUB_H */
|