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 :
12 : #include "coll_all_to_all_v_pipeline_for_910_93_executor.h"
13 :
14 : namespace hccl {
15 :
16 0 : CollAlltoAllVPipelineFor91093::CollAlltoAllVPipelineFor91093(const HcclDispatcher dispatcher,
17 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
18 0 : : CollAlltoAllExecutor(dispatcher, topoMatcher)
19 : {
20 0 : }
21 :
22 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcTransportMemType(
23 : TransportMemType &inputType, TransportMemType &outputType)
24 : {
25 0 : inputType = TransportMemType::CCL_INPUT;
26 0 : outputType = TransportMemType::CCL_OUTPUT;
27 0 : HCCL_INFO("[CollAlltoAllVPipelineFor91093][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]",
28 : tag_.c_str(), inputType, outputType);
29 0 : return HCCL_SUCCESS;
30 : }
31 :
32 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcLevel1CommInfo(TransportMemType inputType,TransportMemType outputType,
33 : std::vector<LevelNSubCommTransport>& opTransport)
34 : {
35 : // level0 + level1 - Mesh建链
36 0 : CommParaInfo commParaCombineL1(COMM_COMBINE_L1, CommType::COMM_TAG_MESH);
37 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaCombineL1, opTransport[COMM_COMBINE_L1], inputType, outputType));
38 0 : return HCCL_SUCCESS;
39 0 : }
40 :
41 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcLevel2CommInfo(TransportMemType inputType, TransportMemType outputType,
42 : std::vector<LevelNSubCommTransport>& opTransport)
43 : {
44 : // level2 - Mesh建链
45 0 : CommParaInfo commParaLevel2(COMM_LEVEL2, CommType::COMM_TAG_MESH);
46 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel2, opTransport[COMM_LEVEL2], inputType, outputType));
47 0 : return HCCL_SUCCESS;
48 0 : }
49 :
50 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
51 : {
52 0 : TransportMemType inputType = TransportMemType::RESERVED;
53 0 : TransportMemType outputType = TransportMemType::RESERVED;
54 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
55 0 : CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
56 0 : CHK_RET(CalcLevel2CommInfo(inputType, outputType, opTransport));
57 0 : return HCCL_SUCCESS;
58 : }
59 :
60 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcStreamNum(u32& streamNum)
61 : {
62 0 : const u32 level0StreamNum = std::min(topoAttr_.deviceNumPerAggregation - 1, DEVICE_EIGHT);
63 0 : const u32 level2StreamNum = 1; // 先固定1条RDMA 流
64 0 : streamNum = level0StreamNum + level2StreamNum; // 最大流数量为9条, RDMA 1条, SDMA 最大8条
65 0 : HCCL_INFO("[CollAlltoAllVPipelineFor91093]tag[%s] level0StreamNum[%u], level2StreamNum[%u], streamNum[%u]",
66 : tag_.c_str(), level0StreamNum, level2StreamNum, streamNum);
67 0 : return HCCL_SUCCESS;
68 : }
69 :
70 0 : HcclResult CollAlltoAllVPipelineFor91093::CalLocalSendRecvInfo(const OpParam ¶m, SendRecvInfo &info)
71 : {
72 0 : if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL) {
73 0 : CalcA2ASendRecvInfo(param, info);
74 0 : } else if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALLV) {
75 0 : CalcA2AvSendRecvInfo(param, info);
76 0 : } else if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALLVC) {
77 0 : CalcA2AvcSendRecvInfo(param, info);
78 : } else {
79 0 : HCCL_ERROR("[CollAlltoAllVPipelineFor91093] get invalid optype.");
80 0 : return HCCL_E_PARA;
81 : }
82 0 : return HCCL_SUCCESS;
83 : }
84 :
85 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcA2ASendRecvInfo(const OpParam ¶m, SendRecvInfo &info)
86 : {
87 0 : const u32 userRankSize = topoAttr_.userRankSize;
88 0 : info.sendCounts.resize(userRankSize);
89 0 : info.sendDispls.resize(userRankSize);
90 0 : info.recvCounts.resize(userRankSize);
91 0 : info.recvDispls.resize(userRankSize);
92 0 : u64 sdispl = 0, rdispl = 0;
93 :
94 0 : for(u32 i = 0; i < userRankSize; i++) {
95 0 : info.sendCounts[i] = param.All2AllDataDes.sendCount;
96 0 : info.recvCounts[i] = param.All2AllDataDes.sendCount;
97 0 : info.sendDispls[i] = sdispl;
98 0 : info.recvDispls[i] = rdispl;
99 0 : sdispl += param.All2AllDataDes.sendCount;
100 0 : rdispl += param.All2AllDataDes.sendCount;
101 : }
102 0 : if (UNLIKELY(HcclCheckLogLevel(DLOG_DEBUG))) {
103 0 : for(u32 i=0; i< userRankSize ;i++) {
104 0 : HCCL_DEBUG("CalcA2ASendRecvInfo sendCounts[%d]=%ld, recvCounts[%d]=%ld, sdispls[%d]=%ld, rdispls[%d]=%ld",
105 : i, info.sendCounts[i], i, info.recvCounts[i], i, info.sendDispls[i], i, info.recvDispls[i]);
106 : }
107 : }
108 0 : return HCCL_SUCCESS;
109 : }
110 :
111 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcA2AvSendRecvInfo(const OpParam ¶m, SendRecvInfo &info)
112 : {
113 0 : const bool hasRecvInfo = param.All2AllDataDes.recvCounts != nullptr;
114 0 : const u32 userRankSize = topoAttr_.userRankSize;
115 :
116 0 : info.sendCounts.resize(userRankSize);
117 0 : info.sendDispls.resize(userRankSize);
118 :
119 0 : if (hasRecvInfo) {
120 0 : info.recvCounts.resize(userRankSize);
121 0 : info.recvDispls.resize(userRankSize);
122 : }
123 :
124 0 : for (u32 i = 0; i < userRankSize; ++i) {
125 0 : info.sendCounts[i] = *(static_cast<const u64 *>(param.All2AllDataDes.sendCounts) + i);
126 0 : info.sendDispls[i] = *(static_cast<const u64 *>(param.All2AllDataDes.sdispls) + i);
127 :
128 0 : if (hasRecvInfo) {
129 0 : info.recvCounts[i] = *(static_cast<const u64 *>(param.All2AllDataDes.recvCounts) + i);
130 0 : info.recvDispls[i] = *(static_cast<const u64 *>(param.All2AllDataDes.rdispls) + i);
131 : }
132 : }
133 :
134 0 : if (UNLIKELY(HcclCheckLogLevel(DLOG_INFO))) {
135 0 : for(u32 i=0; i< userRankSize ;i++) {
136 0 : HCCL_DEBUG("CalcA2AvSendRecvInfo sendCounts[%d]=%ld, recvCounts[%d]=%ld, sdispls[%d]=%ld, rdispls[%d]=%ld",
137 : i, info.sendCounts[i], i, info.recvCounts[i], i, info.sendDispls[i], i, info.recvDispls[i]);
138 : }
139 : }
140 0 : return HCCL_SUCCESS;
141 : }
142 :
143 0 : HcclResult CollAlltoAllVPipelineFor91093::CalcA2AvcSendRecvInfo(const OpParam& param, SendRecvInfo &info)
144 : {
145 0 : const u32 userRankSize = topoAttr_.userRankSize;
146 0 : const u32 userRank = topoAttr_.userRank;
147 0 : info.sendCounts.resize(userRankSize);
148 0 : info.sendDispls.resize(userRankSize);
149 0 : info.recvCounts.resize(userRankSize);
150 0 : info.recvDispls.resize(userRankSize);
151 0 : u64 sdispl = 0, rdispl = 0;
152 :
153 0 : u64* sendCountMatrix = static_cast<u64 *>(param.All2AllDataDes.sendCountMatrix);
154 0 : for(u32 i = 0; i < userRankSize; i++) {
155 0 : info.sendCounts[i] = *(sendCountMatrix + userRank * userRankSize + i);
156 0 : info.recvCounts[i] = *(sendCountMatrix + userRank + userRankSize * i);
157 0 : info.sendDispls[i] = sdispl;
158 0 : info.recvDispls[i] = rdispl;
159 0 : sdispl += *(sendCountMatrix + userRank * userRankSize + i);
160 0 : rdispl += *(sendCountMatrix + userRank + userRankSize * i);
161 : }
162 0 : if (UNLIKELY(HcclCheckLogLevel(DLOG_INFO))) {
163 0 : for(u32 i=0; i< userRankSize ;i++) {
164 0 : HCCL_DEBUG("CalcA2AvcSendRecvInfo sendCounts[%d]=%ld, recvCounts[%d]=%ld, sdispls[%d]=%ld, rdispls[%d]=%ld",
165 : i, info.sendCounts[i], i, info.recvCounts[i], i, info.sendDispls[i], i, info.recvDispls[i]);
166 : }
167 : }
168 0 : return HCCL_SUCCESS;
169 : }
170 :
171 0 : HcclResult CollAlltoAllVPipelineFor91093::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
172 : {
173 0 : HcclUs startut = TIME_NOW();
174 0 : HcclResult ret = HCCL_SUCCESS;
175 0 : tag_ = param.tag;
176 0 : algResResp_ = &algRes;
177 0 : AlltoAllVParam_ = param;
178 0 : ExecMem execMem;
179 0 : execMem.count = 0;
180 0 : execMem.inputPtr = param.inputPtr;
181 0 : execMem.outputPtr = param.outputPtr;
182 0 : execMem.inputMem = algRes.cclInputMem;
183 0 : execMem.outputMem = algRes.cclOutputMem;
184 0 : ret = KernelRun(param, execMem);
185 :
186 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
187 : HCCL_ERROR("[CollAlltoAllVPipelineFor91093][Orchestrate]errNo[0x%016llx]executor run failed",
188 : HCCL_ERROR_CODE(ret)), ret);
189 :
190 0 : HCCL_INFO("tag[%s], CollAlltoAllVPipelineFor91093 tempAlg orchestrate success, take time [%lld]us.",
191 : param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
192 0 : return HCCL_SUCCESS;
193 0 : }
194 :
195 0 : HcclResult CollAlltoAllVPipelineFor91093::KernelRun(const OpParam ¶m, ExecMem &execMem)
196 : {
197 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollAlltoAllVPipelineFor91093][KernelRun] AllToAllV npu direct start.");
198 : // 获取通信域
199 0 : SubCommInfo level1CommInfo;
200 0 : SubCommInfo level2CommInfo;
201 0 : CHK_RET(CheckCommSize(COMM_COMBINE_L1, COMM_INDEX_0 + 1));
202 0 : CHK_RET(CheckCommSize(COMM_LEVEL2, COMM_INDEX_0 + 1));
203 0 : level1CommInfo = GetSubCommInfo(COMM_COMBINE_L1, COMM_INDEX_0);
204 0 : level2CommInfo = GetSubCommInfo(COMM_LEVEL2, COMM_INDEX_0);
205 :
206 : // 执行
207 0 : std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
208 0 : TemplateType::TEMPLATE_ALL_2_ALL_V_CONTINUOUS_PIPELINE, dispatcher_);
209 0 : CHK_SMART_PTR_NULL(tempAlg);
210 :
211 0 : SendRecvInfo sendRecvInfo;
212 0 : CHK_RET(CalLocalSendRecvInfo(param, sendRecvInfo));
213 :
214 0 : A2aPipelineMemory a2aPipelineMemory;
215 0 : a2aPipelineMemory.userInput = algResResp_->paramInputMem;
216 0 : a2aPipelineMemory.userOutput = algResResp_->paramOutputMem;
217 0 : a2aPipelineMemory.cclInBuffer = execMem.inputMem;
218 0 : a2aPipelineMemory.cclOutBuffer = execMem.outputMem;
219 :
220 0 : HCCL_INFO("[CollAlltoAllVPipelineFor91093] Memory info[addr, size]: userInput[%p, %llu], userOutput[%p, %llu], "
221 : "cclInBuffer[%p, %llu] ,cclOutBuffer[%p, %llu].",
222 : a2aPipelineMemory.userInput.ptr(), a2aPipelineMemory.userInput.size(),
223 : a2aPipelineMemory.userOutput.ptr(), a2aPipelineMemory.userOutput.size(),
224 : a2aPipelineMemory.cclInBuffer.ptr(), a2aPipelineMemory.cclInBuffer.size(),
225 : a2aPipelineMemory.cclOutBuffer.ptr(), a2aPipelineMemory.cclOutBuffer.size()
226 : );
227 :
228 : #ifndef OPEN_HCCL_TEST
229 0 : std::vector<SendRecvInfo> sendRecvInfoList{sendRecvInfo};
230 : #else
231 : // 适配算法检查器,传入全局的info
232 : std::vector<SendRecvInfo> sendRecvInfoList = allMeshAggregationSendRecvInfo_;
233 : #endif
234 :
235 0 : CHK_RET(tempAlg->Prepare(topoAttr_.userRank,
236 : a2aPipelineMemory,
237 : level1CommInfo,
238 : level2CommInfo,
239 : param.stream,
240 : algResResp_->slaveStreams,
241 : algResResp_->notifiesMain,
242 : algResResp_->notifiesAux,
243 : sendRecvInfoList,
244 : param.All2AllDataDes.sendType,
245 : workflowMode_));
246 :
247 0 : CHK_RET(tempAlg->RunAsync());
248 :
249 0 : HCCL_INFO("[CollAlltoAllVPipelineFor91093] executor run success.");
250 0 : return HCCL_SUCCESS;
251 0 : }
252 :
253 : REGISTER_EXEC("RunAlltoAllVPipelineFor91093", AlltoAllVPipelineFor91093, CollAlltoAllVPipelineFor91093);
254 : } // namespace hccl
|