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 : #include <algorithm>
14 :
15 : #include "log.h"
16 : #include "template_utils.h"
17 :
18 : #include "ccu_temp_half_alltoallv_mesh_1D.h"
19 : #include "alg_data_trans_wrapper.h"
20 : #include "ccu_instruction_half_alltoallv_mesh1d.h"
21 : #include "ccu_rank_group.h"
22 : #include "ccu_ctx_creator_registry.h"
23 : #include "ccu_context_half_alltoallv_mesh1d.h"
24 :
25 : namespace Hccl {
26 :
27 : static CcuInstRegister<CcuContextHalfAllToAllVMesh1D> registrarAllToAll(CcuInstType::CCU_HALF_ALLTOALLV_MESH_1D);
28 :
29 0 : CcuTempHalfAllToAllVMesh1D::CcuTempHalfAllToAllVMesh1D(
30 : const RankId virtualRank, const u32 tempRankSize, 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 : if (tempVTopo_.size() != 1 || tempVTopo_[0].size() == 0) {
35 0 : THROW<InvalidParamsException>(StringFormat(
36 : "[CcuTempHalfAllToAllVMesh1D] Invalid tempVTopo "
37 : "Size[%u] or Invalid tempVTopo[0] size [%u].",
38 0 : tempVTopo_.size(), tempVTopo_[0].size()));
39 : }
40 0 : }
41 :
42 0 : CcuTempHalfAllToAllVMesh1D::~CcuTempHalfAllToAllVMesh1D() {}
43 :
44 0 : HcclResult CcuTempHalfAllToAllVMesh1D::CalcRes(AlgTempResReq& tempResReq)
45 : {
46 0 : tempResReq.queNum = 1;
47 0 : tempResReq.streamNum = tempResReq.queNum;
48 0 : HCCL_INFO("[CalcRes] tempResReq.queNum[%u]", tempResReq.queNum);
49 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
50 0 : return HcclResult::HCCL_SUCCESS;
51 : }
52 :
53 0 : void CcuTempHalfAllToAllVMesh1D::SetA2ASendRecvInfo(const A2ASendRecvInfo& sendRecvInfo) const
54 : {
55 : (void)sendRecvInfo;
56 0 : return;
57 : }
58 :
59 0 : HcclResult CcuTempHalfAllToAllVMesh1D::Run(
60 : const TempFuncs& tempFuncs, const RankSliceInfo& sliceInfoVec, const BuffInfo& buffInfo, const ResLinks& tempLinks,
61 : std::vector<InsQuePtr>& tempInsQues)
62 : {
63 0 : HCCL_INFO("[CcuTempHalfAllToAllVMesh1D] Run");
64 : (void)sliceInfoVec;
65 : (void)tempFuncs;
66 : (void)buffInfo;
67 :
68 0 : if (!op_.scratchMem) {
69 0 : HCCL_ERROR("[CcuTempHalfAllToAllVMesh1D][Run] Rank[%d] op_.scratchMem is null", myRank_);
70 0 : return HcclResult::HCCL_E_PTR;
71 : }
72 :
73 0 : uint64_t scratchAddr = static_cast<uint64_t>(op_.scratchMem->GetAddr());
74 :
75 : // 暂只支持在1D Fullmesh场景下使用两个context,故使用的link相同
76 0 : std::vector<LinkData> links;
77 0 : for (auto& pair : tempLinks) {
78 0 : if (pair.second.empty()) {
79 0 : continue;
80 : }
81 0 : links.push_back(pair.second[0]);
82 : }
83 0 : RankGroup rankGroup;
84 0 : for (auto& peer : tempVTopo_[0]) {
85 0 : rankGroup.AddRank(peer);
86 : }
87 0 : HCCL_INFO("[CcuTempHalfAllToAllVMesh1D] links.size[%zu]", links.size());
88 0 : int32_t signalNum = (tempRankSize_ + 16 - 1) / 16; // 每个CKE有16个bit
89 :
90 0 : std::unique_ptr<CcuInsGroup> insGroupPtr = std::make_unique<CcuInsGroup>();
91 0 : for (uint32_t mId = 0; mId < 2; mId++) { // 2个mission并发
92 0 : HCCL_INFO("[CcuTempHalfAllToAllVMesh1D][Run] MissionId[%u], Rank[%d], SignalNum[%d].", mId, myRank_, signalNum);
93 0 : CcuInstructionHalfAllToAllVMesh1D ins = CcuInstructionHalfAllToAllVMesh1D();
94 0 : ins.Init(mId, myRank_, scratchAddr, op_, tempVTopo_);
95 0 : ins.SetLinks(links);
96 0 : ins.SetRankGroup(rankGroup);
97 0 : ins.SetCntCkeNum(std::max(3, signalNum)); // 每个transport默认用3个CKE
98 0 : insGroupPtr->Append(std::move(std::make_unique<CcuInstructionHalfAllToAllVMesh1D>(ins)));
99 0 : }
100 0 : if (tempInsQues.size() == 0) {
101 0 : HCCL_ERROR("[CcuTempHalfAllToAllVMesh1D][Run] tempInsQues is empty!");
102 0 : return HcclResult::HCCL_E_INTERNAL;
103 : }
104 0 : CHK_PTR_NULL(tempInsQues[0]);
105 0 : tempInsQues[0]->Append(std::move(insGroupPtr)); // 只有一条流
106 0 : return HcclResult::HCCL_SUCCESS;
107 0 : }
108 : } // namespace Hccl
|