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 : #include "ccuTaskException.h"
11 : #include "ccu_dfx_schema.h"
12 : #include <memory>
13 : #include "log.h"
14 : #include "comm_addr_logger.h"
15 : #include "coll_comm.h"
16 : #include <adapter_error_manager_pub.h>
17 : #include "task_param.h"
18 : #include "ccu_kernel_mgr.h"
19 : #include "hcomm_c_adpt.h"
20 : #include "../../endpoint_pairs/channels/ccu/ccu_urma_channel.h"
21 : #include "orion_adpt_utils.h"
22 : #include "hcomm_adapter_hccp.h"
23 : #include "hccp_tlv_hdc_manager.h"
24 : #include "adapter_rts_common.h"
25 : #include "ccu_rep_loopgroup_bundle_v1.h"
26 : #include "ccu_rep_type_v1.h"
27 : #include "ccu_rep_loc_record_event.h"
28 : #include "ccu_rep_v1.h"
29 : #include "ccu_comp.h"
30 : #include "string_util.h"
31 :
32 : #include "net_instance.h"
33 : #include "hccl_communicator.h"
34 :
35 : #include "sal.h"
36 :
37 : namespace hcomm {
38 :
39 : using namespace std;
40 : constexpr int BYTE = 8;
41 : constexpr size_t CCU_CTX_RAW_CAPACITY = 64;
42 : constexpr uint64_t CCU_MSG_256MB_LEN = 256ULL * 1024 * 1024; // CCU消息长度不能大于256MB
43 : constexpr uint16_t INVALID_U16 = 65535;
44 : constexpr uint8_t CCUM_EXECUTE_ERROR = 0X09;
45 : constexpr uint8_t CCU_MISSION_TASK_KILLED = 0X02;
46 :
47 : const map<uint8_t, string> MISSION_STATUS_MAP{
48 : {0x01, "Unsupported Opcode(0x01)"}, {0x02, "Local Operation Error(0x02)"},
49 : {0x03, "Remote Operation Error(0x03)"}, {0x04, "Transaction Retry Counter Exceeded(0x04)"},
50 : {0x05, "Transaction ACK Timeout(0x05)"}, {0x06, "Jetty Work Request Flushed(0x06)"},
51 : {0x07, "CCUA Alg Task Error(0x07)"}, {0x08, "Memory ECC Error(0x08)"},
52 : {0x09, "CCUM Execute Error(0x09)"}, {0x0A, "CCUA Execute Error(0x0A)"},
53 : };
54 :
55 : const map<uint8_t, map<uint8_t, string>> MISSION_SUB_STATUS_MAP{
56 : {0x02,
57 : {{0x01, "Local Length Error(0x01)"},
58 : {0x02, "Local Access Error(0x02)"},
59 : {0x03, "Remote Response Length Error(0x03)"},
60 : {0x04, "Local Data Poison(0x04)"}}},
61 : {0x03,
62 : {{0x01, "Remote Unsupported Request(0x01)"},
63 : {0x02, "Remote Access Abort(0x02)"},
64 : {0x04, "Remote Data Poison(0x04)"}}},
65 : {0x07,
66 : {{0x01, "Overflow(0x01)"},
67 : {0x02, "Underflow(0x02)"},
68 : {0x04, "NaN(0x04)"},
69 : {0x08, "Inf(0x08)"},
70 : {0x09, "Inf Overflow(0x09)"}}},
71 : {0x09, {{0x01, "SQE instr and key not match(0x01)"}, {0x02, "CCU Mission Task Killed(0x02)"}}},
72 : {0x0A,
73 : {{0x01, "EXOKAY(0x01)"},
74 : {0x11, "EXOKAY(0x11)"},
75 : {0x02, "SLVERR(0x02)"},
76 : {0x12, "SLVERR(0x12)"},
77 : {0x03, "DECERR(0x03)"},
78 : {0x13, "DECERR(0x13)"},
79 : {0x04, "Abort(0x04)"},
80 : {0x14, "Abort(0x14)"},
81 : {0x05, "Write Permission Err(0x05)"},
82 : {0x15, "Write Permission Err(0x15)"},
83 : {0x06, "Read Permission Err(0x06)"},
84 : {0x16, "Read Permission Err(0x16)"},
85 : {0x07, "Atomic Permission Err(0x07)"},
86 : {0x17, "Atomic Permission Err(0x17)"},
87 : {0x08, "Tokenval Err(0x08)"},
88 : {0x18, "Tokenval Err(0x18)"},
89 : {0x09, "Page Fault(0x09)"},
90 : {0x0a, "Page Fault(0x0A)"},
91 : {0x0b, "Page Fault(0x0B)"},
92 : {0x19, "Page Fault(0x19)"},
93 : {0x1a, "Page Fault(0x1A)"},
94 : {0x1b, "Page Fault(0x1B)"},
95 : {0x0c, "Read Local Mem Poison(0x0C)"}}},
96 : };
97 :
98 : const unordered_set<CcuRep::CcuRepType> REP_WITH_CHANNEL = {
99 : {CcuRep::CcuRepType::REM_POST_SEM}, {CcuRep::CcuRepType::REM_WAIT_SEM}, {CcuRep::CcuRepType::REM_POST_VAR},
100 : {CcuRep::CcuRepType::READ}, {CcuRep::CcuRepType::WRITE}, {CcuRep::CcuRepType::BUF_READ},
101 : {CcuRep::CcuRepType::BUF_WRITE},
102 : };
103 :
104 0 : MAKE_ENUM(AuxInfoInType, AUX_INFO_IN_TYPE_CQE, AUX_INFO_IN_TYPE_AE, AUX_INFO_IN_TYPE_MAX);
105 : struct AuxInfoIn {
106 : AuxInfoInType auxInfoInType;
107 : union {
108 : struct {
109 : uint32_t status;
110 : uint8_t sR;
111 : } cqe;
112 : struct {
113 : uint32_t eventType;
114 : } ae;
115 : };
116 : u8 resv[7];
117 : };
118 :
119 : constexpr u32 MAX_AUX_INFO_NUM = 256;
120 : struct AuxInfoOut {
121 : uint32_t auxInfoTypes[MAX_AUX_INFO_NUM];
122 : uint32_t auxInfoValues[MAX_AUX_INFO_NUM];
123 : uint32_t auxInfoNum{0};
124 : };
125 :
126 : std::mutex g_channelMapMutex;
127 : std::unordered_map<uint16_t, uint64_t> g_channelIdToHandle;
128 : std::atomic<bool> isGetCqeErrInfo(
129 : false); // 是否已获取过CQE错误信息,获取过后再次获取的概率较小,且获取过程可能较慢,因此设置标志位避免重复获取
130 : CcuGetErrStatusVecCallBack g_CcuGetErrStatusVecCallBack = nullptr;
131 : GetCcuCqeErrInfoCallBackHcomm g_getCqeErrInfoCallBack = nullptr;
132 :
133 46 : void RegisterCcuGetErrStatusVecCallBack(CcuGetErrStatusVecCallBack callback)
134 : {
135 46 : g_CcuGetErrStatusVecCallBack = callback;
136 46 : return;
137 : }
138 :
139 12 : std::vector<std::string> CcuGetErrStatusVec(s32 deviceLogicID)
140 : {
141 12 : if (g_CcuGetErrStatusVecCallBack != nullptr) {
142 12 : return g_CcuGetErrStatusVecCallBack(deviceLogicID);
143 : } else {
144 0 : HCCL_RUN_WARNING("[GetErrStatusVec]g_CcuGetErrStatusVecCallBack is nullptr.");
145 : }
146 0 : return std::vector<std::string>();
147 : }
148 :
149 12 : std::string CcuGetAndPrintClusterMonitorErr(const u32 deviceId)
150 : {
151 12 : auto errStatusVec = CcuGetErrStatusVec(deviceId);
152 12 : std::string errMsg = "";
153 12 : int errSize = errStatusVec.size();
154 12 : if (errSize > 0) {
155 0 : int maxListSize = 3; // 放入errMsg中的异常事件最多只有3个
156 0 : if (errSize <= maxListSize) {
157 0 : errMsg = "\nthere are(is) " + std::to_string(errSize) + " abnormal device(s):\n";
158 : } else {
159 0 : errMsg = "\nthere are " + std::to_string(errSize) + " abnormal device(s), "
160 0 : + "only the first 3 devices are listed:\n";
161 : }
162 :
163 0 : for (int i = 0; i < errSize; i++) {
164 0 : HCCL_ERROR("%s", errStatusVec[i].c_str());
165 0 : if (i < maxListSize) {
166 0 : errMsg += ("\t" + errStatusVec[i] + "\n");
167 : }
168 : }
169 : }
170 12 : return errMsg;
171 12 : }
172 :
173 46 : void RegisterGetCcuCqeErrInfoCallBackHcomm(GetCcuCqeErrInfoCallBackHcomm p1)
174 : {
175 46 : g_getCqeErrInfoCallBack = p1;
176 46 : return;
177 : }
178 0 : void CcuTaskException::ClusterMoniterGetCcuCqeErrInfo(
179 : u32 RemoteDeviceId, u32 locDeviceId, uint16_t status, std::string LocalEid, std::string RemoteEid,
180 : std::string RemoteInsId)
181 : {
182 0 : if (g_getCqeErrInfoCallBack != nullptr) {
183 0 : g_getCqeErrInfoCallBack(RemoteDeviceId, locDeviceId, status, LocalEid, RemoteEid, RemoteInsId);
184 : }
185 0 : return;
186 : }
187 :
188 5 : static void PrintPanicLogWithOps(const uint8_t* panicLog, const CcuVersionOps* ops)
189 : {
190 5 : if (panicLog == nullptr) {
191 0 : HCCL_ERROR("[CcuTaskException][PrintPanicLogWithOps] panicLog is nullptr.");
192 5 : return;
193 : }
194 5 : if (ops == nullptr || ops->printCcumDfxInfo == nullptr) {
195 5 : HCCL_ERROR("[CcuTaskException][PrintPanicLogWithOps] ops or printCcumDfxInfo is nullptr.");
196 5 : return;
197 : }
198 0 : std::ostringstream oss;
199 0 : oss << "[CCU DFX][ops=" << ops->name << "] CCU DFX INFO:";
200 0 : ops->printCcumDfxInfo(panicLog, oss);
201 0 : std::string logStr = oss.str();
202 0 : HCCL_ERROR("%s", logStr.c_str());
203 0 : }
204 :
205 4 : void CcuTaskException::ProcessCcuException(const rtExceptionInfo_t* exceptionInfo, const Hccl::TaskInfo& taskInfo)
206 : {
207 4 : auto deviceId = exceptionInfo->deviceid;
208 4 : HCCL_ERROR("[CcuTaskException][%s]Task from HCCL run failed.", __func__);
209 4 : HCCL_ERROR(
210 : "[CcuTaskException]Task run failed, base information is deviceID:[%u], %s.", deviceId,
211 : taskInfo.GetIndopBaseInfo().c_str());
212 4 : HCCL_ERROR("[CcuTaskException]Task run failed, groupRank information is %s.", GetGroupRankInfo(taskInfo).c_str());
213 4 : HCCL_ERROR("[CcuTaskException]Task run failed, opData information is %s.", taskInfo.GetIndopDataInfo().c_str());
214 4 : CHK_PRT(InitChannelMap(deviceId, taskInfo.taskParam_.taskPara.Ccu.ccuKernelHandle));
215 4 : auto& ccuExDetailInfo = exceptionInfo->expandInfo.u.ccuInfo;
216 4 : isGetCqeErrInfo = true;
217 :
218 4 : const CcuVersionOps* ops = nullptr;
219 4 : if (GetCcuOps(ops) != HCCL_SUCCESS) {
220 4 : ops = nullptr;
221 : }
222 :
223 9 : for (uint32_t i = 0; i < ccuExDetailInfo.ccuMissionNum; ++i) { // ccuExDetailInfo.ccuMissionNum为1
224 5 : const auto& missionInfo = ccuExDetailInfo.missionInfo[i]; // 异常mission
225 5 : uint16_t status = static_cast<uint16_t>(missionInfo.status) << BYTE | missionInfo.subStatus;
226 5 : PrintCcuErrorInfo(deviceId, status, taskInfo);
227 : // 打印寄存器信息
228 5 : PrintPanicLogWithOps(missionInfo.panicLog, ops);
229 : }
230 :
231 4 : const int32_t devLogicId = static_cast<int32_t>(deviceId);
232 4 : if (CcuComponent::GetInstance(devLogicId).CleanTaskKillState() != HcclResult::HCCL_SUCCESS) {
233 1 : HCCL_ERROR("[CcuTaskException][%s] failed to clean ccu task kill state, devLogicId[%d].", __func__, devLogicId);
234 : }
235 :
236 4 : const uint8_t dieId = taskInfo.taskParam_.taskPara.Ccu.dieId;
237 4 : if (CcuComponent::GetInstance(devLogicId).CleanDieCkes(dieId) != HcclResult::HCCL_SUCCESS) {
238 1 : HCCL_ERROR(
239 : "[CcuTaskException][%s] failed to clean ccu die ckes, dieId[%u], devLogicId[%d].", __func__, dieId,
240 : devLogicId);
241 : }
242 4 : }
243 :
244 10 : HcclResult CcuTaskException::InitChannelMap(s32 deviceId, u64 ccuKernelHandle)
245 : {
246 10 : std::lock_guard<std::mutex> lock(g_channelMapMutex);
247 :
248 10 : auto& kernelMgr = hcomm::CcuKernelMgr::GetInstance(deviceId);
249 10 : auto* kernel = kernelMgr.GetKernel(ccuKernelHandle);
250 10 : CHK_PRT_RET(
251 : kernel == nullptr,
252 : HCCL_ERROR("[%s]GetKernel nullptr, deviceId[%d], ccuKernelHandle[0x%llx]", __func__, deviceId, ccuKernelHandle),
253 : HCCL_E_PARA);
254 :
255 5 : const auto& ccuChannels = kernel->GetChannels();
256 8 : for (const auto& it : ccuChannels) {
257 5 : void* channelPtr = nullptr;
258 6 : CHK_RET(static_cast<HcclResult>(HcommChannelGet(it, &channelPtr)));
259 4 : auto* channelImpl = dynamic_cast<CcuUrmaChannel*>(static_cast<Channel*>(channelPtr));
260 4 : CHK_PTR_NULL(channelImpl);
261 3 : g_channelIdToHandle[channelImpl->GetChannelId()] = it;
262 3 : HCCL_RUN_INFO(
263 : "[%s]deviceId[%d], ccuKernelHandle[0x%llx], channelId[%u], channelHandle[0x%llx]", __func__, deviceId,
264 : ccuKernelHandle, channelImpl->GetChannelId(), it);
265 : }
266 3 : return HCCL_SUCCESS;
267 10 : }
268 :
269 7 : std::string CcuTaskException::GetGroupRankInfo(const Hccl::TaskInfo& taskInfo)
270 : {
271 7 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
272 5 : HCCL_ERROR("[TaskInfo][%s]TaskInfo communicator is nullptr.", __func__);
273 10 : return "";
274 : }
275 :
276 2 : hccl::CollComm* communicator = static_cast<hccl::CollComm*>(taskInfo.dfxOpInfo_->comm_);
277 : return Hccl::StringFormat(
278 2 : "group:[%s], rankSize[%u], rankId[%u]", communicator->GetCommId().c_str(), communicator->GetRankSize(),
279 2 : communicator->GetMyRankId());
280 : }
281 :
282 4 : void CcuTaskException::PrintPanicLogInfo(const uint8_t* panicLog)
283 : {
284 4 : if (panicLog == nullptr) {
285 2 : HCCL_ERROR("[CcuTaskException][%s] panicLog is nullptr.", __func__);
286 4 : return;
287 : }
288 :
289 2 : const CcuVersionOps* ops = nullptr;
290 2 : if (GetCcuOps(ops) != HCCL_SUCCESS) {
291 2 : HCCL_ERROR("[CcuTaskException][%s] Failed to get printer ops for ccum_dfxInfo", __func__);
292 2 : return;
293 : }
294 0 : PrintPanicLogWithOps(panicLog, ops);
295 : }
296 :
297 : namespace {
298 19 : HcclResult QueryCcuCtxRaw(
299 : int32_t deviceId, uint32_t dieId, uint32_t ctxId, CcuOpcodeType op, const char* tag, uint8_t* buf,
300 : size_t bufLen, size_t& copiedLen)
301 : {
302 19 : copiedLen = 0;
303 19 : if (buf == nullptr || bufLen < CCU_CTX_RAW_CAPACITY) {
304 3 : HCCL_ERROR("[%s] invalid buffer: buf=%p, bufLen=%zu, required=%zu", tag, buf, bufLen, CCU_CTX_RAW_CAPACITY);
305 3 : return HCCL_E_PARA;
306 : }
307 16 : const auto memsetRet = memset_s(buf, bufLen, 0, bufLen);
308 16 : if (memsetRet != EOK) {
309 0 : HCCL_ERROR("[%s] memset_s failed, ret[%d]", tag, memsetRet);
310 0 : return HCCL_E_INTERNAL;
311 : }
312 :
313 16 : auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
314 16 : CHK_PRT_RET(
315 : tlvHandle == nullptr, HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), HCCL_E_PTR);
316 :
317 16 : CustomChannelInfoIn inBuff{};
318 16 : CustomChannelInfoOut outBuff{};
319 16 : inBuff.op = op;
320 16 : inBuff.data.dataInfo.udieIdx = dieId;
321 16 : inBuff.offsetStartIdx = ctxId;
322 16 : inBuff.data.dataInfo.dataArraySize = 1; // 读1个MissionContext
323 16 : inBuff.data.dataInfo.dataLen = CCU_CTX_RAW_CAPACITY;
324 :
325 16 : HcclResult ret = HccpRaTlvRequestForCustomChannel(
326 : tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
327 :
328 16 : CHK_PRT_RET(
329 : ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%u]", tag, ret), ret);
330 7 : const auto sret = memcpy_s(buf, bufLen, outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
331 7 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy_s failed, ret[%d]", tag, sret), HCCL_E_MEMORY);
332 7 : copiedLen = inBuff.data.dataInfo.dataLen;
333 7 : return HCCL_SUCCESS;
334 : }
335 : } // namespace
336 :
337 : using GetMissionRawFunc = HcclResult (*)(
338 : int32_t deviceId, uint32_t dieId, uint32_t missionId, uint8_t* buf, size_t bufLen, size_t& copiedLen);
339 : using GenErrorInfoLoopGroupFunc = HcclResult (*)(
340 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase, CcuRep::CcuRepContext& ctx,
341 : std::vector<CcuErrorInfo>& errorInfo);
342 : using GenErrorInfoByRepTypeFunc = void (*)(
343 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase, std::vector<CcuErrorInfo>& errorInfo);
344 :
345 5 : static HcclResult DecodeRawMissionInfo(const uint8_t* raw, CcuMissionInfo& out)
346 : {
347 5 : const CcuVersionOps* ops = nullptr;
348 5 : if (GetCcuOps(ops) != HCCL_SUCCESS) {
349 5 : HCCL_ERROR("[DecodeRawMissionInfo] Failed to get ops for mission context");
350 5 : return HCCL_E_INTERNAL;
351 : }
352 0 : if (ops->getMissionInfo == nullptr) {
353 0 : HCCL_ERROR("[DecodeRawMissionInfo] getMissionInfo is nullptr, ops[%s]", ops->name);
354 0 : return HCCL_E_INTERNAL;
355 : }
356 0 : return ops->getMissionInfo(raw, &out);
357 : }
358 :
359 0 : static HcclResult FetchAndDecodeLoopInfo(int32_t deviceId, uint32_t dieId, uint32_t loopCtxId, CcuLoopInfo& out)
360 : {
361 0 : uint8_t loopRaw[CCU_CTX_RAW_CAPACITY] = {0};
362 0 : size_t loopRawLen = 0;
363 0 : if (QueryCcuCtxRaw(
364 : deviceId, dieId, loopCtxId, CcuOpcodeType::CCU_U_OP_GET_LOOP_CTX, "FetchAndDecodeLoopInfo", loopRaw,
365 : sizeof(loopRaw), loopRawLen)
366 0 : != HCCL_SUCCESS) {
367 0 : HCCL_ERROR("[FetchAndDecodeLoopInfo] Failed to fetch loop raw context, deviceId[%d]", deviceId);
368 0 : return HCCL_E_INTERNAL;
369 : }
370 0 : const CcuVersionOps* ops = nullptr;
371 0 : if (GetCcuOps(ops) != HCCL_SUCCESS) {
372 0 : HCCL_ERROR("[FetchAndDecodeLoopInfo] Failed to get ops for loop context");
373 0 : return HCCL_E_INTERNAL;
374 : }
375 0 : if (ops->getLoopInfo == nullptr) {
376 0 : HCCL_ERROR("[FetchAndDecodeLoopInfo] getLoopInfo is nullptr, ops[%s]", ops->name);
377 0 : return HCCL_E_INTERNAL;
378 : }
379 0 : return ops->getLoopInfo(loopRaw, &out);
380 : }
381 :
382 : // 计算报错指令附近可用 Rep 的起始指令,提取自 GetCcuErrorMsg 以降低其圈复杂度
383 0 : static uint16_t FindSurroundingBeginInstr(CcuRep::CcuRepContext& ctx, uint16_t startIns, uint16_t currIns)
384 : {
385 0 : uint16_t loopUpInstrNum = 10; // 出错指令前 10 条
386 0 : uint16_t beginIns = (currIns < loopUpInstrNum) ?
387 : startIns :
388 0 : ((currIns - loopUpInstrNum) > startIns ? (currIns - loopUpInstrNum) : startIns);
389 : // 从第一个非空 rep 开始,使用有符号变量避免 uint16_t 下溢无限循环
390 0 : for (int32_t instrId = static_cast<int32_t>(currIns); instrId >= static_cast<int32_t>(beginIns); instrId--) {
391 0 : if (ctx.GetRepByInstrId(static_cast<uint16_t>(instrId)) == nullptr) {
392 0 : beginIns = static_cast<uint16_t>(instrId) + 1U;
393 0 : break;
394 : }
395 : }
396 0 : return beginIns;
397 : }
398 :
399 5 : static HcclResult ValidateAndDecodeMissionContext(
400 : int32_t deviceId, uint16_t missionStatus, const Hccl::ParaCcu& ccuTaskParam, GetMissionRawFunc getMissionRaw,
401 : CcuMissionInfo& missionInfo)
402 : {
403 5 : CHK_PRT_RET(
404 : (deviceId < 0 || static_cast<u32>(deviceId) >= MAX_MODULE_DEVICE_NUM),
405 : HCCL_ERROR("[CcuTaskException][GetCcuErrorMsg]deviceId[%d] error.", deviceId), HcclResult::HCCL_E_PARA);
406 :
407 5 : if (missionStatus == 0) {
408 0 : HCCL_ERROR(
409 : "[CcuErrorHandler][%s] no err found, mission status is 0, deviceId[%d], dieId[%u], execMissionId[%u]",
410 : __func__, deviceId, static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.execMissionId));
411 0 : return HCCL_E_PARA;
412 : }
413 :
414 5 : uint8_t missionRaw[CCU_CTX_RAW_CAPACITY] = {0};
415 5 : size_t missionRawLen = 0;
416 10 : if (getMissionRaw(
417 5 : deviceId, ccuTaskParam.dieId, ccuTaskParam.execMissionId, missionRaw, sizeof(missionRaw), missionRawLen)
418 5 : != HCCL_SUCCESS) {
419 0 : HCCL_ERROR("[CcuErrorHandler][%s] Failed to fetch mission raw context, deviceId[%d]", __func__, deviceId);
420 0 : return HCCL_E_INTERNAL;
421 : }
422 5 : if (DecodeRawMissionInfo(missionRaw, missionInfo) != HCCL_SUCCESS) {
423 5 : HCCL_ERROR("[CcuErrorHandler][%s] Failed to decode mission info, deviceId[%d]", __func__, deviceId);
424 5 : return HCCL_E_INTERNAL;
425 : }
426 0 : return HCCL_SUCCESS;
427 : }
428 :
429 0 : static HcclResult ResolveRepContextAndCurrentRep(
430 : int32_t deviceId, const Hccl::ParaCcu& ccuTaskParam, uint16_t currIns, CcuRep::CcuRepContext*& ctx,
431 : std::shared_ptr<CcuRep::CcuRepBase>& rep, std::shared_ptr<CcuRep::CcuRepBase>& prevRep)
432 : {
433 0 : auto& kernelMgr = hcomm::CcuKernelMgr::GetInstance(deviceId);
434 0 : auto* kernel = kernelMgr.GetKernel(ccuTaskParam.ccuKernelHandle);
435 0 : CHK_PRT_RET(
436 : kernel == nullptr,
437 : HCCL_ERROR(
438 : "[%s]GetKernel nullptr, deviceId[%d], ccuKernelHandle[0x%llx]", __func__, deviceId,
439 : ccuTaskParam.ccuKernelHandle),
440 : HCCL_E_PARA);
441 :
442 0 : ctx = reinterpret_cast<CcuRep::CcuRepContext*>(kernel);
443 0 : CHK_PRT_RET(
444 : ctx == nullptr,
445 : HCCL_ERROR(
446 : "CcuContext not found, deviceId[%d], dieId[%u], missionId[%u], executeId[%llu]", deviceId,
447 : static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.missionId), ccuTaskParam.executeId),
448 : HCCL_E_PARA);
449 :
450 0 : rep = ctx->GetRepByInstrId(currIns);
451 0 : CHK_PRT_RET(
452 : rep == nullptr,
453 : HCCL_ERROR("[CcuErrorHandler][%s] cannot find REP from current CcuContext, instrId[%u]", __func__, currIns),
454 : HCCL_E_PARA);
455 :
456 0 : prevRep = nullptr;
457 0 : if (currIns > 0) {
458 0 : prevRep = ctx->GetRepByInstrId(currIns - 1);
459 : }
460 :
461 0 : while (rep->Type() == CcuRep::CcuRepType::FUNC_BLOCK) {
462 0 : auto blockRep = static_pointer_cast<CcuRepBlock>(rep);
463 0 : rep = blockRep->GetRepByInstrId(currIns);
464 0 : CHK_PRT_RET(
465 : rep == nullptr,
466 : HCCL_ERROR(
467 : "Failed to find REP from FuncBlock, instrId[%u], FuncBlock[%s]", currIns, blockRep->GetLabel().c_str()),
468 : HcclResult::HCCL_E_PARA);
469 0 : }
470 0 : return HCCL_SUCCESS;
471 : }
472 :
473 0 : static void HandleSurroundingRepErrorInfo(
474 : int32_t deviceId, uint32_t execMissionId, const ErrorInfoBase& baseInfo, CcuRep::CcuRepContext& ctx,
475 : uint16_t startIns, uint16_t endIns, uint16_t currIns, GenErrorInfoByRepTypeFunc genByRepType,
476 : std::vector<CcuErrorInfo>& errorInfo)
477 : {
478 0 : HCCL_ERROR(
479 : "[CcuErrorHandler]device %d, execMissionId[%u], startIns[%u], endIns[%u], currIns[%u]", deviceId, execMissionId,
480 : startIns, endIns, currIns);
481 0 : if (endIns == currIns) {
482 0 : HCCL_ERROR("[CcuErrorHandler]device %d SQE != CQE, endIns[%u], currIns[%u]", deviceId, endIns, currIns);
483 : }
484 :
485 0 : const uint16_t beginIns = FindSurroundingBeginInstr(ctx, startIns, currIns);
486 0 : for (uint16_t instrId = beginIns; instrId <= currIns; instrId++) {
487 0 : auto surroundingRep = ctx.GetRepByInstrId(instrId);
488 0 : if (surroundingRep == nullptr) {
489 0 : HCCL_WARNING(
490 : "[CcuErrorHandler][%s] cannot find REP from current CcuContext, instrId[%u]", __func__, instrId);
491 0 : continue;
492 : }
493 0 : genByRepType(baseInfo, surroundingRep, errorInfo);
494 0 : }
495 0 : }
496 :
497 13 : HcclResult CcuTaskException::GetCcuMissionContextRaw(
498 : int32_t deviceId, uint32_t dieId, uint32_t missionId, uint8_t* buf, size_t bufLen, size_t& copiedLen)
499 : {
500 13 : return QueryCcuCtxRaw(
501 : deviceId, dieId, missionId, CcuOpcodeType::CCU_U_OP_GET_MISSION_CTX, "GetCcuMissionContextRaw", buf, bufLen,
502 13 : copiedLen);
503 : }
504 :
505 12 : static string StatusCode2Str(uint8_t highPart, uint8_t lowPart)
506 : {
507 12 : HCCL_INFO("Mission Status Code: highPart[0x%02x], lowPart[0x%02x]", highPart, lowPart);
508 12 : const auto status = MISSION_STATUS_MAP.find(highPart);
509 12 : if (status == MISSION_STATUS_MAP.end()) {
510 2 : return "Unknown Status";
511 : }
512 11 : stringstream result;
513 11 : result << status->second;
514 :
515 11 : const auto lowMap = MISSION_SUB_STATUS_MAP.find(highPart);
516 11 : if (lowMap == MISSION_SUB_STATUS_MAP.end()) {
517 6 : return result.str();
518 : }
519 :
520 5 : const auto subStatus = lowMap->second.find(lowPart);
521 6 : const string subStatusMsg = subStatus == lowMap->second.end() ? "Unknown Status" : subStatus->second;
522 5 : result << ", " << subStatusMsg;
523 5 : return result.str();
524 11 : }
525 :
526 12 : void CcuTaskException::GenStatusInfo(const ErrorInfoBase& baseInfo, vector<CcuErrorInfo>& errorInfo)
527 : {
528 12 : CcuErrorInfo errorMsg{};
529 12 : errorMsg.type = CcuErrorType::MISSION;
530 12 : errorMsg.SetBaseInfo(CcuRep::CcuRepType::BASE, baseInfo.dieId, baseInfo.missionId, baseInfo.currentInsId);
531 12 : const auto baseInformation = Hccl::StringFormat("dieId[%u], missionId[%u]", baseInfo.dieId, baseInfo.missionId);
532 : const auto taskInformation
533 12 : = Hccl::StringFormat("currentInsId[%u], status[%u]", baseInfo.currentInsId, baseInfo.status);
534 12 : const uint8_t highPart = (baseInfo.status >> 8) & 0xFF; // 高8位
535 12 : const uint8_t lowPart = baseInfo.status & 0xFF; // 低8位
536 12 : string clusterMonitorErrMsg = CcuGetAndPrintClusterMonitorErr(baseInfo.deviceId);
537 :
538 12 : if (highPart == CCUM_EXECUTE_ERROR && lowPart == CCU_MISSION_TASK_KILLED) {
539 0 : RPT_INPUT_ERR(
540 : true, "EI0002",
541 : std::vector<std::string>({"remote_rankid", "base_information", "task_information", "group_rank_content"}),
542 : std::vector<std::string>(
543 : {std::to_string(baseInfo.deviceId), baseInformation.c_str(),
544 : (taskInformation + clusterMonitorErrMsg).c_str(), "none"}));
545 : }
546 12 : const string statusMsg = StatusCode2Str(highPart, lowPart);
547 : const auto sRet
548 12 : = strncpy_s(errorMsg.msg.mission.missionError, MISSION_STATUS_MSG_LEN, statusMsg.c_str(), statusMsg.length());
549 12 : if (sRet != EOK) {
550 0 : HCCL_ERROR("[CcuErrorHandler][%s] strcpy failed, statusMsg: [%s].sRet:[%d]", __func__, statusMsg.c_str(), sRet);
551 : }
552 :
553 12 : errorInfo.push_back(errorMsg);
554 12 : }
555 :
556 4 : uint16_t CcuTaskException::GetCcuCKEValue(int32_t deviceId, uint32_t dieId, uint32_t ckeId)
557 : {
558 4 : CustomChannelInfoIn inBuff{};
559 4 : CustomChannelInfoOut outBuff{};
560 4 : auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
561 4 : CHK_PRT_RET(
562 : tlvHandle == nullptr, HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), INVALID_U16);
563 :
564 4 : inBuff.op = CcuOpcodeType::CCU_U_OP_GET_CKE;
565 4 : inBuff.data.dataInfo.udieIdx = dieId;
566 4 : inBuff.offsetStartIdx = ckeId;
567 4 : inBuff.data.dataInfo.dataArraySize = 1; // 读1个CKE
568 4 : inBuff.data.dataInfo.dataLen = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
569 :
570 4 : HcclResult ret = HccpRaTlvRequestForCustomChannel(
571 : tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
572 4 : CHK_PRT_RET(
573 : ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%d]", __func__, ret),
574 : INVALID_U16);
575 :
576 2 : uint64_t ckeVal{0};
577 2 : s32 sret = memcpy_s(&ckeVal, sizeof(ckeVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
578 2 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy failed. errorno[%d]:", __func__, sret), INVALID_U16);
579 2 : return static_cast<uint16_t>(ckeVal);
580 : }
581 :
582 28 : HcclResult CcuTaskException::GetCcuUrmaChannel(const ChannelHandle& channel, CcuUrmaChannel*& channelImpl)
583 : {
584 28 : void* channelPtr = nullptr;
585 28 : CHK_RET(static_cast<HcclResult>(HcommChannelGet(channel, &channelPtr)));
586 26 : CHK_PTR_NULL(channelPtr);
587 23 : channelImpl = dynamic_cast<CcuUrmaChannel*>(static_cast<Channel*>(channelPtr));
588 23 : CHK_PTR_NULL(channelImpl);
589 23 : return HCCL_SUCCESS;
590 : }
591 :
592 13 : HcclResult CcuTaskException::GetChannelIdByHandle(const ChannelHandle& channel, uint32_t& channelId)
593 : {
594 13 : CcuUrmaChannel* channelImpl = nullptr;
595 13 : CHK_RET(GetCcuUrmaChannel(channel, channelImpl));
596 10 : channelId = channelImpl->GetChannelId();
597 10 : return HCCL_SUCCESS;
598 : }
599 :
600 : HcclResult
601 10 : CcuTaskException::GetSignalIdByHandle(const ChannelHandle& channel, uint16_t semIdx, bool isRmtSig, uint32_t& signalId)
602 : {
603 10 : CcuUrmaChannel* channelImpl = nullptr;
604 10 : CHK_RET(GetCcuUrmaChannel(channel, channelImpl));
605 9 : if (isRmtSig) {
606 6 : CHK_PRT_RET(
607 : channelImpl->GetRmtCkeByIndex(semIdx, signalId) != HcclResult::HCCL_SUCCESS,
608 : HCCL_ERROR("[%s] failed to get remote cke id, channelHandle[0x%llx].", __func__, channel), HCCL_E_UNAVAIL);
609 : } else {
610 3 : CHK_PRT_RET(
611 : channelImpl->GetLocCkeByIndex(semIdx, signalId) != HcclResult::HCCL_SUCCESS,
612 : HCCL_ERROR("[%s] failed to get local cke id, channelHandle[0x%llx]--sem[%u].", __func__, channel, semIdx),
613 : HCCL_E_UNAVAIL);
614 : }
615 6 : return HCCL_SUCCESS;
616 : }
617 :
618 5 : HcclResult CcuTaskException::GetVariableIdByHandle(const ChannelHandle& channel, uint16_t varIdx, uint32_t& varId)
619 : {
620 5 : CcuUrmaChannel* channelImpl = nullptr;
621 5 : CHK_RET(GetCcuUrmaChannel(channel, channelImpl));
622 4 : CHK_PRT_RET(
623 : channelImpl->GetRmtXnByIndex(varIdx, varId) != HcclResult::HCCL_SUCCESS,
624 : HCCL_ERROR("[%s] failed to get remote xn id, channelHandle[0x%llx]--var[%u].", __func__, channel, varIdx),
625 : HCCL_E_UNAVAIL);
626 2 : return HCCL_SUCCESS;
627 : }
628 :
629 0 : void CcuTaskException::GenErrorInfoLocRecordEvent(
630 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
631 : {
632 0 : CcuErrorInfo errorMsg{};
633 0 : errorMsg.type = CcuErrorType::WAIT_SIGNAL;
634 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
635 :
636 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepLocRecordEvent>(repBase);
637 0 : errorMsg.msg.waitSignal.signalId = rep->GetEventId();
638 0 : errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->GetEventId());
639 0 : errorMsg.msg.waitSignal.signalMask = rep->GetMask();
640 :
641 0 : errorInfo.push_back(errorMsg);
642 0 : }
643 :
644 0 : void CcuTaskException::GenErrorInfoLocWaitEvent(
645 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
646 : {
647 0 : CcuErrorInfo errorMsg{};
648 0 : errorMsg.type = CcuErrorType::WAIT_SIGNAL;
649 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
650 :
651 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepLocWaitEvent>(repBase);
652 0 : errorMsg.msg.waitSignal.signalId = rep->GetEventId();
653 0 : errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->GetEventId());
654 0 : errorMsg.msg.waitSignal.signalMask = rep->GetMask();
655 :
656 0 : errorInfo.push_back(errorMsg);
657 0 : }
658 :
659 0 : void CcuTaskException::GenErrorInfoLocWaitNotify(
660 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
661 : {
662 0 : CcuErrorInfo errorMsg{};
663 0 : errorMsg.type = CcuErrorType::WAIT_SIGNAL;
664 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
665 :
666 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepLocWaitNotify>(repBase);
667 0 : errorMsg.msg.waitSignal.signalId = rep->GetNotifyId();
668 0 : errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->GetNotifyId());
669 0 : errorMsg.msg.waitSignal.signalMask = rep->GetMask();
670 :
671 0 : errorInfo.push_back(errorMsg);
672 0 : }
673 :
674 9 : uint64_t CcuTaskException::GetCcuGSAValue(int32_t deviceId, uint32_t dieId, uint32_t gsaId)
675 : {
676 9 : uint64_t gsaVal{0};
677 :
678 9 : auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
679 9 : CHK_PRT_RET(
680 : tlvHandle == nullptr, HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), DFX_INVALID_U64);
681 :
682 9 : CustomChannelInfoIn inBuff{};
683 9 : CustomChannelInfoOut outBuff{};
684 :
685 9 : inBuff.op = CcuOpcodeType::CCU_U_OP_GET_GSA;
686 9 : inBuff.data.dataInfo.udieIdx = dieId;
687 9 : inBuff.offsetStartIdx = gsaId;
688 9 : inBuff.data.dataInfo.dataArraySize = 1; // 读1个GSA
689 9 : inBuff.data.dataInfo.dataLen = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
690 :
691 9 : HcclResult ret = HccpRaTlvRequestForCustomChannel(
692 : tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
693 9 : CHK_PRT_RET(
694 : ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%d]", __func__, ret),
695 : DFX_INVALID_U64);
696 :
697 7 : auto sret = memcpy_s(&gsaVal, sizeof(gsaVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
698 7 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy failed. errorno[%d]:", __func__, sret), DFX_INVALID_U64);
699 7 : return gsaVal;
700 : }
701 :
702 14 : uint64_t CcuTaskException::GetCcuXnValue(int32_t deviceId, uint32_t dieId, uint32_t xnId)
703 : {
704 14 : auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
705 14 : CHK_PRT_RET(
706 : tlvHandle == nullptr, HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), DFX_INVALID_U64);
707 14 : uint64_t xnVal{0};
708 :
709 14 : CustomChannelInfoIn inBuff{};
710 14 : CustomChannelInfoOut outBuff{};
711 :
712 14 : inBuff.op = CcuOpcodeType::CCU_U_OP_GET_XN;
713 14 : inBuff.data.dataInfo.udieIdx = dieId;
714 14 : inBuff.offsetStartIdx = xnId;
715 14 : inBuff.data.dataInfo.dataArraySize = 1; // 读1个Xn
716 14 : inBuff.data.dataInfo.dataLen = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
717 :
718 14 : HcclResult ret = HccpRaTlvRequestForCustomChannel(
719 : tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
720 :
721 14 : CHK_PRT_RET(
722 : ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%d]", __func__, ret),
723 : DFX_INVALID_U64);
724 :
725 12 : auto sret = memcpy_s(&xnVal, sizeof(xnVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
726 12 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy failed. errorno[%d]:", __func__, sret), DFX_INVALID_U64);
727 12 : return xnVal;
728 : }
729 :
730 2 : void CcuTaskException::GenErrorInfoRemPostSem(
731 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
732 : {
733 2 : CcuErrorInfo errorMsg{};
734 2 : errorMsg.type = CcuErrorType::WAIT_SIGNAL;
735 2 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
736 2 : const auto rep = static_pointer_cast<CcuRep::CcuRepRemPostSem>(repBase);
737 :
738 2 : uint32_t channelId = 0;
739 2 : CHK_PRT_RET(
740 : GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
741 : HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()), );
742 1 : uint32_t signalId = 0;
743 1 : CHK_PRT_RET(
744 : GetSignalIdByHandle(rep->GetChannel(), rep->GetSemIndex(), 1, signalId) != HcclResult::HCCL_SUCCESS,
745 : HCCL_ERROR("GetSignalIdByHandle[0x%llx]--SemIdx[%d] failed", rep->GetChannel(), rep->GetSemIndex()), );
746 :
747 1 : errorMsg.msg.waitSignal.signalId = signalId;
748 1 : errorMsg.msg.waitSignal.signalMask = rep->GetMask();
749 1 : auto sret = memset_s(
750 : errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
751 : sizeof(errorMsg.msg.waitSignal.channelId));
752 1 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset_s failed. errorno[%d]:", __func__, sret), );
753 1 : errorMsg.msg.waitSignal.channelId[0] = channelId;
754 :
755 1 : errorInfo.push_back(errorMsg);
756 2 : }
757 :
758 1 : void CcuTaskException::GenErrorInfoRemWaitSem(
759 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
760 : {
761 1 : CcuErrorInfo errorMsg{};
762 1 : errorMsg.type = CcuErrorType::WAIT_SIGNAL;
763 1 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
764 1 : const auto rep = static_pointer_cast<CcuRep::CcuRepRemWaitSem>(repBase);
765 :
766 1 : uint32_t channelId = 0;
767 1 : CHK_PRT_RET(
768 : GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
769 : HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()), );
770 1 : uint32_t signalId = 0;
771 1 : CHK_PRT_RET(
772 : GetSignalIdByHandle(rep->GetChannel(), rep->GetSemIndex(), 0, signalId) != HcclResult::HCCL_SUCCESS,
773 : HCCL_ERROR("GetSignalIdByHandle[0x%llx]--SemIdx[%d] failed", rep->GetChannel(), rep->GetSemIndex()), );
774 :
775 1 : errorMsg.msg.waitSignal.signalId = signalId;
776 : errorMsg.msg.waitSignal.signalValue
777 1 : = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, errorMsg.msg.waitSignal.signalId);
778 1 : errorMsg.msg.waitSignal.signalMask = rep->GetMask();
779 1 : auto sret = memset_s(
780 : errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
781 : sizeof(errorMsg.msg.waitSignal.channelId));
782 1 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset_s failed. errorno[%d]:", __func__, sret), );
783 :
784 1 : errorMsg.msg.waitSignal.channelId[0] = channelId;
785 :
786 1 : errorInfo.push_back(errorMsg);
787 1 : }
788 :
789 3 : void CcuTaskException::GenErrorInfoRemPostVar(
790 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
791 : {
792 3 : CcuErrorInfo errorMsg{};
793 3 : errorMsg.type = CcuErrorType::WAIT_SIGNAL;
794 3 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
795 3 : const auto rep = static_pointer_cast<CcuRep::CcuRepRemPostVar>(repBase);
796 :
797 : // 通过channelHandle从rep中获取channelId,rmtCkeId,rmtXnId
798 3 : uint32_t channelId = 0;
799 3 : CHK_PRT_RET(
800 : GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
801 : HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()), );
802 3 : uint32_t rmtCkeId = 0;
803 3 : CHK_PRT_RET(
804 : GetSignalIdByHandle(rep->GetChannel(), rep->GetSemIndex(), 1, rmtCkeId) != HcclResult::HCCL_SUCCESS,
805 : HCCL_ERROR("GetSignalIdByHandle[0x%llx]--SemIdx[%d] failed", rep->GetChannel(), rep->GetSemIndex()), );
806 2 : uint32_t rmtXnId = 0;
807 2 : CHK_PRT_RET(
808 : GetVariableIdByHandle(rep->GetChannel(), rep->GetParamIndex(), rmtXnId) != HcclResult::HCCL_SUCCESS,
809 : HCCL_ERROR("GetVariableIdByHandle[0x%llx]--VarIdx[%d] failed", rep->GetChannel(), rep->GetParamIndex()), );
810 :
811 1 : errorMsg.msg.waitSignal.signalId = rmtCkeId;
812 1 : errorMsg.msg.waitSignal.signalMask = rep->GetMask();
813 1 : auto sret = memset_s(
814 : errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
815 : sizeof(errorMsg.msg.waitSignal.channelId));
816 1 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset_s failed. errorno[%d]:", __func__, sret), );
817 :
818 1 : errorMsg.msg.waitSignal.channelId[0] = channelId;
819 1 : errorMsg.msg.waitSignal.paramId = rmtXnId;
820 1 : errorMsg.msg.waitSignal.paramValue = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetParam().Id());
821 :
822 1 : errorInfo.push_back(errorMsg);
823 3 : }
824 :
825 0 : void CcuTaskException::GenErrorInfoPostSharedSem(
826 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
827 : {
828 0 : CcuErrorInfo errorMsg{};
829 0 : errorMsg.type = CcuErrorType::WAIT_SIGNAL;
830 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
831 :
832 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepRecordSharedNotify>(repBase);
833 0 : errorMsg.msg.waitSignal.signalId = rep->GetNotifyId();
834 0 : errorMsg.msg.waitSignal.signalMask = rep->GetMask();
835 :
836 0 : errorInfo.push_back(errorMsg);
837 0 : }
838 :
839 1 : void CcuTaskException::GenErrorInfoRead(
840 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
841 : {
842 1 : CcuErrorInfo errorMsg{};
843 1 : errorMsg.type = CcuErrorType::TRANS_MEM;
844 1 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
845 1 : const auto rep = static_pointer_cast<CcuRep::CcuRepRead>(repBase);
846 :
847 1 : uint32_t channelId = 0;
848 1 : CHK_PRT_RET(
849 : GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
850 : HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()), );
851 :
852 1 : errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocAddrId());
853 1 : errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocTokenId());
854 1 : errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemAddrId());
855 1 : errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemTokenId());
856 1 : errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
857 1 : errorMsg.msg.transMem.signalMask = rep->GetMask();
858 1 : errorMsg.msg.transMem.signalId = rep->GetSemId();
859 1 : errorMsg.msg.transMem.channelId = channelId;
860 1 : errorInfo.push_back(errorMsg);
861 1 : }
862 :
863 1 : void CcuTaskException::GenErrorInfoWrite(
864 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
865 : {
866 1 : CcuErrorInfo errorMsg{};
867 1 : errorMsg.type = CcuErrorType::TRANS_MEM;
868 1 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
869 1 : const auto rep = static_pointer_cast<CcuRep::CcuRepWrite>(repBase);
870 :
871 1 : uint32_t channelId = 0;
872 1 : CHK_PRT_RET(
873 : GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
874 : HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()), );
875 :
876 1 : errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocAddrId());
877 1 : errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocTokenId());
878 1 : errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemAddrId());
879 1 : errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemTokenId());
880 1 : errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
881 1 : errorMsg.msg.transMem.signalId = rep->GetSemId();
882 1 : errorMsg.msg.transMem.signalMask = rep->GetMask();
883 1 : errorMsg.msg.transMem.channelId = channelId;
884 :
885 1 : errorInfo.push_back(errorMsg);
886 1 : }
887 :
888 0 : void CcuTaskException::GenErrorInfoLocalCpy(
889 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
890 : {
891 0 : CcuErrorInfo errorMsg{};
892 0 : errorMsg.type = CcuErrorType::TRANS_MEM;
893 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
894 :
895 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepLocCpy>(repBase);
896 0 : errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
897 0 : errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
898 0 : errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
899 0 : errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
900 0 : errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
901 0 : errorMsg.msg.transMem.signalId = rep->GetSemId();
902 0 : errorMsg.msg.transMem.signalMask = rep->GetMask();
903 :
904 0 : errorInfo.push_back(errorMsg);
905 0 : }
906 :
907 0 : void CcuTaskException::GenErrorInfoLocalReduce(
908 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
909 : {
910 0 : CcuErrorInfo errorMsg{};
911 0 : errorMsg.type = CcuErrorType::TRANS_MEM;
912 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
913 :
914 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepLocCpy>(repBase);
915 0 : errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
916 0 : errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
917 0 : errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
918 0 : errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
919 0 : errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
920 0 : errorMsg.msg.transMem.signalId = rep->GetSemId();
921 0 : errorMsg.msg.transMem.signalMask = rep->GetMask();
922 0 : errorMsg.msg.transMem.opType = rep->GetOpType();
923 0 : errorMsg.msg.transMem.dataType = rep->GetDataType();
924 :
925 0 : errorInfo.push_back(errorMsg);
926 0 : }
927 :
928 1 : void CcuTaskException::GenErrorInfoBufRead(
929 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
930 : {
931 1 : CcuErrorInfo errorMsg{};
932 1 : errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
933 1 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
934 1 : const auto rep = static_pointer_cast<CcuRep::CcuRepBufRead>(repBase);
935 :
936 1 : uint32_t channelId = 0;
937 1 : CHK_PRT_RET(
938 : GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
939 : HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()), );
940 :
941 1 : errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->GetDstAddrId());
942 1 : errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
943 1 : errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
944 1 : errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
945 1 : errorMsg.msg.bufTransMem.signalId = rep->GetSemId();
946 1 : errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
947 1 : errorMsg.msg.bufTransMem.channelId = channelId;
948 1 : errorInfo.push_back(errorMsg);
949 1 : }
950 :
951 1 : void CcuTaskException::GenErrorInfoBufWrite(
952 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
953 : {
954 1 : CcuErrorInfo errorMsg{};
955 1 : errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
956 1 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
957 1 : const auto rep = static_pointer_cast<CcuRep::CcuRepBufWrite>(repBase);
958 :
959 1 : uint32_t channelId = 0;
960 1 : CHK_PRT_RET(
961 : GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
962 : HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()), );
963 :
964 1 : errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->GetSrcId());
965 1 : errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
966 1 : errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
967 1 : errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
968 1 : errorMsg.msg.bufTransMem.signalId = rep->GetSemId();
969 1 : errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
970 1 : errorMsg.msg.bufTransMem.channelId = channelId;
971 :
972 1 : errorInfo.push_back(errorMsg);
973 1 : }
974 :
975 0 : void CcuTaskException::GenErrorInfoBufLocRead(
976 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
977 : {
978 0 : CcuErrorInfo errorMsg{};
979 0 : errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
980 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
981 :
982 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepBufLocRead>(repBase);
983 0 : errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->GetDstId());
984 0 : errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
985 0 : errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
986 0 : errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
987 0 : errorMsg.msg.bufTransMem.signalId = rep->GetSemId();
988 0 : errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
989 :
990 0 : errorInfo.push_back(errorMsg);
991 0 : }
992 :
993 0 : void CcuTaskException::GenErrorInfoBufLocWrite(
994 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
995 : {
996 0 : CcuErrorInfo errorMsg{};
997 0 : errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
998 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
999 :
1000 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepBufLocWrite>(repBase);
1001 0 : errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->GetSrcAddrId());
1002 0 : errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
1003 0 : errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
1004 0 : errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
1005 0 : errorMsg.msg.bufTransMem.signalId = rep->GetSemId();
1006 0 : errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
1007 :
1008 0 : errorInfo.push_back(errorMsg);
1009 0 : }
1010 :
1011 0 : void CcuTaskException::GenErrorInfoBufReduce(
1012 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
1013 : {
1014 0 : CcuErrorInfo errorMsg{};
1015 0 : errorMsg.type = CcuErrorType::BUF_REDUCE;
1016 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
1017 :
1018 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepBufReduce>(repBase);
1019 0 : errorMsg.msg.bufReduce.count = rep->GetCount();
1020 0 : errorMsg.msg.bufReduce.dataType = rep->GetDataType();
1021 0 : errorMsg.msg.bufReduce.outputDataType = rep->GetOutputDataType();
1022 0 : errorMsg.msg.bufReduce.opType = rep->GetOpType();
1023 0 : errorMsg.msg.bufReduce.signalId = rep->GetSemId();
1024 0 : errorMsg.msg.bufReduce.signalMask = rep->GetMask();
1025 0 : errorMsg.msg.bufReduce.xnIdLength = rep->GetXnLengthId();
1026 0 : const auto& buffs = rep->GetMem();
1027 0 : auto sret = memset_s(
1028 : errorMsg.msg.bufReduce.bufIds, sizeof(errorMsg.msg.bufReduce.bufIds), 0xFF,
1029 : sizeof(errorMsg.msg.bufReduce.bufIds));
1030 0 : CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset failed. errorno[%d]:", __func__, sret), );
1031 0 : for (uint32_t i = 0; i < buffs.size() && i < BUF_REDUCE_ID_SIZE; ++i) {
1032 0 : errorMsg.msg.bufReduce.bufIds[i] = GetMSIdPerDie(buffs[i].Id());
1033 : }
1034 :
1035 0 : errorInfo.push_back(errorMsg);
1036 0 : }
1037 0 : void CcuTaskException::GenErrorInfoDefault(
1038 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
1039 : {
1040 0 : CcuErrorInfo errorMsg{};
1041 0 : errorMsg.type = CcuErrorType::DEFAULT;
1042 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
1043 0 : errorInfo.push_back(errorMsg);
1044 0 : }
1045 :
1046 0 : void CcuTaskException::GenErrorInfoByRepType(
1047 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
1048 : {
1049 : using GenErrorInfoFunc = void (*)(
1050 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo);
1051 : static const map<CcuRep::CcuRepType, GenErrorInfoFunc> HANDLER_MAP{
1052 : // WAIT_SIGNAL
1053 : {CcuRep::CcuRepType::LOC_RECORD_EVENT, &CcuTaskException::GenErrorInfoLocRecordEvent},
1054 : {CcuRep::CcuRepType::LOC_WAIT_EVENT, &CcuTaskException::GenErrorInfoLocWaitEvent},
1055 : {CcuRep::CcuRepType::LOC_WAIT_NOTIFY, &CcuTaskException::GenErrorInfoLocWaitNotify},
1056 : {CcuRep::CcuRepType::REM_POST_SEM, &CcuTaskException::GenErrorInfoRemPostSem},
1057 : {CcuRep::CcuRepType::REM_WAIT_SEM, &CcuTaskException::GenErrorInfoRemWaitSem},
1058 : {CcuRep::CcuRepType::REM_POST_VAR, &CcuTaskException::GenErrorInfoRemPostVar},
1059 : {CcuRep::CcuRepType::RECORD_SHARED_NOTIFY, &CcuTaskException::GenErrorInfoPostSharedSem},
1060 : // TRANS_MEM
1061 : {CcuRep::CcuRepType::READ, &CcuTaskException::GenErrorInfoRead},
1062 : {CcuRep::CcuRepType::WRITE, &CcuTaskException::GenErrorInfoWrite},
1063 : {CcuRep::CcuRepType::LOCAL_CPY, &CcuTaskException::GenErrorInfoLocalCpy},
1064 : {CcuRep::CcuRepType::LOCAL_REDUCE, &CcuTaskException::GenErrorInfoLocalReduce},
1065 : // BUF_TRANS_MEM
1066 : {CcuRep::CcuRepType::BUF_READ, &CcuTaskException::GenErrorInfoBufRead},
1067 : {CcuRep::CcuRepType::BUF_WRITE, &CcuTaskException::GenErrorInfoBufWrite},
1068 : {CcuRep::CcuRepType::BUF_LOC_READ, &CcuTaskException::GenErrorInfoBufLocRead},
1069 : {CcuRep::CcuRepType::BUF_LOC_WRITE, &CcuTaskException::GenErrorInfoBufLocWrite},
1070 : // BUF_REDUCE
1071 0 : {CcuRep::CcuRepType::BUF_REDUCE, &CcuTaskException::GenErrorInfoBufReduce}};
1072 0 : const auto funcIt = HANDLER_MAP.find(repBase->Type());
1073 0 : HCCL_INFO("[%s]type[%d]", __func__, repBase->Type());
1074 0 : if (funcIt == HANDLER_MAP.end()) {
1075 : // DEFAULT, chip error
1076 0 : GenErrorInfoDefault(baseInfo, repBase, errorInfo);
1077 : } else {
1078 0 : (funcIt->second)(baseInfo, repBase, errorInfo);
1079 : }
1080 0 : }
1081 :
1082 6 : HcclResult CcuTaskException::GetCcuLoopContextRaw(
1083 : int32_t deviceId, uint32_t dieId, uint32_t loopCtxId, uint8_t* buf, size_t bufLen, size_t& copiedLen)
1084 : {
1085 6 : return QueryCcuCtxRaw(
1086 : deviceId, dieId, loopCtxId, CcuOpcodeType::CCU_U_OP_GET_LOOP_CTX, "GetCcuLoopContextRaw", buf, bufLen,
1087 6 : copiedLen);
1088 : }
1089 :
1090 0 : HcclResult CcuTaskException::GenErrorInfoLoop(
1091 : const ErrorInfoBase& baseInfo, CcuRep::CcuRepContext& ctx, vector<CcuErrorInfo>& errorInfo)
1092 : {
1093 : // 找LoopRep
1094 0 : auto repBase = ctx.GetRepByInstrId(baseInfo.currentInsId);
1095 0 : if (repBase == nullptr || repBase->Type() != CcuRep::CcuRepType::LOOP) {
1096 0 : HCCL_ERROR("Failed to find Loop REP from CcuContext, instrId[%u]", baseInfo.currentInsId);
1097 0 : return HCCL_E_PARA;
1098 : }
1099 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepLoop>(repBase);
1100 :
1101 0 : CcuErrorInfo errorMsg{};
1102 0 : errorMsg.type = CcuErrorType::LOOP;
1103 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, baseInfo.currentInsId);
1104 :
1105 0 : LoopXm loopXm{};
1106 0 : loopXm.value = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLoopParam()->Id());
1107 0 : CcuLoopInfo loopInfo{};
1108 0 : if (FetchAndDecodeLoopInfo(baseInfo.deviceId, baseInfo.dieId, loopXm.loopCtxId, loopInfo) != HCCL_SUCCESS) {
1109 0 : HCCL_ERROR("[GenErrorInfoLoop] Failed to fetch/decode loop info, deviceId[%d]", baseInfo.deviceId);
1110 0 : return HCCL_E_INTERNAL;
1111 : }
1112 0 : errorMsg.msg.loop.startInstrId = rep->GetLoopBlock()->StartInstrId();
1113 0 : errorMsg.msg.loop.endInstrId = rep->GetLoopBlock()->StartInstrId() + rep->GetLoopBlock()->InstrCount() - 1;
1114 0 : errorMsg.msg.loop.loopEngineId = loopXm.loopCtxId;
1115 0 : errorMsg.msg.loop.loopCnt = static_cast<uint16_t>(loopXm.loopCnt);
1116 0 : errorMsg.msg.loop.loopCurrentCnt = loopInfo.currentCnt;
1117 0 : errorMsg.msg.loop.addrStride = loopInfo.addrStride;
1118 :
1119 0 : errorInfo.push_back(errorMsg);
1120 :
1121 : // 解析Loop内的异常Rep
1122 0 : for (uint16_t loopCurrentIns = errorMsg.msg.loop.startInstrId; loopCurrentIns <= errorMsg.msg.loop.endInstrId;
1123 : loopCurrentIns++) {
1124 0 : auto inLoopExRep = rep->GetLoopBlock()->GetRepByInstrId(loopCurrentIns);
1125 0 : if (inLoopExRep == nullptr) {
1126 0 : HCCL_ERROR("Failed to find REP from Loop, instrId[%u], Loop[%s]", loopCurrentIns, rep->GetLabel().c_str());
1127 0 : return HCCL_E_PARA;
1128 : }
1129 : ErrorInfoBase loopErrBase{
1130 0 : baseInfo.deviceId, baseInfo.dieId, baseInfo.missionId, loopCurrentIns, baseInfo.status};
1131 0 : GenErrorInfoByRepType(loopErrBase, inLoopExRep, errorInfo);
1132 0 : }
1133 0 : return HCCL_SUCCESS;
1134 0 : }
1135 :
1136 0 : HcclResult CcuTaskException::GenErrorInfoLoopGroup(
1137 : const ErrorInfoBase& baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase, CcuRep::CcuRepContext& ctx,
1138 : vector<CcuErrorInfo>& errorInfo)
1139 : {
1140 0 : CcuErrorInfo errorMsg{};
1141 0 : errorMsg.type = CcuErrorType::LOOP_GROUP;
1142 0 : errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
1143 :
1144 0 : const auto rep = static_pointer_cast<CcuRep::CcuRepLoopGroupBundle>(repBase);
1145 0 : const auto startLoopInstrId = rep->GetStartLoopInstrId();
1146 0 : LoopGroupXn loopGroupXn{};
1147 0 : loopGroupXn.value = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetOffsetParam().Id());
1148 0 : errorMsg.msg.loopGroup.startLoopInsId = startLoopInstrId;
1149 0 : errorMsg.msg.loopGroup.loopInsCnt = static_cast<uint16_t>(loopGroupXn.loopInsCnt);
1150 0 : errorMsg.msg.loopGroup.expandOffset = static_cast<uint16_t>(loopGroupXn.expandOffset);
1151 0 : errorMsg.msg.loopGroup.expandCnt = static_cast<uint16_t>(loopGroupXn.expandCnt);
1152 :
1153 0 : errorInfo.push_back(errorMsg);
1154 :
1155 : // 处理loop
1156 0 : for (uint16_t i = 0; i < loopGroupXn.loopInsCnt; ++i) {
1157 0 : uint16_t loopInsId = startLoopInstrId + i;
1158 : ErrorInfoBase loopErrInfoBase{
1159 0 : baseInfo.deviceId, baseInfo.dieId, baseInfo.missionId, loopInsId, baseInfo.status};
1160 0 : CHK_RET(GenErrorInfoLoop(loopErrInfoBase, ctx, errorInfo));
1161 : }
1162 0 : return HCCL_SUCCESS;
1163 0 : }
1164 :
1165 0 : static HcclResult HandleCurrentRepErrorInfo(
1166 : const ErrorInfoBase& baseInfo, CcuRep::CcuRepContext& ctx, const std::shared_ptr<CcuRep::CcuRepBase>& rep,
1167 : const std::shared_ptr<CcuRep::CcuRepBase>& prevRep, GenErrorInfoLoopGroupFunc genLoopGroup,
1168 : GenErrorInfoByRepTypeFunc genByRepType, std::vector<CcuErrorInfo>& errorInfo)
1169 : {
1170 0 : if ((prevRep != nullptr && prevRep->Type() == CcuRep::CcuRepType::LOOPGROUP)
1171 0 : || (rep->Type() == CcuRep::CcuRepType::LOOPGROUP)) {
1172 0 : CHK_RET(genLoopGroup(baseInfo, prevRep, ctx, errorInfo));
1173 0 : return HCCL_SUCCESS;
1174 : }
1175 :
1176 0 : if (rep->Type() == CcuRep::CcuRepType::LOC_WAIT_EVENT || rep->Type() == CcuRep::CcuRepType::LOC_WAIT_NOTIFY) {
1177 0 : genByRepType(baseInfo, rep, errorInfo);
1178 0 : uint16_t actValue = errorInfo.back().msg.waitSignal.signalValue;
1179 0 : uint16_t expValue = errorInfo.back().msg.waitSignal.signalMask;
1180 0 : for (uint16_t i = 0; i < 16; ++i) { // CKE的bit数最多为16
1181 0 : uint16_t mask = 1 << i; // 创建一个用于检查第 i 位的掩码
1182 0 : if ((expValue & mask) != 0 && (actValue & mask) == 0) {
1183 0 : auto depRepVec = static_pointer_cast<CcuRep::CcuRepLocWaitEvent>(rep)->GetDependencyInfo(mask);
1184 0 : for (const auto& depRep : depRepVec) {
1185 0 : genByRepType(baseInfo, depRep, errorInfo);
1186 : }
1187 0 : }
1188 : }
1189 0 : return HCCL_SUCCESS;
1190 : }
1191 :
1192 0 : genByRepType(baseInfo, rep, errorInfo);
1193 0 : return HCCL_SUCCESS;
1194 : }
1195 :
1196 5 : HcclResult CcuTaskException::GetCcuErrorMsg(
1197 : int32_t deviceId, uint16_t missionStatus, const Hccl::ParaCcu& ccuTaskParam, std::vector<CcuErrorInfo>& errorInfo)
1198 : {
1199 5 : HCCL_INFO(
1200 : "[CcuTaskException]%s: deviceId[%d], dieId[%u], missionId[%u], execMissionId[%u], executeId[%llu].", __func__,
1201 : deviceId, static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.missionId),
1202 : static_cast<u32>(ccuTaskParam.execMissionId), ccuTaskParam.executeId);
1203 :
1204 5 : CcuMissionInfo missionInfo{};
1205 5 : CHK_RET(
1206 : ValidateAndDecodeMissionContext(deviceId, missionStatus, ccuTaskParam, GetCcuMissionContextRaw, missionInfo));
1207 :
1208 0 : const uint16_t currIns = missionInfo.currentIns;
1209 0 : CcuRep::CcuRepContext* ctx = nullptr;
1210 0 : std::shared_ptr<CcuRep::CcuRepBase> rep = nullptr;
1211 0 : std::shared_ptr<CcuRep::CcuRepBase> prevRep = nullptr;
1212 0 : CHK_RET(ResolveRepContextAndCurrentRep(deviceId, ccuTaskParam, currIns, ctx, rep, prevRep));
1213 :
1214 : // 分类处理Rep, 返回异常信息
1215 0 : ErrorInfoBase baseInfo{deviceId, ccuTaskParam.dieId, ccuTaskParam.missionId, currIns, missionStatus};
1216 0 : GenStatusInfo(baseInfo, errorInfo);
1217 0 : CHK_RET(HandleCurrentRepErrorInfo(
1218 : baseInfo, *ctx, rep, prevRep, GenErrorInfoLoopGroup, GenErrorInfoByRepType, errorInfo));
1219 :
1220 0 : const uint16_t endIns = missionInfo.endIns;
1221 0 : const uint16_t startIns = missionInfo.startIns;
1222 0 : HandleSurroundingRepErrorInfo(
1223 0 : deviceId, ccuTaskParam.execMissionId, baseInfo, *ctx, startIns, endIns, currIns, GenErrorInfoByRepType,
1224 : errorInfo);
1225 0 : return HCCL_SUCCESS;
1226 0 : }
1227 :
1228 0 : void CcuTaskException::GetCcuCqeErrRemoteLocalIdByRankId(hccl::CollComm* collComm, uint32_t rankid, u32& remoteLocalId)
1229 : {
1230 0 : if (collComm == nullptr) {
1231 0 : HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] collComm is nullptr");
1232 0 : return;
1233 : }
1234 :
1235 0 : if (rankid == Hccl::DFX_INVALID_RANKID) {
1236 0 : HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] RemoteLocalId is already set, rankId[%u]", rankid);
1237 0 : return;
1238 : }
1239 :
1240 0 : Hccl::HcclCommunicator* commV2 = static_cast<Hccl::HcclCommunicator*>(collComm->GetCommunicatorV2());
1241 0 : if (commV2 == nullptr) {
1242 0 : HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] commV2 is nullptr");
1243 0 : return;
1244 : }
1245 0 : void* rankGraph = nullptr;
1246 0 : HcclResult ret = commV2->GetRankGraphV2(rankGraph);
1247 0 : if (ret != HCCL_SUCCESS) {
1248 0 : HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId]GetRankGraphV2 failed, rankId[%u], ret[%d]", rankid, ret);
1249 0 : return;
1250 : }
1251 0 : if (rankGraph == nullptr) {
1252 0 : HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] rankGraph is nullptr for rankid[%u]", rankid);
1253 0 : return;
1254 : }
1255 :
1256 0 : Hccl::RankGraph* rankGraphv2 = static_cast<Hccl::RankGraph*>(rankGraph);
1257 0 : if (rankGraphv2 == nullptr) {
1258 0 : HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] rankGraphv2 is nullptr for rankid[%u]", rankid);
1259 0 : return;
1260 : }
1261 0 : u32 LocalId = rankGraphv2->GetLocalId(rankid);
1262 0 : remoteLocalId = LocalId;
1263 0 : return;
1264 : }
1265 :
1266 0 : void CcuTaskException::GetCcuCqeErrNetInstanceByRankId(
1267 : hccl::CollComm* collComm, uint32_t rankid, std::string& netInstanceId)
1268 : {
1269 0 : if (collComm == nullptr) {
1270 0 : HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] collComm is nullptr");
1271 0 : return;
1272 : }
1273 0 : if (rankid == Hccl::DFX_INVALID_RANKID) {
1274 0 : HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] RemoteLocalId is already set, rankId[%u]", rankid);
1275 0 : return;
1276 : }
1277 0 : Hccl::HcclCommunicator* commV2 = static_cast<Hccl::HcclCommunicator*>(collComm->GetCommunicatorV2());
1278 0 : if (commV2 == nullptr) {
1279 0 : HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] commV2 is nullptr");
1280 0 : return;
1281 : }
1282 0 : void* rankGraph = nullptr;
1283 0 : HcclResult ret = commV2->GetRankGraphV2(rankGraph);
1284 0 : if (ret != HCCL_SUCCESS) {
1285 0 : HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId]GetRankGraphV2 failed, rankId[%u], ret[%d]", rankid, ret);
1286 0 : return;
1287 : }
1288 0 : Hccl::RankGraph* rankGraphv2 = static_cast<Hccl::RankGraph*>(rankGraph);
1289 0 : const Hccl::NetInstance* netInstance = rankGraphv2->GetNetInstanceByRankId(0, rankid);
1290 0 : if (netInstance == nullptr) {
1291 0 : HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] netInstance is nullptr for rankid[%u]", rankid);
1292 0 : return;
1293 : }
1294 0 : std::string netInsId = netInstance->GetNetInstId();
1295 0 : netInstanceId = netInsId;
1296 0 : return;
1297 0 : }
1298 :
1299 0 : void CcuTaskException::GetCcuCqeErrorInfo(
1300 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 locDeviceId, uint8_t missionStatus)
1301 : {
1302 0 : uint16_t channelId = GetChannleIdByCcuErrorInfo(ccuErrorInfo);
1303 0 : if (channelId == INVALID_U16) {
1304 0 : HCCL_ERROR("[%s]cannot get channelId from repType[%d]", __func__, ccuErrorInfo.repType);
1305 0 : return;
1306 : }
1307 0 : auto pair = GetAddrPairByChannelId(channelId, taskInfo, locDeviceId);
1308 0 : RankId remoteRankId = GetRankIdByChannelId(channelId, taskInfo, locDeviceId);
1309 0 : hccl::CollComm* collComm = static_cast<hccl::CollComm*>(taskInfo.dfxOpInfo_->comm_);
1310 0 : u32 remoteLocalId = Hccl::DFX_INVALID_RANKID;
1311 0 : GetCcuCqeErrRemoteLocalIdByRankId(collComm, remoteRankId, remoteLocalId);
1312 0 : std::string netInstanceId = "";
1313 0 : GetCcuCqeErrNetInstanceByRankId(collComm, remoteRankId, netInstanceId);
1314 0 : std::string srcEid = pair.first.Describe();
1315 0 : std::string dstEid = pair.second.Describe();
1316 0 : ClusterMoniterGetCcuCqeErrInfo(remoteLocalId, locDeviceId, missionStatus, srcEid, dstEid, netInstanceId);
1317 0 : return;
1318 0 : }
1319 :
1320 5 : void CcuTaskException::PrintCcuErrorInfo(uint32_t deviceId, uint16_t status, const Hccl::TaskInfo& taskInfo)
1321 : {
1322 5 : const Hccl::ParaCcu& ccuTaskParam = taskInfo.taskParam_.taskPara.Ccu;
1323 5 : vector<CcuErrorInfo> errorInfos{};
1324 5 : HcclResult ret = GetCcuErrorMsg(deviceId, status, ccuTaskParam, errorInfos);
1325 5 : if (ret != HcclResult::HCCL_SUCCESS || errorInfos.empty()) {
1326 5 : HCCL_ERROR(
1327 : "Get CCU error info failed. deviceId[%u], dieId[%u], missionId[%u], executeId[%llu].", deviceId,
1328 : ccuTaskParam.dieId, ccuTaskParam.missionId, ccuTaskParam.executeId);
1329 5 : return;
1330 : }
1331 0 : PrintCcuErrorLog(errorInfos, taskInfo, deviceId);
1332 0 : const uint8_t missionStatus = (status >> 8) & 0xFF;
1333 0 : if (missionStatus >= 0x01
1334 0 : && missionStatus <= 0x05) { // 如果是UB错误(missionStatus为[0x01, 0x05]),打印Ub Dfx寄存器信息
1335 0 : PrintCcuUbRegisters(errorInfos, static_cast<s32>(deviceId), taskInfo);
1336 0 : if (isGetCqeErrInfo) {
1337 0 : isGetCqeErrInfo = false; // 只获取一次CQE错误信息,避免重复获取
1338 0 : for (const auto& errorInfo : errorInfos) {
1339 0 : if (errorInfo.repType == CcuRep::CcuRepType::READ || errorInfo.repType == CcuRep::CcuRepType::WRITE
1340 0 : || errorInfo.repType == CcuRep::CcuRepType::BUF_READ
1341 0 : || errorInfo.repType == CcuRep::CcuRepType::BUF_WRITE) {
1342 0 : GetCcuCqeErrorInfo(
1343 : errorInfo, taskInfo, deviceId, missionStatus); // 添加注释errorInfos[0]对应missionStatus异常
1344 : }
1345 : }
1346 : }
1347 : }
1348 5 : }
1349 :
1350 0 : void CcuTaskException::PrintCcuErrorLog(
1351 : const std::vector<CcuErrorInfo>& errorInfos, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1352 : {
1353 0 : if (errorInfos.empty()) {
1354 0 : return;
1355 : }
1356 0 : HCCL_ERROR("[CcuTaskException]Task run failed, ccu runtime information is: %s", __func__);
1357 0 : for (const auto& errorInfo : errorInfos) {
1358 0 : HCCL_ERROR("[CcuTaskException][%s]", GetCcuErrorMsgByType(errorInfo, taskInfo, deviceId).c_str());
1359 : }
1360 : }
1361 :
1362 0 : HcclResult CcuTaskException::PrintCcuUbRegisters(
1363 : const std::vector<CcuErrorInfo>& errorInfos, s32 devLogicId, const Hccl::TaskInfo& taskInfo)
1364 : {
1365 0 : std::vector<CcuJetty*> ccuJettys;
1366 0 : for (const CcuErrorInfo& errorInfo : errorInfos) {
1367 0 : if (REP_WITH_CHANNEL.find(errorInfo.repType) == REP_WITH_CHANNEL.end()) {
1368 0 : HCCL_INFO("[%s]repType[%d] not found in REP_WITH_CHANNEL, skip", __func__, errorInfo.repType);
1369 0 : continue;
1370 : }
1371 :
1372 0 : std::pair<CcuChannelInfo, std::vector<CcuJetty*>> ctx;
1373 0 : (void)GetCcuJettys(errorInfo, ctx);
1374 0 : ccuJettys.insert(ccuJettys.end(), ctx.second.begin(), ctx.second.end());
1375 0 : }
1376 :
1377 0 : u32 jettyNum = ccuJettys.size();
1378 0 : CHK_PRT_RET(jettyNum == 0, HCCL_RUN_INFO("[%s]jettyNum[%u], skip", __func__, jettyNum), HCCL_SUCCESS);
1379 :
1380 0 : std::vector<JettyHandle> jettyHandles;
1381 0 : jettyHandles.reserve(jettyNum);
1382 0 : for (auto& ccuJetty : ccuJettys) {
1383 0 : jettyHandles.push_back(ccuJetty->GetJettyHandle());
1384 : }
1385 :
1386 0 : std::vector<JettyStatus> jettyStatusVec;
1387 0 : CHK_RET(RaBatchQueryJettyStatus(jettyHandles, jettyStatusVec, jettyNum));
1388 :
1389 0 : for (u32 i = 0; i < jettyNum; ++i) {
1390 0 : if (jettyStatusVec[i] == JettyStatus::ERROR || jettyStatusVec[i] == JettyStatus::SUSPENDED) {
1391 0 : HrtRaDumpJettyContext(ccuJettys[i]->GetJettyHandle(), ccuJettys[i]->GetJettyId());
1392 : }
1393 : }
1394 :
1395 0 : for (u32 i = 0; i < jettyNum; ++i) {
1396 0 : if (jettyStatusVec[i] == JettyStatus::ERROR || jettyStatusVec[i] == JettyStatus::SUSPENDED) {
1397 0 : auto rdmaHandle = ccuJettys[i]->GetRdmaHandle();
1398 0 : HCCL_ERROR("[%s]jettyId[%u]", __func__, ccuJettys[i]->GetJettyId());
1399 0 : PrintUbRegisters(devLogicId, rdmaHandle);
1400 0 : break;
1401 : }
1402 : }
1403 0 : return HCCL_SUCCESS;
1404 0 : }
1405 :
1406 4 : uint16_t CcuTaskException::GetChannleIdByCcuErrorInfo(const CcuErrorInfo& errorInfo)
1407 : {
1408 4 : uint16_t channelId = INVALID_U16;
1409 4 : switch (errorInfo.repType) {
1410 1 : case CcuRep::CcuRepType::REM_POST_SEM:
1411 : case CcuRep::CcuRepType::REM_WAIT_SEM:
1412 : case CcuRep::CcuRepType::REM_POST_VAR:
1413 1 : channelId = errorInfo.msg.waitSignal.channelId[0];
1414 1 : break;
1415 1 : case CcuRep::CcuRepType::READ:
1416 : case CcuRep::CcuRepType::WRITE:
1417 1 : channelId = errorInfo.msg.transMem.channelId;
1418 1 : break;
1419 1 : case CcuRep::CcuRepType::BUF_READ:
1420 : case CcuRep::CcuRepType::BUF_WRITE:
1421 1 : channelId = errorInfo.msg.bufTransMem.channelId;
1422 1 : break;
1423 1 : default:
1424 1 : HCCL_ERROR("[%s]repType[%d] does not have jetty", __func__, errorInfo.repType);
1425 1 : break;
1426 : }
1427 4 : HCCL_INFO("[%s]repType[%d], channelId[%u]", __func__, errorInfo.repType, channelId);
1428 4 : return channelId;
1429 : }
1430 :
1431 : HcclResult
1432 0 : CcuTaskException::GetCcuJettys(const CcuErrorInfo& errorInfo, std::pair<CcuChannelInfo, std::vector<CcuJetty*>>& ctx)
1433 : {
1434 0 : if (REP_WITH_CHANNEL.find(errorInfo.repType) == REP_WITH_CHANNEL.end()) {
1435 0 : HCCL_INFO("[%s]repType[%d] does not need to get jettys, skip", __func__, errorInfo.repType);
1436 0 : return HCCL_SUCCESS;
1437 : }
1438 0 : uint16_t channelId = GetChannleIdByCcuErrorInfo(errorInfo);
1439 :
1440 : // channelId -> channelHandle
1441 0 : u64 channelHandle = DFX_INVALID_U64;
1442 0 : CHK_RET(GetCcuChannelHandleById(channelId, channelHandle));
1443 :
1444 : // channelHandle -> CcuUrmaChannel
1445 0 : void* channelPtr{nullptr};
1446 0 : CHK_RET(static_cast<HcclResult>(HcommChannelGet(channelHandle, &channelPtr)));
1447 0 : CHK_PTR_NULL(channelPtr);
1448 0 : auto* channelImpl = dynamic_cast<CcuUrmaChannel*>(static_cast<Channel*>(channelPtr));
1449 :
1450 : // CcuUrmaChannel -> UrmaEndpoint
1451 0 : EndpointHandle locEndPointHandle = channelImpl->GetlocEndPointHandle();
1452 0 : void* endpoint{nullptr};
1453 0 : CHK_RET(static_cast<HcclResult>(HcommEndpointGet(locEndPointHandle, &endpoint)));
1454 0 : CHK_PTR_NULL(endpoint);
1455 0 : UrmaEndpoint* ccuEndpoint = dynamic_cast<UrmaEndpoint*>(static_cast<Endpoint*>(endpoint));
1456 :
1457 : // 打印localEid和remoteEid
1458 0 : CHK_PTR_NULL(ccuEndpoint);
1459 0 : HCCL_ERROR(
1460 : "[GetCcuJettys]localEid[%s], remoteEid[%s]",
1461 : hcomm::logger::CommAddrLogger::ToString(ccuEndpoint->GetEndpointDesc().commAddr).c_str(),
1462 : hcomm::logger::CommAddrLogger::ToString(channelImpl->GetChannelDesc().remoteEndpoint.commAddr).c_str());
1463 :
1464 : // UrmaEndpoint -> CcuChannelCtxPool
1465 0 : CcuChannelCtxPool* ccuChannelCtxPool = ccuEndpoint->GetCcuChannelCtxPool();
1466 0 : CHK_PTR_NULL(ccuChannelCtxPool);
1467 :
1468 : // CcuChannelCtxPool -> CcuJetty
1469 0 : auto channelIdKey = std::make_pair(errorInfo.dieId, channelId);
1470 0 : CHK_RET(ccuChannelCtxPool->GetCcuChannelCtxById(channelIdKey, ctx));
1471 0 : return HCCL_SUCCESS;
1472 : }
1473 :
1474 0 : HcclResult RaGetAuxInfo(const RdmaHandle rdmaHandle, AuxInfoIn auxInfoIn, AuxInfoOut& auxInfoOut)
1475 : {
1476 : HccpAuxInfoIn in;
1477 0 : in.type = static_cast<HccpAuxInfoInType>(static_cast<int>(auxInfoIn.auxInfoInType));
1478 0 : if (auxInfoIn.auxInfoInType == AuxInfoInType::AUX_INFO_IN_TYPE_CQE) {
1479 0 : in.cqe.status = auxInfoIn.cqe.status;
1480 0 : in.cqe.sR = auxInfoIn.cqe.sR;
1481 0 : } else if (auxInfoIn.auxInfoInType == AuxInfoInType::AUX_INFO_IN_TYPE_AE) {
1482 0 : in.ae.eventType = auxInfoIn.ae.eventType;
1483 : }
1484 :
1485 : HccpAuxInfoOut out;
1486 0 : auto ret = RaCtxGetAuxInfo(rdmaHandle, &in, &out);
1487 0 : if (ret != 0) {
1488 0 : HCCL_ERROR("RaGetAuxInfo failed, ret=[%d]", ret);
1489 0 : return HCCL_E_NETWORK;
1490 : }
1491 :
1492 0 : auxInfoOut.auxInfoNum = out.auxInfoNum;
1493 0 : for (uint32_t i = 0; i < out.auxInfoNum; i++) {
1494 0 : auxInfoOut.auxInfoTypes[i] = out.auxInfoType[i];
1495 0 : auxInfoOut.auxInfoValues[i] = out.auxInfoValue[i];
1496 : }
1497 0 : return HCCL_SUCCESS;
1498 : }
1499 0 : HcclResult CcuTaskException::PrintUbRegisters(s32 devLogicId, RdmaHandle rdmaHandle)
1500 : {
1501 0 : HCCL_INFO("[PrintUbRegister] start, devLogicId[%d], rdmaHandle[%p]", devLogicId, rdmaHandle);
1502 0 : AuxInfoIn in;
1503 0 : in.cqe.status = 0xffffffff; // 0xffffffff代表查询所有寄存器
1504 0 : in.auxInfoInType = AuxInfoInType::AUX_INFO_IN_TYPE_CQE;
1505 0 : in.cqe.sR = 0;
1506 0 : AuxInfoOut auxInfo;
1507 0 : auto ret = RaGetAuxInfo(rdmaHandle, in, auxInfo);
1508 0 : if (ret != HCCL_SUCCESS) {
1509 0 : HCCL_ERROR(
1510 : "[PrintUbRegister] RaGetAuxInfo failed, devLogicId[%d], rdmaHandle[%p], ret[%d]", devLogicId, rdmaHandle,
1511 : ret);
1512 0 : return ret;
1513 : }
1514 :
1515 0 : uint16_t isAuxInfoExisted{false};
1516 0 : for (u32 i = 0; i < auxInfo.auxInfoNum; i++) {
1517 0 : if (auxInfo.auxInfoValues[i]) { // 非零进行打印
1518 0 : isAuxInfoExisted = true;
1519 0 : HCCL_ERROR(
1520 : "devLogicId[%d], cqe_aux_info_type[%u], cqe_aux_info_value[0x%x]", devLogicId, auxInfo.auxInfoTypes[i],
1521 : auxInfo.auxInfoValues[i]);
1522 : } else {
1523 0 : HCCL_INFO(
1524 : "devLogicId[%d], cqe_aux_info_type[%u], cqe_aux_info_value[0x%x]", devLogicId, auxInfo.auxInfoTypes[i],
1525 : auxInfo.auxInfoValues[i]);
1526 : }
1527 : }
1528 0 : if (!isAuxInfoExisted) {
1529 0 : HCCL_ERROR("devLogicId[%d], all aux_info values are zero.", devLogicId);
1530 : }
1531 0 : return HCCL_SUCCESS;
1532 : }
1533 :
1534 14 : string CcuTaskException::GetCcuLenErrorMsg(const uint64_t len)
1535 : {
1536 14 : if ((0 < len) && (len <= CCU_MSG_256MB_LEN)) {
1537 14 : return "";
1538 : }
1539 7 : return Hccl::StringFormat("ccu transMem Len[%llu]B > 256MB or is zero, not support!", len);
1540 : }
1541 :
1542 : string
1543 1 : CcuTaskException::GetCcuErrorMsgLoop(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1544 : {
1545 : (void)taskInfo;
1546 : (void)deviceId;
1547 : return Hccl::StringFormat(
1548 : "InstrId[%u]: Loop startInstrId[%u], endInstrId[%u], executorId[%u], "
1549 : "totalIter[%u], curIter[%u], addressStride[0x%llx]",
1550 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.loop.startInstrId, ccuErrorInfo.msg.loop.endInstrId,
1551 1 : ccuErrorInfo.msg.loop.loopEngineId, ccuErrorInfo.msg.loop.loopCnt, ccuErrorInfo.msg.loop.loopCurrentCnt,
1552 1 : ccuErrorInfo.msg.loop.addrStride);
1553 : }
1554 :
1555 1 : string CcuTaskException::GetCcuErrorMsgLoopGroup(
1556 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1557 : {
1558 : (void)taskInfo;
1559 : (void)deviceId;
1560 : return Hccl::StringFormat(
1561 : "InstrId[%u]: LoopGroup startLoopInsId[%u], loopInsCnt[%u], "
1562 : "expandOffset[%u], expandCnt[%u]",
1563 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.loopGroup.startLoopInsId, ccuErrorInfo.msg.loopGroup.loopInsCnt,
1564 1 : ccuErrorInfo.msg.loopGroup.expandOffset, ccuErrorInfo.msg.loopGroup.expandCnt);
1565 : }
1566 :
1567 1 : string CcuTaskException::GetCcuErrorMsgLocPostSem(
1568 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1569 : {
1570 : (void)taskInfo;
1571 : (void)deviceId;
1572 : return Hccl::StringFormat(
1573 1 : "InstrId[%u]: Set sem[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
1574 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
1575 1 : ccuErrorInfo.msg.waitSignal.signalMask);
1576 : }
1577 :
1578 1 : string CcuTaskException::GetCcuErrorMsgLocWaitEvent(
1579 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1580 : {
1581 : (void)taskInfo;
1582 : (void)deviceId;
1583 : return Hccl::StringFormat(
1584 1 : "InstrId[%u]: LocWaitEvent[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
1585 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
1586 1 : ccuErrorInfo.msg.waitSignal.signalMask);
1587 : }
1588 :
1589 1 : string CcuTaskException::GetCcuErrorMsgLocWaitNotify(
1590 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1591 : {
1592 : (void)taskInfo;
1593 : (void)deviceId;
1594 : return Hccl::StringFormat(
1595 1 : "InstrId[%u]: LocWaitNotify[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
1596 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
1597 1 : ccuErrorInfo.msg.waitSignal.signalMask);
1598 : }
1599 :
1600 1 : string CcuTaskException::GetCcuErrorMsgRemPostSem(
1601 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1602 : {
1603 : return Hccl::StringFormat(
1604 1 : "InstrId[%u]: Post, Use sem[%u], mask[0x%04x], rankId[%d]", ccuErrorInfo.instrId,
1605 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalMask,
1606 1 : GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo, deviceId));
1607 : }
1608 :
1609 1 : string CcuTaskException::GetCcuErrorMsgRemWaitSem(
1610 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1611 : {
1612 : return Hccl::StringFormat(
1613 1 : "InstrId[%u]: Wait, Use sem[%u], semValue[0x%04x], mask[0x%04x], rankId[%d]", ccuErrorInfo.instrId,
1614 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
1615 1 : ccuErrorInfo.msg.waitSignal.signalMask,
1616 1 : GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo, deviceId));
1617 : }
1618 :
1619 1 : string CcuTaskException::GetCcuErrorMsgRemPostVar(
1620 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1621 : {
1622 : return Hccl::StringFormat(
1623 : "InstrId[%u]: Post Variable[0x%016llx] To Param[%u], Use sem[%u], mask[0x%04x], rankId[%d]",
1624 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.waitSignal.paramValue, ccuErrorInfo.msg.waitSignal.paramId,
1625 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalMask,
1626 1 : GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo, deviceId));
1627 : }
1628 :
1629 1 : string CcuTaskException::GetCcuErrorMsgPostSharedSem(
1630 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1631 : {
1632 : (void)taskInfo;
1633 : (void)deviceId;
1634 : return Hccl::StringFormat(
1635 1 : "InstrId[%u]: Post, Use sem[%u], mask[0x%04x]", ccuErrorInfo.instrId, ccuErrorInfo.msg.waitSignal.signalId,
1636 1 : ccuErrorInfo.msg.waitSignal.signalMask);
1637 : }
1638 :
1639 : string
1640 1 : CcuTaskException::GetCcuErrorMsgRead(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1641 : {
1642 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId);
1643 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1644 : return Hccl::StringFormat(
1645 : "InstrId[%u]: Read Memory[0x%016llx] To Memory[0x%016llx], Len[%llu], "
1646 : "Set sem[%u] with mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1647 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.rmtAddr, ccuErrorInfo.msg.transMem.locAddr,
1648 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1649 2 : GetRankIdByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId), pair.first.Describe().c_str(),
1650 4 : pair.second.Describe().c_str(), printMsg.c_str());
1651 1 : }
1652 :
1653 : string
1654 1 : CcuTaskException::GetCcuErrorMsgWrite(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1655 : {
1656 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId);
1657 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1658 : return Hccl::StringFormat(
1659 : "InstrId[%u]: Write Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
1660 : "Set sem[%u] with mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1661 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
1662 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1663 2 : GetRankIdByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId), pair.first.Describe().c_str(),
1664 4 : pair.second.Describe().c_str(), printMsg.c_str());
1665 1 : }
1666 :
1667 : string
1668 1 : CcuTaskException::GetCcuErrorMsgLocalCpy(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1669 : {
1670 : (void)taskInfo;
1671 : (void)deviceId;
1672 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1673 : return Hccl::StringFormat(
1674 : "InstrId[%u]: Read Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
1675 : "Set sem[%u] with mask[0x%04x] %s",
1676 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
1677 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1678 2 : printMsg.c_str());
1679 1 : }
1680 :
1681 1 : string CcuTaskException::GetCcuErrorMsgLocalReduce(
1682 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1683 : {
1684 : (void)taskInfo;
1685 : (void)deviceId;
1686 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1687 : return Hccl::StringFormat(
1688 : "InstrId[%u]: Read Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
1689 : "Set sem[%u] with mask[0x%04x], dataType[%u], opType[%u] %s",
1690 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
1691 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1692 2 : ccuErrorInfo.msg.transMem.dataType, ccuErrorInfo.msg.transMem.opType, printMsg.c_str());
1693 1 : }
1694 :
1695 : string
1696 1 : CcuTaskException::GetCcuErrorMsgBufRead(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1697 : {
1698 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId);
1699 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1700 : return Hccl::StringFormat(
1701 : "InstrId[%u]: Read Rmt Mem[0x%016llx] To CcuBuffer[%u], Len[%llu], "
1702 : "sem[%u], mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1703 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.addr, ccuErrorInfo.msg.bufTransMem.bufId,
1704 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1705 1 : ccuErrorInfo.msg.bufTransMem.signalMask,
1706 2 : GetRankIdByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId), pair.first.Describe().c_str(),
1707 4 : pair.second.Describe().c_str(), printMsg.c_str());
1708 1 : }
1709 :
1710 : string
1711 1 : CcuTaskException::GetCcuErrorMsgBufWrite(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1712 : {
1713 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId);
1714 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1715 : return Hccl::StringFormat(
1716 : "InstrId[%u]: Write CcuBuffer[%u] To Rmt Mem[0x%016llx], Len[%llu], "
1717 : "sem[%u], mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1718 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.bufId, ccuErrorInfo.msg.bufTransMem.addr,
1719 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1720 1 : ccuErrorInfo.msg.bufTransMem.signalMask,
1721 2 : GetRankIdByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId), pair.first.Describe().c_str(),
1722 4 : pair.second.Describe().c_str(), printMsg.c_str());
1723 1 : }
1724 :
1725 1 : string CcuTaskException::GetCcuErrorMsgBufLocRead(
1726 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1727 : {
1728 : (void)taskInfo;
1729 : (void)deviceId;
1730 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1731 : return Hccl::StringFormat(
1732 : "InstrId[%u]: Read Loc Mem[0x%016llx] To CcuBuffer[%u], Len[%llu], sem[%u], mask[0x%04x] %s",
1733 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.addr, ccuErrorInfo.msg.bufTransMem.bufId,
1734 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1735 2 : ccuErrorInfo.msg.bufTransMem.signalMask, printMsg.c_str());
1736 1 : }
1737 :
1738 1 : string CcuTaskException::GetCcuErrorMsgBufLocWrite(
1739 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1740 : {
1741 : (void)taskInfo;
1742 : (void)deviceId;
1743 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1744 : return Hccl::StringFormat(
1745 : "InstrId[%u]: Write CcuBuffer[%u] To Loc Mem[0x%016llx], Len[%llu], sem[%u], mask[0x%04x] %s",
1746 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.bufId, ccuErrorInfo.msg.bufTransMem.addr,
1747 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1748 2 : ccuErrorInfo.msg.bufTransMem.signalMask, printMsg.c_str());
1749 1 : }
1750 :
1751 1 : string CcuTaskException::GetCcuErrorMsgBufReduce(
1752 : const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1753 : {
1754 : (void)taskInfo;
1755 : (void)deviceId;
1756 1 : stringstream buffIds;
1757 9 : for (uint32_t i = 0; i < BUF_REDUCE_ID_SIZE; ++i) {
1758 8 : const auto buffId = ccuErrorInfo.msg.bufReduce.bufIds[i];
1759 8 : if (buffId == UINT16_MAX) {
1760 0 : break;
1761 : }
1762 8 : if (i != 0) {
1763 7 : buffIds << ", ";
1764 : }
1765 8 : buffIds << to_string(buffId);
1766 : }
1767 :
1768 : return Hccl::StringFormat(
1769 : "InstrId[%u]: Buffer Reduce count[%u], dataType[%u], outputDataType[%u], opType[%u], "
1770 : "sem[%u], mask[0x%04x], CcuBuffers[%s]",
1771 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufReduce.count, ccuErrorInfo.msg.bufReduce.dataType,
1772 1 : ccuErrorInfo.msg.bufReduce.outputDataType, ccuErrorInfo.msg.bufReduce.opType,
1773 2 : ccuErrorInfo.msg.bufReduce.signalId, ccuErrorInfo.msg.bufReduce.signalMask, buffIds.str().c_str());
1774 1 : }
1775 :
1776 2 : string CcuTaskException::GetCcuErrorMsgDefault(const CcuErrorInfo& ccuErrorInfo)
1777 : {
1778 : return Hccl::StringFormat(
1779 2 : "InstrId[%u]: CcuErrorType[%s]", ccuErrorInfo.instrId, ccuErrorInfo.type.Describe().c_str());
1780 : }
1781 :
1782 2 : string CcuTaskException::GetCcuErrorMsgMission(const CcuErrorInfo& ccuErrorInfo)
1783 : {
1784 : return Hccl::StringFormat(
1785 2 : "InstrId[%u]: dieId[%u], missionId[%u], missionError[%s]", ccuErrorInfo.instrId, ccuErrorInfo.dieId,
1786 2 : ccuErrorInfo.missionId, ccuErrorInfo.msg.mission.missionError);
1787 : }
1788 :
1789 0 : HcclResult CcuTaskException::GetCcuChannelHandleById(u16 channelId, u64& channelHandle)
1790 : {
1791 0 : std::lock_guard<std::mutex> lock(g_channelMapMutex);
1792 0 : auto it = g_channelIdToHandle.find(channelId);
1793 0 : if (it == g_channelIdToHandle.end()) {
1794 0 : HCCL_ERROR("[%s]channelId[%u] not found", __func__, channelId);
1795 0 : for (auto info : g_channelIdToHandle) {
1796 0 : HCCL_ERROR("[%s]g_channelIdToHandle[%u]=[0x%llx]", __func__, info.first, info.second);
1797 : }
1798 0 : return HCCL_E_NOT_FOUND;
1799 : }
1800 0 : channelHandle = it->second;
1801 0 : return HCCL_SUCCESS;
1802 0 : }
1803 :
1804 8 : RankId CcuTaskException::GetRankIdByChannelId(uint16_t channelId, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1805 : {
1806 8 : if (taskInfo.taskParam_.taskType != Hccl::TaskParamType::TASK_CCU) {
1807 0 : HCCL_ERROR("[%s]taskType[%s] is not CCU.", __func__, taskInfo.taskParam_.taskType.Describe().c_str());
1808 0 : return INVALID_UINT;
1809 : }
1810 8 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
1811 8 : HCCL_ERROR("[%s]dfxOpInfo[%p] or comm is nullptr.", __func__, taskInfo.dfxOpInfo_);
1812 8 : return INVALID_UINT;
1813 : }
1814 :
1815 0 : u64 channelHandle = DFX_INVALID_U64;
1816 0 : if (GetCcuChannelHandleById(channelId, channelHandle) != HCCL_SUCCESS) {
1817 0 : HCCL_ERROR(
1818 : "[%s]GetCcuChannelHandleById fail, deviceId[%u], channelId[%u], channelHandle[0x%llx]", __func__, deviceId,
1819 : channelId, channelHandle);
1820 0 : return INVALID_UINT;
1821 : }
1822 :
1823 0 : hccl::CollComm* collComm = static_cast<hccl::CollComm*>(taskInfo.dfxOpInfo_->comm_);
1824 0 : u32 remoteRank = INVALID_UINT;
1825 0 : if (hccl::HcclCommDfx::GetChannelRemoteRankId(collComm->GetCommId(), channelHandle, remoteRank) != HCCL_SUCCESS) {
1826 0 : HCCL_ERROR(
1827 : "[%s]GetChannelRemoteRankId fail, channelHandle[0x%llx], commId[%s]", __func__, channelHandle,
1828 : collComm->GetCommId().c_str());
1829 0 : return INVALID_UINT;
1830 : }
1831 :
1832 0 : HCCL_INFO(
1833 : "[%s]channelId[%u], deviceId[%u], channelHandle[0x%llx], commId[%s], remoteRank[%u]", __func__, channelId,
1834 : deviceId, channelHandle, collComm->GetCommId().c_str(), remoteRank);
1835 0 : return remoteRank;
1836 : }
1837 :
1838 : std::pair<Hccl::IpAddress, Hccl::IpAddress>
1839 5 : CcuTaskException::GetAddrPairByChannelId(uint16_t channelId, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1840 : {
1841 5 : std::pair<Hccl::IpAddress, Hccl::IpAddress> dummy = {Hccl::IpAddress(), Hccl::IpAddress()};
1842 5 : if (taskInfo.taskParam_.taskType != Hccl::TaskParamType::TASK_CCU) {
1843 0 : HCCL_ERROR(
1844 : "[TaskException][%s]Get AddrPair failed, task type error[%s]", __func__,
1845 : taskInfo.taskParam_.Describe().c_str());
1846 0 : return dummy;
1847 : }
1848 5 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
1849 5 : HCCL_ERROR("[TaskException][%s]Get AddrPair failed, communicator is nullptr.", __func__);
1850 5 : return dummy;
1851 : }
1852 :
1853 0 : u64 channelHandle = DFX_INVALID_U64;
1854 0 : if (GetCcuChannelHandleById(channelId, channelHandle) != HCCL_SUCCESS) {
1855 0 : HCCL_ERROR(
1856 : "[%s]GetCcuChannelHandleById fail, deviceId[%u], channelId[%u], channelHandle[0x%llx]", __func__, deviceId,
1857 : channelId, channelHandle);
1858 0 : return dummy;
1859 : }
1860 :
1861 0 : void* channelPtr{nullptr};
1862 0 : HcclResult ret = static_cast<HcclResult>(HcommChannelGet(channelHandle, &channelPtr));
1863 0 : if (ret != HCCL_SUCCESS || channelPtr == nullptr) {
1864 0 : HCCL_ERROR(
1865 : "[%s]HcommChannelGet failed, ret[%d], channelHandle[0x%llx], channelPtr[%p]", __func__, ret, channelHandle,
1866 : channelPtr);
1867 0 : return dummy;
1868 : }
1869 0 : auto* channelImpl = dynamic_cast<CcuUrmaChannel*>(static_cast<Channel*>(channelPtr));
1870 :
1871 : // 获取locAddr
1872 0 : EndpointHandle locEndPointHandle = channelImpl->GetlocEndPointHandle();
1873 0 : void* endpoint{nullptr};
1874 0 : ret = static_cast<HcclResult>(HcommEndpointGet(locEndPointHandle, &endpoint));
1875 0 : if (ret != HCCL_SUCCESS || endpoint == nullptr) {
1876 0 : HCCL_ERROR(
1877 : "[%s]HcommEndpointGet failed, ret[%d], locEndPointHandle[%p], endpoint[%p], channelId[%u]", __func__, ret,
1878 : locEndPointHandle, endpoint, channelId);
1879 0 : return dummy;
1880 : }
1881 0 : UrmaEndpoint* ccuEndpoint = dynamic_cast<UrmaEndpoint*>(static_cast<Endpoint*>(endpoint));
1882 0 : const EndpointDesc& locEndpointDesc = ccuEndpoint->GetEndpointDesc();
1883 0 : HcclResult locRet = CommAddrToIpAddress(locEndpointDesc.commAddr, dummy.first);
1884 :
1885 : // 获取remoteAddr
1886 0 : HcommChannelDesc remoteChannelDesc = channelImpl->GetChannelDesc();
1887 0 : HcclResult remRet = CommAddrToIpAddress(remoteChannelDesc.remoteEndpoint.commAddr, dummy.second);
1888 0 : HCCL_INFO(
1889 : "[%s]channelId[%u], channelHandle[0x%llx], locRet[%d], locIpAddr[%s], remRet[%d], remIpAddr[%s]", __func__,
1890 : channelId, channelHandle, locRet, dummy.first.Describe().c_str(), remRet, dummy.second.Describe().c_str());
1891 0 : return dummy;
1892 : }
1893 :
1894 : string
1895 2 : CcuTaskException::GetCcuErrorMsgByType(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId)
1896 : {
1897 2 : if (ccuErrorInfo.type == CcuErrorType::MISSION) {
1898 1 : return GetCcuErrorMsgMission(ccuErrorInfo);
1899 : }
1900 :
1901 : using GetCcuErrorMsgFunc
1902 : = string (*)(const CcuErrorInfo& ccuErrorInfo, const Hccl::TaskInfo& taskInfo, u32 deviceId);
1903 : static const map<CcuRep::CcuRepType, GetCcuErrorMsgFunc> HANDLER_MAP{
1904 : {CcuRep::CcuRepType::LOOP, &CcuTaskException::GetCcuErrorMsgLoop},
1905 : {CcuRep::CcuRepType::LOOPGROUP, &CcuTaskException::GetCcuErrorMsgLoopGroup},
1906 : {CcuRep::CcuRepType::LOC_RECORD_EVENT, &CcuTaskException::GetCcuErrorMsgLocPostSem},
1907 : {CcuRep::CcuRepType::LOC_WAIT_EVENT, &CcuTaskException::GetCcuErrorMsgLocWaitEvent},
1908 : {CcuRep::CcuRepType::LOC_WAIT_NOTIFY, &CcuTaskException::GetCcuErrorMsgLocWaitNotify},
1909 : {CcuRep::CcuRepType::REM_POST_SEM, &CcuTaskException::GetCcuErrorMsgRemPostSem},
1910 : {CcuRep::CcuRepType::REM_WAIT_SEM, &CcuTaskException::GetCcuErrorMsgRemWaitSem},
1911 : {CcuRep::CcuRepType::REM_POST_VAR, &CcuTaskException::GetCcuErrorMsgRemPostVar},
1912 : {CcuRep::CcuRepType::RECORD_SHARED_NOTIFY, &CcuTaskException::GetCcuErrorMsgPostSharedSem},
1913 : {CcuRep::CcuRepType::READ, &CcuTaskException::GetCcuErrorMsgRead},
1914 : {CcuRep::CcuRepType::WRITE, &CcuTaskException::GetCcuErrorMsgWrite},
1915 : {CcuRep::CcuRepType::LOCAL_CPY, &CcuTaskException::GetCcuErrorMsgLocalCpy},
1916 : {CcuRep::CcuRepType::LOCAL_REDUCE, &CcuTaskException::GetCcuErrorMsgLocalReduce},
1917 : {CcuRep::CcuRepType::BUF_READ, &CcuTaskException::GetCcuErrorMsgBufRead},
1918 : {CcuRep::CcuRepType::BUF_WRITE, &CcuTaskException::GetCcuErrorMsgBufWrite},
1919 : {CcuRep::CcuRepType::BUF_LOC_READ, &CcuTaskException::GetCcuErrorMsgBufLocRead},
1920 : {CcuRep::CcuRepType::BUF_LOC_WRITE, &CcuTaskException::GetCcuErrorMsgBufLocWrite},
1921 3 : {CcuRep::CcuRepType::BUF_REDUCE, &CcuTaskException::GetCcuErrorMsgBufReduce}};
1922 :
1923 1 : const auto funcIt = HANDLER_MAP.find(ccuErrorInfo.repType);
1924 1 : if (funcIt == HANDLER_MAP.end()) {
1925 1 : return GetCcuErrorMsgDefault(ccuErrorInfo);
1926 : } else {
1927 0 : return funcIt->second(ccuErrorInfo, taskInfo, deviceId);
1928 : }
1929 : }
1930 : } // namespace hcomm
|