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_opbase_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllGatherMeshOpbaseExecutor::CollAllGatherMeshOpbaseExecutor(const HcclDispatcher dispatcher,
15 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
16 0 : : CollAllGatherExecutor(dispatcher, topoMatcher)
17 : {
18 0 : DMAReduceFlag_ = true;
19 0 : }
20 :
21 0 : HcclResult CollAllGatherMeshOpbaseExecutor::CalcStreamNum(u32& streamNum)
22 : {
23 0 : u32 totalStreamNum = topoAttr_.deviceNumPerAggregation;
24 0 : streamNum = totalStreamNum - 1U;
25 0 : HCCL_INFO("[CollAllGatherMeshOpbaseExecutor][CalcStreamNum] tag[%s] streamNum[%u]",
26 : tag_.c_str(), streamNum);
27 0 : return HCCL_SUCCESS;
28 : }
29 :
30 0 : HcclResult CollAllGatherMeshOpbaseExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
31 : {
32 0 : TransportMemType inputType = TransportMemType::RESERVED;
33 0 : TransportMemType outputType = TransportMemType::RESERVED;
34 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
35 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
36 0 : return HCCL_SUCCESS;
37 : }
38 :
39 0 : HcclResult CollAllGatherMeshOpbaseExecutor::CalcTransportMemType(TransportMemType &inputType,
40 : TransportMemType &outputType)
41 : {
42 0 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
43 0 : inputType = TransportMemType::CCL_INPUT;
44 0 : outputType = TransportMemType::CCL_OUTPUT;
45 : } else {
46 0 : inputType = TransportMemType::PARAM_INPUT;
47 0 : outputType = TransportMemType::PARAM_OUTPUT;
48 : }
49 0 : HCCL_INFO("[CollAllGatherMeshOpbaseExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]",
50 : tag_.c_str(), inputType, outputType);
51 0 : return HCCL_SUCCESS;
52 : }
53 :
54 0 : HcclResult CollAllGatherMeshOpbaseExecutor::CalcLevel0CommInfo(TransportMemType inputType,
55 : TransportMemType outputType,
56 : std::vector<LevelNSubCommTransport>& opTransport)
57 : {
58 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
59 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
60 0 : return HCCL_SUCCESS;
61 0 : }
62 :
63 0 : u64 CollAllGatherMeshOpbaseExecutor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
64 : {
65 0 : u64 maxCountPerLoop = (cclBuffSize - HCCL_MIN_SLICE_ALIGN_910B) / HCCL_MIN_SLICE_ALIGN
66 0 : * HCCL_MIN_SLICE_ALIGN / unitSize;
67 0 : return maxCountPerLoop;
68 : }
69 :
70 0 : bool CollAllGatherMeshOpbaseExecutor::IsHugeData(const u64 curSize)
71 : {
72 : // 该算法只涉及mesh内,不对RDMA多qp做强制刷新
73 0 : bool hugeData = curSize > SDMA_SEND_MAX_SIZE;
74 0 : return hugeData;
75 : }
76 :
77 0 : bool CollAllGatherMeshOpbaseExecutor::IsSmallData(const u64 size)
78 : {
79 0 : return topoAttr_.deviceType == DevType::DEV_TYPE_910_93;
80 : }
81 :
82 0 : HcclResult CollAllGatherMeshOpbaseExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
83 : {
84 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollAllGatherMeshOpbaseExecutor] AllGather KernelRun");
85 0 : u8 *curInputPtr = static_cast<u8 *>(execMem.inputPtr);
86 0 : u8 *curOutputPtr = static_cast<u8 *>(execMem.outputPtr);
87 0 : CHK_PTR_NULL(curInputPtr);
88 0 : CHK_PTR_NULL(curOutputPtr);
89 :
90 : // 获取子通信域信息
91 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
92 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
93 :
94 0 : u64 inputMemSize = execMem.inputMem.size();
95 0 : u64 baseOffset = 0;
96 0 : std::vector<Slice> dataSegsSlice; // 数据分成ranksize份,每份的起始偏移和大小
97 :
98 0 : CHK_RET(ActiveSlaveStreams(param.stream));
99 :
100 : // 抽取当前用于多环AllGather 的output内存数据
101 0 : DeviceMem currentOutputMem = execMem.outputMem.range(baseOffset, inputMemSize); // 减少dma out大小
102 0 : CHK_SMART_PTR_NULL(currentOutputMem);
103 :
104 : // DMA消减场景,打包opInfo
105 0 : HcomCollOpInfo opInfo = {
106 0 : "", execMem.inputPtr, execMem.outputPtr, param.DataDes.count, param.DataDes.dataType, 0, HCCL_REDUCE_RESERVED
107 0 : };
108 :
109 0 : std::unique_ptr<AlgTemplateBase> level0TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
110 0 : TemplateType::TEMPLATE_ALL_GATHER_MESH_DIRECT, dispatcher_);
111 0 : CHK_SMART_PTR_NULL(level0TempAlg);
112 0 : CHK_RET(level0TempAlg->Prepare(algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux,
113 : topoAttr_.userRank, &opInfo, level0CommInfo.localRank, level0CommInfo.localRankSize));
114 0 : CHK_RET(level0TempAlg->Prepare(currentOutputMem, currentOutputMem, execMem.inputMem, execMem.count,
115 : param.DataDes.dataType, param.stream, HCCL_REDUCE_RESERVED, LEVEL0_BRIDGE_RANK_ID,
116 : dataSegsSlice, baseOffset));
117 :
118 0 : u32 rankSize = level0CommInfo.localRankSize;
119 0 : CHK_RET(level0TempAlg->RegisterProfiler((rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank,
120 : PROF_STAGE_1, HCCL_EXEC_STEP_NOT_SET, param.stream));
121 :
122 0 : CHK_RET(RunTemplate(level0TempAlg, level0CommInfo));
123 :
124 0 : HCCL_INFO("AllGather mesh level0 run success");
125 0 : return HCCL_SUCCESS;
126 0 : }
127 :
128 : REGISTER_EXEC("AllGatherMeshOpbaseExecutor", AllGatherOpbase, CollAllGatherMeshOpbaseExecutor);
129 : } // namespace hccl
|