1 // SPDX-License-Identifier: MIT
2 //
3 // Copyright 2024 Advanced Micro Devices, Inc.
4 
5 #ifndef __DML2_DEBUG_H__
6 #define __DML2_DEBUG_H__
7 
8 #ifdef _DEBUG
9 #define DML2_ASSERT(condition) dml2_assert(condition)
10 #else
11 #define DML2_ASSERT(condition) ((void)0)
12 #endif
13 /*
14  * DML_LOG_FATAL - fatal errors for unrecoverable DML states until a restart.
15  * DML_LOG_ERROR - unexpected but recoverable failures inside DML
16  * DML_LOG_WARN - unexpected inputs or events to DML
17  * DML_LOG_INFO - high level tracing of DML interfaces
18  * DML_LOG_DEBUG - detailed tracing of DML internal components
19  * DML_LOG_VERBOSE - detailed tracing of DML calculation procedure
20  */
21 #if !defined(DML_LOG_LEVEL)
22 #if defined(_DEBUG) && defined(_DEBUG_PRINTS)
23 /* for backward compatibility with old macros */
24 #define DML_LOG_LEVEL 5
25 #else
26 #define DML_LOG_LEVEL 0
27 #endif
28 #endif
29 
30 #define DML_LOG_FATAL(fmt, ...) dml2_log_internal(fmt, ## __VA_ARGS__)
31 #if DML_LOG_LEVEL >= 1
32 #define DML_LOG_ERROR(fmt, ...) dml2_log_internal(fmt, ## __VA_ARGS__)
33 #else
34 #define DML_LOG_ERROR(fmt, ...) ((void)0)
35 #endif
36 #if DML_LOG_LEVEL >= 2
37 #define DML_LOG_WARN(fmt, ...) dml2_log_internal(fmt, ## __VA_ARGS__)
38 #else
39 #define DML_LOG_WARN(fmt, ...) ((void)0)
40 #endif
41 #if DML_LOG_LEVEL >= 3
42 #define DML_LOG_INFO(fmt, ...) dml2_log_internal(fmt, ## __VA_ARGS__)
43 #else
44 #define DML_LOG_INFO(fmt, ...) ((void)0)
45 #endif
46 #if DML_LOG_LEVEL >= 4
47 #define DML_LOG_DEBUG(fmt, ...) dml2_log_internal(fmt, ## __VA_ARGS__)
48 #else
49 #define DML_LOG_DEBUG(fmt, ...) ((void)0)
50 #endif
51 #if DML_LOG_LEVEL >= 5
52 #define DML_LOG_VERBOSE(fmt, ...) dml2_log_internal(fmt, ## __VA_ARGS__)
53 #else
54 #define DML_LOG_VERBOSE(fmt, ...) ((void)0)
55 #endif
56 
57 int dml2_log_internal(const char *format, ...);
58 int dml2_printf(const char *format, ...);
59 void dml2_assert(int condition);
60 
61 #endif
62