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 <ios>
12 : #include <iostream>
13 :
14 : #include "log.h"
15 :
16 : #include "ccu_temp_broadcast_mesh_1D.h"
17 : #include "alg_data_trans_wrapper.h"
18 : #include "ccu_instruction_broadcast_mesh1d.h"
19 : #include "ccu_rank_group.h"
20 : #include "ccu_ctx_creator_registry.h"
21 : #include "ccu_context_broadcast_mesh1d.h"
22 :
23 : namespace Hccl {
24 :
25 : static CcuInstRegister<CcuContextBroadcastMesh1D> registrarBroadcast(
26 : CcuInstType::CCU_BROADCAST_MESH_1D_DIRECT);
27 :
28 0 : CcuTempBroadcastMesh1D::CcuTempBroadcastMesh1D(const RankId virtualRank, const u32 tempRankSize,
29 : const std::vector<std::vector<RankId>> &tempVTopo,
30 0 : const std::map<RankId, u32> &tempVirtRankMap)
31 0 : : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
32 : {
33 0 : }
34 :
35 0 : CcuTempBroadcastMesh1D::~CcuTempBroadcastMesh1D()
36 : {
37 0 : }
38 :
39 0 : void CcuTempBroadcastMesh1D::GetInAndOutAddr(const TempFuncs &tempFuncs, uint64_t &inputAddr, uint64_t &outputAddr)
40 : {
41 0 : if (tempFuncs.isForepart) {
42 : // 从 UserIn 获取数据
43 0 : inputAddr = BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType())
44 0 : + tempFuncs.usrData.usrInSlices[0].GetOffset();
45 0 : HCCL_INFO("[CcuTempBroadcastMesh1D] BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType()) is [%llu], "
46 : "offset is [%llu]",
47 : BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType()),
48 : tempFuncs.usrData.usrInSlices[0].GetOffset());
49 : } else {
50 : // 从 inBuff 获取数据
51 0 : inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff;
52 0 : HCCL_INFO("[CcuTempBroadcastMesh1D] BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType()) is [%llu], "
53 : "offset is [%llu]",
54 : BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType()),
55 : tempFuncs.usrData.usrInSlices[0].GetOffset());
56 : }
57 0 : if (tempFuncs.isBottom) {
58 : // 把数据写入 UserOut
59 0 : outputAddr = BufferTypeToAddr(tempFuncs.usrData.usrOutSlices[0].GetType())
60 0 : + tempFuncs.usrData.usrOutSlices[0].GetOffset();
61 0 : HCCL_INFO("[CcuTempBroadcastMesh1D] BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType()) is [%llu], "
62 : "offset is [%llu]",
63 : BufferTypeToAddr(tempFuncs.usrData.usrOutSlices[0].GetType()),
64 : tempFuncs.usrData.usrOutSlices[0].GetOffset());
65 : } else {
66 : // 把数据写入 outBuff
67 0 : outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
68 0 : HCCL_INFO("[CcuTempBroadcastMesh1D] BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType()) is [%llu], "
69 : "offset is [%llu]",
70 : BufferTypeToAddr(tempFuncs.usrData.usrOutSlices[0].GetType()),
71 : tempFuncs.usrData.usrOutSlices[0].GetOffset());
72 : }
73 0 : HCCL_INFO("[CcuTempBroadcastMesh1D] inputAddr[%llu], outputAddr[%llu]", inputAddr, outputAddr);
74 0 : return;
75 : }
76 :
77 0 : HcclResult CcuTempBroadcastMesh1D::CalcRes(AlgTempResReq &tempResReq)
78 : {
79 0 : tempResReq.queNum = 1;
80 0 : tempResReq.streamNum = tempResReq.queNum;
81 0 : HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
82 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
83 0 : return HcclResult::HCCL_SUCCESS;
84 : }
85 :
86 0 : HcclResult CcuTempBroadcastMesh1D::Run(const TempFuncs &tempFuncs, const RankSliceInfo &sliceInfoVec,
87 : const BuffInfo &buffInfo, const ResLinks &tempLinks,
88 : std::vector<InsQuePtr> &tempInsQues)
89 : {
90 : (void)sliceInfoVec;
91 0 : CHK_PRT_RET(tempInsQues.empty(),
92 : HCCL_ERROR("[CcuTempBroadcastMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
93 0 : CHK_PTR_NULL(tempInsQues[0]);
94 0 : buffInfo_ = buffInfo;
95 0 : opMode_ = tempFuncs.opMode;
96 0 : CcuInstructionBroadcastMesh1D ccuInsBroadcastMesh1D;
97 0 : rootId_ = op_.root;
98 0 : std::vector<uint64_t> dimSize;
99 0 : dimSize.push_back(tempRankSize_);
100 :
101 : // 只传userIn的起始位置,不带偏移,偏移已在offset中包含
102 : uint64_t inputAddr;
103 : // userOut 的位置,需要带上偏移
104 : uint64_t outputAddr;
105 0 : GetInAndOutAddr(tempFuncs, inputAddr, outputAddr);
106 0 : uint64_t sliceSize = tempFuncs.usrData.usrInSlices[0].GetSize(); //
107 :
108 0 : uint64_t offset = 0;
109 :
110 : uint64_t token;
111 0 : CHK_RET(GetToken(op_, token));
112 :
113 0 : ccuInsBroadcastMesh1D.Init(static_cast<uint32_t>(myRank_), static_cast<uint32_t>(rootId_), inputAddr, outputAddr,
114 0 : sliceSize, offset, token, op_, tempVTopo_);
115 :
116 0 : std::vector<LinkData> links;
117 0 : for (auto &pair : tempLinks) {
118 0 : if (pair.second.empty()) {
119 0 : continue;
120 : }
121 0 : links.push_back(pair.second[0]);
122 : }
123 0 : HCCL_INFO("[CcuTempBroadcastMesh1D] links.size[%zu]", links.size());
124 0 : ccuInsBroadcastMesh1D.SetLinks(links);
125 0 : if (tempVTopo_[0].size() == 0) {
126 0 : HCCL_ERROR("[CcuTempBroadcastMesh1D] Invalid tempVTopo[0] size [%zu].", tempVTopo_[0].size());
127 0 : return HcclResult::HCCL_E_PARA;
128 : }
129 0 : RankGroup rankGroup;
130 0 : for (auto &peer : tempVTopo_[0]) {
131 0 : rankGroup.AddRank(peer);
132 : }
133 0 : u32 cntCkeNum = 3;
134 0 : ccuInsBroadcastMesh1D.SetCntCkeNum(cntCkeNum);
135 0 : ccuInsBroadcastMesh1D.SetRankGroup(rankGroup);
136 0 : ccuInsBroadcastMesh1D.Describe();
137 0 : tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionBroadcastMesh1D>(ccuInsBroadcastMesh1D)));
138 :
139 0 : return HcclResult::HCCL_SUCCESS;
140 0 : }
141 :
142 : } // namespace Hccl
|