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