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_reduce_scatter_mesh_graph_pipeline_executor.h"
12 :
13 : namespace hccl {
14 0 : CollReduceScatterMeshGraphPipelineExecutor::CollReduceScatterMeshGraphPipelineExecutor(
15 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
16 0 : : CollReduceScatterExecutor(dispatcher, topoMatcher)
17 0 : {}
18 :
19 0 : void CollReduceScatterMeshGraphPipelineExecutor::ParseParam(const OpParam& param)
20 : {
21 0 : tag_ = param.tag;
22 0 : aicpuUnfoldMode_ = param.aicpuUnfoldMode;
23 0 : }
24 :
25 0 : HcclResult CollReduceScatterMeshGraphPipelineExecutor::CalcStreamNum(u32& streamNum)
26 : {
27 0 : streamNum = topoAttr_.deviceNumPerAggregation;
28 0 : HCCL_INFO(
29 : "[CollReduceScatterMeshGraphPipelineExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
30 0 : return HCCL_SUCCESS;
31 : }
32 :
33 0 : HcclResult CollReduceScatterMeshGraphPipelineExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
34 : {
35 0 : TransportMemType inputType = TransportMemType::RESERVED;
36 0 : TransportMemType outputType = TransportMemType::RESERVED;
37 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
38 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
39 0 : CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
40 0 : return HCCL_SUCCESS;
41 : }
42 :
43 0 : HcclResult CollReduceScatterMeshGraphPipelineExecutor::CalcTransportMemType(
44 : TransportMemType& inputType, TransportMemType& outputType)
45 : {
46 0 : inputType = TransportMemType::PARAM_INPUT;
47 0 : outputType = TransportMemType::PARAM_OUTPUT;
48 0 : HCCL_INFO(
49 : "[CollReduceScatterMeshGraphPipelineExecutor][CalcTransportMemType]tag[%s] inputType[%d], outputType[%d]",
50 : tag_.c_str(), inputType, outputType);
51 0 : return HCCL_SUCCESS;
52 : }
53 :
54 0 : HcclResult CollReduceScatterMeshGraphPipelineExecutor::CalcLevel0CommInfo(
55 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
56 : {
57 0 : CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_MESH);
58 0 : commParaInfo.meshSinglePlane = true;
59 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
60 0 : return HCCL_SUCCESS;
61 0 : }
62 :
63 : // PipeLine模式下使用Ring算法
64 0 : HcclResult CollReduceScatterMeshGraphPipelineExecutor::CalcLevel1CommInfo(
65 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
66 : {
67 0 : CommParaInfo commParaInfo(COMM_LEVEL1, CommType::COMM_TAG_RING_INNER);
68 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL1], inputType, outputType));
69 0 : return HCCL_SUCCESS;
70 0 : }
71 :
72 0 : HcclResult CollReduceScatterMeshGraphPipelineExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
73 : {
74 0 : HCCL_CONFIG_INFO(
75 : HCCL_ALG, "[CollReduceScatterMeshGraphPipelineExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
76 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
77 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
78 0 : u32 commIndex = level0CommInfo.localRank;
79 0 : CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
80 0 : SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
81 :
82 0 : u32 unitSize = SIZE_TABLE[param.DataDes.dataType];
83 0 : DeviceMem userInMem = DeviceMem::create(param.inputPtr, param.DataDes.count * unitSize);
84 0 : u64 reduceAttr = GetReduceAttr(userInMem, userInMem, param.DataDes.dataType, param.reduceType);
85 :
86 0 : CHK_RET(ActiveSlaveStreams(param.stream));
87 :
88 0 : std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
89 0 : TemplateType::TEMPLATE_REDUCESCATTER_GRAPH_PIPELINE, dispatcher_);
90 0 : CHK_SMART_PTR_NULL(tempAlg);
91 :
92 0 : HcomCollOpInfo opInfo = {"",
93 0 : execMem.inputPtr,
94 0 : execMem.outputPtr,
95 0 : param.DataDes.count,
96 0 : param.DataDes.dataType,
97 0 : param.root,
98 0 : param.reduceType,
99 0 : 0};
100 :
101 0 : CHK_RET(tempAlg->Prepare(
102 : &opInfo, execMem.inputMem, param.DataDes.count, 0, 0, level0CommInfo, level1CommInfo,
103 : const_cast<Stream&>(param.stream), algResResp_->slaveStreams, algResResp_->notifiesMain,
104 : algResResp_->notifiesAux, reduceAttr));
105 0 : CHK_RET(tempAlg->RunAsync());
106 :
107 0 : return HCCL_SUCCESS;
108 0 : }
109 :
110 : REGISTER_EXEC(
111 : "ReduceScatterMeshGraphPipelineExecutor", ReduceScatterMeshGraphPipeline,
112 : CollReduceScatterMeshGraphPipelineExecutor);
113 : } // namespace hccl
|