1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef GEMM_WRAPPER_LOG_H 17 #define GEMM_WRAPPER_LOG_H 18 19 #include <stdarg.h> 20 #include <stdbool.h> 21 #include <stdio.h> 22 23 #define TFM_LOG_LEVEL_VERBOSE -2 24 #define TFM_LOG_LEVEL_DEBUG -1 25 #define TFM_LOG_LEVEL_INFO 0 26 #define TFM_LOG_LEVEL_WARNING 1 27 #define TFM_LOG_LEVEL_ERROR 2 28 #define TFM_LOG_LEVEL_FATAL 3 29 30 static int s_log_level = TFM_LOG_LEVEL_INFO; 31 32 static inline bool IsLogOn(int log_level) { return log_level >= s_log_level; } 33 34 static inline void SetLogLevel(int log_level) { s_log_level = log_level; } 35 36 // Do nothing 37 static inline void SetExperimentalDebug() {} 38 39 #define TFMLOGV(fmt, ...) \ 40 do { \ 41 if (!IsLogOn(TFM_LOG_LEVEL_VERBOSE)) break; \ 42 printf(fmt "\n", ##__VA_ARGS__); \ 43 } while (0) 44 45 #define TFMLOGD(fmt, ...) \ 46 do { \ 47 if (!IsLogOn(TFM_LOG_LEVEL_DEBUG)) break; \ 48 printf(fmt "\n", ##__VA_ARGS__); \ 49 } while (0) 50 51 #define TFMLOGI(fmt, ...) \ 52 do { \ 53 if (!IsLogOn(TFM_LOG_LEVEL_INFO)) break; \ 54 printf(fmt "\n", ##__VA_ARGS__); \ 55 } while (0) 56 57 #define TFMLOGE(fmt, ...) \ 58 do { \ 59 if (!IsLogOn(TFM_LOG_LEVEL_ERROR)) break; \ 60 printf(fmt "\n", ##__VA_ARGS__); \ 61 } while (0) 62 63 static inline void PrintLogHexagon(const char* fmt, va_list ap) { 64 char buffer[200]; 65 const int count = snprintf(buffer, 200, fmt, ap); 66 buffer[count] = 0; 67 TFMLOGI("%s", buffer); 68 } 69 70 static inline void LogDHexagon(const char* fmt, ...) { 71 va_list ap; 72 va_start(ap, fmt); 73 PrintLogHexagon(fmt, ap); 74 va_end(ap); 75 } 76 77 static inline void DumpNNId(uint32_t nn_id) { 78 // TODO(satok): Dump more information 79 TFMLOGI("NN Id = %d", nn_id); 80 } 81 82 #endif 83