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 : #ifndef HCCL_TASK_EXCEPTION_FUNC_H
12 : #define HCCL_TASK_EXCEPTION_FUNC_H
13 :
14 : #include <unordered_map>
15 : #include <functional>
16 : #include <memory>
17 : #include "stream_lite.h"
18 : #include "ascend_hal_define.h"
19 : #include "daemon_func.h"
20 : #include "communicator_impl_lite.h"
21 :
22 : namespace Hccl {
23 : extern "C" {
24 : drvError_t __attribute__((weak)) halCqReportRecv(uint32_t devId, struct halReportRecvInfo* info);
25 : drvError_t __attribute__((weak)) drvGetLocalDevIDByHostDevID(uint32_t host_dev_id, uint32_t* local_dev_id);
26 : };
27 :
28 : struct rtLogicCqReport_t {
29 : volatile uint16_t streamId;
30 : volatile uint16_t taskId;
31 : volatile uint32_t errorCode; // cqe acc_status/sq_sw_status
32 : volatile uint8_t errorType; // bit0 ~ bit5 cqe stars_defined_err_code, bit 6 cqe warning bit
33 : volatile uint8_t sqeType;
34 : volatile uint16_t sqId;
35 : volatile uint16_t sqHead;
36 : volatile uint16_t matchFlag : 1;
37 : volatile uint16_t dropFlag : 1;
38 : volatile uint16_t errorBit : 1;
39 : volatile uint16_t accError : 1;
40 : volatile uint16_t reserved0 : 12;
41 : union {
42 : volatile uint64_t timeStamp;
43 : volatile uint16_t sqeIndex;
44 : } u1;
45 : /* Union description:
46 : * Internal: enque_timestamp temporarily used as dfx
47 : * External: reserved1
48 : */
49 : union {
50 : volatile uint64_t enqueTimeStamp;
51 : volatile uint64_t reserved1;
52 : } u2;
53 : };
54 :
55 : class TaskExceptionFunc : public DaemonFunc {
56 : using Callback = std::function<void(CommunicatorImplLite*, rtLogicCqReport_t*)>;
57 :
58 : public:
59 : static TaskExceptionFunc& GetInstance();
60 : void SetEnable(bool isEnable);
61 : void SetDevId(uint32_t devId);
62 1 : uint32_t GetDevId() const { return devId_; }
63 : void Register(StreamLite* streamLite);
64 : void UnRegister(StreamLite* streamLite);
65 : void Call() override;
66 : void RegisterCallback(const Callback& callback);
67 : bool IsExceptionCqe(const rtLogicCqReport_t& reportOfOne) const;
68 : unsigned int GetTrailingZeros(uint8_t num) const;
69 : std::string StringLogicCqReportInfo(const rtLogicCqReport_t& reportOfOne) const;
70 : uint32_t GetReporterInfo(const StreamLite* curStream, std::shared_ptr<halReportRecvInfo> recvInfo);
71 :
72 : private:
73 : // 私有构造函数,防止外部实例化
74 1 : TaskExceptionFunc() {};
75 : // 禁用拷贝构造函数
76 : TaskExceptionFunc(const TaskExceptionFunc&) = delete;
77 : // 禁用赋值运算符
78 : TaskExceptionFunc& operator=(const TaskExceptionFunc&) = delete;
79 :
80 : std::string ErrorType2Str(uint8_t errorType) const;
81 : std::string CqeStatus2Str(uint32_t errorCode) const;
82 :
83 : private:
84 : bool isEnable_{true};
85 : std::unordered_map<uint32_t, StreamLite*> streamLiteMap_; // keymap: sqid
86 : uint32_t devId_{0};
87 : Callback callback_;
88 : };
89 :
90 : } // namespace Hccl
91 :
92 : #endif // HCCL_TASK_EXCEPTION_FUNC_H
|