-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_cc.cpp
49 lines (40 loc) · 1.36 KB
/
check_cc.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
/*
* sample program to check NVIDIA GPU compute capability
*/
#include <stdio.h>
#include <cuda.h>
#include "drvapi_error_string.h"
/* CUDA error check macro */
#define MY_CUDA_CHECK(res, text) \
if ((res) != CUDA_SUCCESS) { \
fprintf(stderr, "%s failed: res = %d->%s\n", (text), (res), getCudaDrvErrorString((res))); \
exit(1); \
}
main()
{
/* initialize CUDA */
CUresult res;
res = cuInit(0);
MY_CUDA_CHECK(res, "cuInit()");
/* check GPU is setted or not */
int device_num;
res = cuDeviceGetCount(&device_num);
MY_CUDA_CHECK(res, "cuDeviceGetCount()");
if (device_num == 0) { // no GPU is detected
fprintf(stderr, "no CUDA capable GPU is detected...\n");
exit(1);
}
printf("%d GPUs are detected\n", device_num);
for (int i=0; i<device_num; i++)
{
/* get device handle of GPU No.i */
CUdevice dev;
res = cuDeviceGet(&dev, i);
MY_CUDA_CHECK(res, "cuDeviceGet()");
/* search compute capability of GPU No.i */
int major=0, minor=0;
res = cuDeviceComputeCapability(&major, &minor, dev);
MY_CUDA_CHECK(res, "cuDeviceComputeCapability()");
printf("GPU[%d] : actual compute capability is : %d%d\n", i, major, minor);
}
}