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