Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / BilatTools_Cuda / src / core / cudatools / cpp / cudaTools.cpp
1 #include <iostream>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string>
5
6 #include "cudaTools.h"
7 #include "StringTools.h"
8
9 using std::string;
10 using std::cout;
11 using std::cerr;
12 using std::endl;
13
14 /*----------------------------------------------------------------------*\
15 |* Declaration *|
16 \*---------------------------------------------------------------------*/
17
18 /*--------------------------------------*\
19 |* Private *|
20 \*-------------------------------------*/
21
22 /*----------------------------------------------------------------------*\
23 |* Implementation *|
24 \*---------------------------------------------------------------------*/
25
26 /*--------------------------------------*\
27 |* Public *|
28 \*-------------------------------------*/
29
30 /**
31 * Cuda
32 */
33 void cudaHandleError(cudaError_t error, const char *file, int line)
34 {
35 if (error != cudaSuccess)
36 {
37 cerr << endl << "[CUDA ERROR] : " << cudaGetErrorString(error) << " in " << file << " at ligne " << line << endl;
38 exit (EXIT_FAILURE);
39 }
40 }
41
42 /**
43 * Curand
44 */
45 void cudaHandleError(curandStatus_t statut, const char *file, int line)
46 {
47 if (statut != CURAND_STATUS_SUCCESS)
48 {
49 cerr << endl << "[CURAND ERROR] : " << statut << " in " << file << " at ligne " << line << endl;
50 exit (EXIT_FAILURE);
51 }
52 }
53
54 /**
55 * Cublas
56 */
57 void cudaHandleError(cublasStatus_t cublasStatus, const char *file, int line)
58 {
59
60 if (cublasStatus != CUBLAS_STATUS_SUCCESS)
61 {
62 switch (cublasStatus)
63 {
64 case CUBLAS_STATUS_INVALID_VALUE:
65 cerr << endl << "[CUBLAS ERROR] : CUBLAS_STATUS_INVALID_VALUE " << " in " << file << " at line " << line << endl;
66 break;
67 case CUBLAS_STATUS_NOT_INITIALIZED:
68 cerr << endl << "[CUBLAS ERROR] : CUBLAS_STATUS_NOT_INITIALIZED " << " in " << file << " at line " << line << endl;
69 break;
70 case CUBLAS_STATUS_INTERNAL_ERROR:
71 cerr << endl << "[CUBLAS ERROR] : CUBLAS_STATUS_INTERNAL_ERROR " << " in " << file << " at line " << line << endl;
72 break;
73 case CUBLAS_STATUS_MAPPING_ERROR:
74 cerr << endl << "[CUBLAS ERROR] : CUBLAS_STATUS_MAPPING_ERROR " << " in " << file << " at line " << line << endl;
75 break;
76
77 case CUBLAS_STATUS_ALLOC_FAILED:
78 cerr << endl << "[CUBLAS ERROR] : CUBLAS_STATUS_ALLOC_FAILED " << " in " << file << " at line " << line << endl;
79 break;
80 case CUBLAS_STATUS_ARCH_MISMATCH:
81 cerr << endl << "[CUBLAS ERROR] : CUBLAS_STATUS_ARCH_MISMATCH" << " in " << file << " at line " << line << endl;
82 break;
83 case CUBLAS_STATUS_EXECUTION_FAILED:
84 cerr << endl << "[CUBLAS ERROR] : CUBLAS_STATUS_EXECUTION_FAILED" << " in " << file << " at line " << line << endl;
85 break;
86 default:
87 cerr << endl << "[CUBLAS ERROR] : Unknown error !" << " in " << file << " at line " << line << endl;
88 break;
89 }
90 exit (EXIT_FAILURE);
91 }
92 }
93
94 /*--------------------------------------*\
95 |* Private *|
96 \*-------------------------------------*/
97
98 /*----------------------------------------------------------------------*\
99 |* End *|
100 \*---------------------------------------------------------------------*/
101