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 COLL_REDUCESCATTER_RING_FOR_910_93_EXECUTOR_H
12 : #define COLL_REDUCESCATTER_RING_FOR_910_93_EXECUTOR_H
13 : #include "coll_reduce_scatter_executor.h"
14 :
15 : namespace hccl {
16 : class CollReduceScatterRingFor91093Executor : public CollReduceScatterExecutor {
17 : public:
18 : explicit CollReduceScatterRingFor91093Executor(
19 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher);
20 4 : ~CollReduceScatterRingFor91093Executor() override = default;
21 :
22 : protected:
23 : u64 CalcTotalCount(const OpParam& param) const;
24 : HcclResult CalcStreamNum(u32& streamNum) override;
25 : u64 CalcLoopMaxCount(const u32 unitSize) override;
26 : bool IsHugeData(const u64 curSize, OpParam* param = nullptr) override;
27 : virtual HcclResult RunIntraSeverReduceScatter(
28 : const std::string& tag, DeviceMem& inputMem, DeviceMem& outputMem, const u64 count,
29 : const HcclDataType& dataType, const HcclReduceOp& reductionOp,
30 : const std::vector<std::vector<Slice>>& multRingsSliceZero, const Stream& stream, s32 profStage,
31 : const u64 baseOffset = 0, const HcomCollOpInfo* opInfo = nullptr,
32 : const std::vector<std::vector<Slice>>& multRingsUserMemSlice = std::vector<std::vector<Slice>>(0),
33 : const bool disableDMAReduce = false);
34 : virtual HcclResult GetLevelCommInfo();
35 : HcomCollOpInfo GetHcomCollOpInfo(const OpParam& param, const ExecMem& execMem) const;
36 : virtual bool IsUnifiedMarch(const OpParam& param) const;
37 : u64 CalcSrcMemOffset(const ExecMem& execMem, const OpParam& param, u32 perDataSize) const;
38 : virtual HcclResult CalLevel0DataSegsSlice(
39 : const ExecMem& execMem, std::vector<std::vector<Slice>>& multiStreamSlice, const OpParam& param, u32 ringNum,
40 : u32 sliceNum, u32 level1RankSize, u32 level2RankSize, HcclDataType dataType,
41 : std::vector<std::vector<Slice>>& level0DataSegsSlice);
42 : virtual HcclResult CalUserMemDataSegsSlice(
43 : const ExecMem& execMem, const std::vector<std::vector<Slice>>& level0DataSegsSlice,
44 : const std::vector<std::vector<Slice>>& multiStreamSlice, const OpParam& param, u32 ringNum, u32 sliceNum,
45 : u32 level1RankSize, u32 level2RankSize, HcclDataType dataType, u32 perDataSize, HcomCollOpInfo* opInfoPtr,
46 : bool disableDMAReduce, std::vector<std::vector<Slice>>& multRingsUserMemSlice);
47 : virtual HcclResult CalLevel1DataSegsSlice(
48 : const ExecMem& execMem, const OpParam& param, CommPlane commPlaneLevel, const u32& commIndex, u32 sliceNum,
49 : u32 level1RankSize, u32 level2RankSize, u32 perDataSize, std::vector<Slice>& level1DataSegsSlice);
50 : virtual HcclResult CalLevel2DataSegsSlice(
51 : const ExecMem& execMem, const OpParam& param, u32 level2RankSize, u32 perDataSize,
52 : std::vector<Slice>& level2DataSegsSlice);
53 :
54 : private:
55 : void ParseParam(const OpParam& param) override;
56 : /* *************** 资源计算 *************** */
57 : bool isZeroCopy_ = false;
58 : HcclResult CalcScratchMemSize(u64& scratchMemSize) override;
59 : HcclResult CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport) override;
60 : HcclResult CalcLevel0CommInfo(
61 : TransportMemType inputType, TransportMemType outputType,
62 : std::vector<LevelNSubCommTransport>& opTransport) override;
63 : HcclResult CalcLevel2CommInfo(
64 : TransportMemType inputType, TransportMemType outputType,
65 : std::vector<LevelNSubCommTransport>& opTransport) override;
66 : HcclResult CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType);
67 :
68 : /* *************** 算法编排 *************** */
69 : HcclResult KernelRun(const OpParam& param, ExecMem& execMem) override;
70 : HcclResult Getlevel1CommRank(SubCommInfo& level1CommInfo) override;
71 : HcclResult SelectTempAlg(std::unique_ptr<AlgTemplateBase>& level1TempAlg, u32 level1RankSize) override;
72 : /* **************** 数据准备*************** */
73 : virtual void FillMultiRingSlice(
74 : const ExecMem& execMem, const std::vector<std::vector<Slice>>& multiStreamSlice, u32 sliceNum,
75 : u32 level1RankSize, u32 level2RankSize, const u32 ringIndex, std::vector<Slice>& dataSlice);
76 :
77 : using Level0SlicesCalculator = void (*)(
78 : const OpParam& param, u32 sliceNum, u32 level1RankSize, u32 level1Index, u32 level2Index, u32 perDataSize,
79 : std::vector<Slice>& segSlices);
80 : static void PrepareLevel0Slices(
81 : const OpParam& param, u32 sliceNum, u32 level1RankSize, u32 level1Index, u32 level2Index, u32 perDataSize,
82 : std::vector<Slice>& cclSegSlices);
83 : static void PrepareLevel0UserSlices(
84 : const OpParam& param, u32 sliceNum, u32 level1RankSize, u32 level1Index, u32 level2Index, u32 perDataSize,
85 : std::vector<Slice>& userSegSlices);
86 : bool IsCceReduceAligned(const std::vector<Slice>& dataSlices) const;
87 : HcclResult FillMultiRingSliceV(
88 : const ExecMem& execMem, const OpParam& param, u32 ringNum, u32 sliceNum, u32 level1RankSize, u32 level2RankSize,
89 : HcclDataType dataType, std::vector<std::vector<Slice>>& level0DataSegsSlice,
90 : std::vector<std::vector<std::vector<Slice>>>& serverSlices, const Level0SlicesCalculator& calcLevel0Slices);
91 : virtual HcclResult CalUserMemDataSegsSliceV(
92 : const ExecMem& execMem, const OpParam& param, u32 ringNum, u32 sliceNum, u32 level1RankSize, u32 level2RankSize,
93 : HcclDataType dataType, std::vector<std::vector<Slice>>& multRingsUserMemSlice);
94 : virtual HcclResult CalLevel0DataSegsSliceV(
95 : const ExecMem& execMem, std::vector<std::vector<Slice>>& multiStreamSlice, const OpParam& param, u32 ringNum,
96 : u32 sliceNum, u32 level1RankSize, u32 level2RankSize, HcclDataType dataType,
97 : std::vector<std::vector<Slice>>& level0DataSegsSlice);
98 : virtual HcclResult CalLevel1DataSegsSliceV(
99 : const OpParam& param, CommPlane commPlaneLevel, const u32& commIndex, u32 sliceNum, u32 level1RankSize,
100 : u32 level2RankSize, u32 perDataSize, std::vector<Slice>& level1DataSegsSlice);
101 : virtual HcclResult CalLevel2DataSegsSliceV(
102 : const OpParam& param, u32 level2RankSize, u32 perDataSize, std::vector<Slice>& level2DataSegsSlice);
103 :
104 : protected:
105 : SubCommInfo logicalLevel0CommInfo_ = {0, 0, {}, {}};
106 : SubCommInfo logicalLevel1CommInfo_ = {0, 0, {}, {}};
107 : CommPlane logicalLevel0plane_ = COMM_LEVEL_RESERVED;
108 : CommPlane logicalLevel1plane_ = COMM_LEVEL_RESERVED;
109 : };
110 :
111 : } // namespace hccl
112 :
113 : #endif
|