forked from bashbaug/SimpleOpenCLSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
237 lines (212 loc) · 6.77 KB
/
main.cpp
File metadata and controls
237 lines (212 loc) · 6.77 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
/*
// Copyright (c) 2019-2026 Ben Ashbaugh
//
// SPDX-License-Identifier: MIT
*/
#include <popl/popl.hpp>
#include <CL/opencl.hpp>
#include <algorithm>
#include "util.hpp"
#define CASE_TO_STRING(_e) case _e: return #_e;
const char* mem_object_type_to_string(cl_mem_object_type mem_object_type)
{
switch (mem_object_type) {
CASE_TO_STRING(CL_MEM_OBJECT_BUFFER);
CASE_TO_STRING(CL_MEM_OBJECT_IMAGE2D);
CASE_TO_STRING(CL_MEM_OBJECT_IMAGE3D);
#ifdef CL_VERSION_1_2
CASE_TO_STRING(CL_MEM_OBJECT_IMAGE2D_ARRAY);
CASE_TO_STRING(CL_MEM_OBJECT_IMAGE1D);
CASE_TO_STRING(CL_MEM_OBJECT_IMAGE1D_ARRAY);
CASE_TO_STRING(CL_MEM_OBJECT_IMAGE1D_BUFFER);
#endif
#ifdef CL_VERSION_2_0
CASE_TO_STRING(CL_MEM_OBJECT_PIPE);
#endif
default: return "Unknown cl_mem_object_type";
}
}
const char* mem_flags_to_string(cl_mem_flags mem_flags)
{
switch (mem_flags) {
CASE_TO_STRING(CL_MEM_READ_WRITE);
CASE_TO_STRING(CL_MEM_WRITE_ONLY);
CASE_TO_STRING(CL_MEM_READ_ONLY);
CASE_TO_STRING(CL_MEM_USE_HOST_PTR);
CASE_TO_STRING(CL_MEM_ALLOC_HOST_PTR);
CASE_TO_STRING(CL_MEM_COPY_HOST_PTR);
#ifdef CL_VERSION_1_2
CASE_TO_STRING(CL_MEM_HOST_WRITE_ONLY)
CASE_TO_STRING(CL_MEM_HOST_READ_ONLY);
CASE_TO_STRING(CL_MEM_HOST_NO_ACCESS);
#endif
#ifdef CL_VERSION_2_0
CASE_TO_STRING(CL_MEM_SVM_FINE_GRAIN_BUFFER);
CASE_TO_STRING(CL_MEM_SVM_ATOMICS);
CASE_TO_STRING(CL_MEM_KERNEL_READ_AND_WRITE);
#endif
default: return "Unknown cl_mem_flags";
}
}
const char* channel_order_to_string(cl_channel_order channel_order)
{
switch (channel_order) {
CASE_TO_STRING(CL_R);
CASE_TO_STRING(CL_A);
CASE_TO_STRING(CL_RG);
CASE_TO_STRING(CL_RA);
CASE_TO_STRING(CL_RGB);
CASE_TO_STRING(CL_RGBA);
CASE_TO_STRING(CL_BGRA);
CASE_TO_STRING(CL_ARGB);
CASE_TO_STRING(CL_INTENSITY);
CASE_TO_STRING(CL_LUMINANCE);
#ifdef CL_VERSION_1_1
CASE_TO_STRING(CL_Rx);
CASE_TO_STRING(CL_RGx);
CASE_TO_STRING(CL_RGBx);
#endif
#ifdef CL_VERSION_1_2
CASE_TO_STRING(CL_DEPTH);
CASE_TO_STRING(CL_DEPTH_STENCIL);
#endif
#ifdef CL_VERSION_2_0
CASE_TO_STRING(CL_sRGB);
CASE_TO_STRING(CL_sRGBx);
CASE_TO_STRING(CL_sRGBA);
CASE_TO_STRING(CL_sBGRA);
CASE_TO_STRING(CL_ABGR);
#endif
#ifdef CL_NV21_IMG // cl_img_yuv_image
CASE_TO_STRING(CL_NV21_IMG);
CASE_TO_STRING(CL_YV12_IMG);
#endif
#ifdef cl_intel_packed_yuv
CASE_TO_STRING(CL_YUYV_INTEL);
CASE_TO_STRING(CL_UYVY_INTEL);
CASE_TO_STRING(CL_YVYU_INTEL);
CASE_TO_STRING(CL_VYUY_INTEL);
#endif
#ifdef CL_NV12_INTEL // cl_intel_planar_yuv
CASE_TO_STRING(CL_NV12_INTEL);
#endif
default: return "Unknown cl_channel_order";
}
}
const char* channel_type_to_string(cl_channel_type channel_type)
{
switch (channel_type) {
CASE_TO_STRING(CL_SNORM_INT8);
CASE_TO_STRING(CL_SNORM_INT16);
CASE_TO_STRING(CL_UNORM_INT8);
CASE_TO_STRING(CL_UNORM_INT16);
CASE_TO_STRING(CL_UNORM_SHORT_565);
CASE_TO_STRING(CL_UNORM_SHORT_555);
CASE_TO_STRING(CL_UNORM_INT_101010);
CASE_TO_STRING(CL_SIGNED_INT8);
CASE_TO_STRING(CL_SIGNED_INT16);
CASE_TO_STRING(CL_SIGNED_INT32);
CASE_TO_STRING(CL_UNSIGNED_INT8);
CASE_TO_STRING(CL_UNSIGNED_INT16);
CASE_TO_STRING(CL_UNSIGNED_INT32);
CASE_TO_STRING(CL_HALF_FLOAT);
CASE_TO_STRING(CL_FLOAT);
#ifdef CL_VERSION_1_2
CASE_TO_STRING(CL_UNORM_INT24);
#endif
#ifdef CL_VERSION_2_1
CASE_TO_STRING(CL_UNORM_INT_101010_2);
#endif
default: return "Unknown cl_channel_type";
}
}
int main(
int argc,
char** argv )
{
int platformIndex = 0;
int deviceIndex = 0;
{
popl::OptionParser op("Supported Options");
op.add<popl::Value<int>>("p", "platform", "Platform Index", platformIndex, &platformIndex);
op.add<popl::Value<int>>("d", "device", "Device Index", deviceIndex, &deviceIndex);
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: enumimageformats [options]\n"
"%s", op.help().c_str());
return -1;
}
}
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (!checkPlatformIndex(platforms, platformIndex)) {
return -1;
}
printf("Querying platform: %s\n",
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
std::vector<cl::Device> devices;
platforms[platformIndex].getDevices(CL_DEVICE_TYPE_ALL, &devices);
printf("Querying device: %s\n",
devices[deviceIndex].getInfo<CL_DEVICE_NAME>().c_str() );
const std::vector<cl_mem_flags> imageAccesses{
{
CL_MEM_READ_ONLY,
CL_MEM_WRITE_ONLY,
CL_MEM_READ_WRITE,
#ifdef CL_VERSION_2_0
CL_MEM_KERNEL_READ_AND_WRITE,
#endif
},
};
const std::vector<cl_mem_object_type> imageTypes{
{
#ifdef CL_VERSION_1_2
CL_MEM_OBJECT_IMAGE1D,
CL_MEM_OBJECT_IMAGE1D_BUFFER,
#endif
CL_MEM_OBJECT_IMAGE2D,
CL_MEM_OBJECT_IMAGE3D,
#ifdef CL_VERSION_1_2
CL_MEM_OBJECT_IMAGE1D_ARRAY,
CL_MEM_OBJECT_IMAGE2D_ARRAY,
#endif
}
};
cl::Context context{devices[deviceIndex]};
for( auto& imageAccess : imageAccesses )
{
for( auto& imageType : imageTypes )
{
std::vector<cl::ImageFormat> imageFormats;
context.getSupportedImageFormats( imageAccess, imageType, &imageFormats );
std::sort(std::begin(imageFormats), std::end(imageFormats),
[](cl::ImageFormat a, cl::ImageFormat b) {
return a.image_channel_order < b.image_channel_order ||
(a.image_channel_order == b.image_channel_data_type &&
a.image_channel_data_type < b.image_channel_data_type);
});
printf("\nFor image access %s (%04X), image type %s (%04X):\n",
mem_flags_to_string(imageAccess),
(cl_uint)imageAccess,
mem_object_type_to_string(imageType),
(cl_uint)imageType);
for( auto& imageFormat : imageFormats )
{
printf("\tChannel Order: %s (%04X),\tChannel Data Type: %s (%04X)\n",
channel_order_to_string(imageFormat.image_channel_order),
(cl_uint)imageFormat.image_channel_order,
channel_type_to_string(imageFormat.image_channel_data_type),
(cl_uint)imageFormat.image_channel_data_type);
}
}
}
printf( "Done.\n" );
return 0;
}