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_REDUCE_MESH_OPBASE_PUB_H
12 : #define ALL_REDUCE_MESH_OPBASE_PUB_H
13 :
14 : #include "alg_template_base_pub.h"
15 :
16 : namespace hccl {
17 : class AllReduceMeshDirect : public AlgTemplateBase {
18 : public:
19 : using AlgTemplateBase::Prepare;
20 : explicit AllReduceMeshDirect(const HcclDispatcher dispatcher);
21 : ~ AllReduceMeshDirect() override;
22 :
23 : // 新增的两段式构造函数,获取实例后要无脑调用实现构造函数功能,后续还要调用其它的基类Prepare函数实现其它成员变量初始化
24 : HcclResult Prepare(u64 reduceAttrBitMap, std::vector<Stream> &meshStreams,
25 : std::vector<std::shared_ptr<LocalNotify>> &meshSignal, std::vector<std::shared_ptr<LocalNotify>> &meshSignalAux,
26 : u32 interRank, u32 interRankSize, u32 userRank, HcomCollOpInfo *opInfo) override;
27 :
28 : HcclResult RunAsync(const u32 rank, const u32 rankSize, const std::vector<LINK> &links) override;
29 :
30 : protected:
31 : private:
32 : HcclResult MainRecordSub();
33 : HcclResult SubWaitMain();
34 : HcclResult MainWaitSub();
35 : HcclResult SubRecordMain();
36 : HcclResult PrepareSlice(u64 dataCount, u32 unitSize, u32 sliceNum, std::vector<Slice>& dataSlice);
37 : HcclResult PrepareAllreduceSliceData();
38 : HcclResult RunReduceScatter(u32 rank, u32 rankSize, const std::vector<LINK> &links);
39 : HcclResult RunAllGather(u32 rank, u32 rankSize, const std::vector<LINK> &links);
40 0 : inline u32 BackwardRank(u32 rank, u32 rankSize, u32 step) const
41 : {
42 0 : if (rankSize == 0) {
43 0 : return 0;
44 : }
45 0 : return (rank + rankSize - step) % rankSize;
46 : }
47 : u64 reduceAttr_;
48 : u32 localRank_;
49 : u32 localRankSize_;
50 : u32 userRank_;
51 : std::vector<Stream> meshStreams_; /* * 多steam* */
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 : HcomCollOpInfo *opInfo_{nullptr};
55 : };
56 : } // namespace hccl
57 : #endif /* ALL_REDUCE_MESH_OPBASE_H */
|