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 AICPUSD_STATUS_H
12 : #define AICPUSD_STATUS_H
13 :
14 : #include <unistd.h>
15 : #include <sys/syscall.h>
16 : #include "aicpusd_weak_log.h"
17 : #include "ascend_hal.h"
18 :
19 : namespace AicpuSchedule {
20 59834 : inline uint64_t GetTid()
21 : {
22 59834 : thread_local static const uint64_t tid = static_cast<uint64_t>(syscall(__NR_gettid));
23 59834 : return tid;
24 : }
25 :
26 : constexpr int32_t INNER_ERROR_BASE = 500000;
27 :
28 : // 21001 ~ 21200: error codes for hwts task execution
29 : // 21201 ~: inner error code
30 : using StatusCode = int32_t;
31 : constexpr int32_t AICPU_SCHEDULE_OK = 0;
32 : constexpr int32_t AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID = 21001;
33 : constexpr int32_t AICPU_SCHEDULE_ERROR_DUMP_FAILED = 21002;
34 : constexpr int32_t AICPU_SCHEDULE_ERROR_FROM_DRV = 21003;
35 : constexpr int32_t AICPU_SCHEDULE_ERROR_TOOL_ERR = 21004;
36 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_LOGICAL_TASK = 21005;
37 : constexpr int32_t AICPU_SCHEDULE_ERROR_TASK_EXECUTE_FAILED = 21006;
38 : constexpr int32_t AICPU_SCHEDULE_ERROR_TASK_EXECUTE_TIMEOUT = 21007;
39 : constexpr int32_t AICPU_SCHEDULE_ERROR_INNER_ERROR = 21008;
40 : // error code for overflow
41 : constexpr int32_t AICPU_SCHEDULE_ERROR_UNDERFLOW = 21010;
42 : constexpr int32_t AICPU_SCHEDULE_ERROR_OVERFLOW = 21011;
43 : constexpr int32_t AICPU_SCHEDULE_ERROR_DIVISIONZERO = 21012;
44 : // error code for model
45 : constexpr int32_t AICPU_SCHEDULE_ERROR_IN_WORKING = 21100;
46 : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND = 21101;
47 : constexpr int32_t AICPU_SCHEDULE_ERROR_STREAM_NOT_FOUND = 21102;
48 : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_STATUS_NOT_ALLOW_OPERATE = 21103;
49 : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_EXIT_ERR = 21104;
50 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_SUPPORT = 21105;
51 : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_EXECUTE_FAILED = 21106;
52 : constexpr int32_t AICPU_SCHEDULE_ERROR_TSCH_OTHER_ERROR = 21107;
53 : constexpr int32_t AICPU_SCHEDULE_ERROR_DISCARD_DATA = 21108;
54 : // reserved inner error
55 : constexpr int32_t AICPU_SCHEDULE_ERROR_RESERVED = 21200;
56 :
57 : // the following error codes are uniformly normalized to AICPU_SCHEDULE_ERROR_INNER_ERROR
58 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_CMD_TYPE = 21201;
59 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_EVENT = 21202;
60 : constexpr int32_t AICPU_SCHEDULE_ERROR_INIT_CP_FAILED = 21203;
61 : constexpr int32_t AICPU_SCHEDULE_ERROR_REPEART_INIT = 21204;
62 : constexpr int32_t AICPU_SCHEDULE_ERROR_INIT_FAILED = 21205;
63 : constexpr int32_t AICPU_SCHEDULE_ERROR_DRV_ERR = 21206;
64 : constexpr int32_t AICPU_SCHEDULE_ERROR_MALLOC_MEM_FAIL_THROUGH_DRV = 21207;
65 : constexpr int32_t AICPU_SCHEDULE_ERROR_SAFE_FUNCTION_ERR = 21208;
66 : constexpr int32_t AICPU_SCHEDULE_ERROR_INVALID_EVENT_SUBMIT = 21209;
67 : constexpr int32_t AICPU_SCHEDULE_ERROR_UNKNOW_AICPU_EVENT = 21210;
68 : constexpr int32_t AICPU_SCHEDULE_ERROR_COMMON_ERROR = 21211;
69 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FIND_KERNEL_ERROR = 21212;
70 : constexpr int32_t AICPU_SCHEDULE_ERROR_LOAD_CONFIG_JSON_FILE_ERROR = 21213;
71 : constexpr int32_t AICPU_SCHEDULE_ERROR_CGROUP_FAILED = 21214;
72 : constexpr int32_t AICPU_SCHEDULE_ERROR_QUEUE_FULL = 21215;
73 : constexpr int32_t AICPU_SCHEDULE_ERROR_MODEL_UNLOAD = 21216;
74 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_VERSION = 21217;
75 : constexpr int32_t AICPU_SCHEDULE_ERROR_INVALID_MAGIC_NUM = 21218;
76 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION = 21219;
77 :
78 : // error code for queue scheduler process
79 : constexpr int32_t AICPU_SCHEDULE_CALL_DRIVER_ERROR = 21300;
80 : constexpr int32_t AICPU_SCHEDULE_ERROR_GRANT_QUEUE_FAILED = 21301;
81 : constexpr int32_t AICPU_SCHEDULE_ERROR_SLAVE_GRP_INVALID = 21302;
82 : constexpr int32_t AICPU_SCHEDULE_ERROR_MULTI_GRP_ERROR = 21303;
83 : constexpr int32_t AICPU_SCHEDULE_ERROR_GRP_AUTH_ERROR = 21304;
84 : constexpr int32_t AICPU_SCHEDULE_ERROR_NOT_FOUND_QUEUE_SUB_EVENT_ID = 21305;
85 : constexpr int32_t AICPU_SCHEDULE_ERROR_CREATE_CALLBACK_FAILED = 21306;
86 : constexpr int32_t AICPU_SCHEDULE_ERROR_ADD_CALLBACK_FAILED = 21307;
87 : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_CALLBACK_FAILED = 21308;
88 : constexpr int32_t AICPU_SCHEDULE_ERROR_REPEATED_BIND_QUEUE_INIT = 21309;
89 : constexpr int32_t AICPU_SCHEDULE_ERROR_BIND_QUEUE_INIT_RET_FAILED = 21310;
90 : constexpr int32_t AICPU_SCHEDULE_ERROR_ROUTE_NUM_IS_ZERO = 21311;
91 : constexpr int32_t AICPU_SCHEDULE_ERROR_CP_QS_PIPELINE_NOT_INIT = 21312;
92 : constexpr int32_t AICPU_SCHEDULE_ERROR_CALL_QS_BIND_FAILED = 21313;
93 : constexpr int32_t AICPU_SCHEDULE_ERROR_TRANS_MODELINFO_FAILED = 21314;
94 : constexpr int32_t AICPU_SCHEDULE_ERROR_SET_PRIORITY_FAILED = 21315;
95 :
96 : // error code for mem info process
97 : constexpr int32_t AICPU_SCHEDULE_ERROR_READ_JSON_FAILED = 21400;
98 : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_PATH_FAILED = 21401;
99 : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_APP_NAME_FAILED = 21402;
100 : constexpr int32_t AICPU_SCHEDULE_ERROR_GET_RUN_MODE_FAILED = 21403;
101 :
102 : // error code for hccl
103 : constexpr int32_t AICPU_SCHEDULE_ERROR_CALL_HCCL = 21500;
104 : } // namespace AicpuSchedule
105 :
106 : #ifdef ONLY_ERROR
107 :
108 : #define aicpusd_err(fmt, ...) \
109 : if (&DlogRecord != nullptr) { \
110 : dlog_error( \
111 : static_cast<int32_t>(CCECPU), "[%s][tid:%llu]" fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), \
112 : ##__VA_ARGS__); \
113 : }
114 :
115 : #define aicpusd_warn(fmt, ...)
116 : #define aicpusd_info(fmt, ...)
117 : #define aicpusd_debug(fmt, ...)
118 : #define aicpusd_memory_log(fmt, ...)
119 : #define aicpusd_run_info(fmt, ...)
120 : #define aicpusd_run_warn(fmt, ...)
121 :
122 : #else
123 : #define aicpusd_err(fmt, ...) \
124 : if (&DlogRecord != nullptr) { \
125 : dlog_error( \
126 : static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), \
127 : ##__VA_ARGS__); \
128 : }
129 :
130 : #define aicpusd_warn(fmt, ...) \
131 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
132 : dlog_warn( \
133 : static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), \
134 : ##__VA_ARGS__); \
135 : }
136 :
137 : #define aicpusd_info(fmt, ...) \
138 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
139 : dlog_info( \
140 : static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), \
141 : ##__VA_ARGS__); \
142 : }
143 :
144 : #define aicpusd_debug(fmt, ...) \
145 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
146 : dlog_debug( \
147 : static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), \
148 : ##__VA_ARGS__); \
149 : }
150 :
151 : #define aicpusd_memory_log(fmt, ...) \
152 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
153 : dlog_info( \
154 : static_cast<int32_t>(CCECPU), "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), \
155 : ##__VA_ARGS__); \
156 : }
157 :
158 : #define aicpusd_run_info(fmt, ...) \
159 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
160 : dlog_info( \
161 : static_cast<int32_t>(static_cast<uint32_t>(CCECPU) | static_cast<uint32_t>(RUN_LOG_MASK)), \
162 : "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__); \
163 : }
164 :
165 : #define aicpusd_run_warn(fmt, ...) \
166 : if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) { \
167 : dlog_warn( \
168 : static_cast<int32_t>(static_cast<uint32_t>(CCECPU) | static_cast<uint32_t>(RUN_LOG_MASK)), \
169 : "[%s][tid:%llu] " fmt, &__FUNCTION__[0], AicpuSchedule::GetTid(), ##__VA_ARGS__); \
170 : }
171 : #endif
172 :
173 : #define UNUSED(expr) \
174 : do { \
175 : (void)(expr); \
176 : } while (false)
177 :
178 : // 注意: 该宏第一项Condition是期望为真,否则将进行后续的返回和日志记录
179 : #define AICPUSD_CHECK(condition, retValue, log, ...) \
180 : do { \
181 : const bool cond = (condition); \
182 : if (!cond) { \
183 : aicpusd_err(log, ##__VA_ARGS__); \
184 : return (retValue); \
185 : } \
186 : } while (false)
187 :
188 : #endif
|