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_reduce_comm_executor.h"
12 :
13 : namespace hccl {
14 :
15 1 : CollReduceCommExecutor::CollReduceCommExecutor(
16 1 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
17 1 : : CollReduceExecutor(dispatcher, topoMatcher)
18 : {
19 1 : desc_.deterministic = 1;
20 1 : }
21 :
22 1 : HcclResult CollReduceCommExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
23 : {
24 1 : TransportMemType inputType = TransportMemType::RESERVED;
25 1 : TransportMemType outputType = TransportMemType::RESERVED;
26 1 : CalcTransportMemType(inputType, outputType);
27 1 : CHK_RET(CalcCombinedCommInfo(inputType, outputType, opTransport));
28 1 : return HCCL_SUCCESS;
29 : }
30 :
31 1 : HcclResult CollReduceCommExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
32 : {
33 1 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
34 0 : inputType = TransportMemType::CCL_INPUT;
35 0 : outputType = TransportMemType::CCL_OUTPUT;
36 : } else {
37 1 : inputType = TransportMemType::PARAM_INPUT;
38 1 : outputType = TransportMemType::PARAM_OUTPUT;
39 : }
40 1 : HCCL_INFO(
41 : "[CollReduceCommExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]", tag_.c_str(), inputType,
42 : outputType);
43 1 : return HCCL_SUCCESS;
44 : }
45 :
46 1 : HcclResult CollReduceCommExecutor::CalcCombinedCommInfo(
47 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
48 : {
49 1 : CommPlane commPlane = COMM_COMBINE;
50 1 : if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93) {
51 0 : commPlane = COMM_COMBINE_ORDER;
52 : }
53 :
54 1 : CommParaInfo commParaInfo(commPlane, CommType::COMM_TAG_MAX);
55 1 : commParaInfo.commType = CommType::COMM_TAG_RING_INNER;
56 1 : CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[commPlane], inputType, outputType));
57 :
58 1 : return HCCL_SUCCESS;
59 1 : }
60 :
61 1 : HcclResult CollReduceCommExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
62 : {
63 1 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] ReduceCommExecutor starts.", __func__);
64 1 : CommPlane commPlane = COMM_COMBINE;
65 1 : if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93) {
66 0 : commPlane = COMM_COMBINE_ORDER;
67 : }
68 :
69 1 : CHK_RET(CheckCommSize(commPlane, COMM_INDEX_0 + 1));
70 1 : SubCommInfo combinedCommInfo = GetSubCommInfo(commPlane, COMM_INDEX_0);
71 :
72 1 : u64 reduceAttr = GetReduceAttr(execMem.inputMem, execMem.outputMem, param.DataDes.dataType, param.reduceType);
73 :
74 1 : std::unique_ptr<AlgTemplateBase> tempAlg;
75 1 : tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_REDUCE_RING, dispatcher_);
76 1 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_REDUCE_RING in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
77 1 : CHK_SMART_PTR_NULL(tempAlg);
78 1 : CHK_RET(tempAlg->Prepare(reduceAttr));
79 :
80 : // 获取root
81 1 : u32 root = 0;
82 1 : CHK_RET(GetRankByUserRank(commPlane, COMM_INDEX_0, param.root, root));
83 :
84 1 : u32 rankSize = combinedCommInfo.localRankSize;
85 5 : CHK_RET(tempAlg->Prepare(
86 : execMem.inputMem, execMem.outputMem, execMem.outputMem, execMem.count, param.DataDes.dataType, param.stream,
87 : param.reduceType, root, std::vector<Slice>(0), 0));
88 :
89 1 : CHK_RET(tempAlg->RegisterProfiler(
90 : (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + combinedCommInfo.localRank, PROF_STAGE_0,
91 : HCCL_EXEC_STEP_NOT_SET, param.stream));
92 :
93 1 : CHK_RET(RunTemplate(tempAlg, combinedCommInfo));
94 1 : HCCL_INFO("[CollReduceCommExecutor] ReduceCommExecutor run success");
95 1 : return HCCL_SUCCESS;
96 1 : }
97 :
98 : REGISTER_EXEC("ReduceComm", ReduceComm, CollReduceCommExecutor);
99 :
100 : } // namespace hccl
|