opencl_utils.h
Go to the documentation of this file.
00001 #ifndef OPENCL_UTILS_H
00002 #define OPENCL_UTILS_H
00003 
00004 #include <CL/cl.h>
00005 
00006 #include <fstream>
00007 
00009 
00010 #define oclCheckErrorEX(a, b, c) __oclCheckErrorEX(a, b, c, __FILE__ , __LINE__)
00011 #define oclCheckError(a, b) oclCheckErrorEX(a, b, 0)
00012 
00013 extern "C" cl_context oclGetGlobalContext( );
00014 extern "C" cl_command_queue oclGetGlobalQueue( );
00015 
00016 extern "C" void oclInit();
00017 extern "C" void oclInitializeKernels(cl_context cxGPUContext, cl_command_queue cqCommandQueue);
00018 
00019 extern "C" void oclShutdown(cl_context clContext, cl_command_queue clQueue);
00020 extern "C" void oclShutdownKernels(void);
00021 
00022 extern "C" cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID);
00023 
00024 extern "C" cl_device_id oclGetFirstDev(cl_context cxGPUContext);
00025 
00026 extern "C" char* oclFindFilePath(const char* filename, const char* executablePath);
00027 extern "C" char* oclLoadProgSource(const char* cFilename, const char* cPreamble, size_t* szFinalLength);
00028 extern "C" const char* oclErrorString(cl_int error);
00029 
00030 extern "C" void oclGetProgBinary( cl_program cpProgram, cl_device_id cdDevice, char** binary, size_t* length);
00031 extern "C" void oclLogPtx(cl_program cpProgram, cl_device_id cdDevice, const char* cPtxFileName);
00032 extern "C" void oclLogBuildInfo(cl_program cpProgram, cl_device_id cdDevice);
00033 
00034 inline void __oclCheckErrorEX(cl_int iSample, cl_int iReference, void (*pCleanup)(int), const char* cFile, const int iLine)
00035 {
00036   if (iReference != iSample)
00037   {
00038     iSample = (iSample == 0) ? -9999 : iSample;
00039     printf("\n !!! OpenCL Error # %i (%s) at line %i , in file %s !!!\n\n", iSample, oclErrorString(iSample), iLine, cFile);
00040 
00041     if (pCleanup != NULL) {
00042       pCleanup(iSample);
00043     } else {
00044       exit(iSample);
00045     }
00046   }
00047 }
00048 
00050 
00051 inline cl_context dxGetDeviceContext( ) { return oclGetGlobalContext(); }
00052 inline cl_command_queue dxGetDeviceQueue( ) { return oclGetGlobalQueue(); }
00053 
00054 inline void dxGlobalSync() { clFinish( dxGetDeviceQueue() ); }
00055 inline void dxInitDevice() { oclInit(); oclInitializeKernels(dxGetDeviceContext(), dxGetDeviceQueue()); }
00056 inline void dxShutdownDevice() { oclShutdown(dxGetDeviceContext(), dxGetDeviceQueue()); oclShutdownKernels(); }
00057 
00059 
00060 
00061 #endif


parallel_quickstep
Author(s): Jared Duke
autogenerated on Wed Apr 23 2014 10:23:51