-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcudacompinit.c
181 lines (119 loc) · 3.87 KB
/
cudacompinit.c
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
179
180
181
/** @file cudacompinit.c
*/
#ifdef HAVE_MAGMA
#include "magma_v2.h"
#include "magma_lapack.h"
#endif
#include "CommandLineInterface/CLIcore.h"
#include "COREMOD_memory/COREMOD_memory.h"
#ifdef HAVE_CUDA
extern int cuda_deviceCount;
// ==========================================
// Forward declaration(s)
// ==========================================
int CUDACOMP_init();
// ==========================================
// Command line interface wrapper function(s)
// ==========================================
static errno_t delete_image_ID__cli()
{
long i = 1;
printf("%ld : %d\n", i, data.cmdargtoken[i].type);
while(data.cmdargtoken[i].type != 0)
{
if(data.cmdargtoken[i].type == 4)
{
delete_image_ID(data.cmdargtoken[i].val.string, DELETE_IMAGE_ERRMODE_WARNING);
}
else
{
printf("Image %s does not exist\n", data.cmdargtoken[i].val.string);
}
i++;
}
return CLICMD_SUCCESS;
}
// ==========================================
// Register CLI command(s)
// ==========================================
errno_t cudacompinit_addCLIcmd()
{
RegisterCLIcommand(
"cudacompinit",
__FILE__,
CUDACOMP_init,
"init CUDA comp",
"no argument",
"cudacompinit",
"int CUDACOMP_init()"
);
return RETURN_SUCCESS;
}
/**
* @brief Initialize CUDA and MAGMA
*
* Finds CUDA devices
* Initializes CUDA and MAGMA libraries
*
* @return number of CUDA devices found
*
*/
int CUDACOMP_init()
{
int device;
struct cudaDeviceProp deviceProp;
cudaGetDeviceCount(&cuda_deviceCount);
printf("%d devices found\n", cuda_deviceCount);
printf("\n");
for(device = 0; device < cuda_deviceCount; ++device)
{
cudaGetDeviceProperties(&deviceProp, device);
printf("Device %d [ %20s ] has compute capability %d.%d.\n",
device, deviceProp.name, deviceProp.major, deviceProp.minor);
printf(" Total amount of global memory: %.0f MBytes (%llu bytes)\n",
(float)deviceProp.totalGlobalMem / 1048576.0f,
(unsigned long long) deviceProp.totalGlobalMem);
printf(" (%2d) Multiprocessors\n", deviceProp.multiProcessorCount);
printf(" GPU Clock rate: %.0f MHz (%0.2f GHz)\n",
deviceProp.clockRate * 1e-3f, deviceProp.clockRate * 1e-6f);
printf("\n");
#ifdef HAVE_MAGMA
printf("Using MAGMA library\n");
magma_print_environment();
#endif
printf("\n");
}
return((int) cuda_deviceCount);
}
void *GPU_scanDevices(void *deviceCount_void_ptr)
{
int *devcnt_ptr = (int *) deviceCount_void_ptr;
int device;
struct cudaDeviceProp deviceProp;
printf("Scanning for GPU devices ...\n");
fflush(stdout);
cudaGetDeviceCount(&cuda_deviceCount);
printf("%d devices found\n", cuda_deviceCount);
fflush(stdout);
printf("\n");
for(device = 0; device < cuda_deviceCount; ++device)
{
cudaGetDeviceProperties(&deviceProp, device);
printf("Device %d [ %20s ] has compute capability %d.%d.\n",
device, deviceProp.name, deviceProp.major, deviceProp.minor);
printf(" Total amount of global memory: %.0f MBytes (%llu bytes)\n",
(float)deviceProp.totalGlobalMem / 1048576.0f,
(unsigned long long) deviceProp.totalGlobalMem);
printf(" (%2d) Multiprocessors\n",
deviceProp.multiProcessorCount);
printf(" GPU Clock rate: %.0f MHz (%0.2f GHz)\n",
deviceProp.clockRate * 1e-3f,
deviceProp.clockRate * 1e-6f);
printf("\n");
}
printf("Done scanning for GPU devices\n");
fflush(stdout);
*devcnt_ptr = cuda_deviceCount;
return NULL;
}
#endif