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_reduce_mesh_graph_pipeline_executor.h"
12 :
13 : namespace hccl {
14 : // 准入条件: pipeLine && 910B && 图模式 && sdmaReduce && rdmaReduce && 多Mesh && MeshTopo && 非确定性
15 0 : CollAllReduceMeshGraphPipelineExecutor::CollAllReduceMeshGraphPipelineExecutor(const HcclDispatcher dispatcher,
16 0 : std::unique_ptr<TopoMatcher> &topoMatcher): CollAllReduceExecutor(dispatcher, topoMatcher)
17 : {
18 0 : }
19 :
20 0 : HcclResult CollAllReduceMeshGraphPipelineExecutor::CalcStreamNum(u32& streamNum)
21 : {
22 0 : u32 totalStreamNum = topoAttr_.deviceNumPerAggregation;
23 0 : streamNum = totalStreamNum - 1U;
24 0 : HCCL_INFO("[CollAllReduceMeshGraphPipelineExecutor][CalcStreamNum] tag[%s] streamNum[%u]",
25 : tag_.c_str(), streamNum);
26 0 : return HCCL_SUCCESS;
27 : }
28 :
29 0 : HcclResult CollAllReduceMeshGraphPipelineExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
30 : {
31 0 : TransportMemType inputType = TransportMemType::RESERVED;
32 0 : TransportMemType outputType = TransportMemType::RESERVED;
33 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
34 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
35 0 : CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
36 0 : return HCCL_SUCCESS;
37 : }
38 :
39 0 : HcclResult CollAllReduceMeshGraphPipelineExecutor::CalcTransportMemType(TransportMemType &inputType,
40 : TransportMemType &outputType)
41 : {
42 0 : inputType = TransportMemType::PARAM_INPUT;
43 0 : outputType = TransportMemType::PARAM_OUTPUT;
44 0 : HCCL_INFO("[CollAllReduceMeshGraphPipelineExecutor][CalcTransportMemType]" \
45 : "tag[%s] inputType[%d], outputType[%d]",
46 : tag_.c_str(), inputType, outputType);
47 0 : return HCCL_SUCCESS;
48 : }
49 :
50 0 : HcclResult CollAllReduceMeshGraphPipelineExecutor::CalcLevel0CommInfo(TransportMemType inputType,
51 : TransportMemType outputType,
52 : std::vector<LevelNSubCommTransport>& opTransport)
53 : {
54 0 : CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_MESH);
55 0 : commParaInfo.meshSinglePlane = true;
56 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
57 0 : return HCCL_SUCCESS;
58 0 : }
59 :
60 : // PipeLine模式下使用Ring算法
61 0 : HcclResult CollAllReduceMeshGraphPipelineExecutor::CalcLevel1CommInfo(TransportMemType inputType,
62 : TransportMemType outputType,
63 : std::vector<LevelNSubCommTransport>& opTransport)
64 : {
65 0 : CommParaInfo commParaInfo(COMM_LEVEL1, CommType::COMM_TAG_RING_INNER);
66 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL1], inputType, outputType));
67 0 : return HCCL_SUCCESS;
68 0 : }
69 :
70 0 : HcclResult CollAllReduceMeshGraphPipelineExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
71 : {
72 0 : HCCL_CONFIG_INFO(HCCL_ALG,
73 : "[CollAllReduceMeshGraphPipelineExecutor][Run]CollAllReduceMeshGraphPipelineExecutor begins.");
74 :
75 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
76 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
77 0 : u32 commIndex = level0CommInfo.localRank;
78 0 : CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
79 0 : SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
80 :
81 0 : CHK_RET(ActiveSlaveStreams(param.stream));
82 :
83 0 : u64 reduceAttr = GetReduceAttr(execMem.inputMem, execMem.inputMem, param.DataDes.dataType, param.reduceType);
84 :
85 0 : HcomCollOpInfo opInfo = {
86 0 : "", execMem.inputPtr, execMem.outputPtr, execMem.count, param.DataDes.dataType, param.root, param.reduceType
87 0 : };
88 :
89 0 : std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
90 0 : TemplateType::TEMPLATE_ALLREDUCE_GRAPH_PIPELINE, dispatcher_);
91 0 : CHK_SMART_PTR_NULL(tempAlg);
92 0 : CHK_RET(tempAlg->Prepare(reduceAttr));
93 0 : CHK_RET(tempAlg->Prepare(&opInfo, execMem.inputMem, execMem.outputMem, execMem.count,
94 : level1CommInfo, level0CommInfo, const_cast<Stream&>(param.stream),
95 : algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux));
96 0 : CHK_RET(tempAlg->RunAsync());
97 0 : return HCCL_SUCCESS;
98 0 : }
99 :
100 : REGISTER_EXEC("AllReduceMeshGraphPipelineExecutor",
101 : AllReduceMeshGraphPipeline, CollAllReduceMeshGraphPipelineExecutor);
102 :
103 : } // namespace hccl
|