12 #ifndef HELPER_CUDA_GL_H
13 #define HELPER_CUDA_GL_H
20 #if defined (__APPLE__) || defined(MACOSX)
21 #include <OpenGL/gl.h>
22 #include <OpenGL/glu.h>
32 #ifdef __DRIVER_TYPES_H__
34 #define DEVICE_RESET cudaDeviceReset()
42 #ifdef __CUDA_GL_INTEROP_H__
46 inline int gpuGLDeviceInit(
int ARGC,
const char **ARGV)
49 checkCudaErrors(cudaGetDeviceCount(&deviceCount));
53 fprintf(stderr,
"CUDA error: no devices supporting CUDA.\n");
65 if (dev > deviceCount-1)
67 fprintf(stderr,
"\n");
68 fprintf(stderr,
">> %d CUDA capable GPU device(s) detected. <<\n", deviceCount);
69 fprintf(stderr,
">> gpuGLDeviceInit (-device=%d) is not a valid GPU device. <<\n", dev);
70 fprintf(stderr,
"\n");
74 cudaDeviceProp deviceProp;
75 checkCudaErrors(cudaGetDeviceProperties(&deviceProp, dev));
77 if (deviceProp.computeMode == cudaComputeModeProhibited)
79 fprintf(stderr,
"Error: device is running in <Compute Mode Prohibited>, no threads can use ::cudaSetDevice().\n");
83 if (deviceProp.major < 1)
85 fprintf(stderr,
"Error: device does not support CUDA.\n");
91 fprintf(stderr,
"Using device %d: %s\n", dev, deviceProp.name);
98 inline int findCudaGLDevice(
int argc,
const char **argv)
105 devID = gpuGLDeviceInit(argc, (
const char **)argv);
109 printf(
"no CUDA capable devices found, exiting...\n");
117 devID = gpuGetMaxGflopsDeviceId();
132 sdkCheckErrorGL(
const char *file,
const int line)
137 GLenum gl_error = glGetError();
139 if (gl_error != GL_NO_ERROR)
141 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
145 sprintf_s(tmpStr, 255,
"\n%s(%i) : GL Error : %s\n\n", file, line, gluErrorString(gl_error));
146 fprintf(stderr,
"%s", tmpStr);
148 fprintf(stderr,
"GL Error in file '%s' in line %d :\n", file, line);
149 fprintf(stderr,
"%s\n", gluErrorString(gl_error));
156 #define SDK_CHECK_ERROR_GL() \
157 if( false == sdkCheckErrorGL( __FILE__, __LINE__)) { \
159 exit(EXIT_FAILURE); \
bool checkCmdLineFlag(const int argc, const char **argv, const char *string_ref)
Definition: helper_string.h:125
#define DEVICE_RESET
Definition: helper_cuda_gl.h:38
typedef GLenum(APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC)(GLenum target)
int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref)
Definition: helper_string.h:183