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 "all_gather_ahc.h"
12 : #include "alg_template_register.h"
13 :
14 : namespace hccl {
15 :
16 0 : AllGatherAHC::AllGatherAHC(const HcclDispatcher dispatcher)
17 0 : : AllGatherAHCBase(dispatcher)
18 : {
19 0 : }
20 :
21 0 : AllGatherAHC::~AllGatherAHC()
22 : {
23 0 : }
24 :
25 0 : HcclResult AllGatherAHC::DisposeSubGroups(const u32 rank)
26 : {
27 0 : CommAHCBaseInfo::DisposeSubGroups(rank, globalSubGroups_, level0SubGroups_, level1SubGroups_);
28 0 : return HCCL_SUCCESS;
29 : }
30 :
31 0 : HcclResult AllGatherAHC::CommAHCInfoInit()
32 : {
33 0 : commAHCBaseInfo_.reset(new (std::nothrow) CommAHCAlignInfo(level0SubGroups_));
34 0 : CHK_SMART_PTR_NULL(commAHCBaseInfo_);
35 0 : CHK_RET(commAHCBaseInfo_->Init(AHCOpType::AHC_OP_TYPE_ALLGATHER, ahcAlgOption_));
36 0 : return HCCL_SUCCESS;
37 : }
38 :
39 0 : HcclResult AllGatherAHC::RunInterAllGather(u32 rank, const std::vector<LINK> &links,
40 : const std::unique_ptr<CommAHCBaseInfo> &commAHCBaseInfo)
41 : {
42 : // 获取当前rank的组间rank
43 0 : HCCL_INFO("[AllGatherAHC][RunInterAllGather] begin inter AllGather rank[%u]", rank);
44 :
45 0 : u32 interRank = commAHCBaseInfo->GetInterRank(0, rank);
46 :
47 : // 创建执行算子实列
48 0 : std::unique_ptr<AlgTemplateBase> tempAlg;
49 0 : commAHCBaseInfo->GetInterAlgTemplateOpInstance(AHCOpType::AHC_OP_TYPE_ALLGATHER, tempAlg, dispatcher_, reduceAttr_,
50 0 : extendFlag_, ahcExtendPreparePara_);
51 :
52 0 : std::vector<std::vector<Slice>> interSlicesVector;
53 0 : std::vector<std::vector<LINK>> interLinksVector;
54 0 : std::vector<u32> logicCardList;
55 0 : CHK_RET(commAHCBaseInfo->CalcInterSlicesAndLinks(rank, DataUnitSize(dataType_), count_, links, interLinksVector, interSlicesVector, logicCardList));
56 :
57 0 : HCCL_DEBUG("[AllGatherAHC][RunInterAllGather] run inst rank[%u] interRank[%u]",
58 : rank, interRank);
59 :
60 0 : for (u32 i = 0; i < logicCardList.size(); i++) {
61 0 : std::vector<Slice> interSlices = interSlicesVector[i];
62 0 : std::vector<LINK> interLinks = interLinksVector[i];
63 0 : if (interLinks.size() <= 1) {
64 0 : continue;
65 : }
66 0 : CHK_RET(RunInstance(interRank, interLinks, interSlices, tempAlg, AHCOpType::AHC_OP_TYPE_ALLGATHER));
67 0 : }
68 :
69 0 : HCCL_DEBUG("[AllGatherAHC][RunInterAllGather] end inter AllGather rank[%u]", rank);
70 :
71 0 : return HCCL_SUCCESS;
72 0 : }
73 : REGISTER_TEMPLATE(TemplateType::TEMPLATE_ALL_GATHER_AHC, AllGatherAHC);
74 : }
|