-
Notifications
You must be signed in to change notification settings - Fork 56
/
main.cc
309 lines (267 loc) · 11.6 KB
/
main.cc
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <sycl/sycl.hpp>
#define TAB std::string(" ")
#define TEXT_WIDTH 50
#define BYTES_IN_KB 1024
#define BYTES_IN_MB (1024 * 1024)
#define BYTES_IN_GB (1024 * 1024 * 1024)
std::string ConvertBytesToString(size_t value) {
if (value / BYTES_IN_KB < 1) {
return std::to_string(value) + "B";
}
if (value / BYTES_IN_MB < 1) {
if (value % BYTES_IN_KB != 0) {
std::stringstream tempstream;
tempstream << std::fixed << std::setprecision(2) <<
static_cast<float>(value) / BYTES_IN_KB << "KiB";
return tempstream.str();
}
return std::to_string(value / BYTES_IN_KB) + "KiB";
}
if (value / BYTES_IN_GB < 1) {
if ((value % BYTES_IN_MB) != 0) {
std::stringstream tempstream;
tempstream << std::fixed << std::setprecision(2) <<
static_cast<float>(value) / BYTES_IN_MB << "MiB";
return tempstream.str();
}
return std::to_string(value / BYTES_IN_MB) + "MiB";
}
if (value % (BYTES_IN_GB) != 0) {
std::stringstream tempstream;
tempstream << std::fixed << std::setprecision(2) <<
static_cast<float>(value) / BYTES_IN_GB << "GiB";
return tempstream.str();
}
return std::to_string(value / BYTES_IN_GB) + "GiB";
}
std::ostream& operator<<(std::ostream& out, sycl::aspect sycl_aspect) {
switch (sycl_aspect) {
#define __SYCL_ASPECT(X, Y) \
case sycl::aspect::X: \
out << "" #X; \
break;
#include <sycl/info/aspects.def>
#undef __SYCL_ASPECT
default:
out << "<unknown-aspect: " << static_cast<std::size_t>(sycl_aspect) << ">";
break;
}
return out;
}
int main(int argc, char* argv[]) {
bool list_mode = false;
if (argc > 1 && std::string(argv[1]).compare("-l") == 0) {
list_mode = true;
}
std::vector<sycl::platform> platforms =
sycl::platform::get_platforms();
if (list_mode) {
for (size_t pl_id = 0; pl_id < platforms.size(); pl_id++) {
std::string name =
platforms[pl_id].get_info<sycl::info::platform::name>();
std::cout << "Platform #" << pl_id << ": " << name << std::endl;
std::vector<sycl::device> devices =
platforms[pl_id].get_devices(sycl::info::device_type::all);
for (size_t device_id = 0; device_id < devices.size(); device_id++) {
std::string name =
devices[device_id].get_info<sycl::info::device::name>();
std::cout << " `-- Device #" << device_id << ": " << name << "\n";
}
}
std::cout << std::endl;
} else {
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Number of platforms " << platforms.size() << std::endl;
for (auto platform : platforms) {
std::string name =
platform.get_info<sycl::info::platform::name>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Platform Name " << name << std::endl;
std::string vendor =
platform.get_info<sycl::info::platform::vendor>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Platform Vendor " << vendor << std::endl;
std::string profile =
platform.get_info<sycl::info::platform::profile>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Platform Profile " << profile << std::endl;
}
for (auto platform : platforms) {
std::string name =
platform.get_info<sycl::info::platform::name>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Platform Name " << name << std::endl;
std::vector<sycl::device> devices =
platform.get_devices(sycl::info::device_type::all);
std::cout << std::setw(TEXT_WIDTH) << std::left <<
"Number of devices " << devices.size() << std::endl;
if (devices.size() == 0) {
std::cout << std::endl;
}
for (auto device : devices) {
std::string name =
device.get_info<sycl::info::device::name>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device Name " << name << std::endl;
std::string vendor =
device.get_info<sycl::info::device::vendor>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device Vendor "<< vendor << std::endl;
cl_uint vendor_id = device.get_info<sycl::info::device::vendor_id>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device vendor ID " << "0x" <<
std::hex << vendor_id << std::dec << std::endl;
std::string device_version =
device.get_info<sycl::info::device::version>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device Version " << device_version << std::endl;
std::string driver_version =
device.get_info<sycl::info::device::driver_version>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Driver Version " << driver_version << std::endl;
std::string version =
device.get_info<sycl::info::device::version>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device SYCL Version " << version << std::endl;
sycl::info::device_type device_type =
device.get_info<sycl::info::device::device_type>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device type ";
switch (device_type) {
case sycl::info::device_type::gpu:
std::cout << "GPU";
break;
case sycl::info::device_type::cpu:
std::cout << "CPU";
break;
case sycl::info::device_type::host:
std::cout << "HOST";
break;
case sycl::info::device_type::accelerator:
std::cout << "ACCELERATOR";
break;
default:
std::cout << "OTHER";
}
std::cout << std::endl;
bool is_avilable =
device.get_info<sycl::info::device::is_available>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device Available " <<
(is_avilable ? "Yes" : "No") << std::endl;
bool is_compiler_avilable =
device.has(sycl::aspect::online_compiler);
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Compiler Available " <<
(is_compiler_avilable ? "Yes" : "No") << std::endl;
bool is_linker_avilable =
device.has(sycl::aspect::online_linker);
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Linker Available " <<
(is_linker_avilable ? "Yes" : "No") << std::endl;
cl_uint max_compute_units =
device.get_info<sycl::info::device::max_compute_units>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Max compute units " << max_compute_units << std::endl;
if (device_type != sycl::info::device_type::host) {
cl_uint maxClockFrequency =
device.get_info<sycl::info::device::max_clock_frequency>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Max clock frequency " <<
maxClockFrequency << "MHz" << std::endl;
}
cl_uint max_work_item_dimensions =
device.get_info<sycl::info::device::max_work_item_dimensions>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Max work item dimensions " <<
max_work_item_dimensions << std::endl;
sycl::id<3> sizes =
device.get_info<sycl::info::device::max_work_item_sizes<3>>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Max work item sizes " <<
sizes[0] << " x " << sizes[1] << " x " << sizes[2] << std::endl;
size_t max_work_group_size =
device.get_info<sycl::info::device::max_work_group_size>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Max work group size " <<
max_work_group_size << std::endl;
cl_ulong global_mem_size =
device.get_info<sycl::info::device::global_mem_size>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Global memory size " << global_mem_size <<
" (" << ConvertBytesToString(global_mem_size) << ")" << std::endl;
sycl::info::global_mem_cache_type global_mem_cache_type =
device.get_info<sycl::info::device::global_mem_cache_type>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Global Memory cache type ";
switch (global_mem_cache_type) {
case sycl::info::global_mem_cache_type::none:
std::cout << "None" << std::endl;
break;
case sycl::info::global_mem_cache_type::read_only:
std::cout << "Read Only" << std::endl;
break;
case sycl::info::global_mem_cache_type::read_write:
std::cout << "Read/Write" << std::endl;
break;
default:
std::cout << "Other" << std::endl;
}
// TODO(matthew.schilling@intel.com): Deprecated, however, I do not
// know a drop-in replacement.
// https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_device_information_descriptors
bool preferred_interop_user_sync =
device.get_info<sycl::info::device::preferred_interop_user_sync>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Prefer user sync for interop " <<
(is_compiler_avilable ? "Yes" : "No") << std::endl;
size_t profiling_timer_resolution =
device.get_info<sycl::info::device::profiling_timer_resolution>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Profiling timer resolution " <<
profiling_timer_resolution << "ns" << std::endl;
// TODO(matthew.schilling@intel.com): Deprecated, however, I do not
// know a drop-in replacement.
// https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_device_information_descriptors
size_t printf_buffer_size =
device.get_info<sycl::info::device::printf_buffer_size>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "printf() buffer size" << printf_buffer_size << " (" <<
ConvertBytesToString(printf_buffer_size) << ")" << std::endl;
auto built_in_kernels =
device.get_info<sycl::info::device::built_in_kernel_ids>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Built-in kernels ";
for (size_t i = 0; i < built_in_kernels.size(); ++i) {
std::cout << built_in_kernels[i].get_name() << " ";
}
std::cout << std::endl;
// TODO(matthew.schilling@intel.com): Deprecated, however, the
// suggested replacement is not 1-for-1. I added the implementation
// using aspects below. Keeping this for now.
// https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_device_information_descriptors
std::vector<std::string> device_extensions =
device.get_info<sycl::info::device::extensions>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device Extensions ";
for (const auto& device_extension : device_extensions) {
std::cout << device_extension << " ";
}
std::cout << std::endl;
auto device_aspects =
device.get_info<sycl::info::device::aspects>();
std::cout << std::setw(TEXT_WIDTH) << std::left <<
TAB + "Device Aspects ";
for (const auto& device_aspect : device_aspects) {
std::cout << device_aspect << " ";
}
std::cout << std::endl << std::endl;
}
}
}
return 0;
}