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_temp_reduce_mesh_1D.h"
17 : #include "alg_data_trans_wrapper.h"
18 : #include "ccu_instruction_reduce_mesh1d.h"
19 : #include "ccu_rank_group.h"
20 : #include "ccu_ctx_creator_registry.h"
21 : #include "ccu_context_reduce_mesh1d.h"
22 :
23 : namespace Hccl {
24 :
25 : static CcuInstRegister<CcuContextReduceMesh1D> registrarReduce(
26 : CcuInstType::CCU_REDUCE_MESH_1D_DIRECT);
27 :
28 0 : CcuTempReduceMesh1D::CcuTempReduceMesh1D(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 : CcuTempReduceMesh1D::~CcuTempReduceMesh1D()
36 : {
37 0 : }
38 :
39 0 : void CcuTempReduceMesh1D::InitReduceInfo(const ReduceOp &reduceOp, const DataType &dataType)
40 : {
41 0 : reduceOp_ = reduceOp;
42 0 : dataType_ = dataType;
43 0 : }
44 :
45 0 : HcclResult CcuTempReduceMesh1D::CalcRes(AlgTempResReq &tempResReq)
46 : {
47 0 : tempResReq.queNum = 1;
48 0 : tempResReq.streamNum = tempResReq.queNum;
49 0 : HCCL_DEBUG("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
50 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
51 0 : return HcclResult::HCCL_SUCCESS;
52 : }
53 :
54 0 : HcclResult CcuTempReduceMesh1D::GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &templateDataParams, const ResLinks &tempLinks,
55 : std::vector<InsQuePtr> &tempInsQues)
56 : {
57 0 : CHK_PRT_RET(tempInsQues.empty(),
58 : HCCL_ERROR("[CcuTempReduceMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
59 0 : CHK_PTR_NULL(tempInsQues[0]);
60 0 : buffInfo_ = templateDataParams.buffInfo;
61 0 : opMode_ = tempFuncs.opMode;
62 0 : CcuInstructionReduceMesh1D ccuIns;
63 0 : rootId_ = op_.root;
64 0 : std::vector<uint64_t> dimSize;
65 0 : dimSize.push_back(tempRankSize_);
66 :
67 0 : uint32_t rankId = myRank_;
68 0 : uint32_t rootId = rootId_;
69 0 : const CollAlgOperator &op = op_;
70 0 : const std::vector<std::vector<RankId>> &tempVTopo = tempVTopo_;
71 0 : uint64_t inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff;
72 0 : uint64_t outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
73 : uint64_t token;
74 0 : CHK_RET(GetToken(op_, token));
75 0 : uint64_t inputSliceStride = templateDataParams.inputSliceStride;
76 0 : uint64_t outputSliceStride = templateDataParams.outputSliceStride;
77 0 : uint64_t inputRepeatStride = templateDataParams.inputRepeatStride;
78 0 : uint64_t outputRepeatStride = templateDataParams.outputRepeatStride;
79 0 : uint64_t repeatNum = templateDataParams.repeatNum;
80 0 : uint64_t normalSliceSize = templateDataParams.sliceSize;
81 0 : uint64_t lastSliceSize = templateDataParams.tailSize;
82 0 : uint64_t repeatNumVar = UINT64_MAX - repeatNum;
83 :
84 0 : ccuIns.Init(rankId, rootId, op, tempVTopo, inputAddr, outputAddr, token, inputSliceStride, outputSliceStride, repeatNum,
85 : inputRepeatStride, outputRepeatStride, normalSliceSize, lastSliceSize, repeatNumVar);
86 :
87 0 : HCCL_DEBUG("[CcuTempReduceMesh1D] Run Init: rankId[%u], inputAddr[%llu], "
88 : "outputAddr[%llu], inputSliceStride[%llu], outputSliceStride[%llu], repeatNum[%llu], "
89 : "inputRepeatStride[%llu], outputRepeatStride[%llu], normalSliceSize[%llu], lastSliceSize[%llu], repeatNumVar[%llu]",
90 : rankId, inputAddr, outputAddr, inputSliceStride, outputSliceStride, repeatNum,
91 : inputRepeatStride, outputRepeatStride, normalSliceSize, lastSliceSize, repeatNumVar);
92 :
93 0 : std::vector<LinkData> links;
94 0 : for (auto &pair : tempLinks) {
95 0 : if (pair.second.empty()) {
96 0 : continue;
97 : }
98 0 : links.push_back(pair.second[0]);
99 : }
100 0 : HCCL_DEBUG("[CcuTempReduceMesh1D] links.size[%llu]", links.size());
101 0 : ccuIns.SetLinks(links);
102 :
103 0 : RankGroup rankGroup;
104 0 : for (auto &peer : tempVTopo_[0]) {
105 0 : rankGroup.AddRank(peer);
106 : }
107 0 : u32 cntCkeNum = 4;
108 0 : ccuIns.SetCntCkeNum(cntCkeNum);
109 0 : ccuIns.SetRankGroup(rankGroup);
110 0 : HCCL_DEBUG("CcuInstructionReduceMesh1D is [%s]", ccuIns.Describe().c_str());
111 0 : tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionReduceMesh1D>(ccuIns)));
112 :
113 0 : return HcclResult::HCCL_SUCCESS;
114 0 : }
115 :
116 0 : HcclResult CcuTempReduceMesh1D::GenExtIns(const RankGraph *rankGraph,
117 : const TemplateInfo &tmpInfo,
118 : const std::vector<InsQuePtr> &tempInsQues) const
119 : {
120 : (void)rankGraph;
121 : (void)tmpInfo;
122 : (void)tempInsQues;
123 : // 框架解析aicpuIns,算法的algCompnnetLite在device侧直接调用Run()
124 0 : return HcclResult::HCCL_SUCCESS;
125 : }
126 :
127 : } // namespace Hccl
|