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