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