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_scatter_v_mesh_executor.h"
12 : #include "alg_template_register.h"
13 :
14 : namespace hccl {
15 :
16 0 : CollReduceScatterVMeshExecutor::CollReduceScatterVMeshExecutor(
17 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
18 0 : : CollReduceScatterVExecutor(dispatcher, topoMatcher)
19 : {
20 0 : DMAReduceFlag_ = false;
21 0 : }
22 :
23 0 : void CollReduceScatterVMeshExecutor::ParseParam(const OpParam& param)
24 : {
25 : // 910B 图模式非确定计算,inlineReduce使能,MESH拓扑场景下,创建一个mesh平面
26 : bool isInlineReduce
27 0 : = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.VDataDes.dataType, param.reduceType);
28 0 : meshSinglePlane_ = (topoAttr_.deviceType == DevType::DEV_TYPE_910B)
29 0 : && topoMatcher_->GetExternalInputHcclDeterministic() == DETERMINISTIC_DISABLE && isInlineReduce
30 0 : && (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB);
31 :
32 : // 记录图模式总数据量
33 0 : u64 totalSize = 0;
34 0 : const u64* counts = static_cast<const u64*>(param.VDataDes.counts);
35 0 : for (u32 i = 0; i < topoAttr_.userRankSize; i++) {
36 0 : totalSize += counts[i] * SIZE_TABLE[param.VDataDes.dataType];
37 : }
38 0 : totalSize_ = totalSize;
39 0 : scratchMemFlag_ = false; // mesh算法不需要使用scrachMem
40 0 : aicpuUnfoldMode_ = param.aicpuUnfoldMode;
41 0 : }
42 :
43 0 : HcclResult CollReduceScatterVMeshExecutor::CalcStreamNum(u32& streamNum)
44 : {
45 0 : u32 totalStreamNum = topoAttr_.deviceNumPerAggregation > 1U ? topoAttr_.deviceNumPerAggregation - 1U : 1U;
46 0 : streamNum = totalStreamNum - 1U;
47 0 : HCCL_INFO("[CollReduceScatterVMeshExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
48 0 : return HCCL_SUCCESS;
49 : }
50 :
51 0 : HcclResult CollReduceScatterVMeshExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
52 : {
53 0 : TransportMemType inputType = TransportMemType::RESERVED;
54 0 : TransportMemType outputType = TransportMemType::RESERVED;
55 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
56 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
57 0 : return HCCL_SUCCESS;
58 : }
59 :
60 : HcclResult
61 0 : CollReduceScatterVMeshExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
62 : {
63 0 : inputType = TransportMemType::PARAM_INPUT;
64 0 : outputType = TransportMemType::PARAM_OUTPUT;
65 :
66 0 : HCCL_INFO(
67 : "[CollReduceScatterVMeshExecutor][CalcTransportMemType] tag[%s] inputType[%d],"
68 : " outputType[%d]",
69 : tag_.c_str(), inputType, outputType);
70 0 : return HCCL_SUCCESS;
71 : }
72 :
73 0 : HcclResult CollReduceScatterVMeshExecutor::CalcLevel0CommInfo(
74 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
75 : {
76 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
77 0 : commParaLevel0.meshSinglePlane = meshSinglePlane_;
78 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
79 0 : return HCCL_SUCCESS;
80 0 : }
81 :
82 0 : HcclResult CollReduceScatterVMeshExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
83 : {
84 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterVMeshExecutor] ReduceScatterV mesh run");
85 0 : HcclDataType dataType = param.VDataDes.dataType;
86 0 : const u32 unitSize = SIZE_TABLE[dataType];
87 :
88 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
89 0 : SubCommInfo subCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
90 0 : u32 rankSize = subCommInfo.localRankSize;
91 :
92 0 : CHK_RET(ActiveSlaveStreams(param.stream));
93 :
94 : /* *******************节点内reducescatter ******************************************/
95 : // reduce_scatter_v 计算slice,数据分成ranksize份,每份的起始偏移和大小
96 0 : std::vector<Slice> inputSlices;
97 0 : const auto counts = static_cast<u64*>(param.VDataDes.counts);
98 0 : const auto displs = static_cast<u64*>(param.VDataDes.displs);
99 0 : for (u32 rank = 0; rank < rankSize; ++rank) {
100 0 : Slice userslice;
101 0 : userslice.offset = displs[rank] * unitSize;
102 0 : userslice.size = counts[rank] * unitSize;
103 0 : inputSlices.emplace_back(std::move(userslice));
104 : }
105 :
106 0 : u64 reduceAttr = GetReduceAttr(execMem.inputMem, execMem.outputMem, dataType, param.reduceType);
107 : std::unique_ptr<AlgTemplateBase> tempAlg
108 0 : = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_REDUCESCATTER_MESH_ATOMIC, dispatcher_);
109 0 : CHK_SMART_PTR_NULL(tempAlg);
110 :
111 0 : CHK_RET(tempAlg->Prepare(
112 : execMem.inputMem, execMem.outputMem, execMem.scratchMem, execMem.count, dataType, param.stream,
113 : param.reduceType, LEVEL0_BRIDGE_RANK_ID, inputSlices, 0, reduceAttr, algResResp_->slaveStreams,
114 : algResResp_->notifiesMain, algResResp_->notifiesAux, topoAttr_.userRank));
115 :
116 0 : CHK_RET(tempAlg->RegisterProfiler(
117 : (subCommInfo.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + subCommInfo.localRank, PROF_STAGE_0,
118 : HCCL_EXEC_STEP_NOT_SET, param.stream));
119 :
120 0 : CHK_RET(RunTemplate(tempAlg, subCommInfo));
121 :
122 0 : return HCCL_SUCCESS;
123 0 : }
124 :
125 : REGISTER_EXEC("ReduceScatterVMeshExecutor", ReduceScatterVMesh, CollReduceScatterVMeshExecutor);
126 : } // namespace hccl
|