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_gatherv_mesh_aiv_smallcount_executor.h"
12 :
13 : namespace hccl {
14 :
15 0 : CollAllGatherVMeshAivSmallCountExecutor::CollAllGatherVMeshAivSmallCountExecutor(const HcclDispatcher dispatcher,
16 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
17 0 : : CollAllGatherVExecutor(dispatcher, topoMatcher)
18 : {
19 0 : desc_.isAivMode = true;
20 0 : }
21 :
22 0 : HcclResult CollAllGatherVMeshAivSmallCountExecutor::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 CollAllGatherVMeshAivSmallCountExecutor::CalcTransportMemType(TransportMemType &inputType, TransportMemType &outputType)
32 : {
33 0 : inputType = TransportMemType::AIV_INPUT;
34 0 : outputType = TransportMemType::AIV_OUTPUT;
35 0 : HCCL_INFO("[CollAllGatherVMeshAivSmallCountExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d].",
36 : tag_.c_str(), inputType, outputType);
37 0 : return HCCL_SUCCESS;
38 : }
39 :
40 0 : HcclResult CollAllGatherVMeshAivSmallCountExecutor::CalcLevel0CommInfo(TransportMemType inputType,
41 : TransportMemType outputType,
42 : 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 CollAllGatherVMeshAivSmallCountExecutor::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("[CollAllGatherVMeshAivSmallCountExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
57 : numBlocks_, numBlocks), HCCL_E_PARA);
58 :
59 0 : HCCL_INFO("[CollAllGatherVMeshAivSmallCountExecutor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]",
60 : numBlocks, numBlocks_, bestNumBlocks);
61 0 : return HCCL_SUCCESS;
62 : }
63 :
64 0 : HcclResult CollAllGatherVMeshAivSmallCountExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
65 : {
66 0 : HcclUs startut = TIME_NOW();
67 0 : tag_ = param.tag;
68 0 : algResResp_ = &algRes;
69 :
70 0 : HcclResult ret = HCCL_SUCCESS;
71 0 : ExecMem execMem;
72 :
73 0 : execMem.inputPtr = param.inputPtr;
74 0 : execMem.outputPtr = param.outputPtr;
75 0 : execMem.count = (static_cast<const u64 *>(param.VDataDes.counts))[topoAttr_.userRank];
76 :
77 0 : execMem.inputMem = algRes.aivInputMem;
78 0 : execMem.outputMem = algRes.aivOutputMem;
79 0 : ret = KernelRun(param, execMem);
80 :
81 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
82 : HCCL_ERROR("[CollAllGatherVMeshAivSmallCountExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel run failed",
83 : HCCL_ERROR_CODE(ret), param.tag.c_str()), ret);
84 :
85 0 : HCCL_INFO("tag[%s], CollAllGatherVMeshAivSmallCountExecutor orchestrate success, take time [%lld]us",
86 : param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
87 0 : return HCCL_SUCCESS;
88 0 : }
89 :
90 0 : HcclResult CollAllGatherVMeshAivSmallCountExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
91 : {
92 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollAllGatherVMeshAivSmallCountExecutor][KernelRun]AllGatherV aiv enter.");
93 :
94 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
95 0 : SubCommInfo outerCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
96 :
97 : void *buffersIn[MAX_RANK_SIZE];
98 : void *buffersOut[MAX_RANK_SIZE];
99 :
100 0 : u32 localRank = outerCommInfo.localRank;
101 0 : u32 localRankSize = outerCommInfo.localRankSize;
102 0 : HCCL_DEBUG("[CollAllGatherVMeshAivSmallCountExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank, localRank);
103 :
104 0 : ExtraArgs extraArgs;
105 0 : for (u32 i = 0; i < localRankSize; i++) {
106 0 : extraArgs.recvCounts[i] = *(static_cast<const u64 *>(param.VDataDes.counts) + i);
107 0 : extraArgs.recvDispls[i] = *(static_cast<const u64 *>(param.VDataDes.displs) + i);
108 0 : if (i != localRank) {
109 0 : CHK_RET(outerCommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
110 0 : CHK_RET(outerCommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
111 : } else {
112 0 : buffersIn[i] = execMem.inputMem.ptr();
113 0 : buffersOut[i] = execMem.outputMem.ptr();
114 : }
115 0 : if (extraArgs.recvCounts[i] > extraArgs.maxCount) {
116 0 : extraArgs.maxCount = extraArgs.recvCounts[i];
117 : }
118 : }
119 :
120 0 : bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
121 0 : AivOpArgs opArgs {
122 0 : HcclCMDType::HCCL_CMD_ALLGATHER_V, execMem.inputPtr, execMem.outputPtr, extraArgs.maxCount,
123 0 : param.VDataDes.dataType, param.reduceType, param.root, isOpbase
124 0 : };
125 0 : AivTopoArgs topoArgs { localRank, localRankSize };
126 : u32 numBlocks;
127 0 : CHK_PRT_RET(CalNumBlocks(numBlocks, localRankSize) != HCCL_SUCCESS,
128 : HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
129 : HCCL_E_PARA);
130 0 : numBlocks_ = numBlocks;
131 0 : topoArgs.identify = algoAttr_.identifier;
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("[CollAllGatherVMeshAivSmallCountExecutor][KernelRun]AllGatherV aiv failed, return[%d]", ret), ret);
144 :
145 0 : HCCL_INFO("[CollAllGatherVMeshAivSmallCountExecutor][KernelRun]AllGatherV aiv run success.");
146 0 : return HCCL_SUCCESS;
147 0 : }
148 :
149 : REGISTER_EXEC("AllGatherVMeshAivSmallCountExecutor", AllGatherVMeshAivSmallCountExecutor,
150 : CollAllGatherVMeshAivSmallCountExecutor);
151 :
152 : } // namespace hccl
|