1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | |
20 | /*! |
21 | * \file include/tvm/runtime/crt/error_codes.h |
22 | * \brief Defines integral error codes returned by the CRT. |
23 | */ |
24 | #ifndef TVM_RUNTIME_CRT_ERROR_CODES_H_ |
25 | #define TVM_RUNTIME_CRT_ERROR_CODES_H_ |
26 | |
27 | #ifdef __cplusplus |
28 | extern "C" { |
29 | #endif |
30 | |
31 | #define TVM_CRT_ERROR_CATEGORY_Pos 8 |
32 | #define TVM_CRT_ERROR_CATEGORY_Msk (0xff << TVM_CRT_ERROR_CATEGORY_Pos) |
33 | #define TVM_CRT_ERROR_CODE_Pos 0 |
34 | #define TVM_CRT_ERROR_CODE_Msk (0xff << TVM_CRT_ERROR_CODE_Pos) |
35 | |
36 | #define DEFINE_TVM_CRT_ERROR(category, code) \ |
37 | (((category) << TVM_CRT_ERROR_CATEGORY_Pos) | ((code) << TVM_CRT_ERROR_CODE_Pos)) |
38 | typedef enum { |
39 | kTvmErrorCategoryFunctionRegistry = 1, |
40 | kTvmErrorCategoryFraming = 2, |
41 | kTvmErrorCategoryWriteStream = 3, |
42 | kTvmErrorCategorySession = 4, |
43 | kTvmErrorCategoryPlatform = 5, |
44 | kTvmErrorCategoryGenerated = 6, |
45 | kTvmErrorCategoryExecutor = 7, |
46 | kTvmErrorCategoryFunctionCall = 8, |
47 | kTvmErrorCategoryTimeEvaluator = 9, |
48 | } tvm_crt_error_category_t; |
49 | |
50 | typedef enum { |
51 | kTvmErrorNoError = 0, |
52 | |
53 | // Function Registry |
54 | kTvmErrorFunctionNameNotFound = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionRegistry, 0), |
55 | kTvmErrorFunctionIndexInvalid = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionRegistry, 1), |
56 | kTvmErrorFunctionRegistryFull = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionRegistry, 2), |
57 | kTvmErrorFunctionAlreadyDefined = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionRegistry, 3), |
58 | kTvmErrorBufferTooSmall = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionRegistry, 4), |
59 | |
60 | // Framing |
61 | kTvmErrorFramingInvalidState = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFraming, 0), |
62 | kTvmErrorFramingShortPacket = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFraming, 1), |
63 | kTvmErrorFramingInvalidEscape = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFraming, 2), |
64 | kTvmErrorFramingPayloadOverflow = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFraming, 3), |
65 | kTvmErrorFramingPayloadIncomplete = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFraming, 4), |
66 | |
67 | // Write stream |
68 | kTvmErrorWriteStreamShortWrite = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryWriteStream, 0), |
69 | kTvmErrorWriteStreamLongWrite = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryWriteStream, 1), |
70 | |
71 | // Session |
72 | kTvmErrorSessionInvalidState = DEFINE_TVM_CRT_ERROR(kTvmErrorCategorySession, 0), |
73 | kTvmErrorSessionReceiveBufferBusy = DEFINE_TVM_CRT_ERROR(kTvmErrorCategorySession, 1), |
74 | kTvmErrorSessionReceiveBufferShortWrite = DEFINE_TVM_CRT_ERROR(kTvmErrorCategorySession, 2), |
75 | |
76 | // Platform |
77 | kTvmErrorPlatformCheckFailure = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryPlatform, 0), |
78 | kTvmErrorPlatformMemoryManagerInitialized = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryPlatform, 1), |
79 | kTvmErrorPlatformShutdown = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryPlatform, 2), |
80 | kTvmErrorPlatformNoMemory = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryPlatform, 3), |
81 | kTvmErrorPlatformTimerBadState = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryPlatform, 4), |
82 | kTvmErrorPlatformStackAllocBadFree = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryPlatform, 5), |
83 | |
84 | // Common error codes returned from generated functions. |
85 | kTvmErrorGeneratedInvalidStorageId = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryGenerated, 0), |
86 | |
87 | // Graph or AoT executor |
88 | kTvmErrorExecutorModuleAlreadyCreated = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryExecutor, 0), |
89 | kTvmErrorExecutorModuleBadContext = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryExecutor, 1), |
90 | kTvmErrorExecutorModuleNoSuchInput = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryExecutor, 2), |
91 | |
92 | // Function Calls - common problems encountered calling functions. |
93 | kTvmErrorFunctionCallNumArguments = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionCall, 0), |
94 | kTvmErrorFunctionCallWrongArgType = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionCall, 1), |
95 | kTvmErrorFunctionCallNotImplemented = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionCall, 2), |
96 | kTvmErrorFunctionCallInvalidArg = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionCall, 3), |
97 | |
98 | // Time Evaluator - times functions for use with debug runtime. |
99 | kTvmErrorTimeEvaluatorBadHandle = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryTimeEvaluator, 0), |
100 | |
101 | // System errors are always negative integers; this mask indicates presence of a system error. |
102 | // Cast tvm_crt_error_t to a signed integer to interpret the negative error code. |
103 | kTvmErrorSystemErrorMask = (1 << (sizeof(int) * 8 - 1)), |
104 | } tvm_crt_error_t; |
105 | |
106 | #ifdef __cplusplus |
107 | } |
108 | #endif |
109 | |
110 | #endif // TVM_RUNTIME_CRT_ERROR_CODES_H_ |
111 | |