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_v_mesh_graph_pipeline_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllGatherVMeshGraphPipelineExecutor::CollAllGatherVMeshGraphPipelineExecutor(
15 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
16 0 : : CollAllGatherVExecutor(dispatcher, topoMatcher)
17 0 : {}
18 :
19 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::CalcStreamNum(u32& streamNum)
20 : {
21 0 : u32 totalStreamNum = topoAttr_.deviceNumPerAggregation + 1U;
22 0 : streamNum = totalStreamNum - 1U;
23 0 : HCCL_INFO(
24 : "[CollAllGatherVMeshGraphPipelineExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
25 0 : return HCCL_SUCCESS;
26 : }
27 :
28 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
29 : {
30 0 : TransportMemType inputType = TransportMemType::RESERVED;
31 0 : TransportMemType outputType = TransportMemType::RESERVED;
32 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
33 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
34 0 : CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
35 0 : return HCCL_SUCCESS;
36 : }
37 :
38 : HcclResult
39 0 : CollAllGatherVMeshGraphPipelineExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
40 : {
41 0 : inputType = TransportMemType::PARAM_INPUT;
42 0 : outputType = TransportMemType::PARAM_OUTPUT;
43 0 : HCCL_INFO(
44 : "[CollAllGatherVMeshGraphPipelineExecutor][CalcTransportMemType]tag[%s] inputType[%d], outputType[%d]",
45 : tag_.c_str(), inputType, outputType);
46 0 : return HCCL_SUCCESS;
47 : }
48 :
49 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::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 CollAllGatherVMeshGraphPipelineExecutor::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 CollAllGatherVMeshGraphPipelineExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
68 : {
69 0 : HCCL_CONFIG_INFO(
70 : HCCL_ALG, "[CollAllGatherVMeshGraphPipelineExecutor][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 : // allgatherv 计算slice,数据分成ranksize份,每份的起始偏移和大小
80 0 : u32 perDataSize = SIZE_TABLE[param.VDataDes.dataType];
81 0 : std::vector<Slice> outputSlices;
82 0 : const auto counts = static_cast<u64*>(param.VDataDes.counts);
83 0 : const auto displs = static_cast<u64*>(param.VDataDes.displs);
84 0 : for (u32 rank = 0; rank < topoAttr_.userRankSize; ++rank) {
85 0 : Slice userslice;
86 0 : userslice.offset = displs[rank] * perDataSize;
87 0 : userslice.size = counts[rank] * perDataSize;
88 0 : outputSlices.emplace_back(std::move(userslice));
89 : }
90 :
91 : // 激活从流
92 0 : CHK_RET(ActiveSlaveStreams(param.stream));
93 :
94 0 : HcomCollOpInfo opInfo
95 0 : = {"", execMem.inputPtr, execMem.outputPtr, 0, param.VDataDes.dataType, 0, HCCL_REDUCE_RESERVED, 0};
96 :
97 0 : std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
98 0 : TemplateType::TEMPLATE_ALL_GATHER_V_GRAPH_PIPELINE, dispatcher_);
99 0 : CHK_SMART_PTR_NULL(tempAlg);
100 0 : CHK_RET(tempAlg->Prepare(
101 : &opInfo, topoAttr_.userRank, execMem.count, execMem.inputMem, execMem.outputMem, level0CommInfo, level1CommInfo,
102 : const_cast<Stream&>(param.stream), algResResp_->slaveStreams, algResResp_->notifiesMain,
103 : algResResp_->notifiesAux, outputSlices));
104 0 : CHK_RET(tempAlg->RunAsync());
105 0 : return HCCL_SUCCESS;
106 0 : }
107 :
108 : REGISTER_EXEC("AllGatherVMeshGraphPipelineExecutor", AllGatherVGraphPipeline, CollAllGatherVMeshGraphPipelineExecutor);
109 :
110 : } // namespace hccl
|