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_instruction_scatter_mesh1d.h"
17 : #include "ccu_rank_group.h"
18 : #include "ccu_ctx_creator_registry.h"
19 : #include "ccu_context_scatter_mesh1d.h"
20 : #include "ccu_temp_scatter_mesh_1D.h"
21 : #include "dev_mode.h"
22 :
23 : namespace Hccl {
24 :
25 : static CcuInstRegister<CcuContextScatterMesh1D> g_registrarScatter(CcuInstType::CCU_SCATTER_MESH_1D_DIRECT);
26 :
27 0 : CcuTempScatterMesh1D::CcuTempScatterMesh1D(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 : CcuTempScatterMesh1D::~CcuTempScatterMesh1D()
35 : {
36 0 : }
37 :
38 0 : uint64_t CcuTempScatterMesh1D::GetExpandedMode() const
39 : {
40 0 : return DeviceMode::CCU;
41 : }
42 :
43 0 : uint64_t CcuTempScatterMesh1D::GetMaxSliceSize() const
44 : {
45 0 : return UB_MAX_DATA_SIZE;
46 : }
47 :
48 0 : HcclResult CcuTempScatterMesh1D::CalcRes(AlgTempResReq &tempResReq)
49 : {
50 0 : tempResReq.queNum = 1;
51 0 : tempResReq.streamNum = tempResReq.queNum;
52 0 : HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
53 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
54 0 : return HcclResult::HCCL_SUCCESS;
55 : }
56 :
57 0 : HcclResult CcuTempScatterMesh1D::GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &templateDataParams,
58 : const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
59 : {
60 0 : CHK_PRT_RET(tempInsQues.empty(),
61 : HCCL_ERROR("[CcuTempScatterMesh1D] empty queue"), HcclResult::HCCL_E_INTERNAL);
62 0 : CHK_PTR_NULL(tempInsQues[0]);
63 0 : HCCL_INFO("[CcuTempScatterMesh1D] Run.");
64 0 : opMode_ = tempFuncs.opMode;
65 0 : buffInfo_ = templateDataParams.buffInfo;
66 0 : CcuInstructionScatterMesh1D ccuIns;
67 0 : uint32_t virtRankId = tempVirtRankMap_[myRank_];
68 :
69 0 : const CollAlgOperator &op = op_;
70 0 : const std::vector<std::vector<RankId>> &tempVTopo = tempVTopo_;
71 0 : uint64_t rootId = tempVirtRankMap_[rootId_];
72 : uint64_t inputAddr
73 0 : = BufferTypeToAddr(templateDataParams.buffInfo.inBuffType) + templateDataParams.buffInfo.inBuffBaseOff;
74 : uint64_t outputAddr
75 0 : = BufferTypeToAddr(templateDataParams.buffInfo.outBuffType) + templateDataParams.buffInfo.outBuffBaseOff;
76 : uint64_t token;
77 0 : CHK_RET(GetToken(op_, token));
78 0 : uint64_t inputSliceStride = templateDataParams.inputSliceStride;
79 0 : uint64_t outputSliceStride = templateDataParams.outputSliceStride;
80 0 : uint64_t inputRepeatStride = templateDataParams.inputRepeatStride;
81 0 : uint64_t outputRepeatStride = templateDataParams.outputRepeatStride;
82 0 : uint64_t normalSliceSize = templateDataParams.sliceSize;
83 0 : uint64_t lastSliceSize = templateDataParams.tailSize;
84 0 : uint64_t repeatNum = templateDataParams.repeatNum;
85 0 : uint64_t repeatNumVar = UINT64_MAX - repeatNum; // 在context中让repeatNumVar累加到UINT64_MAX结束ccu while循环
86 :
87 0 : ccuIns.Init(virtRankId, rootId, op, tempVTopo, inputAddr, outputAddr, token, inputSliceStride, outputSliceStride,
88 : inputRepeatStride, outputRepeatStride, normalSliceSize, lastSliceSize, repeatNumVar);
89 0 : HCCL_INFO("[CcuTempScatterMesh1D] Run Init: virtRankId[%u], rankId[%d], inputAddr[%llu], "
90 : "outputAddr[%llu], inputSliceStride[%llu], outputSliceStride[%llu], "
91 : "inputRepeatStride[%llu], outputRepeatStride[%llu], normalSliceSize[%llu], lastSliceSize[%llu], "
92 : "repeatNumVar[%llu]",
93 : virtRankId, myRank_, inputAddr, outputAddr, inputSliceStride, outputSliceStride, inputRepeatStride,
94 : outputRepeatStride, normalSliceSize, lastSliceSize, repeatNumVar);
95 :
96 0 : if (normalSliceSize == 0) {
97 0 : HCCL_INFO("[CcuTempScatterMesh1D] DataCount == 0, Template Run Ends.");
98 0 : return HCCL_SUCCESS;
99 : }
100 :
101 0 : std::vector<LinkData> links;
102 0 : for (auto &pair : tempLinks) {
103 0 : if (pair.second.empty()) {
104 0 : continue;
105 : }
106 0 : links.push_back(pair.second[0]);
107 : }
108 0 : HCCL_INFO("[CcuTempScatterMesh1D] links.size[%zu]", links.size());
109 0 : ccuIns.SetLinks(links);
110 :
111 0 : RankGroup rankGroup;
112 0 : for (auto &peer : tempVTopo_[0]) {
113 0 : rankGroup.AddRank(peer);
114 : }
115 0 : u32 cntCkeNum = 3;
116 0 : ccuIns.SetCntCkeNum(cntCkeNum);
117 0 : ccuIns.SetRankGroup(rankGroup);
118 0 : HCCL_INFO("CcuInstructionScatterMesh1D is [%s]", ccuIns.Describe().c_str());
119 0 : tempInsQues[0]->Append(std::move(std::make_unique<CcuInstructionScatterMesh1D>(ccuIns)));
120 :
121 0 : return HcclResult::HCCL_SUCCESS;
122 0 : }
123 :
124 0 : HcclResult CcuTempScatterMesh1D::GenExtIns(const RankGraph *rankGraph, const TemplateInfo &tmpInfo,
125 : const std::vector<InsQuePtr> &tempInsQues) const
126 : {
127 : (void)rankGraph;
128 : (void)tmpInfo;
129 : (void)tempInsQues;
130 0 : return HcclResult::HCCL_SUCCESS;
131 : }
132 :
133 : } // namespace Hccl
|