1 #pragma once 2 3 #ifdef __cplusplus 4 #include <cstdio> 5 #else 6 #include <stdio.h> 7 #endif 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #ifdef _WIN32 14 #define unlikely(x) (x) 15 #else 16 #define unlikely(x) __builtin_expect((x), 0) 17 #endif 18 19 #define NULL_CHECK(val) \ 20 if (unlikely((val) == NULL)) { \ 21 fprintf(stderr, "NULL ERROR: %s:%d\n", __FILE__, __LINE__); \ 22 PyErr_Print(); \ 23 abort(); \ 24 } else { \ 25 } 26 27 // CHECK might be previously declared 28 #undef CHECK 29 #define CHECK(cond) \ 30 if (unlikely(!(cond))) { \ 31 fprintf(stderr, "DEBUG CHECK FAILED: %s:%d\n", __FILE__, __LINE__); \ 32 abort(); \ 33 } else { \ 34 } 35 36 // Uncomment next line to print debug message 37 // #define TORCHDYNAMO_DEBUG 1 38 #ifdef TORCHDYNAMO_DEBUG 39 40 #define DEBUG_CHECK(cond) CHECK(cond) 41 #define DEBUG_NULL_CHECK(val) NULL_CHECK(val) 42 #define DEBUG_TRACE(msg, ...) \ 43 fprintf(stderr, "TRACE[%s:%d] " msg "\n", __func__, __LINE__, __VA_ARGS__) 44 #define DEBUG_TRACE0(msg) \ 45 fprintf(stderr, "TRACE[%s:%d] " msg "\n", __func__, __LINE__) 46 47 #else 48 49 #define DEBUG_CHECK(cond) 50 #define DEBUG_NULL_CHECK(val) 51 #define DEBUG_TRACE(msg, ...) 52 #define DEBUG_TRACE0(msg) 53 54 #endif 55 56 #ifdef __cplusplus 57 } // extern "C" 58 #endif 59