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 "ccu_device_manager.h"
12 :
13 : #include "hccl_common_v2.h"
14 : #include "rdma_handle_manager.h"
15 :
16 : #include "ccu_component.h"
17 : #include "ccu_res_specs.h"
18 : #include "ccu_res_batch_allocator.h"
19 :
20 : namespace Hccl {
21 :
22 1 : HcclResult CcuAllocChannels(const int32_t deviceLogicId, const CcuChannelPara &ccuChannelPara,
23 : std::vector<CcuChannelInfo> &ccuChannelInfos)
24 : {
25 3 : HCCL_INFO("[%s] new allocation request: deviceLogicId[%d], ipAddr[%s], "
26 : "channelnum[%u], jettyNum[%u], sqSize[%u].", __func__, deviceLogicId,
27 : ccuChannelPara.ipAddr.Describe().c_str(), ccuChannelPara.channelNum,
28 : ccuChannelPara.jettyNum, ccuChannelPara.sqSize);
29 : // 入参校验拦截
30 1 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
31 : HCCL_ERROR("[CcuAllocChannels]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
32 : HcclResult::HCCL_E_PARA);
33 1 : TRY_CATCH_RETURN(
34 : const uint32_t devPhyId = HrtGetDevicePhyIdByIndex(deviceLogicId);
35 : auto &rdmaHandleMgr = RdmaHandleManager::GetInstance();
36 : const RdmaHandle rdmaHandle = rdmaHandleMgr.GetByIp(devPhyId, ccuChannelPara.ipAddr);
37 : const auto &dieIdAndFuncId = rdmaHandleMgr.GetDieAndFuncId(rdmaHandle);
38 : const uint8_t dieId = dieIdAndFuncId.first;
39 : ChannelPara para{}; // TRY_CATCH_RETURN 宏内不能直接在{}传参
40 : para.feId = dieIdAndFuncId.second;
41 : para.jettyNum = ccuChannelPara.jettyNum;
42 : para.sqSize = ccuChannelPara.sqSize;
43 : return CcuComponent::GetInstance(deviceLogicId).AllocChannels(dieId, para, ccuChannelInfos);
44 : );
45 : }
46 :
47 0 : HcclResult CcuReleaseChannel(const int32_t deviceLogicId, const uint8_t dieId,
48 : const uint32_t ccuChannelId)
49 : {
50 0 : HCCL_INFO("[%s] new release request: deviceLogicId[%d], dieId[%u], "
51 : "ccuChannelId[%u].", __func__, deviceLogicId, dieId, ccuChannelId);
52 : // 入参校验拦截
53 0 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
54 : HCCL_ERROR("[CcuReleaseChannel]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
55 : HcclResult::HCCL_E_PARA);
56 0 : TRY_CATCH_RETURN(
57 : return CcuComponent::GetInstance(deviceLogicId).ReleaseChannel(dieId, ccuChannelId);
58 : );
59 : }
60 :
61 0 : HcclResult CcuGetChannelSpecNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &channelNum)
62 : {
63 0 : HCCL_INFO("[CcuGetChannelSpecNum] Input params: deviceLogicId[%d], dieId[%u], channelNum[%u]", deviceLogicId, dieId, channelNum);
64 : // 入参校验拦截
65 0 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
66 : HCCL_ERROR("[CcuGetChannelSpecNum]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
67 : HcclResult::HCCL_E_PARA);
68 0 : TRY_CATCH_RETURN(
69 : return CcuResSpecifications::GetInstance(deviceLogicId).GetChannelNum(dieId, channelNum);
70 : );
71 : }
72 :
73 6 : bool CcuIsInited(const int32_t deviceLogicId)
74 : {
75 18 : HCCL_INFO("[CcuIsInited] Input params: deviceLogicId[%d]", deviceLogicId);
76 6 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
77 : HCCL_ERROR("[CcuIsInited]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
78 : false);
79 6 : return CcuComponent::GetInstance(deviceLogicId).IsInited();
80 : }
81 :
82 0 : HcclResult CcuSetTaskKill(const int32_t deviceLogicId)
83 : {
84 0 : HCCL_INFO("[CcuSetTaskKill] Input params: deviceLogicId[%d]", deviceLogicId);
85 : // 入参校验拦截
86 0 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
87 : HCCL_ERROR("[CcuSetTaskKill]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
88 : HcclResult::HCCL_E_PARA);
89 0 : TRY_CATCH_RETURN(
90 : return CcuComponent::GetInstance(deviceLogicId).SetTaskKill();
91 : );
92 : }
93 :
94 0 : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId)
95 : {
96 0 : HCCL_INFO("[CcuSetTaskKillDone] Input params: deviceLogicId[%d]", deviceLogicId);
97 : // 入参校验拦截
98 0 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
99 : HCCL_ERROR("[CcuSetTaskKillDone]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
100 : HcclResult::HCCL_E_PARA);
101 0 : TRY_CATCH_RETURN(
102 : return CcuComponent::GetInstance(deviceLogicId).SetTaskKillDone();
103 : );
104 : }
105 :
106 0 : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId)
107 : {
108 0 : HCCL_INFO("[CcuCleanTaskKillState] Input params: deviceLogicId[%d]", deviceLogicId);
109 : // 入参校验拦截
110 0 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
111 : HCCL_ERROR("[CcuCleanTaskKillState]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
112 : HcclResult::HCCL_E_PARA);
113 0 : TRY_CATCH_RETURN(
114 : return CcuComponent::GetInstance(deviceLogicId).CleanTaskKillState();
115 : );
116 : }
117 :
118 0 : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId)
119 : {
120 0 : HCCL_INFO("[CcuCleanDieCkes] Input params: deviceLogicId[%d], dieId[%u]", deviceLogicId, dieId);
121 : // 入参校验拦截
122 0 : CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
123 : HCCL_ERROR("[CcuCleanDieCkes]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
124 : HcclResult::HCCL_E_PARA);
125 0 : TRY_CATCH_RETURN(
126 : return CcuComponent::GetInstance(deviceLogicId).CleanDieCkes(dieId);
127 : );
128 : }
129 :
130 0 : HcclResult CcuDeviceManager::GetCcuVersion(const int32_t deviceLogicId, CcuVersion &ccuVersion)
131 : {
132 0 : TRY_CATCH_RETURN(
133 : ccuVersion = CcuResSpecifications::GetInstance(deviceLogicId).GetCcuVersion();
134 : );
135 :
136 0 : return HcclResult::HCCL_SUCCESS;
137 : }
138 :
139 0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceBufInfo(const int32_t deviceLogicId, const uint8_t dieId,
140 : uint64_t &addr, uint64_t &size)
141 : {
142 0 : TRY_CATCH_RETURN(
143 : return CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceBufInfo(dieId, addr, size);
144 : );
145 : }
146 :
147 0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceTokenInfo(const int32_t deviceLogicId, const uint8_t dieId,
148 : uint64_t &tokenId, uint64_t &tokenValue)
149 : {
150 0 : TRY_CATCH_RETURN(
151 : return CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceTokenInfo(dieId, tokenId, tokenValue);
152 : );
153 : }
154 :
155 0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceTokenInfoForLocal(const int32_t deviceLogicId, const uint8_t dieId,
156 : uint64_t &tokenId, uint64_t &tokenValue)
157 : {
158 0 : TRY_CATCH_RETURN(
159 : return CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceTokenInfoForLocal(dieId, tokenId, tokenValue);
160 : );
161 : }
162 :
163 0 : HcclResult CcuDeviceManager::ConfigChannel(const int32_t deviceLogicId, const uint8_t dieId,
164 : ChannelCfg &cfg)
165 : {
166 0 : TRY_CATCH_RETURN(
167 : return CcuComponent::GetInstance(deviceLogicId).ConfigChannel(dieId, cfg);
168 : );
169 : }
170 :
171 0 : HcclResult CcuDeviceManager::GetLoopChannelId(const int32_t deviceLogicId, const uint8_t srcDieId,
172 : const uint8_t dstDieId, uint32_t &channIdx)
173 : {
174 0 : TRY_CATCH_RETURN(
175 : return CcuComponent::GetInstance(deviceLogicId).GetLoopChannelId(srcDieId, dstDieId, channIdx);
176 : );
177 : }
178 :
179 0 : HcclResult CcuDeviceManager::GetResource(const int32_t deviceLogicId,
180 : const CcuResHandle handle, CcuResRepository &ccuResRepo)
181 : {
182 0 : TRY_CATCH_RETURN(
183 : return CcuResBatchAllocator::GetInstance(deviceLogicId).GetResource(handle, ccuResRepo);
184 : );
185 : }
186 :
187 0 : HcclResult CcuDeviceManager::AllocResHandle(const int32_t deviceLogicId, const CcuResReq resReq,
188 : CcuResHandle &handle)
189 : {
190 0 : TRY_CATCH_RETURN(
191 : return CcuResBatchAllocator::GetInstance(deviceLogicId).AllocResHandle(resReq, handle);
192 : );
193 : }
194 :
195 0 : HcclResult CcuDeviceManager::ReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle handle)
196 : {
197 0 : TRY_CATCH_RETURN(
198 : return CcuResBatchAllocator::GetInstance(deviceLogicId).ReleaseResHandle(handle);
199 : );
200 : }
201 :
202 0 : HcclResult CcuDeviceManager::AllocIns(const int32_t deviceLogicId, const uint8_t dieId,
203 : const uint32_t num, ResInfo &insInfo)
204 : {
205 0 : TRY_CATCH_RETURN(
206 : return CcuComponent::GetInstance(deviceLogicId).AllocIns(dieId, num, insInfo);
207 : );
208 : }
209 :
210 0 : HcclResult CcuDeviceManager::ReleaseIns(const int32_t deviceLogicId, const uint8_t dieId,
211 : ResInfo &insInfo)
212 : {
213 0 : TRY_CATCH_RETURN(
214 : return CcuComponent::GetInstance(deviceLogicId).ReleaseIns(dieId, insInfo);
215 : );
216 : }
217 :
218 176 : HcclResult CcuDeviceManager::AllocCke(const int32_t deviceLogicId, const uint8_t dieId,
219 : const uint32_t num, std::vector<ResInfo> &ckeInfos)
220 : {
221 176 : TRY_CATCH_RETURN(
222 : return CcuComponent::GetInstance(deviceLogicId).AllocCke(dieId, num, ckeInfos);
223 : );
224 : }
225 :
226 22 : HcclResult CcuDeviceManager::ReleaseCke(const int32_t deviceLogicId, const uint8_t dieId,
227 : std::vector<ResInfo> &ckeInfos)
228 : {
229 22 : TRY_CATCH_RETURN(
230 : return CcuComponent::GetInstance(deviceLogicId).ReleaseCke(dieId, ckeInfos);
231 : );
232 : }
233 :
234 0 : HcclResult CcuDeviceManager::AllocXn(const int32_t deviceLogicId, const uint8_t dieId,
235 : const uint32_t num, vector<ResInfo>& xnInfos)
236 : {
237 0 : TRY_CATCH_RETURN(
238 : return CcuComponent::GetInstance(deviceLogicId).AllocXn(dieId, num, xnInfos);
239 : );
240 : }
241 :
242 0 : HcclResult CcuDeviceManager::ReleaseXn(const int32_t deviceLogicId, const uint8_t dieId,
243 : vector<ResInfo> &xnInfos)
244 : {
245 0 : TRY_CATCH_RETURN(
246 : return CcuComponent::GetInstance(deviceLogicId).ReleaseXn(dieId, xnInfos);
247 : );
248 : }
249 :
250 0 : HcclResult CcuDeviceManager::GetMissionKey(const int32_t deviceLogicId, const uint8_t dieId,
251 : uint32_t &missionKey)
252 : {
253 0 : TRY_CATCH_RETURN(
254 : return CcuResSpecifications::GetInstance(deviceLogicId).GetMissionKey(dieId, missionKey);
255 : );
256 : }
257 :
258 0 : HcclResult CcuDeviceManager::GetInstructionNum(const int32_t deviceLogicId, const uint8_t dieId,
259 : uint32_t &instrNum)
260 : {
261 0 : TRY_CATCH_RETURN(
262 : return CcuResSpecifications::GetInstance(deviceLogicId).GetInstructionNum(dieId, instrNum);
263 : );
264 : }
265 :
266 0 : HcclResult CcuDeviceManager::GetXnBaseAddr(const uint32_t devLogicId, const uint8_t dieId,
267 : uint64_t& xnBaseAddr)
268 : {
269 0 : TRY_CATCH_RETURN(
270 : return CcuResSpecifications::GetInstance(devLogicId).GetXnBaseAddr(dieId, xnBaseAddr);
271 : );
272 : }
273 :
274 748 : HcclResult CheckDieValid(const char *funcName, const int32_t devLogicId, const uint8_t dieId,
275 : const std::array<bool, MAX_CCU_IODIE_NUM> &dieEnableFlags)
276 : {
277 769 : CHK_PRT_RET(dieId >= MAX_CCU_IODIE_NUM,
278 : HCCL_ERROR("[%s] failed, dieId[%u] is invalid, shoudle be in [0-%u), devLogicId[%d].",
279 : funcName, dieId, MAX_CCU_IODIE_NUM, devLogicId),
280 : HcclResult::HCCL_E_PARA);
281 :
282 1341 : CHK_PRT_RET(!dieEnableFlags[dieId],
283 : HCCL_WARNING("[%s] failed, dieId[%u] is disable, devLogicId[%d].",
284 : funcName, dieId, devLogicId),
285 : HcclResult::HCCL_E_PARA);
286 :
287 541 : return HcclResult::HCCL_SUCCESS;
288 : }
289 :
290 : }; // namespace Hccl
|