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 "ccu_temp_all_gather_v_mesh_1D.h"
15 : #include "ccu_instruction_all_gather_v_mesh1d.h"
16 : #include "ccu_context_all_gather_v_mesh1d.h"
17 :
18 : #include "log.h"
19 : #include "ccu_rank_group.h"
20 : #include "ccu_ctx_creator_registry.h"
21 : #include "alg_data_trans_wrapper.h"
22 :
23 : namespace Hccl {
24 : static CcuInstRegister<CcuContextAllGatherVMesh1D> g_registrarAllGatherV(CcuInstType::CCU_ALL_GATHER_V_MESH_1D_DIRECT);
25 :
26 0 : CcuTempAllGatherVMesh1D::CcuTempAllGatherVMesh1D(
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 : CcuTempAllGatherVMesh1D::~CcuTempAllGatherVMesh1D() {}
33 :
34 0 : HcclResult CcuTempAllGatherVMesh1D::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 0 : HcclResult CcuTempAllGatherVMesh1D::GenExtIns(
44 : const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
45 : std::vector<InsQuePtr>& tempInsQues)
46 : {
47 0 : CHK_PRT_RET(tempInsQues.empty(), HCCL_ERROR("[CcuTempAllGatherVMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
48 0 : CHK_PTR_NULL(tempInsQues[0]);
49 0 : opMode_ = tempFuncs.opMode;
50 0 : buffInfo_ = templateDataParams.buffInfo;
51 0 : CcuInstructionAllGatherVMesh1D ccuIns;
52 0 : std::vector<uint64_t> dimSize;
53 0 : dimSize.push_back(tempRankSize_);
54 :
55 : uint64_t inputAddr
56 0 : = BufferTypeToAddr(templateDataParams.buffInfo.inBuffType) + templateDataParams.buffInfo.inBuffBaseOff;
57 : uint64_t outputAddr
58 0 : = BufferTypeToAddr(templateDataParams.buffInfo.outBuffType) + templateDataParams.buffInfo.outBuffBaseOff;
59 :
60 0 : uint64_t mySliceSize = templateDataParams.sliceSize;
61 0 : uint64_t mySliceOutputOffset = templateDataParams.outputSliceStride;
62 :
63 : uint64_t token;
64 0 : CHK_RET(GetToken(op_, token));
65 :
66 0 : ccuIns.Init(
67 0 : static_cast<uint32_t>(myRank_), inputAddr, outputAddr, mySliceSize, mySliceOutputOffset, token, op_,
68 0 : tempVTopo_);
69 0 : HCCL_INFO(
70 : "[CcuTempAllGatherVMesh1D] Run Init: myRank_[%d], dimSize[%llu], inputAddr[%llu],"
71 : "outputAddr[%llu], mySliceSize[%llu], mySliceOutputOffset[%llu]",
72 : myRank_, dimSize[0], inputAddr, outputAddr, mySliceSize, mySliceOutputOffset);
73 :
74 0 : std::vector<LinkData> links;
75 0 : for (auto& pair : tempLinks) {
76 0 : if (pair.second.empty()) {
77 0 : continue;
78 : }
79 0 : links.push_back(pair.second[0]);
80 : }
81 0 : HCCL_INFO("[CcuTempAllGatherVMesh1D] links.size[%zu]", links.size());
82 0 : ccuIns.SetLinks(links);
83 :
84 0 : RankGroup rankGroup;
85 0 : for (auto& peer : tempVTopo_[0]) {
86 0 : rankGroup.AddRank(peer);
87 : }
88 0 : ccuIns.SetRankGroup(rankGroup);
89 :
90 0 : u32 cntCkeNum = 3;
91 0 : ccuIns.SetCntCkeNum(cntCkeNum);
92 0 : tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionAllGatherVMesh1D>(ccuIns)));
93 :
94 0 : return HcclResult::HCCL_SUCCESS;
95 0 : }
96 : } // namespace Hccl
|