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_reduce_aiv_deter_executor.h"
12 :
13 : namespace hccl {
14 :
15 0 : CollAllReduceAivDeterExecutor::CollAllReduceAivDeterExecutor(
16 0 : const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
17 0 : : CollAllReduceExecutor(dispatcher, topoMatcher)
18 : {
19 0 : DMAReduceFlag_ = false;
20 0 : desc_.isAivMode = true;
21 0 : }
22 :
23 0 : HcclResult CollAllReduceAivDeterExecutor::CalcStreamNum(u32& streamNum)
24 : {
25 0 : streamNum = 0; // AIV通信不需要申请从流
26 0 : HCCL_INFO("[CollAllReduceAivDeterExecutor][CalcStreamNum] tag[%s] streamNum[%u].", tag_.c_str(), streamNum);
27 0 : return HCCL_SUCCESS;
28 : }
29 :
30 0 : HcclResult CollAllReduceAivDeterExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
31 : {
32 0 : TransportMemType inputType = TransportMemType::RESERVED;
33 0 : TransportMemType outputType = TransportMemType::RESERVED;
34 0 : CHK_RET(CalcTransportMemType(inputType, outputType));
35 0 : CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
36 0 : return HCCL_SUCCESS;
37 : }
38 :
39 : HcclResult
40 0 : CollAllReduceAivDeterExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
41 : {
42 0 : inputType = TransportMemType::CCL_INPUT;
43 0 : outputType = TransportMemType::AIV_OUTPUT;
44 0 : HCCL_INFO(
45 : "[CollAllReduceAivDeterExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d].", tag_.c_str(),
46 : inputType, outputType);
47 0 : return HCCL_SUCCESS;
48 : }
49 :
50 0 : HcclResult CollAllReduceAivDeterExecutor::CalcLevel0CommInfo(
51 : TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
52 : {
53 0 : CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
54 0 : commParaLevel0.meshSinglePlane = true;
55 0 : CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
56 0 : return HCCL_SUCCESS;
57 0 : }
58 :
59 0 : HcclResult CollAllReduceAivDeterExecutor::CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize, HcclCMDType cmdType)
60 : {
61 0 : numBlocks = rankSize; // 默认情况使用rankSize个AIV
62 :
63 0 : numBlocks = NUM_BLOCKS_FACTOR_TWO * rankSize; // 小数据量使用2倍rankSize的AIV core
64 0 : if (dataSize >= AIV_ALL_REDUCE_DETER_SIZE) {
65 0 : numBlocks = NUM_BLOCKS_FACTOR_THREE * rankSize;
66 : }
67 :
68 0 : HCCL_INFO(
69 : "[CollAllReduceAivDeterExecutor][CalNumBlocks] datasize is [%llu], numBlocks is set to [%u]", dataSize,
70 : numBlocks);
71 0 : return HCCL_SUCCESS;
72 : }
73 :
74 0 : HcclResult CollAllReduceAivDeterExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
75 : {
76 0 : HcclUs startut = TIME_NOW();
77 0 : tag_ = param.tag;
78 0 : algResResp_ = &algRes;
79 :
80 0 : HcclResult ret = HCCL_SUCCESS;
81 0 : ExecMem execMem;
82 0 : execMem.count = param.DataDes.count;
83 0 : execMem.inputPtr = param.inputPtr;
84 0 : execMem.outputPtr = param.outputPtr;
85 : // 确定性场景不支持图模式
86 0 : execMem.inputMem = algRes.cclInputMem;
87 0 : execMem.outputMem = algRes.aivOutputMem; // 使用AIVOUT
88 0 : ret = KernelRun(param, execMem);
89 :
90 0 : CHK_PRT_RET(
91 : ret != HCCL_SUCCESS,
92 : HCCL_ERROR(
93 : "[CollAllReduceAivDeterExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel run failed",
94 : HCCL_ERROR_CODE(ret), param.tag.c_str()),
95 : ret);
96 :
97 0 : HCCL_INFO(
98 : "tag[%s], AllReduce executor orchestrate success, take time [%lld]us", param.tag.c_str(),
99 : DURATION_US(TIME_NOW() - startut));
100 0 : return HCCL_SUCCESS;
101 0 : }
102 :
103 0 : HcclResult CollAllReduceAivDeterExecutor::GetAivExecParam(
104 : const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
105 : {
106 0 : return HCCL_SUCCESS;
107 : }
108 :
109 0 : HcclResult CollAllReduceAivDeterExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
110 : {
111 0 : HCCL_INFO("[CollAllReduceAivDeterExecutor][KernelRun]AllReduce aiv enter.");
112 :
113 0 : CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
114 0 : SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
115 :
116 : void* buffersIn[MAX_RANK_SIZE];
117 : void* buffersOut[MAX_RANK_SIZE];
118 :
119 0 : u32 localRank = level0CommInfo.localRank;
120 0 : u32 localRankSize = level0CommInfo.localRankSize;
121 0 : HCCL_CONFIG_DEBUG(
122 : HCCL_ALG, "[CollAllReduceAivDeterExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank,
123 : localRank);
124 :
125 0 : for (u32 i = 0; i < localRankSize; i++) {
126 0 : if (i != localRank) {
127 0 : CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
128 0 : CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
129 : } else {
130 0 : buffersIn[i] = execMem.inputMem.ptr();
131 0 : buffersOut[i] = execMem.outputMem.ptr();
132 : }
133 : }
134 :
135 0 : bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
136 0 : AivOpArgs opArgs{
137 : HcclCMDType::HCCL_CMD_ALLREDUCE,
138 0 : execMem.inputPtr,
139 0 : execMem.outputPtr,
140 0 : execMem.count,
141 0 : param.DataDes.dataType,
142 0 : param.reduceType,
143 : 0,
144 0 : isOpbase};
145 0 : AivTopoArgs topoArgs{localRank, localRankSize, MAX_RANK_SIZE, 0, 1, topoAttr_.deviceType};
146 0 : topoArgs.identify = algoAttr_.identifier;
147 :
148 0 : u64 dataSize = SIZE_TABLE[param.DataDes.dataType] * execMem.count;
149 : u32 numBlocks;
150 0 : CHK_PRT_RET(
151 : CalNumBlocks(numBlocks, localRankSize, dataSize) != HCCL_SUCCESS,
152 : HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
153 0 : numBlocks_ = numBlocks;
154 0 : AivResourceArgs resourceArgs{param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
155 0 : numBlocks_, param.aivTag};
156 0 : AivAlgArgs algArgs{};
157 0 : algArgs.deterministic = 1;
158 0 : algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
159 0 : algArgs.execTimeOutSet = true;
160 0 : struct AivProfilingInfo aivProfilingInfo;
161 0 : aivProfilingInfo.counter = opCounter_;
162 0 : HCCL_INFO(
163 : "[CollAllReduceAivDeterExecutor][KernelRun]AllReduce bufferin[%d] bufferout[%d]", execMem.inputMem.size(),
164 : execMem.outputMem.size());
165 :
166 0 : HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
167 :
168 0 : ExtraArgs extraArgs;
169 0 : CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
170 :
171 0 : CHK_PRT_RET(
172 : ret != HCCL_SUCCESS,
173 : HCCL_ERROR("[CollAllReduceAivDeterExecutor][KernelRun]AllReduce aiv failed, return[%d]", ret), ret);
174 :
175 0 : HCCL_INFO("[CollAllReduceAivDeterExecutor][KernelRun]AllReduce aiv run success.");
176 0 : return HCCL_SUCCESS;
177 0 : }
178 :
179 : REGISTER_EXEC("AllReduceAivDeterExecutor", AllReduceAivDeter, CollAllReduceAivDeterExecutor);
180 :
181 : } // namespace hccl
|