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_reduce_scatter_v_mesh_1D.h"
15 : #include "ccu_instruction_reduce_scatter_v_mesh1d.h"
16 : #include "ccu_context_reduce_scatter_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<CcuContextReduceScatterVMesh1D>
25 : g_registrarReduceScatterV(CcuInstType::CCU_REDUCE_SCATTER_V_MESH_1D_DIRECT);
26 :
27 0 : CcuTempReduceScatterVMesh1D::CcuTempReduceScatterVMesh1D(
28 : const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
29 0 : const std::map<RankId, u32>& tempVirtRankMap)
30 0 : : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
31 0 : {}
32 :
33 0 : CcuTempReduceScatterVMesh1D::~CcuTempReduceScatterVMesh1D() {}
34 :
35 0 : void CcuTempReduceScatterVMesh1D::InitReduceInfo(const ReduceOp& reduceOp, const DataType& dataType)
36 : {
37 0 : reduceOp_ = reduceOp;
38 0 : dataType_ = dataType;
39 0 : }
40 :
41 0 : HcclResult CcuTempReduceScatterVMesh1D::CalcRes(AlgTempResReq& tempResReq)
42 : {
43 0 : tempResReq.queNum = 1;
44 0 : tempResReq.streamNum = tempResReq.queNum;
45 0 : HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
46 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
47 0 : return HcclResult::HCCL_SUCCESS;
48 : }
49 :
50 0 : HcclResult CcuTempReduceScatterVMesh1D::GenExtIns(
51 : const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
52 : std::vector<InsQuePtr>& tempInsQues)
53 : {
54 0 : CHK_PRT_RET(
55 : tempInsQues.empty(), HCCL_ERROR("[CcuTempReduceScatterVMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
56 0 : CHK_PTR_NULL(tempInsQues[0]);
57 0 : opMode_ = tempFuncs.opMode;
58 0 : buffInfo_ = templateDataParams.buffInfo;
59 0 : CcuInstructionReduceScatterVMesh1D ccuIns;
60 0 : std::vector<uint64_t> dimSize;
61 0 : dimSize.push_back(tempRankSize_);
62 :
63 : uint64_t inputAddr
64 0 : = BufferTypeToAddr(templateDataParams.buffInfo.inBuffType) + templateDataParams.buffInfo.inBuffBaseOff;
65 : uint64_t outputAddr
66 0 : = BufferTypeToAddr(templateDataParams.buffInfo.outBuffType) + templateDataParams.buffInfo.outBuffBaseOff;
67 :
68 0 : uint64_t mySliceSize = templateDataParams.sliceSize;
69 0 : uint64_t mySliceInputOffset = templateDataParams.inputSliceStride;
70 :
71 : uint64_t token;
72 0 : CHK_RET(GetToken(op_, token));
73 :
74 0 : ccuIns.Init(
75 0 : static_cast<uint32_t>(myRank_), inputAddr, outputAddr, mySliceSize, mySliceInputOffset, token, op_, tempVTopo_);
76 0 : HCCL_INFO(
77 : "[CcuTempReduceScatterVMesh1D] Run Init: myRank_[%d], dimSize[%llu], inputAddr[%llu],"
78 : "outputAddr[%llu], mySliceSize[%llu], mySliceInputOffset[%llu]",
79 : myRank_, dimSize[0], inputAddr, outputAddr, mySliceSize, mySliceInputOffset);
80 :
81 0 : std::vector<LinkData> links;
82 0 : for (auto& pair : tempLinks) {
83 0 : if (pair.second.empty()) {
84 0 : continue;
85 : }
86 0 : links.push_back(pair.second[0]);
87 : }
88 0 : HCCL_INFO("[CcuTempReduceScatterVMesh1D] links.size[%zu]", links.size());
89 0 : ccuIns.SetLinks(links);
90 :
91 0 : RankGroup rankGroup;
92 0 : for (auto& peer : tempVTopo_[0]) {
93 0 : rankGroup.AddRank(peer);
94 : }
95 0 : ccuIns.SetRankGroup(rankGroup);
96 :
97 0 : u32 cntCkeNum = 3;
98 0 : ccuIns.SetCntCkeNum(cntCkeNum);
99 0 : tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionReduceScatterVMesh1D>(ccuIns)));
100 :
101 0 : return HcclResult::HCCL_SUCCESS;
102 0 : }
103 : } // namespace Hccl
|