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 "coll_all_gather_semi_ring_executor.h"
12 :
13 : namespace hccl {
14 :
15 0 : CollAllGatherSemiRingExecutor::CollAllGatherSemiRingExecutor(const HcclDispatcher dispatcher,
16 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
17 0 : : CollAllGatherRingFor91093Executor(dispatcher, topoMatcher)
18 : {
19 0 : }
20 :
21 0 : HcclResult CollAllGatherSemiRingExecutor::CalcNotifyNum(u32 streamNum, u32 ¬ifyNum)
22 : {
23 : // notify数量是从流的两倍 + 新增带notifyId的notify资源
24 0 : notifyNum = 2U * streamNum + (topoAttr_.deviceNumPerAggregation + 4U);
25 0 : HCCL_INFO("[CollAllGatherSemiRingExecutor][CalcNotifyNum]tag[%s] notifyNum_ is [%u]", tag_.c_str(), notifyNum);
26 0 : return HCCL_SUCCESS;
27 : }
28 :
29 0 : HcclResult CollAllGatherSemiRingExecutor::CalcStreamNum(u32& streamNum)
30 : {
31 0 : u32 totalStreamNum = LEVEL0_PLANE_NUM_IN_NPRING_DOUBLE + 1U;
32 :
33 0 : streamNum = totalStreamNum - 1U;
34 0 : HCCL_INFO("[CollAllGatherSemiRingExecutor][CalcStreamNum] tag[%s] streamNum_[%u]",
35 : tag_.c_str(), streamNum);
36 0 : return HCCL_SUCCESS;
37 : }
38 :
39 0 : HcclResult CollAllGatherSemiRingExecutor::CalcLevel0CommInfo(TransportMemType inputType,
40 : TransportMemType outputType,
41 : std::vector<LevelNSubCommTransport>& opTransport)
42 : {
43 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
44 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
45 :
46 0 : LevelNSubCommTransport &commTransportLevel0 = opTransport[COMM_LEVEL0];
47 0 : for (u32 subCommIndex = 0; subCommIndex < commTransportLevel0.size(); subCommIndex++) {
48 0 : for (auto &transportRequest : commTransportLevel0[subCommIndex].transportRequests) {
49 0 : transportRequest.notifyNum = topoAttr_.deviceNumPerAggregation + 4U; //只传递额外的notify个数
50 0 : HCCL_INFO("[CollAllGatherSemiRingExecutor][CalcLevel0CommInfo] set extral notifyNum[%u]",
51 : transportRequest.notifyNum);
52 : }
53 : }
54 0 : return HCCL_SUCCESS;
55 0 : }
56 :
57 0 : HcclResult CollAllGatherSemiRingExecutor::DoubleRingMidCountAllGather(
58 : const std::string &tag, DeviceMem &inputMem, DeviceMem &outputMem,
59 : const u64 count, const HcclDataType &dataType, const std::vector<std::vector<Slice>> &multRingsSliceZero,
60 : const Stream &stream, s32 profStage, const u64 baseOffset, const HcomCollOpInfo *opInfo,
61 : const std::vector<std::vector<Slice>> &multRingsUserMemSlice)
62 : {
63 : (void) multRingsSliceZero;
64 : (void) baseOffset;
65 : (void) opInfo;
66 : (void) tag;
67 0 : HCCL_CONFIG_INFO(HCCL_ALG,
68 : "[CollAllGatherSemiRingExecutor][KernelRun]CollAllGatherSemiRingExecutor starts.");
69 :
70 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
71 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
72 :
73 : // 执行
74 0 : std::unique_ptr<AlgTemplateBase> executor = AlgTemplateRegistry::Instance().GetAlgTemplate(
75 0 : TemplateType::TEMPLATE_ALL_GATHER_UNIFIED_MARCH, dispatcher_);
76 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_GATHER_UNIFIED_MARCH in COMM_LEVEL0", __func__);
77 0 : CHK_SMART_PTR_NULL(executor);
78 :
79 0 : CHK_RET(executor->Prepare(stream, level0CommInfo, algResResp_->paramInputMem, algResResp_->paramOutputMem,
80 : inputMem, outputMem, count * SIZE_TABLE[dataType], algResResp_->slaveStreams, algResResp_->notifiesMain,
81 : algResResp_->notifiesAux, multRingsUserMemSlice));
82 :
83 0 : HcclResult ret = executor->RegisterProfiler(
84 : ((COMM_INDEX_0 + 1) << PROF_RINGINDEX_OFFSET_OF_PLANEID) +
85 0 : (level0CommInfo.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank,
86 : profStage, HCCL_EXEC_STEP_NOT_SET, stream);
87 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
88 : HCCL_ERROR("[CollAllGatherSemiRingExecutor][DoubleRingMidCountAllGather]Double ring "
89 : "AllGather failed, return[%d]", ret), ret);
90 :
91 0 : CHK_RET(executor->RunAsync());
92 :
93 0 : HCCL_INFO("[CollAllGatherSemiRingExecutor] AllGather double ring level1 run success");
94 0 : return ret;
95 0 : }
96 :
97 0 : HcclResult CollAllGatherSemiRingExecutor::RunIntraSeverAllGather(
98 : const std::string &tag, DeviceMem &inputMem, DeviceMem &outputMem,
99 : const u64 count, const HcclDataType &dataType, const std::vector<std::vector<Slice>> &multRingsSliceZero,
100 : const Stream &stream, s32 profStage, const u64 baseOffset, const HcomCollOpInfo *opInfo,
101 : const std::vector<std::vector<Slice>> &multRingsUserMemSlice)
102 : {
103 0 : CHK_RET(DoubleRingMidCountAllGather(tag, inputMem, outputMem, count, dataType,
104 : multRingsSliceZero, stream, profStage, baseOffset, opInfo, multRingsUserMemSlice));
105 0 : return HCCL_SUCCESS;
106 : }
107 :
108 : REGISTER_EXEC("AllGatherSemiRingExecutor", AllGatherDoubleRingMidCount,
109 : CollAllGatherSemiRingExecutor);
110 :
111 : } // namespace hccl
|