-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmain.cpp
More file actions
290 lines (254 loc) · 10.8 KB
/
main.cpp
File metadata and controls
290 lines (254 loc) · 10.8 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
// Copyright (c) 2019-2026 Ben Ashbaugh
//
// SPDX-License-Identifier: MIT
*/
#include <stdio.h>
#include <vector>
#include <popl/popl.hpp>
#include <CL/opencl.hpp>
#if defined(CL_VERSION_3_0)
static void PrintPlatformInfoSummary(
cl::Platform platform )
{
printf("\tName: %s\n", platform.getInfo<CL_PLATFORM_NAME>().c_str() );
printf("\tVendor: %s\n", platform.getInfo<CL_PLATFORM_VENDOR>().c_str() );
printf("\tPlatform Version: %s\n", platform.getInfo<CL_PLATFORM_VERSION>().c_str() );
// Use the query for the platform numeric version as a test for
// OpenCL 3.0 support. If this query fails then this probably
// isn't an OpenCL 3.0 platform:
cl_int test = CL_SUCCESS;
cl_version platformVersion =
platform.getInfo<CL_PLATFORM_NUMERIC_VERSION>(&test);
if( test == CL_SUCCESS )
{
printf("\tPlatform Numeric Version: %u.%u.%u\n",
CL_VERSION_MAJOR(platformVersion),
CL_VERSION_MINOR(platformVersion),
CL_VERSION_PATCH(platformVersion));
}
else
{
printf("Query for CL_PLATFORM_NUMERIC_VERSION failed.\n");
return;
}
std::vector<cl_name_version> extensions =
platform.getInfo<CL_PLATFORM_EXTENSIONS_WITH_VERSION>();
for( auto& extension : extensions )
{
printf("\t\tExtension (version): %s (%u.%u.%u)\n",
extension.name,
CL_VERSION_MAJOR(extension.version),
CL_VERSION_MINOR(extension.version),
CL_VERSION_PATCH(extension.version) );
}
}
static void PrintDeviceType(
const char* label,
cl_device_type type )
{
printf("%s%s%s%s%s%s\n",
label,
( type & CL_DEVICE_TYPE_DEFAULT ) ? "DEFAULT " : "",
( type & CL_DEVICE_TYPE_CPU ) ? "CPU " : "",
( type & CL_DEVICE_TYPE_GPU ) ? "GPU " : "",
( type & CL_DEVICE_TYPE_ACCELERATOR ) ? "ACCELERATOR " : "",
( type & CL_DEVICE_TYPE_CUSTOM ) ? "CUSTOM " : "");
}
static void PrintDeviceAtomicCapabilities(
const char* label,
cl_device_atomic_capabilities caps )
{
printf("%s: %s%s%s%s%s%s%s\n",
label,
( caps & CL_DEVICE_ATOMIC_ORDER_RELAXED ) ? "\n\t\tCL_DEVICE_ATOMIC_ORDER_RELAXED" : "",
( caps & CL_DEVICE_ATOMIC_ORDER_ACQ_REL ) ? "\n\t\tCL_DEVICE_ATOMIC_ORDER_ACQ_REL" : "",
( caps & CL_DEVICE_ATOMIC_ORDER_SEQ_CST ) ? "\n\t\tCL_DEVICE_ATOMIC_ORDER_SEQ_CST" : "",
( caps & CL_DEVICE_ATOMIC_SCOPE_WORK_ITEM ) ? "\n\t\tCL_DEVICE_ATOMIC_SCOPE_WORK_ITEM" : "",
( caps & CL_DEVICE_ATOMIC_SCOPE_WORK_GROUP ) ? "\n\t\tCL_DEVICE_ATOMIC_SCOPE_WORK_GROUP" : "",
( caps & CL_DEVICE_ATOMIC_SCOPE_DEVICE ) ? "\n\t\tCL_DEVICE_ATOMIC_SCOPE_DEVICE" : "",
( caps & CL_DEVICE_ATOMIC_SCOPE_ALL_DEVICES ) ? "\n\t\tCL_DEVICE_ATOMIC_SCOPE_ALL_DEVICES" : "");
}
#if defined(CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES)
static void PrintDeviceDeviceEnqueueCapabilities(
const char* label,
cl_device_device_enqueue_capabilities caps )
{
printf("%s: %s%s\n",
label,
( caps & CL_DEVICE_QUEUE_SUPPORTED ) ? "\n\t\tCL_DEVICE_QUEUE_SUPPORTED" : "",
( caps & CL_DEVICE_QUEUE_REPLACEABLE_DEFAULT) ? "\n\t\tCL_DEVICE_QUEUE_REPLACEABLE_DEFAULT" : "");
}
#endif
static void PrintDeviceInfoSummary(
const std::vector<cl::Device>& devices )
{
size_t i = 0;
for( i = 0; i < devices.size(); i++ )
{
printf("Device[%d]:\n", (int)i );
cl_device_type deviceType = devices[i].getInfo<CL_DEVICE_TYPE>();
PrintDeviceType("\tType: ", deviceType);
printf("\tName: %s\n", devices[i].getInfo<CL_DEVICE_NAME>().c_str() );
printf("\tVendor: %s\n", devices[i].getInfo<CL_DEVICE_VENDOR>().c_str() );
printf("\tDevice Version: %s\n", devices[i].getInfo<CL_DEVICE_VERSION>().c_str() );
printf("\tOpenCL C Version: %s\n", devices[i].getInfo<CL_DEVICE_OPENCL_C_VERSION>().c_str() );
printf("\tDriver Version: %s\n", devices[i].getInfo<CL_DRIVER_VERSION>().c_str() );
// Use the query for the device numeric version as a test for
// OpenCL 3.0 support. If this query fails then this probably
// isn't an OpenCL 3.0 device:
cl_int test = CL_SUCCESS;
cl_version deviceVersion =
devices[i].getInfo<CL_DEVICE_NUMERIC_VERSION>(&test);
if( test == CL_SUCCESS )
{
printf("\tDevice Numeric Version: %u.%u.%u\n",
CL_VERSION_MAJOR(deviceVersion),
CL_VERSION_MINOR(deviceVersion),
CL_VERSION_PATCH(deviceVersion));
}
else
{
printf("Query for CL_DEVICE_NUMERIC_VERSION failed.\n");
continue;
}
std::vector<cl_name_version> clcVersions =
devices[i].getInfo<CL_DEVICE_OPENCL_C_ALL_VERSIONS>();
for( auto& clcVersion : clcVersions )
{
printf("\t\tOpenCL C (version): %s (%u.%u.%u)\n",
clcVersion.name,
CL_VERSION_MAJOR(clcVersion.version),
CL_VERSION_MINOR(clcVersion.version),
CL_VERSION_PATCH(clcVersion.version));
}
std::vector<cl_name_version> clcFeatures =
devices[i].getInfo<CL_DEVICE_OPENCL_C_FEATURES>();
for( auto& clcFeature : clcFeatures )
{
printf("\t\tOpenCL C Feature (version): %s (%u.%u.%u)\n",
clcFeature.name,
CL_VERSION_MAJOR(clcFeature.version),
CL_VERSION_MINOR(clcFeature.version),
CL_VERSION_PATCH(clcFeature.version));
}
std::vector<cl_name_version> extensions =
devices[i].getInfo<CL_DEVICE_EXTENSIONS_WITH_VERSION>();
for( auto& extension : extensions )
{
printf("\t\tExtension (version): %s (%u.%u.%u)\n",
extension.name,
CL_VERSION_MAJOR(extension.version),
CL_VERSION_MINOR(extension.version),
CL_VERSION_PATCH(extension.version) );
}
std::vector<cl_name_version> ils =
devices[i].getInfo<CL_DEVICE_ILS_WITH_VERSION>();
for( auto& il : ils )
{
printf("\t\tIL (version): %s (%u.%u.%u)\n",
il.name,
CL_VERSION_MAJOR(il.version),
CL_VERSION_MINOR(il.version),
CL_VERSION_PATCH(il.version) );
}
std::vector<cl_name_version> builtInKernels =
devices[i].getInfo<CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION>();
for( auto& builtInFunction : builtInKernels )
{
printf("\t\tBuilt-in Function (version): %s (%u.%u.%u)\n",
builtInFunction.name,
CL_VERSION_MAJOR(builtInFunction.version),
CL_VERSION_MINOR(builtInFunction.version),
CL_VERSION_PATCH(builtInFunction.version) );
}
cl_device_atomic_capabilities deviceAtomicMemoryCapabilities =
devices[i].getInfo<CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES>();
PrintDeviceAtomicCapabilities("\tAtomic Memory Capabilities", deviceAtomicMemoryCapabilities);
cl_device_atomic_capabilities deviceAtomicFenceCapabilities =
devices[i].getInfo<CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES>();
PrintDeviceAtomicCapabilities("\tAtomic Fence Capabilities", deviceAtomicFenceCapabilities);
size_t devicePreferredWorkGroupSizeMultiple =
devices[i].getInfo<CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE>();
cl_bool deviceNonUniformWorkGroupSupport =
devices[i].getInfo<CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT>();
cl_bool deviceWorkGroupCollectiveFunctionsSupport =
devices[i].getInfo<CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT>();
cl_bool deviceGenericAddressSpaceSupport =
devices[i].getInfo<CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT>();
// This is an older query that should eventually be removed.
// It was replaced by CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES.
#if defined(CL_DEVICE_DEVICE_ENQUEUE_SUPPORT)
cl_bool deviceDeviceEnqueueSupport =
devices[i].getInfo<CL_DEVICE_DEVICE_ENQUEUE_SUPPORT>();
#endif
// This is the newer query.
// The ifdefs are only needed until this enum is in the official headers.
#if defined(CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES)
cl_device_device_enqueue_capabilities deviceDeviceEnqueueCapabilities =
devices[i].getInfo<CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES>();
#endif
cl_bool devicePipeSupport =
devices[i].getInfo<CL_DEVICE_PIPE_SUPPORT>();
printf("\tPreferred Work Group Size Multiple: %u\n",
(cl_uint)devicePreferredWorkGroupSizeMultiple);
printf("\tNon-Uniform Work Group Support: %s\n",
deviceNonUniformWorkGroupSupport ? "CL_TRUE" : "CL_FALSE" );
printf("\tWork Group Collective Functions Support: %s\n",
deviceWorkGroupCollectiveFunctionsSupport ? "CL_TRUE" : "CL_FALSE" );
printf("\tGeneric Address Space Support: %s\n",
deviceGenericAddressSpaceSupport ? "CL_TRUE" : "CL_FALSE" );
#if defined(CL_DEVICE_DEVICE_ENQUEUE_SUPPORT)
printf("\tDevice Enqueue Support: %s\n",
deviceDeviceEnqueueSupport ? "CL_TRUE" : "CL_FALSE" );
#endif
#if defined(CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES)
PrintDeviceDeviceEnqueueCapabilities("\tDevice Enqueue Capabilities",
deviceDeviceEnqueueCapabilities);
#endif
printf("\tPipe Support: %s\n",
devicePipeSupport ? "CL_TRUE" : "CL_FALSE" );
}
}
int main(
int argc,
char** argv )
{
{
popl::OptionParser op("Supported Options");
bool printUsage = false;
try {
op.parse(argc, argv);
} catch (std::exception& e) {
fprintf(stderr, "Error: %s\n\n", e.what());
printUsage = true;
}
if (printUsage || !op.unknown_options().empty() || !op.non_option_args().empty()) {
fprintf(stderr,
"Usage: newqueriespp [options]\n"
"%s", op.help().c_str());
return -1;
}
}
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
for( auto& platform : platforms )
{
printf( "Platform:\n" );
PrintPlatformInfoSummary( platform );
std::vector<cl::Device> devices;
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
PrintDeviceInfoSummary( devices );
printf( "\n" );
}
printf( "Done.\n" );
return 0;
}
#else
#pragma message("newqueriespp: OpenCL 3.0 not found. Please update your OpenCL headers.")
int main()
{
printf("newqueriespp: OpenCL 3.0 not found. Please update your OpenCL headers.\n");
return 0;
};
#endif