-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cu
69 lines (61 loc) · 1.77 KB
/
main.cu
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
#include "matrix_utils.cpp"
#include "matrix_utils.cu"
#include <iostream>
#include <cuda_runtime.h>
#define RANDOM 1
#define FROM_FILE 2
#define WITH_CPU 1
#define WITH_GPU 2
int main(int argc, char **argv) {
size_t n = 0;
int get_mode = RANDOM;
int exec_mode = WITH_GPU;
string in_path;
string out_path;
// arg parsing
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'n':
n = strtoul(argv[++i], nullptr, 0);
break;
case 'r':
get_mode = RANDOM;
break;
case 'f':
get_mode = FROM_FILE;
in_path = argv[++i];
break;
case 'g':
exec_mode = WITH_GPU;
break;
case 'c':
exec_mode = WITH_CPU;
break;
case 'o':
out_path = argv[++i];
break;
default:
cout << "invalid arguments";
}
}
}
double **matrix = mxalloc(n, n, malloc);
double **inverse = mxalloc(n, n, malloc);
float runtime = 0.0;
if (get_mode == RANDOM)
fill_random(n, matrix, pair<float, float>(-1e6, 1e6));
else
get_from_file(n, matrix, in_path);
if (exec_mode == WITH_GPU)
gpu_inverse(matrix, n, inverse, &runtime);
else
cpu_inverse(matrix, n, inverse, &runtime);
if (!out_path.empty())
save_to_file(n, inverse, out_path);
cout << "calculation time: " << runtime << "(ms)";
mxfree(matrix, n, free);
mxfree(inverse, n, free);
cudaDeviceReset();
return 0;
}