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, return[%d]",
67 : ret),
68 : ret);
69 0 : u32 ringIndexOp = COMM_INDEX_0;
70 0 : u32 rankSize = level0RingCommInfo.localRankSize;
71 0 : ret = tempAlg->RegisterProfiler(
72 0 : ((ringIndexOp + 1) << PROF_RINGINDEX_OFFSET_OF_PLANEID) + (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID)
73 0 : + level0RingCommInfo.localRank,
74 : profStage, HCCL_EXEC_STEP_NOT_SET, stream);
75 0 : CHK_PRT_RET(
76 : ret != HCCL_SUCCESS,
77 : HCCL_ERROR(
78 : "[CollAlignedReduceScatterDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring ReduceScatter "
79 : "failed, return[%d]",
80 : ret),
81 : ret);
82 : // 空拷贝用于后续操作附着
83 0 : CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
84 0 : ret = RunTemplate(tempAlg, level0RingCommInfo);
85 0 : CHK_PRT_RET(
86 : ret != HCCL_SUCCESS,
87 : HCCL_ERROR(
88 : "[CollAlignedReduceScatterDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring ReduceScatter "
89 : "failed, return[%d]",
90 : ret),
91 : ret);
92 :
93 0 : CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
94 0 : return HCCL_SUCCESS;
95 0 : }
96 :
97 17 : HcclResult CollAlignedReduceScatterDoubleRingFor91093Executor::RunIntraSeverReduceScatter(
98 : const std::string& tag, DeviceMem& inputMem, DeviceMem& outputMem, const u64 count, const HcclDataType& dataType,
99 : const HcclReduceOp& reductionOp, const std::vector<std::vector<Slice>>& multRingsSliceZero, const Stream& stream,
100 : s32 profStage, const u64 baseOffset, const HcomCollOpInfo* opInfo,
101 : const std::vector<std::vector<Slice>>& multRingsUserMemSlice, const bool disableDMAReduce)
102 : {
103 17 : CHK_RET(DoubleRingReduceScatter(
104 : tag, inputMem, outputMem, count, dataType, reductionOp, multRingsSliceZero, stream, profStage, baseOffset,
105 : opInfo, multRingsUserMemSlice, disableDMAReduce));
106 16 : return HCCL_SUCCESS;
107 : }
108 : REGISTER_EXEC(
109 : "AlignedReduceScatterDoubleRingFor91093Executor", AlignedReduceScatterDoubleRingFor91093,
110 : CollAlignedReduceScatterDoubleRingFor91093Executor);
111 : } // namespace hccl
|