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