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