forked from isaidnocookies/DisplayGPUInfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayGPUInfo.cpp
93 lines (91 loc) · 3.32 KB
/
displayGPUInfo.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
#include <OpenCL/opencl.h>
#include <iostream>
using namespace std;
void PrintDeviceInfo(cl_device_id device)
{
char queryBuffer[1024];
int queryInt;
cl_int clError;
clError = clGetDeviceInfo(device, CL_DEVICE_NAME,
sizeof(queryBuffer),
&queryBuffer, NULL);
printf(" CL_DEVICE_NAME: %s\n", queryBuffer);
queryBuffer[0] = '\0';
clError = clGetDeviceInfo(device, CL_DEVICE_VENDOR,
sizeof(queryBuffer), &queryBuffer,
NULL);
printf(" CL_DEVICE_VENDOR: %s\n", queryBuffer);
queryBuffer[0] = '\0';
clError = clGetDeviceInfo(device, CL_DRIVER_VERSION,
sizeof(queryBuffer), &queryBuffer,
NULL);
printf(" CL_DRIVER_VERSION: %s\n", queryBuffer);
queryBuffer[0] = '\0';
clError = clGetDeviceInfo(device, CL_DEVICE_VERSION,
sizeof(queryBuffer), &queryBuffer,
NULL);
printf(" CL_DEVICE_VERSION: %s\n", queryBuffer);
queryBuffer[0] = '\0';
clError = clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(int), &queryInt, NULL);
printf(" CL_DEVICE_MAX_COMPUTE_UNITS: %d\n", queryInt);
queryBuffer[0] = '\0';
clError = clGetDeviceInfo(device, CL_KERNEL_WORK_GROUP_SIZE,
sizeof(int), &queryInt, NULL);
printf(" CL_KERNEL_WORK_GROUP_SIZE: %d\n", queryInt);
}
int main(void)
{
int lError;
cl_uint lGPUCount = 10;
cl_device_id lDeviceId[10];
lError = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, lGPUCount, lDeviceId, &lGPUCount);
//cout << "lError = " << lError << endl;
for( cl_uint lGPUIndex = 0; lGPUIndex < lGPUCount; lGPUIndex++ )
{
cout << lGPUIndex << " Device Id " << lDeviceId[lGPUIndex] << endl;
{ // New scope.
size_t lResult = 0;
if (CL_SUCCESS == clGetDeviceInfo(lDeviceId[lGPUIndex], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(lResult), &lResult, NULL))
{
cout << " Workgroup size = " << lResult << endl;
}
else
{
cerr << " Unable to retrieve workgroup size!" << endl;
}
}
{ // New scope.
cl_device_type lResult = 0;
if (CL_SUCCESS == clGetDeviceInfo(lDeviceId[lGPUIndex], CL_DEVICE_TYPE, sizeof(lResult), &lResult, NULL))
{
switch (lResult)
{
case CL_DEVICE_TYPE_CPU:
cout << " Device type = CPU (" << lResult << ")" << endl;
break;
case CL_DEVICE_TYPE_GPU:
cout << " Device type = GPU (" << lResult << ")" << endl;
break;
case CL_DEVICE_TYPE_ACCELERATOR:
cout << " Device type = ACCELERATOR (" << lResult << ")" << endl;
break;
case CL_DEVICE_TYPE_DEFAULT:
cout << " Device type = DEFAULT (" << lResult << ")" << endl;
break;
default:
cout << " Device type = UNKNOWN (" << lResult << ")" << endl;
break;
}
PrintDeviceInfo(lDeviceId[lGPUIndex]);
}
else
{
cerr << " Unable to retrieve device type!" << endl;
}
}
cout << endl << endl;
}
cout << endl;
return 0;
}