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 REDUCE_SCATTER_MESH_PUB_H
12 : #define REDUCE_SCATTER_MESH_PUB_H
13 :
14 : #include "alg_template_base_pub.h"
15 : #include "reducer_pub.h"
16 : #include "sender_pub.h"
17 :
18 : namespace hccl {
19 : class ReduceScatterMesh : public AlgTemplateBase {
20 : public:
21 : explicit ReduceScatterMesh(const HcclDispatcher dispatcher);
22 :
23 : ~ReduceScatterMesh() override;
24 :
25 : HcclResult Prepare(u64 reduceAttrBitMap, u32 streamIndex) override;
26 : HcclResult
27 : RunAsync(const u32 rank, const u32 rankSize, const std::vector<std::shared_ptr<Transport>>& links) override;
28 :
29 : protected:
30 : private:
31 0 : inline u32 ForwardRank(u32 rank, u32 rankSize, u32 step) const
32 : {
33 0 : if (rankSize == 0) {
34 0 : return 0;
35 : }
36 0 : return (rank + rankSize - step) % rankSize;
37 : }
38 0 : inline u32 BackwardRank(u32 rank, u32 rankSize, u32 step) const
39 : {
40 0 : if (rankSize == 0) {
41 0 : return 0;
42 : }
43 0 : return (rank + step) % rankSize;
44 : }
45 : HcclResult RunSourceReducer(const LINK& link, const Slice& txSlice, const Slice& dstSlice);
46 :
47 : HcclResult RunDestRducer(const LINK& link, const Slice& rxSlice, const Slice& dstSlice);
48 :
49 : HcclResult RunReduceScatter(
50 : const std::vector<LINK>& links, const std::vector<Slice>& inputSlices, const std::vector<Slice>& scratchSlices);
51 : std::unique_ptr<Sender> senderInfo_;
52 : std::unique_ptr<Reducer> reducerInfo_;
53 : u32 interRank_ = 0; // 在所有rank环上的rankid?
54 : u32 interRankSize_ = 0; // 指的服务器的个数? 应当是所有服务器上rank总数和?
55 :
56 : u64 reduceAttr_ = 0; /* 0x1:表示data_type + reduce_type支持inlinereduce */
57 : u32 streamIndex_ = 0;
58 : };
59 : } // namespace hccl
60 :
61 : #endif /* REDUCE_SCATTER_MESH_PUB_H */
|