Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:43

0001 #pragma once
0002 
0003 
0004 #include "QUDARAP_API_EXPORT.hh"
0005 #include <stdexcept>
0006 #include <sstream>
0007 
0008 
0009 #define QUDA_CHECK( call )                                                     \
0010     do                                                                         \
0011     {                                                                          \
0012         cudaError_t error = call;                                              \
0013         if( error != cudaSuccess )                                             \
0014         {                                                                      \
0015             std::stringstream ss;                                              \
0016             ss << "CUDA call (" << #call << " ) failed with error: '"          \
0017                << cudaGetErrorString( error )                                  \
0018                << "' (" __FILE__ << ":" << __LINE__ << ")\n";                  \
0019             throw QUDA_Exception( ss.str().c_str() );                        \
0020         }                                                                      \
0021     } while( 0 )
0022 
0023 
0024 #define QUDA_SYNC_CHECK()                                                      \
0025     do                                                                         \
0026     {                                                                          \
0027         cudaDeviceSynchronize();                                               \
0028         cudaError_t error = cudaGetLastError();                                \
0029         if( error != cudaSuccess )                                             \
0030         {                                                                      \
0031             std::stringstream ss;                                              \
0032             ss << "CUDA error on synchronize with error '"                     \
0033                << cudaGetErrorString( error )                                  \
0034                << "' (" __FILE__ << ":" << __LINE__ << ")\n";                  \
0035             throw QUDA_Exception( ss.str().c_str() );                        \
0036         }                                                                      \
0037     } while( 0 )
0038 
0039 
0040 
0041 
0042 class QUDARAP_API QUDA_Exception : public std::runtime_error
0043 {
0044  public:
0045      QUDA_Exception( const char* msg )
0046          : std::runtime_error( msg )
0047      { }
0048 
0049 };
0050 
0051 
0052 struct QUDA
0053 {
0054     static void  before_kernel( cudaEvent_t& start, cudaEvent_t& stop ); 
0055     static float after_kernel(  cudaEvent_t& start, cudaEvent_t& stop );
0056 }; 
0057 
0058 inline void QUDA::before_kernel( cudaEvent_t& start, cudaEvent_t& stop )
0059 {
0060     QUDA_CHECK( cudaEventCreate( &start ) );
0061     QUDA_CHECK( cudaEventCreate( &stop ) );
0062     QUDA_CHECK( cudaEventRecord( start,0 ) );
0063 }
0064 
0065 inline float QUDA::after_kernel( cudaEvent_t& start, cudaEvent_t& stop )
0066 {
0067     float kernel_time = 0.f ;
0068 
0069     QUDA_CHECK( cudaEventRecord( stop,0 ) );
0070     QUDA_CHECK( cudaEventSynchronize(stop) );
0071 
0072     QUDA_CHECK( cudaEventElapsedTime(&kernel_time, start, stop) );
0073     QUDA_CHECK( cudaEventDestroy( start ) );
0074     QUDA_CHECK( cudaEventDestroy( stop ) );
0075 
0076     QUDA_CHECK( cudaDeviceSynchronize() );
0077 
0078     return kernel_time ;
0079 }
0080 
0081 
0082 
0083