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