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