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_MIX_SINGLE_STREAM_PUB_H
12 : #define REDUCE_SCATTER_MESH_MIX_SINGLE_STREAM_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 ReduceScatterMeshMixSingleStream : public AlgTemplateBase {
20 : public:
21 : explicit ReduceScatterMeshMixSingleStream(const HcclDispatcher dispatcher);
22 :
23 : ~ReduceScatterMeshMixSingleStream() 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
46 : RunSourceReducer(const LINK& link, const std::vector<Slice>& txSlices, const std::vector<Slice>& dstSlices);
47 :
48 : HcclResult
49 : RunDestReducer(const LINK& link, const std::vector<Slice>& rxSlices, const std::vector<Slice>& dstSlices);
50 :
51 : HcclResult RunReduceScatter(
52 : const u32 rank, const u32 rankSize, const std::vector<LINK>& links, const std::vector<Slice>& inputSlices,
53 : const std::vector<Slice>& scratchSlices);
54 : std::unique_ptr<Sender> senderInfo_;
55 : std::unique_ptr<Reducer> reducerInfo_;
56 :
57 : u64 reduceAttr_ = 0; /* 0x1:表示data_type + reduce_type支持inlinereduce */
58 : u32 streamIndex_ = 0;
59 : };
60 : } // namespace hccl
61 :
62 : #endif /* REDUCE_SCATTER_MESH_MIX_SINGLE_STREAM_PUB_H */
|