Line data Source code
1 : /**
2 : * Copyright (c) 2026 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_rank_group.h"
17 : #include "ccu_ctx_creator_registry.h"
18 : #include "ccu_context_all_gather_mesh1d_2die.h"
19 : #include "ccu_temp_all_gather_mesh_1D_2die.h"
20 : #include "ccu_ins_group.h"
21 :
22 : namespace Hccl {
23 :
24 : static CcuInstRegister<CcuContextAllGatherMesh1D2Die> g_registrarAllGather(
25 : CcuInstType::CCU_ALLGATHER_MESH_1D_2DIE);
26 :
27 0 : CcuTempAllGatherMesh1D2Die::CcuTempAllGatherMesh1D2Die(const RankId virtualRank, const u32 tempRankSize,
28 : const std::vector<std::vector<RankId>> &tempVTopo,
29 0 : const std::map<RankId, u32> &tempVirtRankMap)
30 0 : : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
31 : {
32 0 : }
33 :
34 0 : CcuTempAllGatherMesh1D2Die::~CcuTempAllGatherMesh1D2Die()
35 : {
36 0 : }
37 :
38 0 : HcclResult CcuTempAllGatherMesh1D2Die::CalcRes(AlgTempResReq &tempResReq)
39 : {
40 0 : tempResReq.queNum = 1;
41 0 : tempResReq.streamNum = tempResReq.queNum + 1;
42 0 : HCCL_DEBUG("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
43 :
44 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
45 0 : return HcclResult::HCCL_SUCCESS;
46 : }
47 :
48 0 : uint64_t CcuTempAllGatherMesh1D2Die::GetMaxSliceSize() const
49 : {
50 0 : return UB_MAX_DATA_SIZE;
51 : }
52 :
53 0 : HcclResult CcuTempAllGatherMesh1D2Die::GenExtIns(const TempFuncs &tempFuncs, TemplateDataParams &tempAlgParams,
54 : const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
55 : {
56 0 : CHK_PRT_RET(tempInsQues.empty(),
57 : HCCL_ERROR("[CcuTempAllGatherMesh1D2Die] empty queue"), HcclResult::HCCL_E_INTERNAL);
58 0 : CHK_PTR_NULL(tempInsQues[0]);
59 0 : opMode_ = tempFuncs.opMode;
60 0 : CcuInstructionAllGatherMesh1D2Die ccuInsAllGatherMesh1D2Die;
61 0 : std::vector<uint64_t> dimSize;
62 0 : dimSize.push_back(tempRankSize_);
63 :
64 0 : uint64_t sliceSize = tempAlgParams.sliceSize;
65 0 : uint64_t inputAddr = BufferTypeToAddr(tempAlgParams.buffInfo.inBuffType) + tempAlgParams.buffInfo.inBuffBaseOff;
66 0 : uint64_t outputAddr = BufferTypeToAddr(tempAlgParams.buffInfo.outBuffType) + tempAlgParams.buffInfo.outBuffBaseOff;
67 0 : uint64_t outputSliceStride = tempAlgParams.outputSliceStride;
68 : uint64_t token;
69 0 : CHK_RET(GetToken(op_, token));
70 0 : HCCL_INFO("[CcuTempAllGatherMesh1D2Die] dimSize[%llu], sliceSize[%llu], inputAddr[%llu],"\
71 : "outputAddr[%llu], outputSliceStride[%llu]",
72 : dimSize[0], sliceSize, inputAddr, outputAddr, outputSliceStride);
73 :
74 : // key表示为dieId
75 0 : std::map<uint32_t, std::vector<LinkData>> linksDie;
76 0 : std::map<uint32_t, RankGroup> rankGroup;
77 :
78 0 : for (auto link: tempLinks) {
79 0 : std::vector<LinkData> linkData = link.second;
80 0 : RankId peerRankId = link.first;
81 0 : if (linkData.size() == 0){
82 0 : continue;
83 : }
84 :
85 0 : linksDie[linkData[0].GetLocalDieId()].push_back(linkData[0]);
86 0 : rankGroup[linkData[0].GetLocalDieId()].AddRank(peerRankId);
87 0 : }
88 :
89 0 : HCCL_INFO("[CcuTempAllGatherMesh1D2Die] linksDie0Size[%llu], linksDie1Size[%llu]", linksDie[0].size(), linksDie[1].size());
90 :
91 0 : rankGroup[0].AddRank(myRank_);
92 0 : rankGroup[1].AddRank(myRank_);
93 :
94 0 : std::unique_ptr<CcuInsGroup> insGroupPtr = std::make_unique<CcuInsGroup>();
95 0 : for (uint32_t dieId = 0; dieId < 2; dieId++) { // 2Die算法,需要下发 2 条通信指令
96 0 : CcuInstructionAllGatherMesh1D2Die ccuInstruction;
97 0 : bool withMyRank = linksDie[dieId].size() > linksDie[1 - dieId].size() ? false : true;
98 0 : ccuInstruction.Init(myRank_, inputAddr, outputAddr, sliceSize, outputSliceStride, token, withMyRank, op_, tempVTopo_);
99 0 : ccuInstruction.SetLinks(linksDie[dieId]);
100 0 : ccuInstruction.SetRankGroup(rankGroup[dieId]);
101 0 : ccuInstruction.SetCntCkeNum(5); // 每个transport用5个CKE
102 0 : insGroupPtr->Append(std::move(std::make_unique<CcuInstructionAllGatherMesh1D2Die>(ccuInstruction)));
103 0 : }
104 0 : tempInsQues[0]->Append(std::move(insGroupPtr)); // 只有一条que
105 0 : HCCL_INFO("[CcuTempAllGatherMesh1D2Die] Template Run for all steps Ends.");
106 0 : return HcclResult::HCCL_SUCCESS;
107 0 : }
108 :
109 : } // namespace Hccl
|