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_instruction_all_gather_mesh1d.h"
17 : #include "ccu_rank_group.h"
18 : #include "ccu_ctx_creator_registry.h"
19 : #include "ccu_context_all_gather_mesh1d.h"
20 : #include "ccu_temp_all_gather_mesh_1D.h"
21 :
22 : namespace Hccl {
23 :
24 : static CcuInstRegister<CcuContextAllGatherMesh1D> g_registrarAllGather(CcuInstType::CCU_ALLGATHER_MESH_1D_DIRECT);
25 :
26 0 : CcuTempAllGatherMesh1D::CcuTempAllGatherMesh1D(const RankId virtualRank, const u32 tempRankSize,
27 : const std::vector<std::vector<RankId>> &tempVTopo,
28 0 : const std::map<RankId, u32> &tempVirtRankMap)
29 0 : : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
30 : {
31 0 : }
32 :
33 0 : CcuTempAllGatherMesh1D::~CcuTempAllGatherMesh1D()
34 : {
35 0 : }
36 :
37 0 : HcclResult CcuTempAllGatherMesh1D::CalcRes(AlgTempResReq &tempResReq)
38 : {
39 0 : tempResReq.queNum = 1;
40 0 : tempResReq.streamNum = tempResReq.queNum;
41 0 : HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
42 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
43 0 : return HcclResult::HCCL_SUCCESS;
44 : }
45 :
46 0 : HcclResult CcuTempAllGatherMesh1D::CalcSliceInfo(const AllignInfo &allignInfo, const u64 dataSize,
47 : RankSliceInfo &sliceInfoVec)
48 : {
49 0 : std::vector<SliceInfo> tmp(tempVTopo_.size());
50 0 : sliceInfoVec.resize(tempRankSize_, tmp);
51 :
52 0 : CHK_RET(CalcRsAgSliceInfoMesh(myRank_, tempRankSize_, allignInfo, dataSize, sliceInfoVec));
53 :
54 0 : return HcclResult::HCCL_SUCCESS;
55 0 : }
56 :
57 0 : uint64_t CcuTempAllGatherMesh1D::GetMaxSliceSize() const
58 : {
59 0 : return UB_MAX_DATA_SIZE;
60 : }
61 :
62 0 : HcclResult CcuTempAllGatherMesh1D::Run(const TempFuncs &tempFuncs, const RankSliceInfo &sliceInfoVec,
63 : const BuffInfo &buffInfo, const ResLinks &tempLinks,
64 : std::vector<InsQuePtr> &tempInsQues)
65 : {
66 0 : CHK_PRT_RET(tempInsQues.empty(),
67 : HCCL_ERROR("[CcuTempAllGatherMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
68 0 : CHK_PTR_NULL(tempInsQues[0]);
69 0 : opMode_ = tempFuncs.opMode;
70 0 : buffInfo_ = buffInfo;
71 0 : CcuInstructionAllGatherMesh1D ccuInsAllGatherMesh1D;
72 0 : std::vector<uint64_t> dimSize;
73 0 : dimSize.push_back(tempRankSize_);
74 :
75 : uint64_t inputAddr;
76 : uint64_t outputAddr;
77 : uint64_t offset;
78 0 : if (opMode_ == OpMode::OPBASE) {
79 0 : if (tempFuncs.isForepart) {
80 0 : inputAddr = BufferTypeToAddr(tempFuncs.usrData.usrInSlices[0].GetType())
81 0 : + tempFuncs.usrData.usrInSlices[0].GetOffset();
82 : } else {
83 0 : inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff;
84 : }
85 0 : if (tempFuncs.isBottom) {
86 0 : outputAddr = BufferTypeToAddr(tempFuncs.usrData.usrOutSlices[0].GetType());
87 : // 需要加上 UserOUt 的偏移,包含了 loop 偏移和 rank 偏移
88 0 : offset = tempFuncs.usrData.usrOutSlices[myRank_].GetOffset();
89 : } else {
90 0 : outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
91 : // 从 inBuff 获取数据,只需要加上 rank 偏移
92 0 : offset = sliceInfoVec[myRank_][0].offset;
93 : }
94 : } else {
95 0 : inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff + tempFuncs.usrData.usrInSlices[0].GetOffset();
96 0 : outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
97 0 : offset = tempFuncs.usrData.usrOutSlices[myRank_].GetOffset();
98 : }
99 :
100 0 : uint64_t sliceSize = sliceInfoVec[myRank_][0].size; // 获取本rank需要处理的数据量
101 : uint64_t token;
102 0 : CHK_RET(GetToken(op_, token));
103 0 : ccuInsAllGatherMesh1D.Init(static_cast<uint32_t>(myRank_), inputAddr, outputAddr, sliceSize, offset, token, op_, tempVTopo_);
104 0 : HCCL_INFO("[CcuTempAllGatherMesh1D] Run Init: myRank_[%d], dimSize[%llu], inputAddr[%llu],"\
105 : "outputAddr[%llu], sliceSize[%llu], offset[%llu]",
106 : myRank_, dimSize[0], inputAddr, outputAddr, sliceSize, offset);
107 :
108 0 : std::vector<LinkData> links;
109 0 : for (auto &pair : tempLinks) {
110 0 : if (pair.second.empty()) {
111 0 : continue;
112 : }
113 0 : links.push_back(pair.second[0]);
114 : }
115 0 : HCCL_INFO("[CcuTempAllGatherMesh1D] links.size[%zu]", links.size());
116 0 : ccuInsAllGatherMesh1D.SetLinks(links);
117 :
118 0 : RankGroup rankGroup;
119 0 : for (auto &peer : tempVTopo_[0]) {
120 0 : rankGroup.AddRank(peer);
121 : }
122 0 : u32 cntCkeNum = 3;
123 0 : ccuInsAllGatherMesh1D.SetCntCkeNum(cntCkeNum);
124 0 : ccuInsAllGatherMesh1D.SetRankGroup(rankGroup);
125 0 : HCCL_INFO("CCUInsAllGathermesh1D is [%s]", ccuInsAllGatherMesh1D.Describe().c_str());
126 0 : ccuInsAllGatherMesh1D.Describe();
127 0 : tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionAllGatherMesh1D>(ccuInsAllGatherMesh1D)));
128 :
129 0 : return HcclResult::HCCL_SUCCESS;
130 0 : }
131 :
132 0 : HcclResult CcuTempAllGatherMesh1D::GenExtIns(const RankGraph *rankGraph, const TemplateInfo &tmpInfo,
133 : const std::vector<InsQuePtr> &tempInsQues) const
134 : {
135 : (void)rankGraph;
136 : (void)tmpInfo;
137 : (void)tempInsQues;
138 : // 框架解析aicpuIns,算法的algCompnnetLite在device侧直接调用Run()
139 0 : return HcclResult::HCCL_SUCCESS;
140 : }
141 :
142 : } // namespace Hccl
|