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_all_gather_mesh_aiv_smallcount_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllGatherMeshAivSmallCountExecutor::CollAllGatherMeshAivSmallCountExecutor(
15 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
16 0 : : CollAllGatherExecutor(dispatcher, topoMatcher)
17 : {
18 0 : DMAReduceFlag_ = false;
19 0 : desc_.isAivMode = true;
20 0 : }
21 :
22 0 : HcclResult CollAllGatherMeshAivSmallCountExecutor::CalcStreamNum(u32& streamNum)
23 : {
24 0 : streamNum = 0; // AIV通信不需要申请从流
25 0 : HCCL_INFO("[CollAllGatherMeshAivSmallCountExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
26 0 : return HCCL_SUCCESS;
27 : }
28 :
29 0 : HcclResult CollAllGatherMeshAivSmallCountExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
30 : {
31 0 : TransportMemType inputType = TransportMemType::RESERVED;
32 0 : TransportMemType outputType = TransportMemType::RESERVED;
33 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
34 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
35 0 : return HCCL_SUCCESS;
36 : }
37 :
38 : HcclResult
39 0 : CollAllGatherMeshAivSmallCountExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
40 : {
41 0 : inputType = TransportMemType::AIV_INPUT;
42 0 : outputType = TransportMemType::AIV_OUTPUT;
43 0 : HCCL_INFO(
44 : "[CollAllGatherMeshAivSmallCountExecutor][CalcTransportMemType] tag[%s] inputType[%d],"
45 : " outputType[%d].",
46 : tag_.c_str(), inputType, outputType);
47 0 : return HCCL_SUCCESS;
48 : }
49 :
50 0 : HcclResult CollAllGatherMeshAivSmallCountExecutor::CalcLevel0CommInfo(
51 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
52 : {
53 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
54 0 : commParaLevel0.meshSinglePlane = true;
55 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
56 0 : return HCCL_SUCCESS;
57 0 : }
58 :
59 0 : HcclResult CollAllGatherMeshAivSmallCountExecutor::CalNumBlocks(
60 : u32& numBlocks, u32 rankSize, [[maybe_unused]] u64 dataSize, [[maybe_unused]] HcclCMDType cmdType)
61 : {
62 0 : numBlocks = rankSize; // 默认情况使用rankSize个AIV
63 :
64 0 : bool isOpBase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
65 0 : if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93 && !isOpBase) {
66 0 : numBlocks = rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3 > MAX_NUM_BLOCKS ? rankSize * NUM_BLOCKS_THREE_PER_RANK_A3 :
67 : rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3;
68 : }
69 :
70 0 : u32 bestNumBlocks = numBlocks;
71 0 : if (isOpBase || topoAttr_.deviceType == DevType::DEV_TYPE_910B) {
72 0 : CHK_PRT_RET(
73 : numBlocks_ < numBlocks,
74 : HCCL_WARNING(
75 : "[CollAllGatherMeshAivSmallCountExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
76 : numBlocks_, numBlocks),
77 : HCCL_E_PARA);
78 0 : } else if (!isOpBase && topoAttr_.deviceType == DevType::DEV_TYPE_910_93) {
79 0 : CHK_PRT_RET(
80 : numBlocks_ < rankSize,
81 : HCCL_WARNING(
82 : "[CollAllGatherMeshAivSmallCountExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
83 : numBlocks_, rankSize),
84 : HCCL_E_PARA);
85 0 : if (numBlocks_ < numBlocks) {
86 0 : numBlocks = numBlocks_ / rankSize * rankSize;
87 : }
88 : }
89 :
90 0 : HCCL_INFO(
91 : "[CollAllGatherMeshAivSmallCountExecutor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]",
92 : numBlocks, numBlocks_, bestNumBlocks);
93 0 : return HCCL_SUCCESS;
94 : }
95 :
96 0 : HcclResult CollAllGatherMeshAivSmallCountExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
97 : {
98 0 : HcclUs startut = TIME_NOW();
99 0 : tag_ = param.tag;
100 0 : algResResp_ = &algRes;
101 :
102 0 : HcclResult ret = HCCL_SUCCESS;
103 0 : ExecMem execMem;
104 0 : execMem.count = param.DataDes.count;
105 0 : execMem.inputPtr = param.inputPtr;
106 0 : execMem.outputPtr = param.outputPtr;
107 :
108 : // 单算子大数据量
109 0 : execMem.inputMem = algRes.aivInputMem; // 仍然使用CCLIN
110 0 : execMem.outputMem = algRes.aivOutputMem;
111 0 : ret = KernelRun(param, execMem);
112 :
113 0 : CHK_PRT_RET(
114 : ret != HCCL_SUCCESS,
115 : HCCL_ERROR(
116 : "[CollAllGatherMeshAivSmallCountExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
117 : "run failed",
118 : HCCL_ERROR_CODE(ret), param.tag.c_str()),
119 : ret);
120 :
121 0 : HCCL_INFO(
122 : "tag[%s], AllGather executor orchestrate success, take time [%lld]us.", param.tag.c_str(),
123 : DURATION_US(TIME_NOW() - startut));
124 0 : return HCCL_SUCCESS;
125 0 : }
126 :
127 0 : HcclResult CollAllGatherMeshAivSmallCountExecutor::GetAivExecParam(
128 : const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
129 : {
130 0 : HcclUs startut = TIME_NOW();
131 0 : tag_ = param.tag;
132 0 : algResResp_ = &algRes;
133 :
134 0 : HcclResult ret = HCCL_SUCCESS;
135 0 : ExecMem execMem;
136 0 : execMem.count = param.DataDes.count;
137 0 : execMem.inputPtr = param.inputPtr;
138 0 : execMem.outputPtr = param.outputPtr;
139 :
140 : // 单算子大数据量
141 0 : execMem.inputMem = algRes.aivInputMem;
142 0 : execMem.outputMem = algRes.aivOutputMem;
143 :
144 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
145 :
146 0 : u32 localRank = level0CommInfo.localRank;
147 0 : u32 localRankSize = level0CommInfo.localRankSize;
148 0 : HCCL_DEBUG(
149 : "[CollAllGatherMeshAivSmallCountExecutor][GetAivExecParam] userRank [%d] localRank [%d]", topoAttr_.userRank,
150 : localRank);
151 :
152 0 : for (u32 i = 0; i < localRankSize; i++) {
153 0 : if (i != localRank) {
154 0 : CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(args.buffersIn[i])));
155 0 : CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(args.buffersOut[i])));
156 : } else {
157 0 : args.buffersIn[i] = execMem.inputMem.ptr();
158 0 : args.buffersOut[i] = execMem.outputMem.ptr();
159 : }
160 : }
161 0 : args.rank = localRank;
162 0 : args.rankSize = localRankSize;
163 0 : args.len = execMem.count;
164 0 : args.dataType = param.DataDes.dataType;
165 0 : args.unitSize = SIZE_TABLE[param.DataDes.dataType];
166 0 : args.reduceOp = param.reduceType;
167 0 : args.devType = static_cast<u32>(topoAttr_.deviceType);
168 0 : CHK_PRT_RET(
169 : ret != HCCL_SUCCESS,
170 : HCCL_ERROR(
171 : "[CollAllGatherMeshAivSmallCountExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
172 : "run failed",
173 : HCCL_ERROR_CODE(ret), param.tag.c_str()),
174 : ret);
175 :
176 0 : HCCL_INFO(
177 : "tag[%s], AllGather executor getalgexecparam success, take time [%lld]us.", param.tag.c_str(),
178 : DURATION_US(TIME_NOW() - startut));
179 0 : return HCCL_SUCCESS;
180 0 : }
181 :
182 0 : HcclResult CollAllGatherMeshAivSmallCountExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
183 : {
184 0 : HCCL_INFO("[CollAllGatherMeshAivSmallCountExecutor][KernelRun]AllGather aiv enter");
185 :
186 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
187 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
188 :
189 : void* buffersIn[MAX_RANK_SIZE];
190 : void* buffersOut[MAX_RANK_SIZE];
191 :
192 0 : u32 localRank = level0CommInfo.localRank;
193 0 : u32 localRankSize = level0CommInfo.localRankSize;
194 0 : HCCL_DEBUG(
195 : "[CollAllGatherMeshAivSmallCountExecutor][KernelRun] userRank [%d] localRank [%d]", topoAttr_.userRank,
196 : localRank);
197 :
198 0 : for (u32 i = 0; i < localRankSize; i++) {
199 0 : if (i != localRank) {
200 0 : CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
201 0 : CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
202 : } else {
203 0 : buffersIn[i] = execMem.inputMem.ptr();
204 0 : buffersOut[i] = execMem.outputMem.ptr();
205 : }
206 : }
207 :
208 0 : bool isOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
209 :
210 0 : AivOpArgs opArgs{
211 : HcclCMDType::HCCL_CMD_ALLGATHER,
212 0 : execMem.inputPtr,
213 0 : execMem.outputPtr,
214 0 : execMem.count,
215 0 : param.DataDes.dataType,
216 0 : param.reduceType,
217 : 0,
218 0 : isOpbase};
219 0 : AivTopoArgs topoArgs{localRank, localRankSize, MAX_RANK_SIZE, 0, 1, topoAttr_.deviceType, algoAttr_.identifier};
220 : u32 numBlocks;
221 0 : CHK_PRT_RET(
222 : CalNumBlocks(numBlocks, localRankSize) != HCCL_SUCCESS, HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
223 : HCCL_E_PARA);
224 0 : numBlocks_ = numBlocks;
225 0 : AivResourceArgs resourceArgs{param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
226 0 : numBlocks_, param.aivTag};
227 0 : AivAlgArgs algArgs{};
228 0 : algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
229 0 : algArgs.execTimeOutSet = true;
230 0 : struct AivProfilingInfo aivProfilingInfo;
231 0 : aivProfilingInfo.counter = opCounter_;
232 :
233 0 : HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
234 0 : CHK_PRT_RET(
235 : ret != HCCL_SUCCESS,
236 : HCCL_ERROR("[CollAllGatherMeshAivSmallCountExecutor][KernelRun]AllGather aiv failed, return[%d]", ret), ret);
237 :
238 0 : ExtraArgs extraArgs;
239 0 : CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
240 :
241 0 : HCCL_INFO("[CollAllGatherMeshAivSmallCountExecutor][KernelRun]AllGather aiv run success");
242 0 : return HCCL_SUCCESS;
243 0 : }
244 :
245 : REGISTER_EXEC("AllGatherMeshAivSmallCountExecutor", AllGatherMeshAivSmallCount, CollAllGatherMeshAivSmallCountExecutor);
246 :
247 : } // namespace hccl
|