xref: /aosp_15_r20/external/XNNPACK/src/xnnpack/log.h (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 // All rights reserved.
3 //
4 // Copyright 2019 Google LLC
5 //
6 // This source code is licensed under the BSD-style license found in the
7 // LICENSE file in the root directory of this source tree.
8 
9 #pragma once
10 
11 #include <inttypes.h>
12 #include <stdarg.h>
13 #include <stdlib.h>
14 
15 #include <xnnpack.h>
16 #include <xnnpack/node-type.h>
17 #include <xnnpack/operator-type.h>
18 #include <xnnpack/ukernel-type.h>
19 
20 #ifndef XNN_LOG_LEVEL
21   #error "Undefined XNN_LOG_LEVEL"
22 #endif
23 
24 #define XNN_LOG_NONE 0
25 #define XNN_LOG_FATAL 1
26 #define XNN_LOG_ERROR 2
27 #define XNN_LOG_WARNING 3
28 #define XNN_LOG_INFO 4
29 #define XNN_LOG_DEBUG 5
30 
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #if XNN_LOG_LEVEL >= XNN_LOG_DEBUG
37   void xnn_vlog_debug(const char* format, va_list args);
38 #endif
39 
40 #if XNN_LOG_LEVEL >= XNN_LOG_INFO
41   void xnn_vlog_info(const char* format, va_list args);
42 #endif
43 
44 #if XNN_LOG_LEVEL >= XNN_LOG_WARNING
45   void xnn_vlog_warning(const char* format, va_list args);
46 #endif
47 
48 #if XNN_LOG_LEVEL >= XNN_LOG_ERROR
49   void xnn_vlog_error(const char* format, va_list args);
50 #endif
51 
52 #if XNN_LOG_LEVEL >= XNN_LOG_FATAL
53   void xnn_vlog_fatal(const char* format, va_list args);
54 #endif
55 
56 #if XNN_LOG_LEVEL == XNN_LOG_NONE
xnn_datatype_to_string(enum xnn_datatype type)57   inline static const char* xnn_datatype_to_string(enum xnn_datatype type) {
58     return "Unknown";
59   }
60 
xnn_node_type_to_string(enum xnn_node_type type)61   inline static const char* xnn_node_type_to_string(enum xnn_node_type type) {
62     return "Unknown";
63   }
64 #else
65   const char* xnn_datatype_to_string(enum xnn_datatype type);
66   const char* xnn_node_type_to_string(enum xnn_node_type type);
67 #endif
68 const char* xnn_operator_type_to_string(enum xnn_operator_type type);
69 const char* xnn_ukernel_type_to_string(enum xnn_ukernel_type type);
70 
71 #ifdef __cplusplus
72 }  // extern "C"
73 #endif
74 
75 #ifndef XNN_LOG_ARGUMENTS_FORMAT
76   #ifdef __GNUC__
77     #define XNN_LOG_ARGUMENTS_FORMAT __attribute__((__format__(__printf__, 1, 2)))
78   #else
79     #define XNN_LOG_ARGUMENTS_FORMAT
80   #endif
81 #endif
82 
xnn_log_debug(const char * format,...)83 XNN_LOG_ARGUMENTS_FORMAT inline static void xnn_log_debug(const char* format, ...) {
84   #if XNN_LOG_LEVEL >= XNN_LOG_DEBUG
85     va_list args;
86     va_start(args, format);
87     xnn_vlog_debug(format, args);
88     va_end(args);
89   #endif
90 }
91 
xnn_log_info(const char * format,...)92 XNN_LOG_ARGUMENTS_FORMAT inline static void xnn_log_info(const char* format, ...) {
93   #if XNN_LOG_LEVEL >= XNN_LOG_INFO
94     va_list args;
95     va_start(args, format);
96     xnn_vlog_info(format, args);
97     va_end(args);
98   #endif
99 }
100 
xnn_log_warning(const char * format,...)101 XNN_LOG_ARGUMENTS_FORMAT inline static void xnn_log_warning(const char* format, ...) {
102   #if XNN_LOG_LEVEL >= XNN_LOG_WARNING
103     va_list args;
104     va_start(args, format);
105     xnn_vlog_warning(format, args);
106     va_end(args);
107   #endif
108 }
109 
xnn_log_error(const char * format,...)110 XNN_LOG_ARGUMENTS_FORMAT inline static void xnn_log_error(const char* format, ...) {
111   #if XNN_LOG_LEVEL >= XNN_LOG_ERROR
112     va_list args;
113     va_start(args, format);
114     xnn_vlog_error(format, args);
115     va_end(args);
116   #endif
117 }
118 
xnn_log_fatal(const char * format,...)119 XNN_LOG_ARGUMENTS_FORMAT inline static void xnn_log_fatal(const char* format, ...) {
120   #if XNN_LOG_LEVEL >= XNN_LOG_FATAL
121     va_list args;
122     va_start(args, format);
123     xnn_vlog_fatal(format, args);
124     va_end(args);
125   #endif
126   abort();
127 }
128