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_mesh_graph_pipeline_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllGatherMeshGraphPipelineExecutor::CollAllGatherMeshGraphPipelineExecutor(
15 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
16 0 : : CollAllGatherExecutor(dispatcher, topoMatcher)
17 0 : {}
18 :
19 0 : HcclResult CollAllGatherMeshGraphPipelineExecutor::CalcStreamNum(u32& streamNum)
20 : {
21 0 : u32 totalStreamNum = topoAttr_.deviceNumPerAggregation + 1U;
22 0 : streamNum = totalStreamNum - 1U;
23 0 : HCCL_INFO("[CollAllGatherMeshGraphPipelineExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
24 0 : return HCCL_SUCCESS;
25 : }
26 :
27 0 : HcclResult CollAllGatherMeshGraphPipelineExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
28 : {
29 0 : TransportMemType inputType = TransportMemType::RESERVED;
30 0 : TransportMemType outputType = TransportMemType::RESERVED;
31 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
32 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
33 0 : CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
34 0 : return HCCL_SUCCESS;
35 : }
36 :
37 : HcclResult
38 0 : CollAllGatherMeshGraphPipelineExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
39 : {
40 0 : inputType = TransportMemType::PARAM_INPUT;
41 0 : outputType = TransportMemType::PARAM_OUTPUT;
42 0 : HCCL_INFO(
43 : "[CollAllGatherMeshGraphPipelineExecutor][CalcTransportMemType]"
44 : "tag[%s] inputType[%d], outputType[%d]",
45 : tag_.c_str(), inputType, outputType);
46 0 : return HCCL_SUCCESS;
47 : }
48 :
49 0 : HcclResult CollAllGatherMeshGraphPipelineExecutor::CalcLevel0CommInfo(
50 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
51 : {
52 0 : CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_MESH);
53 0 : commParaInfo.meshSinglePlane = true;
54 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
55 0 : return HCCL_SUCCESS;
56 0 : }
57 :
58 : // PipeLine模式下使用Ring算法
59 0 : HcclResult CollAllGatherMeshGraphPipelineExecutor::CalcLevel1CommInfo(
60 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
61 : {
62 0 : CommParaInfo commParaInfo(COMM_LEVEL1, CommType::COMM_TAG_RING_INNER);
63 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL1], inputType, outputType));
64 0 : return HCCL_SUCCESS;
65 0 : }
66 :
67 0 : HcclResult CollAllGatherMeshGraphPipelineExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
68 : {
69 0 : HCCL_CONFIG_INFO(
70 : HCCL_ALG, "[CollAllGatherMeshGraphPipelineExecutor][KernelRun]AllGatherMeshGraphPipelineExecutor begins.");
71 :
72 : // 先获取 comm level0 和 comm level1 的value
73 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
74 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
75 0 : u32 commIndex = level0CommInfo.localRank;
76 0 : CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
77 0 : SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
78 :
79 : // 激活从流
80 0 : CHK_RET(ActiveSlaveStreams(param.stream));
81 :
82 0 : HcomCollOpInfo opInfo = {
83 0 : "", execMem.inputPtr, execMem.outputPtr, param.DataDes.count, param.DataDes.dataType, 0, HCCL_REDUCE_RESERVED,
84 0 : 0};
85 :
86 : std::unique_ptr<AlgTemplateBase> tempAlg
87 0 : = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_GRAPH_PIPELINE, dispatcher_);
88 0 : CHK_SMART_PTR_NULL(tempAlg);
89 0 : CHK_RET(tempAlg->Prepare(
90 : &opInfo, topoAttr_.userRank, execMem.count, execMem.inputMem, execMem.outputMem, level0CommInfo, level1CommInfo,
91 : const_cast<Stream&>(param.stream), algResResp_->slaveStreams, algResResp_->notifiesMain,
92 : algResResp_->notifiesAux));
93 0 : CHK_RET(tempAlg->RunAsync());
94 0 : return HCCL_SUCCESS;
95 0 : }
96 :
97 : REGISTER_EXEC("AllGatherMeshGraphPipelineExecutor", AllGatherGraphPipeline, CollAllGatherMeshGraphPipelineExecutor);
98 :
99 : } // namespace hccl
|