Skip to content
Snippets Groups Projects
Assert.h 3.98 KiB
Newer Older
  • Learn to ignore specific revisions
  • /***************************************************************************
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
                              Assert.h  -  description
    
                                 -------------------
        begin                : Jan 12, 2010
        copyright            : (C) 2013 by Tomas Oberhuber
        email                : tomas.oberhuber@fjfi.cvut.cz
     ***************************************************************************/
    
    
    /* See Copyright Notice in tnl/Copyright */
    
    #pragma once
    
    
    /****
     * Debugging assert
     */
    
    Tomáš Oberhuber's avatar
    Tomáš Oberhuber committed
    #ifndef NDEBUG
    
    
    #include <iostream>
    #include <stdlib.h>
    
    #include <assert.h>
    
    #endif
    
    #ifndef NDEBUG   
       
    
    // __CUDA_ARCH__ is defined by the compiler only for code executed on GPU
    #ifdef __CUDA_ARCH__
    
    #define TNL_ASSERT( ___tnl__assert_condition, ___tnl__assert_command )                                     \
       if( ! ( ___tnl__assert_condition ) )                                                                    \
       {                                                                                                       \
    
       printf( "Assertion '%s' failed !!! \n File: %s \n Line: %d \n Diagnostics: Not supported with CUDA.\n", \
    
               __STRING( ___tnl__assert_condition ),                                                           \
               __FILE__,                                                                                       \
               __LINE__ );                                                                                     \
                                                                                                               \
    
    #else // __CUDA_ARCH__
    
    #if ( __CUDA_API_VERSION >= 8000 )
       #define TNL_ASSERT( ___tnl__assert_condition, ___tnl__assert_command )                                  \
          if( ! ( ___tnl__assert_condition ) )                                                                 \
          {                                                                                                    \
          std::cerr << "Assertion '" << __STRING( ___tnl__assert_condition ) << "' failed !!!" << std::endl    \
                    << "File: " << __FILE__ << std::endl                                                       \
                    << "Function: " << __PRETTY_FUNCTION__ << std::endl                                        \
                    << "Line: " << __LINE__ << std::endl                                                       \
                    << "Diagnostics: ";                                                                        \
               ___tnl__assert_command;                                                                         \
               throw EXIT_FAILURE;                                                                             \
          }
    #else //  ( __CUDA_API_VERSION >= 8000 )
       #define TNL_ASSERT( ___tnl__assert_condition, ___tnl__assert_command )                                  \
          if( ! ( ___tnl__assert_condition ) )                                                                 \
          {                                                                                                    \
          std::cerr << "Assertion '" << __STRING( ___tnl__assert_condition ) << "' failed !!!" << std::endl    \
                    << "File: " << __FILE__ << std::endl                                                       \
                    << "Function: (not known in CUDA 7.5 or older)" << std::endl                               \
                    << "Line: " << __LINE__ << std::endl                                                       \
                    << "Diagnostics: ";                                                                        \
               ___tnl__assert_command;                                                                         \
               throw EXIT_FAILURE;                                                                             \
          }
    #endif //  ( __CUDA_API_VERSION >= 8000 )             
    
    #endif // __CUDA_ARCH__
    
    
    #else /* #ifndef NDEBUG */
    
    #define TNL_ASSERT( ___tnl__assert_condition, ___tnl__assert_command )
    
    #endif /* #ifndef NDEBUG */