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