7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include < CL/sycl/detail/device_info.hpp>
10
+ #include < CL/sycl/detail/os_util.hpp>
11
+ #include < CL/sycl/detail/platform_util.hpp>
10
12
#include < CL/sycl/device.hpp>
11
13
#include < chrono>
12
- #include < sys/sysinfo.h>
13
14
#include < thread>
14
15
15
16
#ifdef __GNUG__
@@ -21,22 +22,6 @@ namespace cl {
21
22
namespace sycl {
22
23
namespace detail {
23
24
24
- // Used by methods that duplicate OpenCL behaviour in order to get CPU info
25
- // TODO add Windows support
26
- // TODO add support for x86-64 ABI selected using ifdef.
27
- static void cpuid (unsigned int cpuid_info[], unsigned int type) {
28
- unsigned int eax, ebx, ecx, edx;
29
- __asm__ __volatile__ (" mov %%ebx, %%edi\n\r "
30
- " cpuid\n\r "
31
- " xchg %%edi, %%ebx\n\r "
32
- : " =a" (eax), " =D" (ebx), " =c" (ecx), " =d" (edx)
33
- : " a" (type));
34
- cpuid_info[0 ] = eax;
35
- cpuid_info[1 ] = ebx;
36
- cpuid_info[2 ] = ecx;
37
- cpuid_info[3 ] = edx;
38
- }
39
-
40
25
vector_class<info::fp_config> read_fp_bitfield (cl_device_fp_config bits) {
41
26
vector_class<info::fp_config> result;
42
27
if (bits & CL_FP_DENORM)
@@ -156,109 +141,51 @@ cl_uint get_device_info_host<info::device::preferred_vector_width_half>() {
156
141
return 0 ;
157
142
}
158
143
159
- // SSE4.2 has 16 byte (XMM) registers
160
- static const cl_uint NATIVE_VECTOR_WIDTH_SSE42[] = {16 , 8 , 4 , 2 , 4 , 2 , 0 };
161
- // AVX supports 32 byte (YMM) registers only for floats and doubles
162
- static const cl_uint NATIVE_VECTOR_WIDTH_AVX[] = {16 , 8 , 4 , 2 , 8 , 4 , 0 };
163
- // AVX2 has a full set of 32 byte (YMM) registers
164
- static const cl_uint NATIVE_VECTOR_WIDTH_AVX2[] = {32 , 16 , 8 , 4 , 8 , 4 , 0 };
165
- // AVX512 has 64 byte (ZMM) registers
166
- static const cl_uint NATIVE_VECTOR_WIDTH_AVX512[] = {64 , 32 , 16 , 8 , 16 , 8 , 0 };
167
-
168
- cl_uint get_native_vector_width (size_t idx) {
169
- #if (__GNUG__ && GCC_VERSION > 40900)
170
- if (__builtin_cpu_supports (" avx512f" )) {
171
- return NATIVE_VECTOR_WIDTH_AVX512[idx];
172
- }
173
- #endif
174
-
175
- if (__builtin_cpu_supports (" avx2" )) {
176
- return NATIVE_VECTOR_WIDTH_AVX2[idx];
177
- }
178
- if (__builtin_cpu_supports (" avx" )) {
179
- return NATIVE_VECTOR_WIDTH_AVX[idx];
180
- }
181
- return NATIVE_VECTOR_WIDTH_SSE42[idx];
182
- }
183
-
184
144
template <>
185
145
cl_uint get_device_info_host<info::device::native_vector_width_char>() {
186
- return get_native_vector_width ( 0 );
146
+ return PlatformUtil::getNativeVectorWidth (PlatformUtil::TypeIndex::Char );
187
147
}
188
148
189
149
template <>
190
150
cl_uint get_device_info_host<info::device::native_vector_width_short>() {
191
- return get_native_vector_width ( 1 );
151
+ return PlatformUtil::getNativeVectorWidth (PlatformUtil::TypeIndex::Short );
192
152
}
193
153
194
154
template <>
195
155
cl_uint get_device_info_host<info::device::native_vector_width_int>() {
196
- return get_native_vector_width ( 2 );
156
+ return PlatformUtil::getNativeVectorWidth (PlatformUtil::TypeIndex::Int );
197
157
}
198
158
199
159
template <>
200
160
cl_uint get_device_info_host<info::device::native_vector_width_long>() {
201
- return get_native_vector_width ( 3 );
161
+ return PlatformUtil::getNativeVectorWidth (PlatformUtil::TypeIndex::Long );
202
162
}
203
163
204
164
template <>
205
165
cl_uint get_device_info_host<info::device::native_vector_width_float>() {
206
- return get_native_vector_width ( 4 );
166
+ return PlatformUtil::getNativeVectorWidth (PlatformUtil::TypeIndex::Float );
207
167
}
208
168
209
169
template <>
210
170
cl_uint get_device_info_host<info::device::native_vector_width_double>() {
211
- return get_native_vector_width ( 5 );
171
+ return PlatformUtil::getNativeVectorWidth (PlatformUtil::TypeIndex::Double );
212
172
}
213
173
214
174
template <>
215
175
cl_uint get_device_info_host<info::device::native_vector_width_half>() {
216
- return get_native_vector_width ( 6 );
176
+ return PlatformUtil::getNativeVectorWidth (PlatformUtil::TypeIndex::Half );
217
177
}
218
178
219
179
template <> cl_uint get_device_info_host<info::device::max_clock_frequency>() {
220
- throw runtime_error (
221
- " max_clock_frequency parameter is not supported for host device" );
222
- unsigned int cpuInfo[4 ] = {0 - 1u };
223
- string_class buff (sizeof (cpuInfo) * 3 + 1 , 0 );
224
- size_t offset = 0 ;
225
-
226
- for (unsigned int i = 0x80000002 ; i <= 0x80000004 ; i++) {
227
- cpuid (cpuInfo, i);
228
- std::copy (reinterpret_cast <char *>(cpuInfo),
229
- reinterpret_cast <char *>(cpuInfo) + sizeof (cpuInfo),
230
- buff.begin () + offset);
231
- offset += sizeof (cpuInfo);
232
- }
233
- std::size_t found = buff.rfind (" Hz" );
234
- // Bail out if frequency is not found in CPUID string
235
- if (found == std::string::npos)
236
- return 0 ;
237
-
238
- buff = buff.substr (0 , found);
239
-
240
- cl_uint freq = 0 ;
241
- switch (buff[buff.size () - 1 ]) {
242
- case ' M' :
243
- freq = 1 ;
244
- break ;
245
- case ' G' :
246
- freq = 1000 ;
247
- break ;
248
- }
249
- buff = buff.substr (buff.rfind (' ' ), buff.length ());
250
- freq *= std::stod (buff);
251
- return freq;
180
+ return PlatformUtil::getMaxClockFrequency ();
252
181
}
253
182
254
183
template <> cl_uint get_device_info_host<info::device::address_bits>() {
255
184
return sizeof (void *) * 8 ;
256
185
}
257
186
258
187
template <> cl_ulong get_device_info_host<info::device::global_mem_size>() {
259
- struct sysinfo meminfo;
260
- sysinfo (&meminfo);
261
- return meminfo.totalram * meminfo.mem_unit ;
188
+ return static_cast <cl_ulong>(OSUtil::getOSMemSize ());
262
189
}
263
190
264
191
template <> cl_ulong get_device_info_host<info::device::max_mem_alloc_size>() {
@@ -362,16 +289,12 @@ get_device_info_host<info::device::global_mem_cache_type>() {
362
289
363
290
template <>
364
291
cl_uint get_device_info_host<info::device::global_mem_cache_line_size>() {
365
- unsigned int viCPUInfo[4 ] = {(unsigned int )-1 };
366
- cpuid (viCPUInfo, 0x80000006 );
367
- return viCPUInfo[2 ] & 0xff ;
292
+ return PlatformUtil::getMemCacheLineSize ();
368
293
}
369
294
370
295
template <>
371
296
cl_ulong get_device_info_host<info::device::global_mem_cache_size>() {
372
- unsigned int viCPUInfo[4 ] = {(unsigned int )-1 };
373
- cpuid (viCPUInfo, 0x80000006 );
374
- return ((viCPUInfo[2 ] >> 16 ) & 0xffff ) * 1024 ;
297
+ return PlatformUtil::getMemCacheSize ();
375
298
}
376
299
377
300
template <>
0 commit comments