12 #    ifndef SLOPTIXHELPER_H 
   13 #        define SLOPTIXHELPER_H 
   19 #        include <functional> 
   26 using namespace std::placeholders;
 
   27 using namespace std::chrono;
 
   34 #        include <optix_stubs.h> 
   37 #define OPTIX_CHECK( call )                                                    \ 
   39         OptixResult res = call;                                                \ 
   40         if( res != OPTIX_SUCCESS )                                             \ 
   43             ss << "Optix call '" << #call << "' failed: " __FILE__ ":"         \
 
   44                << __LINE__ << ")\n";                                           \
 
   45             throw SLOptixException( res, ss.str().c_str() );                   \
 
   49 #define OPTIX_CHECK_LOG( call )                                                \ 
   51         OptixResult res = call;                                                \ 
   52         if( res != OPTIX_SUCCESS )                                             \ 
   55             ss << "Optix call '" << #call << "' failed: " __FILE__ ":"         \
 
   56                << __LINE__ << ")\nLog:\n" << log                               \
 
   57                << ( sizeof_log > sizeof( log ) ? "<TRUNCATED>" : "" )          \
 
   59             throw SLOptixException( res, ss.str().c_str() );                   \
 
   66 #define CUDA_CHECK( call )                                                     \ 
   68         CUresult result = call;                                                \ 
   69         if( result != CUDA_SUCCESS )                                           \ 
   71             const char *errorstr;                                              \ 
   72             cuGetErrorString(result, &errorstr);                               \ 
   74             ss << "CUDA call (" << #call << " ) failed with error: '"          \
 
   76                << "' (" __FILE__ << ":" << __LINE__ << ")\n"                   \
 
   78             throw SLOptixException( ss.str().c_str() );                        \
 
   82 #define CUDA_SYNC_CHECK( call )                                                \ 
   84         CUstream stream = call;                                                \ 
   85         CUresult result = cuStreamSynchronize(stream);                         \ 
   86         if( result != CUDA_SUCCESS )                                           \ 
   88             const char *errorstr;                                              \ 
   89             cuGetErrorString(result, &errorstr);                               \ 
   91             ss << "CUDA error on synchronize with error '"                     \
 
   93                << "' (" __FILE__ << ":" << __LINE__ << ")\n";                  \
 
   94             throw SLOptixException( ss.str().c_str() );                        \
 
   99 class SLOptixException : 
public std::runtime_error
 
  102     SLOptixException(
const char* msg)
 
  103       : std::runtime_error(msg)
 
  107     SLOptixException(OptixResult res, 
const char* msg)
 
  108       : std::runtime_error(createMessage(res, msg).c_str())
 
  113     string createMessage(OptixResult res, 
const char* msg)
 
  115         std::ostringstream os;
 
  116         os << optixGetErrorName(res) << 
": " << msg;
 
  122 string getPtxStringFromFile(
 
  124   const char** 
log = NULL); 
 
  126 float4 make_float4(
const SLVec4f& f);
 
  128 float3 make_float3(
const SLVec3f& f);
 
void log(const char *tag, const char *format,...)
logs a formatted string platform independently