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_temp_all_to_all_mesh_1D_2Die.h"
17 : #include "alg_data_trans_wrapper.h"
18 : #include "ccu_instruction_all_to_all_mesh1d_2Die.h"
19 : #include "ccu_rank_group.h"
20 : #include "ccu_ctx_creator_registry.h"
21 : #include "ccu_context_all_to_all_mesh1d_2Die.h"
22 : #include "ccu_ins_group.h"
23 :
24 : namespace Hccl {
25 :
26 : static CcuInstRegister<CcuContextAllToAllMesh1D2Die> registrarAllToAll(CcuInstType::CCU_ALLTOALL_MESH_1D_2DIE);
27 :
28 0 : CcuTempAllToAllMesh1D2Die::CcuTempAllToAllMesh1D2Die(
29 : const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
30 0 : const std::map<RankId, u32>& tempVirtRankMap)
31 0 : : CcuAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
32 0 : {}
33 :
34 0 : CcuTempAllToAllMesh1D2Die::~CcuTempAllToAllMesh1D2Die() {}
35 :
36 0 : HcclResult CcuTempAllToAllMesh1D2Die::CalcRes(AlgTempResReq& tempResReq)
37 : {
38 0 : tempResReq.queNum = 1;
39 0 : tempResReq.streamNum = tempResReq.queNum + 1;
40 0 : HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
41 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
42 0 : return HcclResult::HCCL_SUCCESS;
43 : }
44 :
45 0 : HcclResult CcuTempAllToAllMesh1D2Die::SetBuffBlockSize(const u64 buffBlockSize)
46 : {
47 0 : CHK_PRT_RET(
48 : buffBlockSize == 0,
49 : HCCL_ERROR("[CcuTempAllToAllMesh1D2Die][SetBuffBlockSize] buffBlockSize should not be zero"),
50 : HcclResult::HCCL_E_PARA);
51 0 : buffBlockSize_ = buffBlockSize;
52 0 : return HcclResult::HCCL_SUCCESS;
53 : }
54 :
55 0 : HcclResult CcuTempAllToAllMesh1D2Die::SetConcurrentSendRecvNum(const u32 concurrentSendRecvNum)
56 : {
57 0 : CHK_PRT_RET(
58 : concurrentSendRecvNum == 0,
59 : HCCL_ERROR("[CcuTempAllToAllMesh1D2Die][SetConcurrentSendRecvNum] concurrentSendRecvNum should not be zero"),
60 : HcclResult::HCCL_E_PARA);
61 0 : concurrentSendRecvNum_ = concurrentSendRecvNum;
62 0 : return HcclResult::HCCL_SUCCESS;
63 : }
64 :
65 0 : HcclResult CcuTempAllToAllMesh1D2Die::GenExtIns(
66 : const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
67 : std::vector<InsQuePtr>& tempInsQues)
68 : {
69 0 : HCCL_INFO("[CcuTempAllToAllMesh1D2Die] Run");
70 0 : opMode_ = tempFuncs.opMode;
71 0 : buffInfo_ = templateDataParams.buffInfo;
72 :
73 0 : CcuInstructionAllToAllMesh1D2Die ccuInsAllToAllMesh1D2Die;
74 0 : CHK_PRT_RET(
75 : tempInsQues.empty(), HCCL_ERROR("[CcuTempAllToAllMesh1D2Die] empty queue"), HcclResult::HCCL_E_INTERNAL);
76 0 : CHK_PTR_NULL(tempInsQues[0]);
77 :
78 0 : std::vector<uint64_t> dimSize;
79 0 : dimSize.push_back(tempRankSize_);
80 :
81 0 : uint64_t inputAddr = BufferTypeToAddr(buffInfo_.inBuffType) + buffInfo_.inBuffBaseOff;
82 0 : uint64_t outputAddr = BufferTypeToAddr(buffInfo_.outBuffType) + buffInfo_.outBuffBaseOff;
83 : uint64_t token;
84 0 : CHK_RET(GetToken(op_, token));
85 0 : uint64_t sliceSize = templateDataParams.sliceSize;
86 0 : uint64_t inputSliceStride = templateDataParams.inputSliceStride;
87 0 : uint64_t outputSliceStride = templateDataParams.outputSliceStride;
88 0 : uint64_t outBuffBaseOff = buffInfo_.outBuffBaseOff;
89 :
90 0 : HCCL_INFO(
91 : "[CcuTempAllToAllMesh1D2Die] myRank_[%d], dimSize[%llu], inputAddr[%llu],"
92 : "outputAddr[%llu], sliceSize[%llu], outBuffBaseOff[%llu], inputSliceStride[%llu],",
93 : myRank_, dimSize[0], inputAddr, outputAddr, sliceSize, outBuffBaseOff, inputSliceStride);
94 :
95 : // key表示为dieId
96 0 : std::map<uint32_t, std::vector<LinkData>> linksDie;
97 0 : std::map<uint32_t, RankGroup> rankGroup;
98 :
99 0 : for (auto& link : tempLinks) {
100 0 : std::vector<LinkData> linkData = link.second;
101 0 : RankId peerRankId = link.first;
102 0 : if (link.second.empty()) {
103 0 : continue;
104 : }
105 0 : linksDie[linkData[0].GetLocalDieId()].push_back(linkData[0]);
106 0 : rankGroup[linkData[0].GetLocalDieId()].AddRank(peerRankId);
107 0 : }
108 :
109 0 : HCCL_INFO(
110 : "[CcuTempAllToAllMesh1D2Die] linksDie0Size[%zu], linksDie1Size[%zu]", linksDie[0].size(), linksDie[1].size());
111 :
112 0 : rankGroup[0].AddRank(myRank_);
113 0 : rankGroup[1].AddRank(myRank_);
114 :
115 0 : std::unique_ptr<CcuInsGroup> insGroupPtr = std::make_unique<CcuInsGroup>();
116 0 : for (uint32_t dieId = 0; dieId < 2; dieId++) { // 2Die算法,需要下发 2 条通信指令
117 0 : CcuInstructionAllToAllMesh1D2Die ccuInstruction;
118 0 : bool withMyRank = linksDie[dieId].size() > linksDie[1 - dieId].size() ? false : true;
119 0 : u32 bitNum = min(linksDie[dieId].size(), linksDie[1 - dieId].size()) + 1;
120 0 : ccuInstruction.Init(
121 0 : static_cast<uint32_t>(myRank_), inputAddr, outputAddr, sliceSize, token, inputSliceStride,
122 0 : outputSliceStride, outBuffBaseOff, op_, tempVTopo_, withMyRank, bitNum);
123 0 : ccuInstruction.SetLinks(linksDie[dieId]);
124 0 : ccuInstruction.SetRankGroup(rankGroup[dieId]);
125 0 : ccuInstruction.SetCntCkeNum(5); // 每个transport用5个CKE
126 0 : insGroupPtr->Append(std::move(std::make_unique<CcuInstructionAllToAllMesh1D2Die>(ccuInstruction)));
127 0 : }
128 0 : tempInsQues[0]->Append(std::move(insGroupPtr)); // 只有一条que
129 0 : HCCL_INFO("[CcuTempAllToAllMesh1D2Die] Template Run for all steps Ends.");
130 0 : return HcclResult::HCCL_SUCCESS;
131 0 : }
132 : } // namespace Hccl
|