-
Notifications
You must be signed in to change notification settings - Fork 0
/
TESTcheckCudaErrors.cpp
executable file
·178 lines (153 loc) · 5.39 KB
/
TESTcheckCudaErrors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright 2019 André Hodapp
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <builtin_types.h> // z.B. für dim3
// C++ Headers
#include <string>
#include <vector>
#include <iostream>
#include "checkCudaErrors.hpp"
#include <nvrtc.h>
void testNvrtcResultNeu() {
nvrtcResult result = NVRTC_ERROR_INVALID_PROGRAM;
char *r = (char *) nvrtcGetErrorString(result);
//handle with nvtrtcGetErrorString
printf("With nvrtcGetErrorString you can print out the following string:\n%s\n\n", r);
printf("this is my new function, which returns a exception:\n");
//handle with my function
try {
checkNvrtcResultError(result);
} catch (nvrtcResultException &e) {
switch(e.type){
case NVRTC_ERROR_INVALID_PROGRAM:
std::cout << "Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
case (nvrtcResult) 1 : // NVRTC_ERROR_OUT_OF_MEMORY
std::cout << "Wrong Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
default:
std::cout << "Not Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
}
} catch (nvidiaException& e) {
std::cout << "almost correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
}catch (std::exception &e) {
// Other errors
std::cout << "anderer Error\n";
std::cout << e.what() << std::endl;
}
}
void testCudaResultNeu() {
printf("ha\n");
CUresult result = CUDA_ERROR_DEINITIALIZED;
printf("ha%i\n", (int) result);
const char* name;
cuGetErrorName(result, &name); //method to get the error name from NVIDIA
const char* description;
cuGetErrorString(result, &description); //method to get the error description from NVIDIA
printf("With cuGetErrorName you can print out the following string:\n%s\n\n", name);
printf("With cuGetErrorString you can print out the following string:\n%s\n\n", description);
printf("this is my new function, which returns a exception:\n");
//handle with my function
try {
checkCUresultError(result);
} catch (CUresultException &e) {
switch(e.type){
case CUDA_ERROR_DEINITIALIZED:
std::cout << "Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
default:
std::cout << "Not Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
}
}catch (nvidiaException &e) {
std::cout << "almost correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
}catch (std::exception &e) {
// Other errors
std::cout << "anderer Error\n";
std::cout << e.what() << std::endl;
}
}
void printAllCUresultExceptions();
void ErrorPointerThrow() {
int nBytes = 10;
CUdeviceptr d_A;
try {
checkCUresultError(cuMemAlloc(&d_A, (unsigned int)nBytes));
} catch(CUresultException& e) {
switch(e.type){
case (CUresult)1 : // CUDA_ERROR_INVALID_VALUE
std::cout << "Wrong Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
case CUDA_ERROR_NOT_INITIALIZED:
std::cout << "Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
default:
std::cout << "Not Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
}
} catch(std::exception& e) {
// Other errors
std::cout << "anderer Error\n";
std::cout << e.what() << std::endl;
}
}
void giveColumnsSizeCommandConsole(){
printf("command_line_size=%u\n", Unterfunktionen_checkCudaErrors::askTerminalSize());
}
void testNvrtcResult(){
nvrtcProgram* prog =NULL;
nvrtcResult result = nvrtcDestroyProgram(prog);
char* r =(char*) nvrtcGetErrorString(result);
//handle with nvtrtcGetErrorString
printf("With nvrtcGetErrorString you can print out the following string:\n%s\n\n", r);
printf("this is my new function, which returns a exception:\n");
//handle with my function
try {
checkNvrtcResultError(nvrtcDestroyProgram(prog));
} catch(nvrtcResultException& e) {
switch (e.type) {
case (nvrtcResult)1: // NVRTC_ERROR_OUT_OF_MEMORY
std::cout << "Wrong Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
case NVRTC_ERROR_INVALID_PROGRAM:
std::cout << "Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
default:
std::cout << "Not Correct Exception caught" << std::endl;
std::cout << e.what() << std::endl;
break;
}
} catch(std::exception& e) {
// Other errors
std::cout << "anderer Error\n";
std::cout << e.what() << std::endl;
}
}
void errorWithoutCatch(){
// throw new CUresultException<(CUresult) 1>("hey");
// int nBytes = 10;
CUdeviceptr d_A;
checkCUresultError(cuMemAlloc(&d_A, (unsigned int)10));
}
int main(void) {
// ErrorPointerThrow();
// giveColumnsSizeCommandConsole();
// printAllCUresultExceptions();
// testNvrtcResult();
errorWithoutCatch();
return 0;
}