Blame view

stim/cuda/cudatools/error.h 2.61 KB
2781a48c   David Mayerich   fixed cuBLAS func...
1
2
3
  #ifndef STIM_CUDA_ERROR_H
  #define STIM_CUDA_ERROR_H
  
0174d823   dmayerich   bug fixes and exits
4
5
  #include <stdio.h>
  #include <iostream>
3eb12494   David Mayerich   removed CUDA depe...
6
7
  using namespace std;
  #include "cuda_runtime.h"
6e257ab3   dmayerich   ENVI and colormap...
8
  #include "device_launch_parameters.h"
3eb12494   David Mayerich   removed CUDA depe...
9
  #include "cufft.h"
2781a48c   David Mayerich   fixed cuBLAS func...
10
  #include "cublas_v2.h"
3eb12494   David Mayerich   removed CUDA depe...
11
12
  
  //handle error macro
2781a48c   David Mayerich   fixed cuBLAS func...
13
  static void cuHandleError( cudaError_t err, const char *file,  int line ) {
3eb12494   David Mayerich   removed CUDA depe...
14
     	if (err != cudaSuccess) {
3eb12494   David Mayerich   removed CUDA depe...
15
              printf("%s in %s at line %d\n", cudaGetErrorString( err ),  file, line );
2781a48c   David Mayerich   fixed cuBLAS func...
16
  
3eb12494   David Mayerich   removed CUDA depe...
17
18
     	}
  }
2781a48c   David Mayerich   fixed cuBLAS func...
19
  #define HANDLE_ERROR( err ) (cuHandleError( err, __FILE__, __LINE__ ))
6e257ab3   dmayerich   ENVI and colormap...
20
  
2781a48c   David Mayerich   fixed cuBLAS func...
21
  static void cufftHandleError( cufftResult err, const char*file, int line )
6e257ab3   dmayerich   ENVI and colormap...
22
23
24
25
  {
      if (err != CUFFT_SUCCESS)
      {
          if(err == CUFFT_INVALID_PLAN)
0174d823   dmayerich   bug fixes and exits
26
27
28
29
30
31
32
33
34
35
36
37
38
              cout<<"The plan parameter is not a valid handle."<<endl;
          else if(err == CUFFT_ALLOC_FAILED)
              cout<<"Allocation failed."<<endl;
          else if(err == CUFFT_INVALID_VALUE)
              cout<<"At least one of the parameters idata, odata, and direction is not valid."<<endl;
          else if(err == CUFFT_INTERNAL_ERROR)
              cout<<"An internal driver error was detected."<<endl;
          else if(err == CUFFT_EXEC_FAILED)
              cout<<"CUFFT failed to execute the transform on the GPU."<<endl;
          else if(err == CUFFT_SETUP_FAILED)
              cout<<"The CUFFT library failed to initialize."<<endl;
          else
              cout<<"Unknown error: "<<err<<endl;
6e257ab3   dmayerich   ENVI and colormap...
39
40
  
      }
3eb12494   David Mayerich   removed CUDA depe...
41
  }
2781a48c   David Mayerich   fixed cuBLAS func...
42
  #define CUFFT_HANDLE_ERROR( err ) (cufftHandleError( err, __FILE__, __LINE__ ))
3eb12494   David Mayerich   removed CUDA depe...
43
  
2781a48c   David Mayerich   fixed cuBLAS func...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  static void cublasHandleError( cublasStatus_t err, const char*file, int line ){
  	if(err != CUBLAS_STATUS_SUCCESS){
  		if(err == CUBLAS_STATUS_NOT_INITIALIZED)
  			std::cout<<"CUBLAS_STATUS_NOT_INITIALIZED" <<" in file "<<file<<" line "<<std::endl;
  		else if(err == CUBLAS_STATUS_ALLOC_FAILED)
  			std::cout<<"CUBLAS_STATUS_ALLOC_FAILED" <<" in file "<<file<<" line "<<std::endl;
  		else if(err == CUBLAS_STATUS_INVALID_VALUE)
  			std::cout<<"CUBLAS_STATUS_INVALID_VALUE" <<" in file "<<file<<" line "<<std::endl;
  		else if(err == CUBLAS_STATUS_ARCH_MISMATCH)
  			std::cout<<"CUBLAS_STATUS_ARCH_MISMATCH" <<" in file "<<file<<" line "<<std::endl;
  		else if(err == CUBLAS_STATUS_MAPPING_ERROR)
  			std::cout<<"CUBLAS_STATUS_MAPPING_ERROR" <<" in file "<<file<<" line "<<std::endl;
  		else if(err == CUBLAS_STATUS_EXECUTION_FAILED)
  			std::cout<<"CUBLAS_STATUS_EXECUTION_FAILED" <<" in file "<<file<<" line "<<std::endl;
  		else if(err == CUBLAS_STATUS_INTERNAL_ERROR)
  			std::cout<<"CUBLAS_STATUS_INTERNAL_ERROR" <<" in file "<<file<<" line "<<std::endl;
  		else
  			std::cout<<"Unknown error"<<" in file "<<file<<" line "<<std::endl;
  	}
  }
  #define CUBLAS_HANDLE_ERROR( err ) (cublasHandleError( err, __FILE__, __LINE__ ))
3eb12494   David Mayerich   removed CUDA depe...
65
66
  
  
f1402849   dmayerich   renewed commit
67
  #endif