Skip to content

Commit 33594db

Browse files
[SYCL] Build fixes for Apple silicon (#6932)
Added more macro guards when including `immintrin.h` and `cpuid.h`. Removed dead code from `PlatformUtil::getMaxClockFrequency`. With this fixes, the project can be built on Apple silicon (M1). Signed-off-by: Alexey Sachkov <sachkov2011@gmail.com>
1 parent 4cbd459 commit 33594db

File tree

2 files changed

+3
-32
lines changed

2 files changed

+3
-32
lines changed

sycl/source/detail/platform_util.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
#elif defined(__SYCL_RT_OS_WINDOWS)
2020
#include <intrin.h>
2121
#elif defined(__SYCL_RT_OS_DARWIN)
22+
#if defined(__x86_64__) || defined(__i386__)
2223
#include <cpuid.h>
2324
#endif
25+
#endif
2426

2527
namespace sycl {
2628
__SYCL_INLINE_VER_NAMESPACE(_V1) {
@@ -41,37 +43,6 @@ uint32_t PlatformUtil::getMaxClockFrequency() {
4143
throw runtime_error(
4244
"max_clock_frequency parameter is not supported for host device",
4345
PI_ERROR_INVALID_DEVICE);
44-
#if defined(__x86_64__) || defined(__i386__)
45-
uint32_t CPUInfo[4];
46-
std::string Buff(sizeof(CPUInfo) * 3 + 1, 0);
47-
size_t Offset = 0;
48-
49-
for (uint32_t i = 0x80000002; i <= 0x80000004; i++) {
50-
cpuid(CPUInfo, i);
51-
std::copy(reinterpret_cast<char *>(CPUInfo),
52-
reinterpret_cast<char *>(CPUInfo) + sizeof(CPUInfo),
53-
Buff.begin() + Offset);
54-
Offset += sizeof(CPUInfo);
55-
}
56-
std::size_t Found = Buff.rfind("Hz");
57-
// Bail out if frequency is not found in CPUID string
58-
if (Found == std::string::npos)
59-
return 0;
60-
61-
Buff = Buff.substr(0, Found);
62-
uint32_t Freq = 0;
63-
switch (Buff[Buff.size() - 1]) {
64-
case 'M':
65-
Freq = 1;
66-
break;
67-
case 'G':
68-
Freq = 1000;
69-
break;
70-
}
71-
Buff = Buff.substr(Buff.rfind(' '), Buff.length());
72-
Freq *= std::stod(Buff);
73-
return Freq;
74-
#endif
7546
return 0;
7647
}
7748

xptifw/include/spin_lock.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define __has_include(x)
1313
#endif
1414

15-
#if __has_include(<immintrin.h>)
15+
#if __has_include(<immintrin.h>) && defined(__x86_64__)
1616
#define HAS_PAUSE
1717
#include <immintrin.h>
1818
#endif

0 commit comments

Comments
 (0)