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 HCCLV2_INS_TEMP_ALL_REDUCE_2D_MESH_TWO_SHOT
12 : #define HCCLV2_INS_TEMP_ALL_REDUCE_2D_MESH_TWO_SHOT
13 :
14 : #include "string_util.h"
15 : #include "ins_alg_template_base.h"
16 : #include "executor_utils.h"
17 :
18 : namespace Hccl {
19 :
20 : struct SubStageArgs{
21 : BufferType inType;
22 : BufferType outType;
23 : u64 inbaseOff;
24 : u64 outbaesOff;
25 : };
26 :
27 : class InsTempAllReduceMesh2DTwoShot : public InsAlgTemplateBase {
28 : public:
29 : explicit InsTempAllReduceMesh2DTwoShot(const RankId virtualRank, const u32 tempRankSize,
30 : const std::vector<std::vector<RankId>> &tempVTopo, const std::map<RankId, u32> &tempVirtRankMap);
31 : ~InsTempAllReduceMesh2DTwoShot() override;
32 :
33 0 : std::string Describe() const override
34 : {
35 0 : return StringFormat("Template of all reduce 1D mesh with tempRankSize [%u].", tempRankSize_);
36 : }
37 : HcclResult GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &tempAlgParams, const ResLinks &tempLinks,
38 : std::vector<InsQuePtr> &tempInsQues);
39 : HcclResult CalcRes(AlgTempResReq &tempResReq) override;
40 : u32 CalcScratchMultiple(BufferType input, BufferType output) const;
41 :
42 : private:
43 : std::vector<std::tuple<QId, QId, u32>> CreateQueNotifiesRequest(
44 : u32 queueNum, u32 pairNum, QId masterIdX, QId masterIdY) const;
45 : HcclResult BuildSlice(const std::vector<RankId> &rankInfo, const u64 dataSize, const u64 chunkSize,
46 : RankSliceInfo &sliceInfoVec) const;
47 : HcclResult RunReduceScatter(SubStageArgs& subparams,
48 : const RankSliceInfo &sliceInfoVec, const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues,
49 : const std::vector<RankId> &rankInfo) const;
50 : HcclResult RunAllgather(SubStageArgs& subparams,
51 : const RankSliceInfo &sliceInfoVec, const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues,
52 : const std::vector<RankId> &rankInfo) const;
53 : HcclResult InitInnerParams(const TempFuncs &tempFuncs,
54 : const TemplateDataParams &tempAlgParams, const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues);
55 :
56 : RankSliceInfo XsliceInfoVec_;
57 : RankSliceInfo YsliceInfoVec_;
58 : RankSliceInfo XsliceInfoVecS2_;
59 : RankSliceInfo YsliceInfoVecS2_;
60 : u64 XDataSize_{0};
61 : u64 YDataSize_{0};
62 : u32 M_{0};
63 : u32 N_{0};
64 : u64 chunkSize_{0};
65 : u32 XAlgrankId_{0};
66 : u32 YAlgrankId_{0};
67 : std::vector<InsQuePtr> XtempInsQues_;
68 : std::vector<InsQuePtr> YtempInsQues_;
69 : u64 YDataSizeS2_{0};
70 : u64 XDataSizeS2_{0};
71 : };
72 :
73 : } // namespace Hccl
74 :
75 : #endif // !HCCLV2_INS_TEMP_ALL_REDUCE_2D_MESH_TWO_SHOT
|