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 <algorithm>
12 : #include "coll_reduce_scatter_v_aiv_big_count_executor.h"
13 :
14 : namespace hccl {
15 0 : CollReduceScatterVAIVBigCountExecutor::CollReduceScatterVAIVBigCountExecutor(
16 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
17 0 : : CollReduceScatterVExecutor(dispatcher, topoMatcher)
18 : {
19 0 : desc_.isAivMode = true;
20 0 : }
21 :
22 0 : HcclResult CollReduceScatterVAIVBigCountExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
23 : {
24 0 : TransportMemType inputType = TransportMemType::RESERVED;
25 0 : TransportMemType outputType = TransportMemType::RESERVED;
26 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
27 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
28 0 : return HCCL_SUCCESS;
29 : }
30 :
31 : HcclResult
32 0 : CollReduceScatterVAIVBigCountExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
33 : {
34 : // ReduceScatterV 大数据量场景下不支持图模式
35 0 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
36 0 : inputType = TransportMemType::CCL_INPUT;
37 0 : outputType = TransportMemType::AIV_OUTPUT;
38 : }
39 :
40 0 : HCCL_INFO(
41 : "[CollReduceScatterVAIVBigCountExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]",
42 : tag_.c_str(), inputType, outputType);
43 0 : return HCCL_SUCCESS;
44 : }
45 :
46 0 : HcclResult CollReduceScatterVAIVBigCountExecutor::CalcLevel0CommInfo(
47 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
48 : {
49 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
50 0 : commParaLevel0.meshSinglePlane = true;
51 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
52 0 : return HCCL_SUCCESS;
53 0 : }
54 :
55 0 : HcclResult CollReduceScatterVAIVBigCountExecutor::CalNumBlocks(
56 : u32& numBlocks, u32 rankSize, [[maybe_unused]] u64 dataSize, [[maybe_unused]] HcclCMDType cmdType)
57 : {
58 0 : numBlocks = NUM_BLOCKS_FACTOR_TWO * rankSize; // 单机场景,单算子ReduceScatter大数据使用2倍 rankSize个aiv
59 0 : u32 bestNumBlocks = numBlocks;
60 :
61 0 : CHK_PRT_RET(
62 : numBlocks_ < numBlocks,
63 : HCCL_WARNING(
64 : "[CollReduceScatterVAIVBigCountExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
65 : numBlocks_, numBlocks),
66 : HCCL_E_PARA);
67 :
68 0 : HCCL_INFO(
69 : "[CollReduceScatterVAIVBigCountExecutor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]",
70 : numBlocks, numBlocks_, bestNumBlocks);
71 0 : return HCCL_SUCCESS;
72 : }
73 :
74 0 : HcclResult CollReduceScatterVAIVBigCountExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
75 : {
76 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterVAIVBigCountExecutor][Orchestrate] aiv ReduceScatterV start");
77 0 : HcclUs startut = TIME_NOW();
78 0 : tag_ = param.tag;
79 0 : algResResp_ = &algRes;
80 :
81 0 : HcclResult ret = HCCL_SUCCESS;
82 0 : ExecMem execMem;
83 :
84 0 : execMem.inputPtr = param.inputPtr;
85 0 : execMem.outputPtr = param.outputPtr;
86 :
87 : // ReduceScatterV 大数据量场景下不支持图模式
88 0 : if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
89 0 : execMem.inputMem = algRes.cclInputMem;
90 0 : execMem.outputMem = algRes.aivOutputMem;
91 0 : ret = KernelRun(param, execMem);
92 : }
93 :
94 0 : CHK_PRT_RET(
95 : ret != HCCL_SUCCESS,
96 : HCCL_ERROR(
97 : "[CollReduceScatterVAIVBigCountExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel run failed",
98 : HCCL_ERROR_CODE(ret), param.tag.c_str()),
99 : ret);
100 :
101 0 : HCCL_INFO(
102 : "tag[%s], ReduceScatterV executor orchestrate success, take time [%lld]us", param.tag.c_str(),
103 : DURATION_US(TIME_NOW() - startut));
104 0 : return HCCL_SUCCESS;
105 0 : }
106 :
107 0 : HcclResult CollReduceScatterVAIVBigCountExecutor::GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo)
108 : {
109 : (void)algRes;
110 : (void)adjInfo;
111 0 : return HCCL_SUCCESS;
112 : }
113 :
114 0 : HcclResult CollReduceScatterVAIVBigCountExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
115 : {
116 0 : HCCL_INFO("[CollReduceScatterVAIVBigCountExecutor][KernelRun]ReduceScatterV aiv enter.");
117 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
118 0 : SubCommInfo outerCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
119 :
120 : void* buffersIn[MAX_RANK_SIZE];
121 : void* buffersOut[MAX_RANK_SIZE];
122 :
123 0 : u32 localRank = outerCommInfo.localRank;
124 0 : u32 localRankSize = outerCommInfo.localRankSize;
125 0 : HCCL_DEBUG(
126 : "[CollReduceScatterVAIVBigCountExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank,
127 : localRank);
128 :
129 0 : ExtraArgs extraArgs;
130 0 : for (u32 i = 0; i < localRankSize; i++) {
131 0 : if (i != localRank) {
132 0 : CHK_RET(outerCommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
133 0 : CHK_RET(outerCommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
134 : } else {
135 0 : buffersIn[i] = execMem.inputMem.ptr();
136 0 : buffersOut[i] = execMem.outputMem.ptr();
137 : }
138 0 : extraArgs.sendCounts[i] = *(static_cast<const u64*>(param.VDataDes.counts) + i);
139 0 : extraArgs.sendDispls[i] = *(static_cast<const u64*>(param.VDataDes.displs) + i);
140 0 : extraArgs.maxCount = std::max(extraArgs.maxCount, extraArgs.sendCounts[i]);
141 : }
142 :
143 0 : bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
144 :
145 0 : execMem.count = (static_cast<const u64*>(param.VDataDes.counts))[topoAttr_.userRank];
146 :
147 0 : AivOpArgs opArgs{
148 : HcclCMDType::HCCL_CMD_REDUCE_SCATTER_V,
149 0 : execMem.inputPtr,
150 0 : execMem.outputPtr,
151 0 : extraArgs.maxCount,
152 0 : param.VDataDes.dataType,
153 0 : param.reduceType,
154 0 : param.root,
155 0 : isOpbase};
156 0 : AivTopoArgs topoArgs{localRank, localRankSize};
157 0 : topoArgs.identify = algoAttr_.identifier;
158 : u32 numBlocks;
159 0 : CHK_PRT_RET(
160 : CalNumBlocks(numBlocks, localRankSize) != HCCL_SUCCESS, HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
161 : HCCL_E_PARA);
162 0 : numBlocks_ = numBlocks;
163 0 : HCCL_DEBUG("[CollReduceScatterVAIVBigCountExecutor][KernelRun]numBlocks is [%u]", numBlocks_);
164 0 : AivResourceArgs resourceArgs{param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
165 0 : numBlocks_, param.aivTag};
166 0 : AivAlgArgs algArgs{};
167 0 : algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
168 0 : algArgs.execTimeOutSet = true;
169 0 : struct AivProfilingInfo aivProfilingInfo;
170 0 : aivProfilingInfo.counter = opCounter_;
171 :
172 0 : HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo);
173 0 : CHK_PRT_RET(
174 : ret != HCCL_SUCCESS,
175 : HCCL_ERROR(
176 : "[CollReduceScatterVAIVBigCountExecutor][KernelRun]"
177 : "ReduceScatterV aiv failed, return[%d]",
178 : ret),
179 : ret);
180 :
181 0 : HCCL_INFO("[CollReduceScatterVAIVBigCountExecutor][KernelRun]ReduceScatterV aiv run success.");
182 :
183 0 : return HCCL_SUCCESS;
184 0 : }
185 :
186 : REGISTER_EXEC("ReduceScatterVAIVBigCountExecutor", ReduceScatterVAIVBigCount, CollReduceScatterVAIVBigCountExecutor);
187 : } // namespace hccl
|