29# pragma warning( disable : 4996 )
42# define DLL_MAPPING __declspec(dllexport)
44# define DLL_MAPPING __declspec(dllimport)
51 #define CUTIL_API __stdcall
89 cutCheckBankAccess(
unsigned int tidx,
unsigned int tidy,
unsigned int tidz,
90 unsigned int bdimx,
unsigned int bdimy,
91 unsigned int bdimz,
const char* file,
const int line,
92 const char* aname,
const int index);
102 cutFindFilePath(
const char* filename,
const char* executablePath);
117 cutReadFilef(
const char* filename,
float** data,
unsigned int* len,
118 bool verbose =
false);
133 cutReadFiled(
const char* filename,
double** data,
unsigned int* len,
134 bool verbose =
false);
149 cutReadFilei(
const char* filename,
int** data,
unsigned int* len,
bool verbose =
false);
164 cutReadFileui(
const char* filename,
unsigned int** data,
165 unsigned int* len,
bool verbose =
false);
180 cutReadFileb(
const char* filename,
char** data,
unsigned int* len,
181 bool verbose =
false);
196 cutReadFileub(
const char* filename,
unsigned char** data,
197 unsigned int* len,
bool verbose =
false);
210 cutWriteFilef(
const char* filename,
const float* data,
unsigned int len,
211 const float epsilon,
bool verbose =
false);
224 cutWriteFiled(
const char* filename,
const float* data,
unsigned int len,
225 const double epsilon,
bool verbose =
false);
236 cutWriteFilei(
const char* filename,
const int* data,
unsigned int len,
237 bool verbose =
false);
248 cutWriteFileui(
const char* filename,
const unsigned int* data,
249 unsigned int len,
bool verbose =
false);
260 cutWriteFileb(
const char* filename,
const char* data,
unsigned int len,
261 bool verbose =
false);
272 cutWriteFileub(
const char* filename,
const unsigned char* data,
273 unsigned int len,
bool verbose =
false);
288 cutLoadPGMub(
const char* file,
unsigned char** data,
289 unsigned int *w,
unsigned int *h);
301 cutLoadPPMub(
const char* file,
unsigned char** data,
302 unsigned int *w,
unsigned int *h);
315 cutLoadPPM4ub(
const char* file,
unsigned char** data,
316 unsigned int *w,
unsigned int *h);
331 cutLoadPGMi(
const char* file,
unsigned int** data,
332 unsigned int* w,
unsigned int* h);
347 cutLoadPGMs(
const char* file,
unsigned short** data,
348 unsigned int* w,
unsigned int* h);
362 cutLoadPGMf(
const char* file,
float** data,
363 unsigned int* w,
unsigned int* h);
374 cutSavePGMub(
const char* file,
unsigned char* data,
375 unsigned int w,
unsigned int h);
386 cutSavePPMub(
const char* file,
unsigned char *data,
387 unsigned int w,
unsigned int h);
399 cutSavePPM4ub(
const char* file,
unsigned char *data,
400 unsigned int w,
unsigned int h);
411 cutSavePGMi(
const char* file,
unsigned int* data,
412 unsigned int w,
unsigned int h);
423 cutSavePGMs(
const char* file,
unsigned short* data,
424 unsigned int w,
unsigned int h);
435 cutSavePGMf(
const char* file,
float* data,
436 unsigned int w,
unsigned int h);
456 cutCheckCmdLineFlag(
const int argc,
const char** argv,
457 const char* flag_name);
470 cutGetCmdLineArgumenti(
const int argc,
const char** argv,
471 const char* arg_name,
int* val);
484 cutGetCmdLineArgumentf(
const int argc,
const char** argv,
485 const char* arg_name,
float* val);
498 cutGetCmdLineArgumentstr(
const int argc,
const char** argv,
499 const char* arg_name,
char** val);
513 cutGetCmdLineArgumentListstr(
const int argc,
const char** argv,
514 const char* arg_name,
char** val,
527 cutCheckCondition(
int val,
const char* file,
const int line);
539 cutComparef(
const float* reference,
const float* data,
540 const unsigned int len);
552 cutComparei(
const int* reference,
const int* data,
553 const unsigned int len );
566 cutCompareuit(
const unsigned int* reference,
const unsigned int* data,
567 const unsigned int len,
const float epsilon,
const float threshold );
579 cutCompareub(
const unsigned char* reference,
const unsigned char* data,
580 const unsigned int len );
594 cutCompareubt(
const unsigned char* reference,
const unsigned char* data,
595 const unsigned int len,
const float epsilon,
const float threshold );
608 cutCompareube(
const unsigned char* reference,
const unsigned char* data,
609 const unsigned int len,
const float epsilon );
622 cutComparefe(
const float* reference,
const float* data,
623 const unsigned int len,
const float epsilon );
637 cutComparefet(
const float* reference,
const float* data,
638 const unsigned int len,
const float epsilon,
const float threshold );
652 cutCompareL2fe(
const float* reference,
const float* data,
653 const unsigned int len,
const float epsilon );
667 cutComparePPM(
const char *src_file,
const char *ref_file,
const float epsilon,
const float threshold,
bool verboseErrors =
false );
680 cutCreateTimer(
unsigned int* name);
689 cutDeleteTimer(
unsigned int name);
697 cutStartTimer(
const unsigned int name);
705 cutStopTimer(
const unsigned int name);
713 cutResetTimer(
const unsigned int name);
722 cutGetTimerValue(
const unsigned int name);
733 cutGetAverageTimerValue(
const unsigned int name);
740 #if __DEVICE_EMULATION__
742 #define CUT_BANK_CHECKER( array, index) \
743 (cutCheckBankAccess( threadIdx.x, threadIdx.y, threadIdx.z, blockDim.x, \
744 blockDim.y, blockDim.z, \
745 __FILE__, __LINE__, #array, index ), \
748 #define CUT_BANK_CHECKER( array, index) array[index]
751 #define CUT_BANK_CHECKER( array, index) array[index]
754# define CU_SAFE_CALL_NO_SYNC( call ) { \
755 CUresult err = call; \
756 if( CUDA_SUCCESS != err) { \
757 fprintf(stderr, "Cuda driver error %x in file '%s' in line %i.\n", \
758 err, __FILE__, __LINE__ ); \
759 exit(EXIT_FAILURE); \
762# define CU_SAFE_CALL( call ) CU_SAFE_CALL_NO_SYNC(call);
764# define CU_SAFE_CTX_SYNC( ) { \
765 CUresult err = cuCtxSynchronize(); \
766 if( CUDA_SUCCESS != err) { \
767 fprintf(stderr, "Cuda driver error %x in file '%s' in line %i.\n", \
768 err, __FILE__, __LINE__ ); \
769 exit(EXIT_FAILURE); \
772# define CUDA_SAFE_CALL_NO_SYNC( call) { \
773 cudaError err = call; \
774 if( cudaSuccess != err) { \
775 fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \
776 __FILE__, __LINE__, cudaGetErrorString( err) ); \
777 exit(EXIT_FAILURE); \
780# define CUDA_SAFE_CALL( call) CUDA_SAFE_CALL_NO_SYNC(call); \
782# define CUDA_SAFE_THREAD_SYNC( ) { \
783 cudaError err = cudaDeviceSynchronize(); \
784 if ( cudaSuccess != err) { \
785 fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \
786 __FILE__, __LINE__, cudaGetErrorString( err) ); \
789# define CUFFT_SAFE_CALL( call) { \
790 cufftResult err = call; \
791 if( CUFFT_SUCCESS != err) { \
792 fprintf(stderr, "CUFFT error in file '%s' in line %i.\n", \
793 __FILE__, __LINE__); \
794 exit(EXIT_FAILURE); \
797# define CUT_SAFE_CALL( call) \
798 if( CUTTrue != call) { \
799 fprintf(stderr, "Cut error in file '%s' in line %i.\n", \
800 __FILE__, __LINE__); \
801 exit(EXIT_FAILURE); \
806# define CUT_CHECK_ERROR(errorMessage) { \
807 cudaError_t err = cudaGetLastError(); \
808 if( cudaSuccess != err) { \
809 fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
810 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
811 exit(EXIT_FAILURE); \
813 err = cudaDeviceSynchronize(); \
814 if( cudaSuccess != err) { \
815 fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
816 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
817 exit(EXIT_FAILURE); \
821# define CUT_CHECK_ERROR(errorMessage) { \
822 cudaError_t err = cudaGetLastError(); \
823 if( cudaSuccess != err) { \
824 fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
825 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
826 exit(EXIT_FAILURE); \
832# define CUT_SAFE_MALLOC( mallocCall ) { \
833 if( !(mallocCall)) { \
834 fprintf(stderr, "Host malloc failure in file '%s' in line %i\n", \
835 __FILE__, __LINE__); \
836 exit(EXIT_FAILURE); \
840# define CUT_CONDITION( val) \
841 if( CUTFalse == cutCheckCondition( val, __FILE__, __LINE__)) { \
842 exit(EXIT_FAILURE); \
845#if __DEVICE_EMULATION__
847# define CUT_DEVICE_INIT(ARGC, ARGV)
851# define CUT_DEVICE_INIT(ARGC, ARGV) { \
853 CUDA_SAFE_CALL_NO_SYNC(cudaGetDeviceCount(&deviceCount)); \
854 if (deviceCount == 0) { \
855 fprintf(stderr, "cutil error: no devices supporting CUDA.\n"); \
856 exit(EXIT_FAILURE); \
859 cutGetCmdLineArgumenti(ARGC, (const char **) ARGV, "device", &dev); \
860 if (dev < 0) dev = 0; \
861 if (dev > deviceCount-1) dev = deviceCount - 1; \
862 cudaDeviceProp deviceProp; \
863 CUDA_SAFE_CALL_NO_SYNC(cudaGetDeviceProperties(&deviceProp, dev)); \
864 if (deviceProp.major < 1) { \
865 fprintf(stderr, "cutil error: device does not support CUDA.\n"); \
866 exit(EXIT_FAILURE); \
868 if (cutCheckCmdLineFlag(ARGC, (const char **) ARGV, "quiet") == CUTFalse) \
869 fprintf(stderr, "Using device %d: %s\n", dev, deviceProp.name); \
870 CUDA_SAFE_CALL(cudaSetDevice(dev)); \
875# define CUDA_CHECK_CTX_LOST(errorMessage) { \
876 cudaError_t err = cudaGetLastError(); \
877 if( cudaSuccess != err) { \
878 fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
879 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
880 exit(EXIT_FAILURE); \
882 err = cudaDeviceSynchronize(); \
883 if( cudaSuccess != err) { \
884 fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
885 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
886 exit(EXIT_FAILURE); \
890# define CU_CHECK_CTX_LOST(errorMessage) { \
891 cudaError_t err = cudaGetLastError(); \
892 if( CUDA_ERROR_INVALID_CONTEXT != err) { \
893 fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
894 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
895 exit(EXIT_FAILURE); \
897 err = cudaDeviceSynchronize(); \
898 if( cudaSuccess != err) { \
899 fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
900 errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
901 exit(EXIT_FAILURE); \
907# define CUT_DEVICE_INIT_DRV(cuDevice, ARGC, ARGV) { \
909 int deviceCount = 0; \
910 CUresult err = cuInit(0); \
911 if (CUDA_SUCCESS == err) \
912 CU_SAFE_CALL_NO_SYNC(cuDeviceGetCount(&deviceCount)); \
913 if (deviceCount == 0) { \
914 fprintf(stderr, "cutil error: no devices supporting CUDA\n"); \
915 exit(EXIT_FAILURE); \
918 cutGetCmdLineArgumenti(ARGC, (const char **) ARGV, "device", &dev); \
919 if (dev < 0) dev = 0; \
920 if (dev > deviceCount-1) dev = deviceCount - 1; \
921 CU_SAFE_CALL_NO_SYNC(cuDeviceGet(&cuDevice, dev)); \
923 cuDeviceGetName(name, 100, cuDevice); \
924 if (cutCheckCmdLineFlag(ARGC, (const char **) ARGV, "quiet") == CUTFalse) \
925 fprintf(stderr, "Using device %d: %s\n", dev, name); \
928#define CUT_EXIT(argc, argv) \
929 if (!cutCheckCmdLineFlag(argc, (const char**)argv, "noprompt")) { \
930 printf("\nPress ENTER to exit...\n"); \