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_for_910_93_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAllGatherMeshAivFor91093Executor::CollAllGatherMeshAivFor91093Executor(
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 : desc_.isAivCrossNode = true;
21 0 : }
22 :
23 0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalcStreamNum(u32& streamNum)
24 : {
25 0 : streamNum = 0; // AIV通信不需要申请从流
26 0 : HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][CalcStreamNum] tag[%s] streamNum[%u].", tag_.c_str(), streamNum);
27 0 : return HCCL_SUCCESS;
28 : }
29 :
30 0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
31 : {
32 0 : TransportMemType inputType = TransportMemType::RESERVED;
33 0 : TransportMemType outputType = TransportMemType::RESERVED;
34 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
35 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
36 0 : return HCCL_SUCCESS;
37 : }
38 :
39 : HcclResult
40 0 : CollAllGatherMeshAivFor91093Executor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
41 : {
42 : inputType
43 0 : = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE ? TransportMemType::CCL_INPUT :
44 : TransportMemType::PARAM_INPUT);
45 0 : outputType = TransportMemType::AIV_OUTPUT;
46 0 : HCCL_INFO(
47 : "[CollAllGatherMeshAivFor91093Executor][CalcTransportMemType] tag[%s] inputType[%d],"
48 : " outputType[%d].",
49 : tag_.c_str(), inputType, outputType);
50 0 : return HCCL_SUCCESS;
51 : }
52 :
53 0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalcLevel0CommInfo(
54 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
55 : {
56 0 : CommParaInfo commCombinePara(COMM_COMBINE_ORDER, CommType::COMM_TAG_MESH);
57 0 : commCombinePara.meshSinglePlane = true;
58 0 : CHK_RET(CalcCommPlaneInfo(tag_, commCombinePara, opTransport[COMM_COMBINE_ORDER], inputType, outputType));
59 :
60 0 : LevelNSubCommTransport& commTransportLevel0 = opTransport[COMM_COMBINE_ORDER];
61 0 : for (u32 subCommIndex = 0; subCommIndex < commTransportLevel0.size(); subCommIndex++) {
62 0 : for (auto& transportRequest : commTransportLevel0[subCommIndex].transportRequests) {
63 0 : transportRequest.isUsedRdma = false;
64 : }
65 : }
66 0 : return HCCL_SUCCESS;
67 0 : }
68 :
69 0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalNumBlocks(
70 : u32& numBlocks, u32 rankSize, u64 dataSize, [[maybe_unused]] HcclCMDType cmdType)
71 : {
72 0 : u32 minNumBlocks = (rankSize + MAX_TARGET_NUM - 1) / MAX_TARGET_NUM;
73 0 : numBlocks = rankSize; // 默认情况使用rankSize个AIV
74 :
75 : // A3超节点内多机场景
76 : // 多核并行优化
77 0 : if (rankSize > HALF_MAX_NUM_BLOCKS || dataSize < AIV_A3_CROSSNODE_TINY_SIZE) {
78 0 : numBlocks = rankSize;
79 0 : } else if (rankSize > ONE_THIRD_MAX_NUM_BLOCKS || dataSize < AIV_A3_CROSSNODE_SMALL_SIZE) {
80 0 : numBlocks = rankSize * NUM_BLOCKS_FACTOR_TWO;
81 0 : } else if (rankSize > ONE_FOURTH_MAX_NUM_BLOCKS) {
82 0 : numBlocks = rankSize * NUM_BLOCKS_FACTOR_THREE;
83 : } else {
84 0 : numBlocks = rankSize * NUM_BLOCKS_FACTOR_FOUR;
85 : }
86 0 : HCCL_DEBUG("[CollAllGatherMeshAivFor91093Executor][CalNumBlocks]aivCore at least is [%u]", minNumBlocks);
87 0 : u32 bestNumBlocks = numBlocks;
88 : numBlocks
89 0 : = numBlocks_ < rankSize ? numBlocks_ : (numBlocks_ < numBlocks ? numBlocks_ / rankSize * rankSize : numBlocks);
90 :
91 0 : CHK_PRT_RET(
92 : numBlocks < minNumBlocks,
93 : HCCL_ERROR(
94 : "[CollAllGatherMeshAivFor91093Executor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
95 : numBlocks_, minNumBlocks),
96 : HCCL_E_PARA);
97 :
98 0 : HCCL_INFO(
99 : "[CollAllGatherMeshAivFor91093Executor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u].",
100 : numBlocks, numBlocks_, bestNumBlocks);
101 0 : return HCCL_SUCCESS;
102 : }
103 :
104 0 : HcclResult CollAllGatherMeshAivFor91093Executor::GetAivExecParam(
105 : const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
106 : {
107 0 : HcclUs startut = TIME_NOW();
108 0 : tag_ = param.tag;
109 0 : algResResp_ = &algRes;
110 :
111 0 : HcclResult ret = HCCL_SUCCESS;
112 0 : ExecMem execMem;
113 0 : execMem.count = param.DataDes.count;
114 0 : execMem.inputPtr = param.inputPtr;
115 0 : execMem.outputPtr = param.outputPtr;
116 :
117 0 : execMem.inputMem = algRes.paramInputMem;
118 0 : execMem.outputMem = algRes.aivOutputMem;
119 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_COMBINE_ORDER, COMM_INDEX_0);
120 :
121 0 : u32 localRank = level0CommInfo.localRank;
122 0 : u32 localRankSize = level0CommInfo.localRankSize;
123 0 : HCCL_DEBUG(
124 : "[CollAllGatherMeshAivFor91093Executor][GetAivExecParam] userRank [%d] localRank [%d]", topoAttr_.userRank,
125 : localRank);
126 :
127 0 : args.buffersIn[0] = execMem.inputMem.ptr();
128 0 : args.buffersOut[0] = execMem.outputMem.ptr();
129 0 : constexpr u32 BUFFER_IDX_ONE = 1;
130 0 : args.buffersOut[BUFFER_IDX_ONE] = algRes.aivCommInfoMem.ptr(); // 通信域信息
131 :
132 0 : args.rank = localRank;
133 0 : args.rankSize = localRankSize;
134 0 : args.len = execMem.count;
135 0 : args.dataType = param.DataDes.dataType;
136 0 : args.unitSize = SIZE_TABLE[param.DataDes.dataType];
137 0 : args.reduceOp = param.reduceType;
138 0 : args.devType = static_cast<u32>(topoAttr_.deviceType);
139 0 : HCCL_INFO(
140 : "SPK [CollAllGatherMeshAivFor91093Executor][GetAivExecParam], rank[%llu], rankSize[%llu], "
141 : "len[%llu],datatype[%llu], op[%llu]",
142 : args.rank, args.rankSize, args.len, args.dataType, args.reduceOp);
143 :
144 0 : CHK_PRT_RET(
145 : ret != HCCL_SUCCESS,
146 : HCCL_ERROR(
147 : "[CollAllGatherMeshAivFor91093Executor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
148 : "run failed",
149 : HCCL_ERROR_CODE(ret), param.tag.c_str()),
150 : ret);
151 :
152 0 : HCCL_INFO(
153 : "tag[%s], AllGather executor getalgexecparam success, take time [%lld]us.", param.tag.c_str(),
154 : DURATION_US(TIME_NOW() - startut));
155 0 : return HCCL_SUCCESS;
156 0 : }
157 :
158 0 : HcclResult CollAllGatherMeshAivFor91093Executor::PrepareCommInfoToDevice(AlgResourceResponse& algResource)
159 : {
160 0 : HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][PrepareCommInfoToDevice]AllGather aiv copy comm info to device.");
161 0 : CHK_RET(CopyAivCommInfoToDevice(COMM_COMBINE_ORDER, COMM_INDEX_0, algResource));
162 0 : return HCCL_SUCCESS;
163 : }
164 :
165 0 : HcclResult CollAllGatherMeshAivFor91093Executor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
166 : {
167 0 : HcclUs startut = TIME_NOW();
168 0 : tag_ = param.tag;
169 0 : algResResp_ = &algRes;
170 :
171 0 : ExecMem execMem;
172 0 : execMem.count = param.DataDes.count;
173 0 : execMem.inputPtr = param.inputPtr;
174 0 : execMem.outputPtr = param.outputPtr;
175 :
176 : execMem.inputMem
177 0 : = (workflowMode_ != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE ? algRes.paramInputMem : algRes.cclInputMem);
178 0 : execMem.outputMem = algRes.aivOutputMem;
179 0 : HcclResult ret = KernelRun(param, execMem);
180 :
181 0 : CHK_PRT_RET(
182 : ret != HCCL_SUCCESS,
183 : HCCL_ERROR(
184 : "[CollAllGatherMeshAivFor91093Executor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
185 : "run failed",
186 : HCCL_ERROR_CODE(ret), param.tag.c_str()),
187 : ret);
188 :
189 0 : HCCL_INFO(
190 : "tag[%s], AllGather executor orchestrate success, take time [%lld]us.", param.tag.c_str(),
191 : DURATION_US(TIME_NOW() - startut));
192 0 : return HCCL_SUCCESS;
193 0 : }
194 :
195 0 : HcclResult CollAllGatherMeshAivFor91093Executor::KernelRun(const OpParam& param, ExecMem& execMem)
196 : {
197 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollAllGatherMeshAivFor91093Executor][KernelRun]AllGather aiv enter.");
198 :
199 0 : CHK_RET(CheckCommSize(COMM_COMBINE_ORDER, COMM_INDEX_0 + 1));
200 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_COMBINE_ORDER, COMM_INDEX_0);
201 :
202 : void* buffersIn[MAX_RANK_SIZE];
203 : void* buffersOut[MAX_RANK_SIZE];
204 :
205 0 : u32 localRank = level0CommInfo.localRank;
206 0 : u32 localRankSize = level0CommInfo.localRankSize;
207 0 : HCCL_DEBUG(
208 : "[CollAllGatherMeshAivFor91093Executor][KernelRun] userRank [%d] localRank [%d].", topoAttr_.userRank,
209 : localRank);
210 :
211 0 : buffersIn[0] = execMem.inputMem.ptr();
212 0 : buffersOut[0] = execMem.outputMem.ptr();
213 0 : constexpr u32 BUFFER_IDX_ONE = 1;
214 0 : buffersOut[BUFFER_IDX_ONE] = algResResp_->aivCommInfoMem.ptr(); // 通信域信息
215 :
216 0 : bool isOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
217 0 : AivOpArgs opArgs{
218 : HcclCMDType::HCCL_CMD_ALLGATHER,
219 0 : execMem.inputPtr,
220 0 : execMem.outputPtr,
221 0 : execMem.count,
222 0 : param.DataDes.dataType,
223 0 : param.reduceType,
224 : 0,
225 0 : isOpbase};
226 :
227 : AivTopoArgs topoArgs{localRank, localRankSize, MAX_RANK_SIZE, 0,
228 0 : topoAttr_.serverNum, topoAttr_.deviceType, algoAttr_.identifier};
229 : u32 numBlocks;
230 0 : CHK_PRT_RET(
231 : CalNumBlocks(numBlocks, localRankSize, opArgs.count * SIZE_TABLE[opArgs.dataType]) != HCCL_SUCCESS,
232 : HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
233 0 : numBlocks_ = numBlocks;
234 0 : AivResourceArgs resourceArgs{param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
235 0 : numBlocks_, param.aivTag};
236 0 : AivAlgArgs algArgs{};
237 0 : algArgs.argsType = KernelArgsType::ARGS_TYPE_SIMPLE;
238 0 : if (numBlocks_ >= localRankSize) {
239 0 : algArgs.step = localRankSize;
240 : } else {
241 0 : algArgs.step = numBlocks_;
242 : }
243 0 : algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
244 0 : algArgs.execTimeOutSet = true;
245 0 : struct AivProfilingInfo aivProfilingInfo;
246 0 : aivProfilingInfo.counter = opCounter_;
247 :
248 0 : HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
249 :
250 0 : CHK_PRT_RET(
251 : ret != HCCL_SUCCESS,
252 : HCCL_ERROR("[CollAllGatherMeshAivFor91093Executor][KernelRun]AllGather aiv failed, return[%d]", ret), ret);
253 :
254 0 : ExtraArgs extraArgs;
255 0 : CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, true));
256 :
257 0 : HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][KernelRun]AllGather aiv run success");
258 0 : return HCCL_SUCCESS;
259 0 : }
260 :
261 : REGISTER_EXEC("AllGatherMeshAivFor91093Executor", AllGatherMeshAivFor91093, CollAllGatherMeshAivFor91093Executor);
262 :
263 : } // namespace hccl
|