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_aligned_reduce_scatter_double_ring_for_910_93_executor.h"
12 : #include "alg_template_register.h"
13 :
14 : namespace hccl {
15 2 : CollAlignedReduceScatterDoubleRingFor91093Executor::CollAlignedReduceScatterDoubleRingFor91093Executor(
16 2 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
17 2 : : CollReduceScatterRingFor91093Executor(dispatcher, topoMatcher)
18 : {
19 2 : DMAReduceFlag_ = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
20 2 : }
21 :
22 0 : HcclResult CollAlignedReduceScatterDoubleRingFor91093Executor::DoubleRingReduceScatter(
23 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
24 : const HcclReduceOp reductionOp, const std::vector<std::vector<Slice>> multRingsSliceZero, Stream stream,
25 : s32 profStage, const u64 baseOffset, const HcomCollOpInfo* opInfo,
26 : const std::vector<std::vector<Slice>> multRingsUserMemSlice, const bool disableDMAReduce)
27 : {
28 : (void)tag;
29 0 : HCCL_CONFIG_INFO(
30 : HCCL_ALG,
31 : "[CollAlignedReduceScatterDoubleRingFor91093Executor][DoubleRingReduceScatter] DoubleRingReduceScatter starts");
32 0 : HcclResult ret = HCCL_SUCCESS;
33 0 : u32 ringNum = multRingsSliceZero.size();
34 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, ringNum));
35 :
36 : // 拿到ring环映射关系
37 0 : SubCommInfo level0ZeroCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
38 0 : auto nicList = topoAttr_.nicList;
39 : std::vector<std::vector<u32>> multiRingsOrder
40 0 : = GetRingsOrderByTopoType(level0ZeroCommInfo.localRankSize, topoType_, nicList);
41 :
42 0 : u64 reduceAttr = GetReduceAttr(inputMem, outputMem, dataType, reductionOp);
43 :
44 0 : SubCommInfo level0RingCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
45 : // 生成两个ring上的userMemIn_上对应的slices
46 0 : std::vector<std::vector<Slice>> userMemInputSlicesOfDoubleRing;
47 0 : CHK_RET(CollectMultiRingsUserMemSlices(
48 : ringNum, dataType, opInfo, multRingsSliceZero, multiRingsOrder, multRingsUserMemSlice,
49 : userMemInputSlicesOfDoubleRing));
50 : // 生成两个ring上的rankOrder
51 0 : std::vector<std::vector<u32>> rankOrders;
52 0 : CHK_RET(CollectMultiRingsRankOrder(ringNum, multiRingsOrder, rankOrders));
53 : // 初始化executor
54 : std::unique_ptr<AlgTemplateBase> tempAlg
55 0 : = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_REDUCESCATTER_DB_RING, dispatcher_);
56 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_REDUCESCATTER_DB_RING in COMM_LEVEL0", __func__);
57 0 : CHK_SMART_PTR_NULL(tempAlg);
58 0 : ret = tempAlg->Prepare(
59 : inputMem, inputMem, outputMem, count, dataType, stream, multRingsSliceZero, reductionOp, LEVEL0_BRIDGE_RANK_ID,
60 0 : baseOffset, disableDMAReduce, reduceAttr, opInfo, topoAttr_.userRank, algResResp_->slaveStreams,
61 0 : algResResp_->notifiesMain, algResResp_->notifiesAux, rankOrders, userMemInputSlicesOfDoubleRing);
62 0 : CHK_PRT_RET(
63 : ret != HCCL_SUCCESS,
64 : HCCL_ERROR(
65 : "[CollAlignedReduceScatterDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring ReduceScatter "
66 : "failed"
67 : "failed,return[%d]",
68 : ret),
69 : ret);
70 0 : u32 ringIndexOp = COMM_INDEX_0;
71 0 : u32 rankSize = level0RingCommInfo.localRankSize;
72 0 : ret = tempAlg->RegisterProfiler(
73 0 : ((ringIndexOp + 1) << PROF_RINGINDEX_OFFSET_OF_PLANEID) + (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID)
74 0 : + level0RingCommInfo.localRank,
75 : profStage, HCCL_EXEC_STEP_NOT_SET, stream);
76 0 : CHK_PRT_RET(
77 : ret != HCCL_SUCCESS,
78 : HCCL_ERROR(
79 : "[CollAlignedReduceScatterDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring ReduceScatter "
80 : "failed "
81 : "failed,return[%d]",
82 : ret),
83 : ret);
84 : // 空拷贝用于后续操作附着
85 0 : CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
86 0 : ret = RunTemplate(tempAlg, level0RingCommInfo);
87 0 : CHK_PRT_RET(
88 : ret != HCCL_SUCCESS,
89 : HCCL_ERROR(
90 : "[CollAlignedReduceScatterDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring ReduceScatter "
91 : "failed "
92 : "failed,return[%d]",
93 : ret),
94 : ret);
95 :
96 0 : CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
97 0 : return HCCL_SUCCESS;
98 0 : }
99 :
100 17 : HcclResult CollAlignedReduceScatterDoubleRingFor91093Executor::RunIntraSeverReduceScatter(
101 : const std::string& tag, DeviceMem& inputMem, DeviceMem& outputMem, const u64 count, const HcclDataType& dataType,
102 : const HcclReduceOp& reductionOp, const std::vector<std::vector<Slice>>& multRingsSliceZero, const Stream& stream,
103 : s32 profStage, const u64 baseOffset, const HcomCollOpInfo* opInfo,
104 : const std::vector<std::vector<Slice>>& multRingsUserMemSlice, const bool disableDMAReduce)
105 : {
106 17 : CHK_RET(DoubleRingReduceScatter(
107 : tag, inputMem, outputMem, count, dataType, reductionOp, multRingsSliceZero, stream, profStage, baseOffset,
108 : opInfo, multRingsUserMemSlice, disableDMAReduce));
109 16 : return HCCL_SUCCESS;
110 : }
111 : REGISTER_EXEC(
112 : "AlignedReduceScatterDoubleRingFor91093Executor", AlignedReduceScatterDoubleRingFor91093,
113 : CollAlignedReduceScatterDoubleRingFor91093Executor);
114 : } // namespace hccl
|