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 "executor_utils.h"
12 : #include "hccl_aiv_utils.h"
13 : #include "aiv_ins.h"
14 : #include "aiv_temp_reduce_mesh_1D.h"
15 :
16 : namespace Hccl {
17 :
18 0 : AivTempReduceMesh1D::AivTempReduceMesh1D(
19 : const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
20 0 : const std::map<RankId, u32>& tempVirtRankMap)
21 0 : : AivAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
22 0 : {}
23 :
24 0 : AivTempReduceMesh1D::~AivTempReduceMesh1D() {}
25 :
26 0 : HcclResult AivTempReduceMesh1D::CalcRes(AlgTempResReq& tempResReq)
27 : {
28 0 : HCCL_INFO("[AivTempReduceMesh1D] Calculate communication resources start");
29 0 : tempResReq.queNum = 1;
30 0 : tempResReq.streamNum = tempResReq.queNum;
31 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
32 0 : HCCL_INFO(
33 : "[AivTempReduceMesh1D] Calculate communication resources finished, queNum[%u], streamNum[%u], linkNum[%u]",
34 : tempResReq.queNum, tempResReq.streamNum, tempResReq.links.size());
35 0 : return HcclResult::HCCL_SUCCESS;
36 : }
37 :
38 0 : u32 AivTempReduceMesh1D::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
39 : {
40 : (void)inBuffType;
41 : (void)outBuffType;
42 0 : HCCL_INFO("[AivTempReduceMesh1D] Scratch multiple is [%u]", (tempRankSize_ - 1));
43 0 : return tempRankSize_ - 1;
44 : }
45 :
46 0 : HcclResult AivTempReduceMesh1D::GenExtIns(
47 : const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
48 : std::vector<InsQuePtr>& tempInsQues)
49 : {
50 0 : HCCL_INFO("[AivTempReduceMesh1D] GenExtIns start rank[%u]", u32(myRank_));
51 0 : CHK_PRT_RET(tempInsQues.empty(), HCCL_ERROR("[AivTempReduceMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
52 0 : CHK_PTR_NULL(tempInsQues[0]);
53 0 : std::vector<LinkData> allLinks;
54 0 : for (auto iter = tempLinks.begin(); iter != tempLinks.end(); ++iter) {
55 0 : allLinks.emplace_back(iter->second.at(0));
56 : }
57 :
58 0 : IncSliceId(); // 自动增长sliceId,传入aivTag
59 :
60 0 : AivOpArgs aivReduceArgs;
61 0 : aivReduceArgs.cmdType = HcclCMDType::HCCL_CMD_REDUCE;
62 0 : aivReduceArgs.input = templateDataParams.buffInfo.inBuffBaseOff;
63 0 : aivReduceArgs.output = templateDataParams.buffInfo.outBuffBaseOff;
64 0 : aivReduceArgs.rank = u32(myRank_);
65 0 : aivReduceArgs.rankSize = tempRankSize_;
66 0 : aivReduceArgs.count = templateDataParams.sliceSize / DataTypeSizeGet(dataType_);
67 0 : aivReduceArgs.dataType = dataType_;
68 0 : aivReduceArgs.op = reduceOp_;
69 0 : aivReduceArgs.root = root_;
70 0 : aivReduceArgs.aivTag = sliceId_; // 传入aivTag,Lauch时重新组装为aivTag
71 0 : aivReduceArgs.isOpBase = (tempFuncs.opMode == OpMode::OPBASE);
72 0 : aivReduceArgs.xRankSize = tempVTopo_[0].size();
73 0 : aivReduceArgs.yRankSize = 0;
74 0 : aivReduceArgs.zRankSize = 0;
75 :
76 0 : constexpr u32 level0 = 0;
77 0 : constexpr u32 level1 = 1;
78 0 : constexpr u32 level2 = 2;
79 0 : for (u32 i = 0; i < tempVTopo_[level0].size(); i++) {
80 0 : aivReduceArgs.topo_[i] = tempVTopo_[level0][i];
81 : }
82 0 : if (tempVTopo_.size() > level1) {
83 0 : aivReduceArgs.yRankSize = tempVTopo_[level1].size();
84 0 : for (u32 i = 0; i < tempVTopo_[level1].size(); i++) {
85 0 : aivReduceArgs.topo_[TOPO_LEN_Y_OFFSET + i] = tempVTopo_[level1][i];
86 : }
87 : }
88 0 : if (tempVTopo_.size() > level2) {
89 0 : aivReduceArgs.zRankSize = tempVTopo_[level2].size();
90 0 : for (u32 i = 0; i < tempVTopo_[level2].size(); i++) {
91 0 : aivReduceArgs.topo_[TOPO_LEN_Z_OFFSET + i] = tempVTopo_[level2][i];
92 : }
93 : }
94 :
95 0 : aivReduceArgs.inputSliceStride = templateDataParams.inputSliceStride;
96 0 : aivReduceArgs.outputSliceStride = templateDataParams.outputSliceStride;
97 0 : aivReduceArgs.repeatNum = templateDataParams.repeatNum;
98 0 : aivReduceArgs.inputRepeatStride = templateDataParams.inputRepeatStride;
99 0 : aivReduceArgs.outputRepeatStride = templateDataParams.outputRepeatStride;
100 :
101 0 : std::unique_ptr<Instruction> aivInsReduceMesh1D = std::make_unique<AivInstruction>(allLinks, aivReduceArgs);
102 :
103 0 : tempInsQues[0]->Append(std::move(aivInsReduceMesh1D));
104 0 : HCCL_INFO("[AivTempReduceMesh1D] GenExtIns finished rank[%u]", u32(myRank_));
105 0 : return HcclResult::HCCL_SUCCESS;
106 0 : }
107 :
108 : } // namespace Hccl
|