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 : #include "log.h"
12 :
13 : #include "alg_data_trans_wrapper.h"
14 : #include "ins_temp_all_reduce_aicpu_reduce_mesh_2D.h"
15 : #include "ins_temp_all_gather_mesh_2D.h"
16 :
17 : namespace Hccl {
18 0 : InsTempAllReduceAicpuReduceMesh2D::InsTempAllReduceAicpuReduceMesh2D(const RankId virtualRank, const u32 tempRankSize,
19 : const std::vector<std::vector<RankId>> &tempVTopo,
20 0 : const std::map<RankId, u32> &tempVirtRankMap)
21 0 : : InsAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
22 : {
23 0 : }
24 :
25 0 : InsTempAllReduceAicpuReduceMesh2D::~InsTempAllReduceAicpuReduceMesh2D()
26 : {
27 0 : }
28 :
29 0 : HcclResult InsTempAllReduceAicpuReduceMesh2D::CalcRes(AlgTempResReq &tempResReq)
30 : {
31 0 : const int TwoD = 2;
32 0 : CHK_PRT_RET(
33 : tempVTopo_.size() < TwoD,
34 : HCCL_ERROR("[InsTempAllReduceAicpuReduceMesh2D] tempVTopo_ mismatch size:%zu", tempVTopo_.size()),
35 : HcclResult::HCCL_E_INTERNAL);
36 0 : CHK_PRT_RET(
37 : tempVTopo_[0].size() <= 1 || tempVTopo_[1].size() <= 1,
38 : HCCL_ERROR("[InsTempAllReduceAicpuReduceMesh2D] tempVTopo_ size error, size:%zu %zu", tempVTopo_[0].size(), tempVTopo_[1].size()),
39 : HcclResult::HCCL_E_INTERNAL);
40 0 : tempResReq.queNum = tempVTopo_[0].size() - 1 + tempVTopo_[1].size() - 1;
41 :
42 0 : tempResReq.streamNum = tempResReq.queNum;
43 0 : tempResReq.queNotifys = CreateMasterSlaveQueNotifiesRequest(tempResReq.queNum);
44 0 : HCCL_DEBUG("InsTempAllReduceAicpuReduceMesh2D::CalcRes queNotifys size[%u]", tempResReq.queNotifys.size());
45 :
46 0 : QId centerQ = 0;
47 0 : tempResReq.localWaitGroupCntNotify.emplace_back(centerQ, 0);
48 0 : tempResReq.localBcastPostCntNotify.emplace_back(centerQ, 0);
49 0 : CHK_RET(CalcResLinksMesh2D(myRank_, tempVTopo_, linkNumBtwPeers_, tempResReq));
50 0 : return HcclResult::HCCL_SUCCESS;
51 : }
52 :
53 0 : u32 InsTempAllReduceAicpuReduceMesh2D::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType) const
54 : {
55 : (void) inBuffType;
56 : (void) outBuffType;
57 0 : return tempRankSize_;
58 : }
59 :
60 0 : HcclResult InsTempAllReduceAicpuReduceMesh2D::RunAicpuLocalReduce(const TemplateDataParams &templateDataParams, std::vector<InsQuePtr> &tempInsQues)
61 : {
62 0 : DataSlice dataSlice = DataSlice(BufferType::SCRATCH, 0, templateDataParams.sliceSize);
63 0 : for (u32 rankId = 1; rankId < tempRankSize_; rankId++) {
64 0 : DataSlice addSlice = DataSlice(BufferType::SCRATCH, templateDataParams.sliceSize * rankId, templateDataParams.sliceSize);
65 0 : AicpuReduce(tempInsQues[0], addSlice, dataSlice, dataType_, redOp_);
66 : }
67 0 : DataSlice outputSlice = DataSlice(BufferType::OUTPUT, templateDataParams.buffInfo.inBuffBaseOff, templateDataParams.sliceSize);
68 0 : LocalCopy(tempInsQues[0], dataSlice, outputSlice);
69 0 : return HCCL_SUCCESS;
70 : }
71 :
72 0 : HcclResult InsTempAllReduceAicpuReduceMesh2D::GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &templateDataParams,
73 : const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
74 : {
75 0 : HCCL_INFO("[InsTempAllReduceAicpuReduceMesh2D] Run start");
76 0 : if (tempVTopo_[0].size() == 1) {
77 0 : return HcclResult::HCCL_SUCCESS;
78 : }
79 0 : opMode_ = tempFuncs.opMode;
80 0 : queNum_ = tempVTopo_[0].size() - 1 + tempVTopo_[1].size() - 1;
81 0 : CHK_PRT_RET(queNum_ > tempInsQues.size(),
82 : HCCL_ERROR("[CollAlgFactory] [InsTempAllReduceAicpuReduceMesh2D] Rank [%d], requiredQue Error.", myRank_),
83 : HcclResult::HCCL_E_INTERNAL);
84 :
85 0 : InsTempAllGatherMesh2D allgatherMesh2D(myRank_, tempRankSize_, tempVTopo_, tempVirtRankMap_);
86 0 : TempFuncs allgatherFuncs = tempFuncs;
87 0 : TemplateDataParams allgatherParams = templateDataParams;
88 0 : allgatherFuncs.isBottom = false;
89 0 : allgatherParams.buffInfo.outBuffBaseOff = 0;
90 0 : allgatherParams.outputSliceStride = templateDataParams.sliceSize;
91 0 : allgatherMesh2D.SetDataType(dataType_);
92 0 : allgatherMesh2D.GenExtIns(allgatherFuncs, allgatherParams, tempLinks, tempInsQues);
93 0 : StreamSync(tempInsQues);
94 0 : RunAicpuLocalReduce(templateDataParams, tempInsQues);
95 0 : HCCL_INFO("[InsTempAllReduceAicpuReduceMesh2D] Run finished");
96 0 : return HCCL_SUCCESS;
97 0 : }
98 :
99 : } // namespace Hccl
|