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("[CollAllGatherVMeshGraphPipelineExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
24 0 : return HCCL_SUCCESS;
25 : }
26 :
27 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::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 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::CalcTransportMemType(
38 : TransportMemType &inputType, TransportMemType &outputType)
39 : {
40 0 : inputType = TransportMemType::PARAM_INPUT;
41 0 : outputType = TransportMemType::PARAM_OUTPUT;
42 0 : HCCL_INFO("[CollAllGatherVMeshGraphPipelineExecutor][CalcTransportMemType]tag[%s] inputType[%d], outputType[%d]",
43 : tag_.c_str(), inputType, outputType);
44 0 : return HCCL_SUCCESS;
45 : }
46 :
47 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::CalcLevel0CommInfo(
48 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport> &opTransport)
49 : {
50 0 : CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_MESH);
51 0 : commParaInfo.meshSinglePlane = true;
52 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
53 0 : return HCCL_SUCCESS;
54 0 : }
55 :
56 : // PipeLine模式下使用Ring算法
57 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::CalcLevel1CommInfo(
58 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport> &opTransport)
59 : {
60 0 : CommParaInfo commParaInfo(COMM_LEVEL1, CommType::COMM_TAG_RING_INNER);
61 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL1], inputType, outputType));
62 0 : return HCCL_SUCCESS;
63 0 : }
64 :
65 0 : HcclResult CollAllGatherVMeshGraphPipelineExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
66 : {
67 0 : HCCL_CONFIG_INFO(HCCL_ALG,
68 : "[CollAllGatherVMeshGraphPipelineExecutor][KernelRun]AllGatherMeshGraphPipelineExecutor begins.");
69 :
70 : // 先获取 comm level0 和 comm level1 的value
71 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
72 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
73 0 : u32 commIndex = level0CommInfo.localRank;
74 0 : CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
75 0 : SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
76 :
77 : // allgatherv 计算slice,数据分成ranksize份,每份的起始偏移和大小
78 0 : u32 perDataSize = SIZE_TABLE[param.VDataDes.dataType];
79 0 : std::vector<Slice> outputSlices;
80 0 : const auto counts = static_cast<u64*>(param.VDataDes.counts);
81 0 : const auto displs = static_cast<u64*>(param.VDataDes.displs);
82 0 : for (u32 rank = 0; rank < topoAttr_.userRankSize; ++rank) {
83 0 : Slice userslice;
84 0 : userslice.offset = displs[rank] * perDataSize;
85 0 : userslice.size = counts[rank] * perDataSize;
86 0 : outputSlices.emplace_back(std::move(userslice));
87 : }
88 :
89 : // 激活从流
90 0 : CHK_RET(ActiveSlaveStreams(param.stream));
91 :
92 0 : HcomCollOpInfo opInfo = {
93 0 : "", execMem.inputPtr, execMem.outputPtr, 0, param.VDataDes.dataType, 0, HCCL_REDUCE_RESERVED};
94 :
95 : std::unique_ptr<AlgTemplateBase> tempAlg =
96 0 : AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_V_GRAPH_PIPELINE, dispatcher_);
97 0 : CHK_SMART_PTR_NULL(tempAlg);
98 0 : CHK_RET(tempAlg->Prepare(&opInfo, topoAttr_.userRank, execMem.count, execMem.inputMem, execMem.outputMem,
99 : level0CommInfo, level1CommInfo, const_cast<Stream &>(param.stream),
100 : algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux, outputSlices));
101 0 : CHK_RET(tempAlg->RunAsync());
102 0 : return HCCL_SUCCESS;
103 0 : }
104 :
105 : REGISTER_EXEC("AllGatherVMeshGraphPipelineExecutor", AllGatherVGraphPipeline, CollAllGatherVMeshGraphPipelineExecutor);
106 :
107 : } // namespace hccl
|