-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.c
138 lines (114 loc) · 4.88 KB
/
test1.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
#include <CL/cl.h>
#include <stdio.h>
void checkErr(cl_int err, const char *name)
{
if(err != CL_SUCCESS)
{
printf("ERROR: %s(%d)\n", name, err);
exit(EXIT_FAILURE);
}
}
int main(int argc, char **argv)
{
cl_platform_id platform;
cl_uint numPlatforms, numEntries=1;
cl_int errorcode;
//get list of platforms. choose one platform
errorcode = clGetPlatformIDs(numEntries, &platform, &numPlatforms);
checkErr(errorcode, "clGetPlatformIDs");
printf("Number of available OpenCL platforms is %d\n", numPlatforms);
cl_device_id device;
cl_device_type deviceType;
cl_uint numDevices;
//get list of devices that can be used. device type and number can be chosen
//get total number of all OpenCL devices
deviceType = CL_DEVICE_TYPE_ALL;
numEntries = 0;
errorcode = clGetDeviceIDs(platform, deviceType, 0, NULL, &numDevices);
checkErr(errorcode, "clGetDeviceIDs");
printf("Total number of OpenCL devices is %d\n", numDevices);
deviceType = CL_DEVICE_TYPE_CPU;
numEntries = 1;
errorcode = clGetDeviceIDs(platform, deviceType, 0, NULL, &numDevices);
checkErr(errorcode, "clGetDeviceIDs");
printf("Number of CPU devices is %d\n", numDevices);
//get number of GPU devices
deviceType = CL_DEVICE_TYPE_GPU;
errorcode = clGetDeviceIDs(platform, deviceType, 0, NULL, &numDevices);
checkErr(errorcode, "clGetDeviceIDs");
printf("Number of GPU devices is %d\n", numDevices);
//get CPU device info
printf("CPU device info\n");
deviceType = CL_DEVICE_TYPE_CPU;
numEntries = 1;
device = NULL;
errorcode = clGetDeviceIDs(platform, deviceType, numEntries, &device, &numDevices);
checkErr(errorcode, "clGetDeviceIDs");
if(device != NULL)
{
cl_uint info;
size_t actual_return_size;
//get OpenCL device vendor ID
errorcode = clGetDeviceInfo(device, CL_DEVICE_VENDOR_ID, sizeof(info), &info, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Vendor ID: %d\n", info);
//get OpenCL device vendor
char stringinfo[1000];
errorcode = clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(stringinfo), stringinfo, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Vendor: %s\n", stringinfo);
//get OpenCL device name
errorcode = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(stringinfo), stringinfo, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Device name: %s\n", stringinfo);
//get OpenCL device maximum number of compute units
errorcode = clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(info), &info, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Maximum number of compute units: %d\n", info);
//get OpenCL device extensions
errorcode = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, sizeof(stringinfo), stringinfo, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Device OpenCL extensions: %s\n", stringinfo);
}
//get GPU device info
printf("GPU device info\n");
deviceType = CL_DEVICE_TYPE_GPU;
numEntries = 1;
device = NULL;
errorcode = clGetDeviceIDs(platform, deviceType, numEntries, &device, &numDevices);
checkErr(errorcode, "clGetDeviceIDs");
if(device != NULL)
{
cl_uint info;
size_t actual_return_size;
//get OpenCL device vendor ID
errorcode = clGetDeviceInfo(device, CL_DEVICE_VENDOR_ID, sizeof(info), &info, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Vendor ID: %u\n", info);
//get OpenCL device vendor
char stringinfo[1000];
errorcode = clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(stringinfo), stringinfo, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Vendor: %s\n", stringinfo);
//get OpenCL device name
errorcode = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(stringinfo), stringinfo, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Device name: %s\n", stringinfo);
//get OpenCL device maximum number of compute units
errorcode = clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(info), &info, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Maximum number of compute units: %d\n", info);
//get OpenCL device maximum workgroup size
size_t sizeinfo;
errorcode = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(sizeinfo), &sizeinfo, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Maximum workgroup size: %d\n", sizeinfo);
//get OpenCL device extensions
errorcode = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, sizeof(stringinfo), stringinfo, &actual_return_size);
checkErr(errorcode, "clGetDeviceInfo");
printf("Device OpenCL extensions: %s\n", stringinfo);
}
//create context
//cl_context context = clCreateContext(NULL, );
return 0;
}