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