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 INS_TEMP_REDUCE_SCATTER_MESH_2D_H
12 : #define INS_TEMP_REDUCE_SCATTER_MESH_2D_H
13 :
14 : #include "string_util.h"
15 : #include "ins_temp_all_gather_nhr.h"
16 : #include "ins_alg_template_base.h"
17 : #include "executor_utils.h"
18 :
19 : #define DATASLICE_ONE 1
20 :
21 : namespace Hccl {
22 :
23 : constexpr u32 PARALLEL_SIZE = 2;
24 : class InsTempReduceScatterMesh2D : public InsAlgTemplateBase {
25 : public:
26 : explicit InsTempReduceScatterMesh2D(const RankId virtualRank, const u32 tempRankSize,
27 : const std::vector<std::vector<RankId>> &tempVTopo,
28 : const std::map<RankId, u32> &tempVirtRankMap);
29 : ~InsTempReduceScatterMesh2D() override;
30 :
31 0 : std::string Describe() const override
32 : {
33 0 : return StringFormat("Template of reduce scatter Mesh2D with tempRankSize [%u].", tempRankSize_);
34 : }
35 : u64 CalcScratchMultiple(const BufferType &inBuffType, const BufferType &outBuffType);
36 : HcclResult CalcRes(AlgTempResReq &tempResReq) override;
37 : HcclResult GenExtIns(const TempFuncs &tempFuncs, TemplateDataParams &tempAlgParams, const ResLinks &tempLinks,
38 : std::vector<InsQuePtr> &tempInsQues);
39 : private:
40 : HcclResult CalcResLinksMesh2D(const u32 linkNumBtwPeers, AlgTempResReq &tempResReq);
41 : HcclResult PreCopy(const TemplateDataParams &tempAlgParams, std::vector<InsQuePtr> &tempInsQues);
42 : HcclResult SendRecvProcess(const ResLinks &tempLinks, std::vector<std::vector<DataSlice>> allSliceVec,
43 : std::vector<InsQuePtr> &tempInsQues, u32 remoteRank, u32 queIdx) const;
44 : HcclResult RunFirstLevel(const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues, const TemplateDataParams &tempAlgParams);
45 : HcclResult RunFirstReduce(std::vector<InsQuePtr> &tempInsQues, const TemplateDataParams &tempAlgParams);
46 : HcclResult RunSecondLevel(const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues, const TemplateDataParams &tempAlgParams);
47 : HcclResult RunSecondReduce(std::vector<InsQuePtr> &tempInsQues, const TemplateDataParams &tempAlgParams);
48 : RankId GetRankFromMap(const u32 rankIdx);
49 : u32 xQueNum_ = 0;
50 : u32 yQueNum_ = 0;
51 : u32 xRankSize_ = 0;
52 : u32 yRankSize_ = 0;
53 : u32 xRankId_ = 0;
54 : u32 yRankId_ = 0;
55 : u64 halfDataSize_ = 0;
56 : };
57 :
58 : } // namespace Hccl
59 :
60 : #endif //INS_TEMP_REDUCE_SCATTER_MESH_2D_H
|