LibCudaOptimize
1.0
|
00001 //*************************************************************************// 00002 // // 00003 // LibCudaOptimize // 00004 // Copyright (C) 2012 Ibislab, University of Parma // 00005 // Authors: Youssef S.G. Nashed, Roberto Ugolotti // 00006 // // 00007 // You should have received a copy of the GNU General Public License // 00008 // along with this program. If not, see <http://www.gnu.org/licenses/> // 00009 // // 00010 //*************************************************************************// 00011 00012 #ifndef __UTILITIES_H 00013 #define __UTILITIES_H 00014 00016 #include "OptimizerLog.h" 00017 #include <stdlib.h> 00018 #include <cuda_runtime.h> 00019 00026 inline void optimizerCudaCheckError( const char *errorMessage, const char* file, int line, const std::string logger="") 00027 { 00028 cudaError_t err = cudaGetLastError(); 00029 if( cudaSuccess != err) 00030 { 00031 char msg[1024]; 00032 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 00033 sprintf_s(msg, "%s(%i) : CUDA error : %s : (%d) %s.\n", file, line, errorMessage, (int)err, cudaGetErrorString( err ) ); 00034 #else 00035 sprintf(msg, "%s(%i) : CUDA error : %s : (%d) %s.\n", file, line, errorMessage, (int)err, cudaGetErrorString( err ) ); 00036 #endif 00037 FILE_LOG(logERROR,logDEBUG4,logger) << msg; //always show CUDA errors 00038 exit(-1); 00039 } 00040 } 00041 00043 00044 #define IMUL(a, b) __mul24(a, b) 00045 00047 // Common host and device function 00049 00051 extern "C" int iDivUp(int a, int b); 00052 00054 extern "C" int iDivDown(int a, int b); 00055 00057 extern "C" int iAlignUp(int a, int b); 00058 00060 extern "C" int iAlignDown(int a, int b); 00061 00063 extern "C" bool isBetter(float arg1, float arg2, bool maximization=false); 00064 #endif 00065