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