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