forked from HLRA-JHPCN/comm_bench
-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkgpu.cu
77 lines (72 loc) · 2.1 KB
/
checkgpu.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
70
71
72
73
74
75
76
// -*- c++ -*-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cuda.h>
void initDevice(int argc, char **argv)
{
cudaError_t ret;
int devicenum = -1;
int i;
for(i=1; i<argc; i++){
if(strncmp(argv[i], "-devicenum", 10)==0){
devicenum = atoi(argv[++i]);
printf("devicenum = %d\n", devicenum);
}
}
//cudaSetDeviceFlags(cudaDeviceMapHost);
if(devicenum==-1){
int nMaxDevices=-1;
int nDevice=-1;
int nMajor=-1, nMinor=-1;
cudaDeviceProp deviceProp;
ret = cudaGetDeviceCount(&nMaxDevices);
if(ret!=cudaSuccess){
printf("cudaGetDeviceCount failed, exit\n");
exit(-1);
}
printf("%d device(s) found\n", nMaxDevices);
for(i=0; i<nMaxDevices; i++){
cudaGetDeviceProperties(&deviceProp, i);
printf("GPU %d: %s, has %d processors\n", i, deviceProp.name, deviceProp.multiProcessorCount);
if(deviceProp.major > nMajor){
nDevice=i;
nMajor = deviceProp.major;
nMinor = deviceProp.minor;
}else if(deviceProp.major == nMajor){
if(deviceProp.minor > nMinor){
nDevice=i;
nMajor = deviceProp.major;
nMinor = deviceProp.minor;
}
}
}
cudaGetDeviceProperties(&deviceProp, nDevice);
printf("use %d: %s, has %d processors\n", nDevice, deviceProp.name, deviceProp.multiProcessorCount);
cudaSetDevice(nDevice);
}else{
int nMaxDevices=-1;
int nDevice=devicenum;
cudaDeviceProp deviceProp;
ret = cudaGetDeviceCount(&nMaxDevices);
if(ret!=cudaSuccess){
printf("cudaGetDeviceCount failed, exit\n");
exit(-1);
}
printf("%d device(s) found\n", nMaxDevices);
for(i=0; i<nMaxDevices; i++){
cudaGetDeviceProperties(&deviceProp, i);
printf("GPU %d: %s, has %d processors\n", i, deviceProp.name, deviceProp.multiProcessorCount);
}
cudaGetDeviceProperties(&deviceProp, nDevice);
printf("use %d: %s, has %d processors\n", nDevice, deviceProp.name, deviceProp.multiProcessorCount);
cudaSetDevice(nDevice);
}
cudaDeviceReset();
printf("initDevice: done\n"); fflush(stdout);
}
int main(int argc, char **argv)
{
initDevice(argc, argv);
return 0;
}