-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathDeviceInfo.c
More file actions
142 lines (119 loc) · 5.38 KB
/
DeviceInfo.c
File metadata and controls
142 lines (119 loc) · 5.38 KB
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
/*
* Display Device Information
*
* Script to print out some information about the OpenCL devices
* and platforms available on your system
*
* History: C++ version written by Tom Deakin, 2012
* Ported to C by Tom Deakin, July 2013
* Updated by Tom Deakin, October 2014
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#include <unistd.h>
#else
#include <CL/cl.h>
#endif
#include "err_code.h"
int main(void)
{
cl_int err;
// Find the number of OpenCL platforms
cl_uint num_platforms;
err = clGetPlatformIDs(0, NULL, &num_platforms);
checkError(err, "Finding platforms");
if (num_platforms == 0)
{
printf("Found 0 platforms!\n");
return EXIT_FAILURE;
}
// Create a list of platform IDs
cl_platform_id *platform = malloc(num_platforms * sizeof(cl_platform_id));
err = clGetPlatformIDs(num_platforms, platform, NULL);
checkError(err, "Getting platforms");
printf("\nNumber of OpenCL platforms: %d\n", num_platforms);
printf("\n-------------------------\n");
// Investigate each platform
for (int i = 0; i < num_platforms; i++)
{
cl_char string[10240] = {0};
// Print out the platform name
err = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, sizeof(string), &string, NULL);
checkError(err, "Getting platform name");
printf("Platform: %s\n", string);
// Print out the platform vendor
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VENDOR, sizeof(string), &string, NULL);
checkError(err, "Getting platform vendor");
printf("Vendor: %s\n", string);
// Print out the platform OpenCL version
err = clGetPlatformInfo(platform[i], CL_PLATFORM_VERSION, sizeof(string), &string, NULL);
checkError(err, "Getting platform OpenCL version");
printf("Version: %s\n", string);
// Count the number of devices in the platform
cl_uint num_devices;
err = clGetDeviceIDs(platform[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
checkError(err, "Finding devices");
// Get the device IDs
cl_device_id *device = malloc(num_devices * sizeof(cl_device_id));
err = clGetDeviceIDs(platform[i], CL_DEVICE_TYPE_ALL, num_devices, device, NULL);
checkError(err, "Getting devices");
printf("Number of devices: %d\n", num_devices);
// Investigate each device
for (int j = 0; j < num_devices; j++)
{
printf("\t-------------------------\n");
// Get device name
err = clGetDeviceInfo(device[j], CL_DEVICE_NAME, sizeof(string), &string, NULL);
checkError(err, "Getting device name");
printf("\t\tName: %s\n", string);
// Get device OpenCL version
err = clGetDeviceInfo(device[j], CL_DEVICE_OPENCL_C_VERSION, sizeof(string), &string, NULL);
checkError(err, "Getting device OpenCL C version");
printf("\t\tVersion: %s\n", string);
// Get Max. Compute units
cl_uint num;
err = clGetDeviceInfo(device[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &num, NULL);
checkError(err, "Getting device max compute units");
printf("\t\tMax. Compute Units: %d\n", num);
// Get local memory size
cl_ulong mem_size;
err = clGetDeviceInfo(device[j], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(cl_ulong), &mem_size, NULL);
checkError(err, "Getting device local memory size");
printf("\t\tLocal Memory Size: %llu KB\n", mem_size/1024);
// Get global memory size
err = clGetDeviceInfo(device[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), &mem_size, NULL);
checkError(err, "Getting device global memory size");
printf("\t\tGlobal Memory Size: %llu MB\n", mem_size/(1024*1024));
// Get maximum buffer alloc. size
err = clGetDeviceInfo(device[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(cl_ulong), &mem_size, NULL);
checkError(err, "Getting device max allocation size");
printf("\t\tMax Alloc Size: %llu MB\n", mem_size/(1024*1024));
// Get work-group size information
size_t size;
err = clGetDeviceInfo(device[j], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &size, NULL);
checkError(err, "Getting device max work-group size");
printf("\t\tMax Work-group Total Size: %ld\n", size);
// Find the maximum dimensions of the work-groups
err = clGetDeviceInfo(device[j], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), &num, NULL);
checkError(err, "Getting device max work-item dims");
// Get the max. dimensions of the work-groups
size_t *dims = malloc(num * sizeof(size_t));
err = clGetDeviceInfo(device[j], CL_DEVICE_MAX_WORK_ITEM_SIZES, num * sizeof(size_t), dims, NULL);
checkError(err, "Getting device max work-item sizes");
printf("\t\tMax Work-group Dims: ( ");
for (size_t k = 0; k < num; k++)
{
printf("%ld ", dims[k]);
}
free(dims);
printf(")\n");
printf("\t-------------------------\n");
}
free(device);
printf("\n-------------------------\n");
}
free(platform);
return EXIT_SUCCESS;
}