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