1212//
1313// ===----------------------------------------------------------------------===//
1414#include < CL/sycl.hpp>
15+ #include < cstdint>
1516#include < iostream>
1617#include < string>
18+ #include < strstream>
1719
1820using namespace cl ::sycl;
1921
20- template <typename T> std::string info_to_string (T info) {
22+ // Handle unknown info, e.g., from non-standard extensions.
23+ template <typename T>
24+ std::string unknown_info_to_string (T info) {
25+ std::strstream stream;
26+ stream << std::hex << static_cast <std::uint64_t >(info) << " (unknown value)"
27+ << " \n " ;
28+ return stream.str ();
29+ }
30+
31+ template <typename T>
32+ std::string info_to_string (T info) {
2133 return std::to_string (info);
2234}
2335
24- template <> std::string info_to_string (string_class info) {
36+ template <>
37+ std::string info_to_string (string_class info) {
2538 if (info.empty ()) {
2639 return " none" ;
2740 }
2841 return info;
2942}
3043
31- template <> std::string info_to_string (bool info) {
44+ template <>
45+ std::string info_to_string (bool info) {
3246 if (info) {
3347 return " true" ;
3448 }
3549 return " false" ;
3650}
37- template <> std::string info_to_string (info::device_type info) {
51+ template <>
52+ std::string info_to_string (info::device_type info) {
3853 switch (info) {
3954 case info::device_type::cpu:
4055 return " cpu" ;
@@ -50,10 +65,13 @@ template <> std::string info_to_string(info::device_type info) {
5065 return " host" ;
5166 case info::device_type::all:
5267 return " all" ;
68+ default :
69+ return unknown_info_to_string (info);
5370 }
5471}
5572
56- template <> std::string info_to_string (info::fp_config info) {
73+ template <>
74+ std::string info_to_string (info::fp_config info) {
5775 switch (info) {
5876 case info::fp_config::denorm:
5977 return " denorm" ;
@@ -71,41 +89,53 @@ template <> std::string info_to_string(info::fp_config info) {
7189 return " correctly_rounded_divide_sqrt" ;
7290 case info::fp_config::soft_float:
7391 return " soft_float" ;
92+ default :
93+ return unknown_info_to_string (info);
7494 }
7595}
7696
77- template <> std::string info_to_string (info::global_mem_cache_type info) {
97+ template <>
98+ std::string info_to_string (info::global_mem_cache_type info) {
7899 switch (info) {
79100 case info::global_mem_cache_type::none:
80101 return " none" ;
81102 case info::global_mem_cache_type::read_only:
82103 return " read_only" ;
83104 case info::global_mem_cache_type::read_write:
84105 return " read_write" ;
106+ default :
107+ return unknown_info_to_string (info);
85108 }
86109}
87110
88- template <> std::string info_to_string (info::local_mem_type info) {
111+ template <>
112+ std::string info_to_string (info::local_mem_type info) {
89113 switch (info) {
90114 case info::local_mem_type::none:
91115 return " none" ;
92116 case info::local_mem_type::local:
93117 return " local" ;
94118 case info::local_mem_type::global:
95119 return " global" ;
120+ default :
121+ return unknown_info_to_string (info);
96122 }
97123}
98124
99- template <> std::string info_to_string (info::execution_capability info) {
125+ template <>
126+ std::string info_to_string (info::execution_capability info) {
100127 switch (info) {
101128 case info::execution_capability::exec_kernel:
102129 return " exec_kernel" ;
103130 case info::execution_capability::exec_native_kernel:
104131 return " exec_native_kernel" ;
132+ default :
133+ return unknown_info_to_string (info);
105134 }
106135}
107136
108- template <> std::string info_to_string (info::partition_property info) {
137+ template <>
138+ std::string info_to_string (info::partition_property info) {
109139 switch (info) {
110140 case info::partition_property::no_partition:
111141 return " no_partition" ;
@@ -115,10 +145,13 @@ template <> std::string info_to_string(info::partition_property info) {
115145 return " partition_by_counts" ;
116146 case info::partition_property::partition_by_affinity_domain:
117147 return " partition_by_affinity_domain" ;
148+ default :
149+ return unknown_info_to_string (info);
118150 }
119151}
120152
121- template <> std::string info_to_string (info::partition_affinity_domain info) {
153+ template <>
154+ std::string info_to_string (info::partition_affinity_domain info) {
122155 switch (info) {
123156 case info::partition_affinity_domain::not_applicable:
124157 return " not_applicable" ;
@@ -134,32 +167,38 @@ template <> std::string info_to_string(info::partition_affinity_domain info) {
134167 return " L1_cache" ;
135168 case info::partition_affinity_domain::next_partitionable:
136169 return " next_partitionable" ;
170+ default :
171+ return unknown_info_to_string (info);
137172 }
138173}
139174
140- template <> std::string info_to_string (platform info) {
175+ template <>
176+ std::string info_to_string (platform info) {
141177 if (info.is_host ()) {
142178 return " SYCL host platform" ;
143179 }
144180 return " SYCL OpenCL platform" ;
145181}
146182
147- template <> std::string info_to_string (device info) {
183+ template <>
184+ std::string info_to_string (device info) {
148185 if (info.is_host ()) {
149186 return " SYCL host device" ;
150187 }
151188 return " SYCL OpenCL device" ;
152189}
153190
154- template <> std::string info_to_string (id<3 > info) {
191+ template <>
192+ std::string info_to_string (id<3 > info) {
155193 std::string str;
156194 for (size_t i = 0 ; i < 3 ; ++i) {
157195 str += info_to_string (info[i]) + " " ;
158196 }
159197 return str;
160198}
161199
162- template <typename T> std::string info_to_string (vector_class<T> info) {
200+ template <typename T>
201+ std::string info_to_string (vector_class<T> info) {
163202 if (info.empty ()) {
164203 return " none" ;
165204 }
@@ -184,7 +223,8 @@ void print_info(const platform &plt, const std::string &name) {
184223
185224int main () {
186225 std::string separator (std::string (80 , ' -' ) + " \n " );
187- std::cout << separator << " Device information\n " << separator;
226+ std::cout << separator << " Device information\n "
227+ << separator;
188228 default_selector selector;
189229 device dev (selector.select_device ());
190230
@@ -336,7 +376,8 @@ int main() {
336376 print_info<info::device::reference_count, cl::sycl::cl_uint>(
337377 dev, " Reference count" );
338378
339- std::cout << separator << " Platform information\n " << separator;
379+ std::cout << separator << " Platform information\n "
380+ << separator;
340381 platform plt (dev.get_platform ());
341382 print_info<info::platform::profile, string_class>(plt, " Profile" );
342383 print_info<info::platform::version, string_class>(plt, " Version" );
@@ -345,20 +386,23 @@ int main() {
345386 print_info<info::platform::extensions, vector_class<string_class>>(
346387 plt, " Extensions" );
347388
348- std::cout << separator << " Queue information\n " << separator;
389+ std::cout << separator << " Queue information\n "
390+ << separator;
349391 queue q (selector);
350392 auto qdev = q.get_info <cl::sycl::info::queue::device>();
351393 std::cout << " Device from queue information\n " ;
352394 print_info<info::device::name, string_class>(qdev, " Name" );
353395 auto ctx = q.get_info <cl::sycl::info::queue::context>();
354396
355- std::cout << separator << " Context information\n " << separator;
397+ std::cout << separator << " Context information\n "
398+ << separator;
356399 std::cout << " Devices from context information\n " ;
357400 auto cdevs = ctx.get_info <cl::sycl::info::context::devices>();
358401 for (auto cdev : cdevs) {
359402 print_info<info::device::name, string_class>(cdev, " Name" );
360403 }
361- std::cout << separator << " Platform from context information\n " << separator;
404+ std::cout << separator << " Platform from context information\n "
405+ << separator;
362406 auto cplt = ctx.get_info <cl::sycl::info::context::platform>();
363407 print_info<info::platform::name, string_class>(cplt, " Name" );
364408}
0 commit comments