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_semi_ring_executor.h"
12 :
13 : namespace hccl {
14 :
15 0 : CollReduceScatterSemiRingExecutor::CollReduceScatterSemiRingExecutor(
16 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
17 0 : : CollReduceScatterRingFor91093Executor(dispatcher, topoMatcher)
18 0 : {}
19 :
20 0 : HcclResult CollReduceScatterSemiRingExecutor::CalcNotifyNum(u32 streamNum, u32& notifyNum)
21 : {
22 : // notify数量是从流的两倍 + 新增带notifyId的notify资源
23 0 : notifyNum = 2U * streamNum + (topoAttr_.deviceNumPerAggregation + 4U);
24 0 : HCCL_INFO("[CollReduceScatterSemiRingExecutor][CalcNotifyNum]tag[%s] notifyNum_ is [%u]", tag_.c_str(), notifyNum);
25 0 : return HCCL_SUCCESS;
26 : }
27 :
28 0 : HcclResult CollReduceScatterSemiRingExecutor::CalcStreamNum(u32& streamNum)
29 : {
30 0 : u32 totalStreamNum = LEVEL0_PLANE_NUM_IN_NPRING_DOUBLE + 1U;
31 :
32 0 : streamNum = totalStreamNum - 1U;
33 0 : HCCL_INFO("[CollReduceScatterSemiRingExecutor][CalcStreamNum] tag[%s] streamNum_[%u]", tag_.c_str(), streamNum);
34 0 : return HCCL_SUCCESS;
35 : }
36 :
37 0 : void CollReduceScatterSemiRingExecutor::ParseParam(const OpParam& param)
38 : {
39 0 : tag_ = param.tag;
40 :
41 : // 是否需要scratch memory
42 0 : if (isSupportSDMAReduce_ && topoAttr_.serverNum == 1) {
43 0 : scratchMemFlag_ = false;
44 : } else {
45 0 : scratchMemFlag_ = true;
46 : }
47 :
48 : // 记录图模式总数据量
49 0 : const HcclDataType dataType = param.GetDataType();
50 0 : totalSize_ = CalcTotalCount(param) * SIZE_TABLE[dataType];
51 0 : aicpuUnfoldMode_ = param.aicpuUnfoldMode;
52 0 : }
53 :
54 0 : HcclResult CollReduceScatterSemiRingExecutor::CalcLevel0CommInfo(
55 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
56 : {
57 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
58 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
59 :
60 0 : LevelNSubCommTransport& commTransportLevel0 = opTransport[COMM_LEVEL0];
61 0 : for (u32 subCommIndex = 0; subCommIndex < commTransportLevel0.size(); subCommIndex++) {
62 0 : for (auto& transportRequest : commTransportLevel0[subCommIndex].transportRequests) {
63 0 : transportRequest.notifyNum = topoAttr_.deviceNumPerAggregation + 4U; // 只传递额外的notify个数
64 0 : HCCL_INFO(
65 : "[CollReduceScatterSemiRingExecutor][CalcLevel0CommInfo] set extral notifyNum[%u]",
66 : transportRequest.notifyNum);
67 : }
68 : }
69 0 : return HCCL_SUCCESS;
70 0 : }
71 :
72 0 : HcclResult CollReduceScatterSemiRingExecutor::DoubleRingMidCountReduceScatter(
73 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
74 : const HcclReduceOp reductionOp, const std::vector<std::vector<Slice>> multRingsSliceZero, Stream stream,
75 : s32 profStage, const u64 baseOffset, const HcomCollOpInfo* opInfo,
76 : const std::vector<std::vector<Slice>> multRingsUserMemSlice, const bool retryEnable)
77 : {
78 : (void)tag;
79 : (void)baseOffset;
80 : (void)opInfo;
81 : (void)multRingsSliceZero;
82 : (void)retryEnable;
83 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterSemiRingExecutor] DoubleRingMidCountReduceScatter starts.");
84 :
85 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
86 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
87 :
88 : // 此处计算reduceAttr计算outputmem使用scratchmem
89 0 : u64 reduceAttr = GetReduceAttr(inputMem, outputMem, dataType, reductionOp);
90 : // 执行
91 0 : std::unique_ptr<AlgTemplateBase> executor = AlgTemplateRegistry::Instance().GetAlgTemplate(
92 0 : TemplateType::TEMPLATE_REDUCESCATTER_UNIFIED_MARCH, dispatcher_);
93 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_REDUCESCATTER_UNIFIED_MARCH in COMM_LEVEL0", __func__);
94 0 : CHK_SMART_PTR_NULL(executor);
95 :
96 0 : CHK_RET(executor->Prepare(
97 : stream, level0CommInfo, algResResp_->paramInputMem, algResResp_->paramOutputMem, inputMem, outputMem, count,
98 : algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux, dataType, reductionOp,
99 : multRingsUserMemSlice, reduceAttr));
100 :
101 0 : HcclResult ret = executor->RegisterProfiler(
102 : ((COMM_INDEX_0 + 1) << PROF_RINGINDEX_OFFSET_OF_PLANEID)
103 0 : + (level0CommInfo.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank,
104 : profStage, HCCL_EXEC_STEP_NOT_SET, stream);
105 0 : CHK_PRT_RET(
106 : ret != HCCL_SUCCESS,
107 : HCCL_ERROR(
108 : "[CollReduceScatterSemiRingExecutor][DoubleRingMidCountReduceScatter]"
109 : "Double ring ReduceScatter failed,return[%d]",
110 : ret),
111 : ret);
112 :
113 0 : CHK_RET(executor->RunAsync());
114 :
115 0 : HCCL_INFO("[CollReduceScatterSemiRingExecutor] ReduceScatter double ring level1 run success");
116 0 : return ret;
117 0 : }
118 :
119 0 : HcclResult CollReduceScatterSemiRingExecutor::RunIntraSeverReduceScatter(
120 : const std::string& tag, DeviceMem& inputMem, DeviceMem& outputMem, const u64 count, const HcclDataType& dataType,
121 : const HcclReduceOp& reductionOp, const std::vector<std::vector<Slice>>& multRingsSliceZero, const Stream& stream,
122 : s32 profStage, const u64 baseOffset, const HcomCollOpInfo* opInfo,
123 : const std::vector<std::vector<Slice>>& multRingsUserMemSlice, const bool retryEnable)
124 : {
125 0 : CHK_RET(DoubleRingMidCountReduceScatter(
126 : tag, inputMem, outputMem, count, dataType, reductionOp, multRingsSliceZero, stream, profStage, baseOffset,
127 : opInfo, multRingsUserMemSlice, retryEnable));
128 0 : return HCCL_SUCCESS;
129 : }
130 :
131 : REGISTER_EXEC("ReduceScatterSemiRingExecutor", ReduceScatterDoubleRingMidCount, CollReduceScatterSemiRingExecutor);
132 :
133 : } // namespace hccl
|