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_opbase_executor.h"
12 :
13 : namespace hccl {
14 :
15 2 : CollAllReduceMeshOpbaseExecutor::CollAllReduceMeshOpbaseExecutor(const HcclDispatcher dispatcher,
16 2 : std::unique_ptr<TopoMatcher> &topoMatcher)
17 2 : : CollAllReduceExecutor(dispatcher, topoMatcher)
18 : {
19 2 : CCLMemSlice_ = false;
20 2 : DMAReduceFlag_ = true;
21 2 : }
22 :
23 2 : HcclResult CollAllReduceMeshOpbaseExecutor::CalcStreamNum(u32& streamNum)
24 : {
25 2 : u32 totalStreamNum = 0U;
26 2 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB) {
27 0 : totalStreamNum = topoAttr_.deviceNumPerAggregation - 1U;
28 : } else {
29 2 : totalStreamNum = topoAttr_.deviceNumPerAggregation;
30 : }
31 2 : streamNum = totalStreamNum - 1U;
32 2 : HCCL_INFO("[CollAllReduceMeshOpbaseExecutor][CalcStreamNum] tag[%s] streamNum[%u].",
33 : tag_.c_str(), streamNum);
34 2 : return HCCL_SUCCESS;
35 : }
36 :
37 2 : HcclResult CollAllReduceMeshOpbaseExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
38 : {
39 2 : TransportMemType inputType = TransportMemType::RESERVED;
40 2 : TransportMemType outputType = TransportMemType::RESERVED;
41 2 : CHK_RET(CalcTransportMemType(inputType, outputType));
42 2 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
43 2 : return HCCL_SUCCESS;
44 : }
45 :
46 2 : HcclResult CollAllReduceMeshOpbaseExecutor::CalcTransportMemType(TransportMemType &inputType,
47 : TransportMemType &outputType)
48 : {
49 2 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
50 2 : inputType = TransportMemType::CCL_INPUT;
51 2 : outputType = TransportMemType::CCL_OUTPUT;
52 : } else {
53 0 : inputType = TransportMemType::PARAM_INPUT;
54 0 : outputType = TransportMemType::PARAM_OUTPUT;
55 : }
56 2 : HCCL_INFO("[CollAllReduceMeshOpbaseExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d].",
57 : tag_.c_str(), inputType, outputType);
58 2 : return HCCL_SUCCESS;
59 : }
60 :
61 2 : HcclResult CollAllReduceMeshOpbaseExecutor::CalcLevel0CommInfo(TransportMemType inputType,
62 : TransportMemType outputType,
63 : std::vector<LevelNSubCommTransport>& opTransport)
64 : {
65 2 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
66 2 : commParaLevel0.meshSinglePlane = true;
67 2 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
68 2 : return HCCL_SUCCESS;
69 2 : }
70 :
71 2 : u64 CollAllReduceMeshOpbaseExecutor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
72 : {
73 : // 中转内存单次最多能够接受的output count
74 2 : u64 maxCountPerLoop = cclBuffSize / unitSize * topoAttr_.userRankSize;
75 2 : return maxCountPerLoop;
76 : }
77 :
78 2 : bool CollAllReduceMeshOpbaseExecutor::IsHugeData(const u64 curSize)
79 : {
80 : // 只有server内通信,多QP哈希散列下不刷新子图
81 2 : bool hugeData = curSize > SDMA_SEND_MAX_SIZE;
82 2 : return hugeData;
83 : }
84 :
85 2 : bool CollAllReduceMeshOpbaseExecutor::IsSmallData(const u64 totalSize, const u64 curSize)
86 : {
87 2 : bool smallData = totalSize <= HCCL_SMALL_COUNT_256_KB;
88 2 : return smallData;
89 : }
90 :
91 2 : HcclResult CollAllReduceMeshOpbaseExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
92 : {
93 2 : HCCL_CONFIG_INFO(HCCL_ALG,
94 : "[CollAllReduceMeshOpbaseExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
95 2 : std::vector<Slice> dataSegsSlice; // 数据分成ranksize份,每份的起始偏移和大小
96 2 : std::unique_ptr<AlgTemplateBase> level0TempAlg;
97 :
98 2 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
99 2 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
100 :
101 2 : CHK_RET(ActiveSlaveStreams(param.stream));
102 2 : u64 reduceAttr = GetReduceAttr(execMem.inputMem, execMem.outputMem, param.DataDes.dataType, param.reduceType);
103 :
104 2 : HcomCollOpInfo opInfo = {
105 2 : "", execMem.inputPtr, execMem.outputPtr, execMem.count, param.DataDes.dataType, param.root, param.reduceType
106 2 : };
107 :
108 4 : level0TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_MESH_DIRECT,
109 2 : dispatcher_);
110 2 : CHK_SMART_PTR_NULL(level0TempAlg);
111 2 : CHK_RET(level0TempAlg->Prepare(reduceAttr, algResResp_->slaveStreams, algResResp_->notifiesMain,
112 : algResResp_->notifiesAux, level0CommInfo.localRank, level0CommInfo.localRankSize,
113 : topoAttr_.userRank, &opInfo));
114 6 : CHK_RET(level0TempAlg->Prepare(execMem.outputMem, execMem.outputMem, execMem.inputMem, execMem.count,
115 : param.DataDes.dataType, param.stream, param.reduceType, LEVEL0_BRIDGE_RANK_ID, dataSegsSlice, 0));
116 2 : CHK_RET(level0TempAlg->RegisterProfiler(
117 : (level0CommInfo.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank,
118 : PROF_STAGE_2,
119 : HCCL_EXEC_STEP_NOT_SET,
120 : param.stream));
121 :
122 2 : CHK_RET(RunTemplate(level0TempAlg, level0CommInfo));
123 2 : HCCL_INFO("AllReduce mesh opbase run success.");
124 2 : return HCCL_SUCCESS;
125 2 : }
126 :
127 : REGISTER_EXEC("AllReduceMeshOpbaseLoopExecutor", AllReduceMeshOpbase, CollAllReduceMeshOpbaseExecutor);
128 :
129 : } // namespace hccl
|