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_mesh_dma_elimination.h"
12 :
13 : namespace hccl {
14 :
15 5 : CollReduceScatterMeshDmaEliminationExecutor::CollReduceScatterMeshDmaEliminationExecutor(
16 5 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
17 5 : : CollReduceScatterExecutor(dispatcher, topoMatcher)
18 : {
19 8 : DMAReduceFlag_ = true;
20 8 : CCLMemSlice_ = false;
21 8 : }
22 :
23 8 : void CollReduceScatterMeshDmaEliminationExecutor::ParseParam(const OpParam& param)
24 : {
25 8 : tag_ = param.tag;
26 8 : aicpuUnfoldMode_ = param.aicpuUnfoldMode;
27 8 : }
28 :
29 8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcStreamNum(u32& streamNum)
30 : {
31 8 : u32 totalStreamNum = topoAttr_.deviceNumPerAggregation;
32 8 : streamNum = totalStreamNum - 1U;
33 8 : HCCL_INFO(
34 : "[CollReduceScatterMeshDmaEliminationExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
35 8 : return HCCL_SUCCESS;
36 : }
37 :
38 8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
39 : {
40 8 : TransportMemType inputType = TransportMemType::RESERVED;
41 8 : TransportMemType outputType = TransportMemType::RESERVED;
42 8 : CHK_RET(CalcTransportMemType(inputType, outputType));
43 8 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
44 8 : return HCCL_SUCCESS;
45 : }
46 :
47 8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcTransportMemType(
48 : TransportMemType& inputType, TransportMemType& outputType)
49 : {
50 8 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
51 8 : inputType = TransportMemType::CCL_INPUT;
52 8 : outputType = TransportMemType::CCL_OUTPUT;
53 : } else {
54 0 : inputType = TransportMemType::PARAM_INPUT;
55 0 : outputType = TransportMemType::PARAM_OUTPUT;
56 : }
57 8 : HCCL_INFO(
58 : "[CollReduceScatterMeshDmaEliminationExecutor][CalcTransportMemType] tag[%s] inputType[%d],"
59 : " outputType[%d]",
60 : tag_.c_str(), inputType, outputType);
61 8 : return HCCL_SUCCESS;
62 : }
63 :
64 8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcLevel0CommInfo(
65 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
66 : {
67 8 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
68 8 : commParaLevel0.meshSinglePlane = true;
69 8 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
70 8 : return HCCL_SUCCESS;
71 8 : }
72 :
73 0 : u64 CollReduceScatterMeshDmaEliminationExecutor::CalcLoopMaxCount(const u32 unitSize)
74 : {
75 : // 中转内存单次最多能够接受的output count,放开ranksize限制
76 0 : u64 maxCountPerLoop = inCCLbufferSize_ / unitSize;
77 0 : return maxCountPerLoop;
78 : }
79 :
80 0 : bool CollReduceScatterMeshDmaEliminationExecutor::IsHugeData(const u64 curSize, [[maybe_unused]] OpParam* param)
81 : {
82 : // 只有server内通信,多QP哈希散列下不刷新子图
83 0 : bool hugeData = curSize > SDMA_SEND_MAX_SIZE;
84 0 : return hugeData;
85 : }
86 :
87 0 : bool CollReduceScatterMeshDmaEliminationExecutor::IsSmallData(const u64 totalSize, [[maybe_unused]] const u64 curSize)
88 : {
89 0 : bool smallData = totalSize <= HCCL_SMALL_COUNT_32_KB;
90 0 : return smallData;
91 : }
92 :
93 0 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
94 : {
95 0 : HCCL_CONFIG_INFO(
96 : HCCL_ALG, "[CollReduceScatterMeshDmaEliminationExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
97 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
98 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
99 :
100 0 : u32 commIndex = level0CommInfo.localRank; // 找到rank所在的节点间平面
101 :
102 : /* *******************节点内reducescatter ******************************************/
103 0 : CHK_RET(ActiveSlaveStreams(param.stream));
104 :
105 0 : u32 sliceNum = level0CommInfo.localRankSize;
106 : // 根据数据量算每个环上数据的偏移和大小,把做完hd的slice均分成RankSize份
107 0 : std::vector<Slice> dataSegsSlice;
108 :
109 0 : HCCL_DEBUG(
110 : "inputMem.size()=%llu, level0CommInfo.localRankSize=%u, commIndex=%u", execMem.inputMem.size(),
111 : level0CommInfo.localRankSize, commIndex);
112 :
113 0 : HcomCollOpInfo* opInfoPtr = nullptr;
114 0 : HcomCollOpInfo opInfo = {"",
115 0 : execMem.inputPtr,
116 0 : execMem.outputPtr,
117 0 : param.DataDes.count,
118 0 : param.DataDes.dataType,
119 0 : param.root,
120 0 : param.reduceType,
121 0 : 0};
122 0 : if (DMAReduceFlag_) {
123 0 : opInfoPtr = &opInfo;
124 : }
125 :
126 0 : if (topoMatcher_->GetExternalInputHcclDeterministic() == DETERMINISTIC_DISABLE
127 0 : && (param.DataDes.dataType != HCCL_DATA_TYPE_INT64)
128 0 : && (topoAttr_.deviceType == DevType::DEV_TYPE_910B && param.reduceType != HCCL_REDUCE_PROD)) {
129 0 : CHK_RET(MultiStreamReduceScatterMeshAtomic(
130 : param.tag, execMem.inputMem, execMem.scratchMem, execMem.count, param.DataDes.dataType, param.reduceType,
131 : dataSegsSlice, const_cast<Stream&>(param.stream), COMM_LEVEL0, 0, opInfoPtr));
132 : } else {
133 0 : std::vector<std::vector<Slice>> multiStreamSlice; // 每个stream使用的数据基于用户buffer的偏移
134 : // mesh算法stream数量为rank数减1
135 0 : CHK_RET(AlgTemplateBase::PrepareSliceMeshStreams(dataSegsSlice, sliceNum - 1, multiStreamSlice));
136 0 : CHK_RET(MultiStreamReduceScatterMesh(
137 : param.tag, execMem.inputMem, execMem.scratchMem, execMem.count, param.DataDes.dataType, param.reduceType,
138 : multiStreamSlice, param.stream, COMM_LEVEL0, 0));
139 0 : }
140 :
141 0 : return HCCL_SUCCESS;
142 0 : }
143 :
144 : REGISTER_EXEC(
145 : "ReduceScatterMeshDmaEliminationExecutor", ReduceScatterMeshDmaElimination,
146 : CollReduceScatterMeshDmaEliminationExecutor);
147 : } // namespace hccl
|