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