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(
27 : const RankId virtualRank, const u32 tempRankSize, 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(
38 : const TempFuncs& tempFuncs, TemplateDataParams& tempAlgParams, const ResLinks& tempLinks,
39 : std::vector<InsQuePtr>& tempInsQues);
40 :
41 : private:
42 : HcclResult CalcResLinksMesh2D(const u32 linkNumBtwPeers, AlgTempResReq& tempResReq);
43 : HcclResult PreCopy(const TemplateDataParams& tempAlgParams, std::vector<InsQuePtr>& tempInsQues);
44 : HcclResult SendRecvProcess(
45 : const ResLinks& tempLinks, std::vector<std::vector<DataSlice>> allSliceVec, std::vector<InsQuePtr>& tempInsQues,
46 : u32 remoteRank, u32 queIdx) const;
47 : HcclResult RunFirstLevel(
48 : const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues, const TemplateDataParams& tempAlgParams);
49 : HcclResult RunFirstReduce(std::vector<InsQuePtr>& tempInsQues, const TemplateDataParams& tempAlgParams);
50 : HcclResult RunSecondLevel(
51 : const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues, const TemplateDataParams& tempAlgParams);
52 : HcclResult RunSecondReduce(std::vector<InsQuePtr>& tempInsQues, const TemplateDataParams& tempAlgParams);
53 : RankId GetRankFromMap(const u32 rankIdx);
54 : u32 xQueNum_ = 0;
55 : u32 yQueNum_ = 0;
56 : u32 xRankSize_ = 0;
57 : u32 yRankSize_ = 0;
58 : u32 xRankId_ = 0;
59 : u32 yRankId_ = 0;
60 : u64 halfDataSize_ = 0;
61 : };
62 :
63 : } // namespace Hccl
64 :
65 : #endif // INS_TEMP_REDUCE_SCATTER_MESH_2D_H
|