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_for_310p_doubling_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllReduceFor310PDoublingExecutor::CollAllReduceFor310PDoublingExecutor(
15 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
16 0 : : CollAllReduceExecutor(dispatcher, topoMatcher)
17 : {
18 0 : DMAReduceFlag_ = false;
19 0 : }
20 :
21 0 : HcclResult CollAllReduceFor310PDoublingExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
22 : {
23 0 : TransportMemType inputType = TransportMemType::RESERVED;
24 0 : TransportMemType outputType = TransportMemType::RESERVED;
25 :
26 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
27 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
28 0 : return HCCL_SUCCESS;
29 : }
30 :
31 : HcclResult
32 0 : CollAllReduceFor310PDoublingExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
33 : {
34 0 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
35 0 : inputType = TransportMemType::CCL_INPUT;
36 0 : outputType = TransportMemType::CCL_OUTPUT;
37 : } else {
38 0 : inputType = TransportMemType::PARAM_INPUT;
39 0 : outputType = TransportMemType::PARAM_OUTPUT;
40 : }
41 0 : HCCL_INFO(
42 : "[CollAllReduceFor310PDoublingExecutor][CalcTransportMemType]"
43 : "tag[%s] inputType[%d], outputType[%d]",
44 : tag_.c_str(), inputType, outputType);
45 0 : return HCCL_SUCCESS;
46 : }
47 :
48 0 : HcclResult CollAllReduceFor310PDoublingExecutor::CalcLevel0CommInfo(
49 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
50 : {
51 0 : HCCL_INFO("[CollAllReduceFor310PDoublingExecutor][CalcLevel0CommInfo]tag[%s] start", tag_.c_str());
52 :
53 0 : if (algType_.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_NP_HD) {
54 0 : CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_HALVING_DOUBLING);
55 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
56 0 : } else if (
57 0 : algType_.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_WHOLE_RING
58 0 : && algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_WHOLE_RING) {
59 0 : CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_RING_INNER);
60 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
61 0 : } else {
62 0 : HCCL_ERROR("unsupported algType %d plus %d", algType_.algoLevel0, algType_.algoLevel1);
63 0 : return HCCL_E_INTERNAL;
64 : }
65 :
66 0 : HCCL_INFO("[CollAllReduceFor310PDoublingExecutor][CalcLevel0CommInfo]tag[%s] Calc RingComm finish", tag_.c_str());
67 0 : return HCCL_SUCCESS;
68 : }
69 :
70 0 : HcclResult CollAllReduceFor310PDoublingExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
71 : {
72 0 : bool isInlineReduce = IsSupportSDMAReduce(
73 0 : execMem.inputMem.ptr(), execMem.outputMem.ptr(), param.DataDes.dataType, param.reduceType);
74 0 : HCCL_CONFIG_INFO(
75 : HCCL_ALG, "[CollAllReduceFor310PDoublingExecutor][KernelRun] userRank[%u] starts with isInlineReduce[%d]",
76 : topoAttr_.userRank, isInlineReduce);
77 0 : u64 reduceAttr = 0;
78 0 : if (isInlineReduce) {
79 0 : SalSetBitOne(reduceAttr, ATTR_POS_INLINE_REDUCE);
80 : }
81 :
82 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
83 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
84 :
85 0 : std::unique_ptr<AlgTemplateBase> tempAlg;
86 0 : tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_DOUBLING, dispatcher_);
87 0 : CHK_SMART_PTR_NULL(tempAlg);
88 0 : CHK_RET(tempAlg->Prepare(reduceAttr));
89 :
90 0 : CHK_RET(tempAlg->Prepare(
91 : execMem.inputMem, execMem.outputMem, execMem.outputMem, execMem.count, param.DataDes.dataType, param.stream,
92 : param.reduceType, LEVEL0_BRIDGE_RANK_ID, std::vector<Slice>(0), 0));
93 :
94 0 : CHK_RET(tempAlg->RegisterProfiler(
95 : (level0CommInfo.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank, PROF_STAGE_0,
96 : HCCL_EXEC_STEP_NOT_SET, param.stream));
97 :
98 0 : CHK_RET(RunTemplate(tempAlg, level0CommInfo));
99 0 : return HCCL_SUCCESS;
100 0 : }
101 :
102 : REGISTER_EXEC("AllReduceDoubling", AllReduceFor310PDoubling, CollAllReduceFor310PDoublingExecutor);
103 : } // namespace hccl
|