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_ins_group.h"
19 : #include "ccu_context_reduce_scatter_mesh1d_2die.h"
20 : #include "ccu_temp_reduce_scatter_mesh_1D_2die.h"
21 : #include "alg_data_trans_wrapper.h"
22 :
23 : namespace Hccl {
24 :
25 : static CcuInstRegister<CcuContextReduceScatterMesh1D2Die>
26 : g_registrarReduceScatter(CcuInstType::CCU_REDUCE_SCATTER_MESH_1D_2DIE);
27 :
28 0 : CcuTempReduceScatterMesh1D2Die::CcuTempReduceScatterMesh1D2Die(const RankId virtualRank, const u32 tempRankSize,
29 : const std::vector<std::vector<RankId>> &tempVTopo,
30 0 : const std::map<RankId, u32> &tempVirtRankMap)
31 0 : : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
32 : {
33 0 : }
34 :
35 0 : CcuTempReduceScatterMesh1D2Die::~CcuTempReduceScatterMesh1D2Die()
36 : {
37 0 : }
38 :
39 0 : u32 CcuTempReduceScatterMesh1D2Die::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
40 : {
41 : (void)inBuffType;
42 : (void)outBuffType;
43 0 : return 2;
44 : }
45 :
46 0 : void CcuTempReduceScatterMesh1D2Die::InitReduceInfo(const ReduceOp &reduceOp, const DataType &dataType)
47 : {
48 0 : reduceOp_ = reduceOp;
49 0 : dataType_ = dataType;
50 0 : }
51 :
52 0 : HcclResult CcuTempReduceScatterMesh1D2Die::CalcRes(AlgTempResReq &tempResReq)
53 : {
54 0 : tempResReq.queNum = 1;
55 0 : tempResReq.streamNum = tempResReq.queNum + 1;
56 0 : HCCL_INFO("[CcuTempReduceScatterMesh1D2Die][CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
57 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
58 0 : return HcclResult::HCCL_SUCCESS;
59 : }
60 :
61 0 : uint64_t CcuTempReduceScatterMesh1D2Die::GetMaxSliceSize() const
62 : {
63 0 : u64 msSize = 4 * 1024;
64 0 : u64 loopNum = 64;
65 0 : u64 maxIterNum = 8192;
66 0 : return msSize * loopNum * maxIterNum; // 2G
67 : }
68 :
69 0 : HcclResult CcuTempReduceScatterMesh1D2Die::GenExtIns(const TempFuncs &tempFuncs, TemplateDataParams &tempAlgParams,
70 : const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
71 : {
72 : (void) tempFuncs;
73 0 : HCCL_INFO("[CcuTempReduceScatterMesh1D2Die] sliceSize[%llu], inputSliceStride[%llu], outputSliceStride[%llu], "
74 : "repeatNum[%llu], inputRepeatStride[%llu], outputRepeatStride[%llu], tailSize[%llu]",
75 : tempAlgParams.sliceSize, tempAlgParams.inputSliceStride, tempAlgParams.outputSliceStride,
76 : tempAlgParams.repeatNum, tempAlgParams.inputRepeatStride, tempAlgParams.outputRepeatStride,
77 : tempAlgParams.tailSize);
78 0 : CHK_PRT_RET(tempInsQues.empty(),
79 : HCCL_ERROR("[CcuTempReduceScatterMesh1D2Die] empty queue"), HcclResult::HCCL_E_INTERNAL);
80 0 : CHK_PTR_NULL(tempInsQues[0]);
81 0 : uint64_t inputAddr = BufferTypeToAddr(tempAlgParams.buffInfo.inBuffType) + tempAlgParams.buffInfo.inBuffBaseOff;
82 0 : uint64_t outputAddr = BufferTypeToAddr(tempAlgParams.buffInfo.outBuffType) + tempAlgParams.buffInfo.outBuffBaseOff;
83 : uint64_t scratchAddr
84 0 : = BufferTypeToAddr(tempAlgParams.buffInfo.scratBuffType) + tempAlgParams.buffInfo.scratchBuffBaseOff;
85 0 : uint64_t inputSliceStride = tempAlgParams.inputSliceStride;
86 0 : uint64_t outputSliceStride = tempAlgParams.outputSliceStride;
87 0 : u64 sliceSize = tempAlgParams.sliceSize;
88 :
89 : uint64_t token;
90 0 : CHK_RET(GetToken(op_, token));
91 0 : HCCL_INFO("[CcuTempReduceScatterMesh1D2Die] inputAddr[%llu], outputAddr[%llu], scratchAddr0[%llu], "
92 : "inputSliceStride[%llu], outputSliceStride[%llu]",
93 : inputAddr, outputAddr, scratchAddr, inputSliceStride, outputSliceStride);
94 :
95 0 : u32 dieNum = 2;
96 0 : std::vector<std::vector<LinkData>> linksForDie(dieNum);
97 0 : std::vector<RankGroup> rankGroupForDie(dieNum);
98 0 : for (auto &pair : tempLinks) {
99 0 : const RankId rank = pair.first;
100 0 : const std::vector<LinkData> &links = pair.second;
101 0 : if (links.size() == 0) {
102 0 : continue;
103 : }
104 0 : const LinkData &link = links[0];
105 0 : u32 dieIdx = link.GetLocalDieId();
106 0 : linksForDie[dieIdx].push_back(link);
107 0 : rankGroupForDie[dieIdx].AddRank(rank);
108 : }
109 0 : for (auto &rankGroup : rankGroupForDie) {
110 0 : rankGroup.AddRank(myRank_);
111 : }
112 0 : std::unique_ptr<CcuInsGroup> insGroupPtr = std::make_unique<CcuInsGroup>();
113 0 : for (u32 die = 0; die < dieNum; die++) {
114 0 : bool rmtReduceWithMyRank = linksForDie[die].size() > linksForDie[1 - die].size() ? false : true;
115 0 : CcuInstructionReduceScatterMesh1D2Die ccuInstruction;
116 0 : ccuInstruction.Init(tempVirtRankMap_[myRank_], op_, rmtReduceWithMyRank, tempVTopo_, inputAddr, outputAddr,
117 : scratchAddr, sliceSize, token);
118 0 : ccuInstruction.SetLinks(linksForDie[die]);
119 0 : ccuInstruction.SetRankGroup(rankGroupForDie[die]);
120 0 : ccuInstruction.SetCntCkeNum(3);
121 0 : insGroupPtr->Append(std::move(std::make_unique<CcuInstructionReduceScatterMesh1D2Die>(ccuInstruction)));
122 0 : }
123 0 : tempInsQues[0]->Append(std::move(insGroupPtr));
124 :
125 0 : DataSlice srcSlice(tempAlgParams.buffInfo.scratBuffType, tempAlgParams.buffInfo.scratchBuffBaseOff, sliceSize);
126 0 : DataSlice dstSlice(tempAlgParams.buffInfo.outBuffType, tempAlgParams.buffInfo.outBuffBaseOff, sliceSize);
127 0 : LocalReduce(tempInsQues[0], srcSlice, dstSlice, op_.dataType, op_.reduceOp);
128 :
129 0 : HCCL_INFO("[CcuTempReduceScatterMesh1D2Die] Template Run for all steps Ends.");
130 0 : return HcclResult::HCCL_SUCCESS;
131 0 : }
132 : } // namespace Hccl
|