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_reduce_scatter_v_mesh_aiv_smallcount_executor.h"
12 :
13 : namespace hccl {
14 0 : CollReduceScatterVMeshAivSmallCountExecutor::CollReduceScatterVMeshAivSmallCountExecutor(
15 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher)
16 0 : : CollReduceScatterVExecutor(dispatcher, topoMatcher)
17 : {
18 0 : DMAReduceFlag_ = false;
19 0 : desc_.isAivMode = true;
20 0 : }
21 :
22 0 : HcclResult CollReduceScatterVMeshAivSmallCountExecutor::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 CollReduceScatterVMeshAivSmallCountExecutor::CalcTransportMemType(TransportMemType &inputType,
32 : TransportMemType &outputType)
33 : {
34 0 : inputType = TransportMemType::AIV_INPUT;
35 0 : outputType = TransportMemType::AIV_OUTPUT;
36 0 : HCCL_INFO("[CollReduceScatterVMeshAivSmallCountExecutor][CalcTransportMemType] tag[%s] inputType[%d],"
37 : " outputType[%d].", tag_.c_str(), inputType, outputType);
38 0 : return HCCL_SUCCESS;
39 : }
40 :
41 0 : HcclResult CollReduceScatterVMeshAivSmallCountExecutor::CalcLevel0CommInfo(TransportMemType inputType,
42 : TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
43 : {
44 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
45 0 : commParaLevel0.meshSinglePlane = true;
46 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
47 0 : return HCCL_SUCCESS;
48 0 : }
49 :
50 0 : HcclResult CollReduceScatterVMeshAivSmallCountExecutor::CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize, HcclCMDType cmdType)
51 : {
52 0 : numBlocks = rankSize; // 默认情况使用rankSize个AIV
53 0 : u32 bestNumBlocks = numBlocks;
54 :
55 0 : CHK_PRT_RET(numBlocks_ < numBlocks,
56 : HCCL_WARNING("[CollReduceScatterVMeshAivSmallCountExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
57 : numBlocks_, numBlocks), HCCL_E_PARA);
58 :
59 0 : HCCL_INFO("[CollReduceScatterVMeshAivSmallCountExecutor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]",
60 : numBlocks, numBlocks_, bestNumBlocks);
61 0 : return HCCL_SUCCESS;
62 : }
63 :
64 0 : HcclResult CollReduceScatterVMeshAivSmallCountExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
65 : {
66 0 : HcclUs startut = TIME_NOW();
67 0 : algResResp_ = &algRes;
68 :
69 0 : HcclResult ret = HCCL_SUCCESS;
70 0 : ExecMem execMem;
71 0 : execMem.inputPtr = param.inputPtr;
72 0 : execMem.outputPtr = param.outputPtr;
73 :
74 : // 单算子中/小数据量
75 0 : execMem.inputMem = algRes.aivInputMem;
76 0 : execMem.outputMem = algRes.aivOutputMem;
77 0 : ret = KernelRun(param, execMem);
78 :
79 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
80 : HCCL_ERROR("[CollReduceScatterVMeshAivSmallCountExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
81 : "run failed.", HCCL_ERROR_CODE(ret), param.tag.c_str()), ret);
82 :
83 0 : HCCL_INFO("tag[%s], ReduceScatterV executor orchestrate success, take time [%lld]us.",
84 : param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
85 0 : return HCCL_SUCCESS;
86 0 : }
87 :
88 0 : HcclResult CollReduceScatterVMeshAivSmallCountExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
89 : {
90 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterVMeshAivSmallCountExecutor][KernelRun]ReduceScatterV aiv enter.");
91 :
92 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
93 0 : SubCommInfo outerCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
94 :
95 : void *buffersIn[MAX_RANK_SIZE];
96 : void *buffersOut[MAX_RANK_SIZE];
97 :
98 0 : u32 localRank = outerCommInfo.localRank;
99 0 : u32 localRankSize = outerCommInfo.localRankSize;
100 0 : HCCL_DEBUG("[CollReduceScatterVMeshAivSmallCountExecutor][KernelRun] userRank [%d] localRank [%d]",
101 : topoAttr_.userRank, localRank);
102 :
103 0 : ExtraArgs extraArgs;
104 0 : for (u32 i = 0; i < localRankSize; i++) {
105 0 : if (i != localRank) {
106 0 : CHK_RET(outerCommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
107 0 : CHK_RET(outerCommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
108 : } else {
109 0 : buffersIn[i] = execMem.inputMem.ptr();
110 0 : buffersOut[i] = execMem.outputMem.ptr();
111 : }
112 0 : extraArgs.sendCounts[i] = *(static_cast<const u64 *>(param.VDataDes.counts) + i);
113 0 : extraArgs.sendDispls[i] = *(static_cast<const u64 *>(param.VDataDes.displs) + i);
114 0 : extraArgs.maxCount = std::max(extraArgs.maxCount, extraArgs.sendCounts[i]);
115 0 : HCCL_INFO("[CollReduceScatterVMeshAivSmallCountExecutor][KernelRun]rank[%u], sendCount[%llu], sendDispl[%llu]",
116 : i, extraArgs.sendCounts[i], extraArgs.sendDispls[i]);
117 : }
118 :
119 0 : bool isOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
120 :
121 0 : AivOpArgs opArgs {
122 0 : HcclCMDType::HCCL_CMD_REDUCE_SCATTER_V, execMem.inputPtr, execMem.outputPtr, extraArgs.maxCount,
123 0 : param.VDataDes.dataType, param.reduceType, 0, isOpbase
124 0 : };
125 0 : AivTopoArgs topoArgs { localRank, localRankSize };
126 0 : topoArgs.identify = algoAttr_.identifier;
127 : u32 numBlocks;
128 0 : CHK_PRT_RET(CalNumBlocks(numBlocks, localRankSize) != HCCL_SUCCESS,
129 : HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
130 : HCCL_E_PARA);
131 0 : numBlocks_ = numBlocks;
132 : AivResourceArgs resourceArgs {
133 0 : param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(), numBlocks_, param.aivTag
134 0 : };
135 0 : AivAlgArgs algArgs {};
136 0 : algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
137 0 : algArgs.execTimeOutSet = true;
138 0 : struct AivProfilingInfo aivProfilingInfo;
139 0 : aivProfilingInfo.counter = opCounter_;
140 :
141 0 : HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo);
142 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
143 : HCCL_ERROR("[CollReduceScatterVMeshAivSmallCountExecutor][KernelRun]ReduceScatterV aiv failed, return[%d].",
144 : ret), ret);
145 :
146 0 : HCCL_INFO("[CollReduceScatterVMeshAivSmallCountExecutor][KernelRun]ReduceScatterV aiv run success.");
147 0 : return HCCL_SUCCESS;
148 0 : }
149 :
150 : REGISTER_EXEC("ReduceScatterVMeshAivSmallCountExecutor", ReduceScatterVMeshAivSmallCount,
151 : CollReduceScatterVMeshAivSmallCountExecutor);
152 :
153 : } // namespace hccl
|