22 # ifndef SLOPTIXHELPER_H
23 # define SLOPTIXHELPER_H
29 # include <functional>
36 using namespace std::placeholders;
37 using namespace std::chrono;
44 # include <optix_stubs.h>
47 #define OPTIX_CHECK( call ) \
49 OptixResult res = call; \
50 if( res != OPTIX_SUCCESS ) \
53 ss << "Optix call '" << #call << "' failed: " __FILE__ ":" \
54 << __LINE__ << ")\n"; \
55 throw SLOptixException( res, ss.str().c_str() ); \
59 #define OPTIX_CHECK_LOG( call ) \
61 OptixResult res = call; \
62 if( res != OPTIX_SUCCESS ) \
65 ss << "Optix call '" << #call << "' failed: " __FILE__ ":" \
66 << __LINE__ << ")\nLog:\n" << log \
67 << ( sizeof_log > sizeof( log ) ? "<TRUNCATED>" : "" ) \
69 throw SLOptixException( res, ss.str().c_str() ); \
76 #define CUDA_CHECK( call ) \
78 CUresult result = call; \
79 if( result != CUDA_SUCCESS ) \
81 const char *errorstr; \
82 cuGetErrorString(result, &errorstr); \
84 ss << "CUDA call (" << #call << " ) failed with error: '" \
86 << "' (" __FILE__ << ":" << __LINE__ << ")\n" \
88 throw SLOptixException( ss.str().c_str() ); \
92 #define CUDA_SYNC_CHECK( call ) \
94 CUstream stream = call; \
95 CUresult result = cuStreamSynchronize(stream); \
96 if( result != CUDA_SUCCESS ) \
98 const char *errorstr; \
99 cuGetErrorString(result, &errorstr); \
101 ss << "CUDA error on synchronize with error '" \
103 << "' (" __FILE__ << ":" << __LINE__ << ")\n"; \
104 throw SLOptixException( ss.str().c_str() ); \
110 class SLOptixException :
public std::runtime_error
114 SLOptixException(
const char* msg)
115 : std::runtime_error(msg)
122 SLOptixException(OptixResult res,
const char* msg)
123 : std::runtime_error(createMessage(res, msg).c_str())
129 string createMessage(OptixResult res,
const char* msg)
131 std::ostringstream os;
132 os << optixGetErrorName(res) <<
": " << msg;
142 string getPtxStringFromFile(
144 const char**
log = NULL);
147 float4 make_float4(
const SLVec4f& f);
150 float3 make_float3(
const SLVec3f& f);
void log(const char *tag, const char *format,...)
logs a formatted string platform independently