view hello/oclUtils.h @ 0:0e6e76dbdb0f

add file
author Yutaka_Kinjyo
date Tue, 12 Jul 2011 11:12:51 +0900
parents
children
line wrap: on
line source

#ifndef OCL_UTILS_H
#define OCL_UTILS_H

#include <OpenCL/opencl.h>
#include <stdio.h>
#include <stdlib.h>

// SDK Revision #
#define OCL_SDKREVISION "6161726"

// Error and Exit Handling Macros... 
// *********************************************************************
// Full error handling macro with Cleanup() callback (if supplied)... 
// (Companion Inline Function lower on page)
#define oclCheckErrorEX(a, b, c) __oclCheckErrorEX(a, b, c, __FILE__ , __LINE__) 

// Short version without Cleanup() callback pointer
// Both Input (a) and Reference (b) are specified as args
#define oclCheckError(a, b) oclCheckErrorEX(a, b, 0) 

extern "C" const char* oclErrorString(cl_int error);

inline void __oclCheckErrorEX(cl_int iSample, cl_int iReference, void (*pCleanup)(int), const char* cFile, const int iLine)
{
    // An error condition is defined by the sample/test value not equal to the reference
    if (iReference != iSample)
    {
        // If the sample/test value isn't equal to the ref, it's an error by defnition, so override 0 sample/test value
        iSample = (iSample == 0) ? -9999 : iSample; 

        // Log the error info
        //shrLog("\n !!! Error # %i (%s) at line %i , in file %s !!!\n\n", iSample, oclErrorString(iSample), iLine, cFile);

	printf("\n !!! Error # %i (%s) at line %i , in file %s !!!\n\n", iSample, oclErrorString(iSample), iLine, cFile);

        // Cleanup and exit, or just exit if no cleanup function pointer provided.  Use iSample (error code in this case) as process exit code.
        if (pCleanup != NULL)
        {
            pCleanup(iSample);
        }
        else 
        {
	  //shrLogEx(LOGBOTH | CLOSELOG, 0, "Exiting...\n");
            exit(iSample);
        }
    }
}

#endif