Skip to content

Commit 31880df

Browse files
authored
[OpenMP] get logical core count on modern apple platform (llvm#87231)
`hw.logicalcpu` returns the available logical core count Fix build error for watchOS ``` runtime/src/z_Linux_util.cpp:1821:8: error: 'host_info' is unavailable: not available on watchOS rc = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&info, &num); ^ /Applications/Xcode_15.2.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS10.2.sdk/usr/include/mach/mach_host.h:82:15: note: 'host_info' has been explicitly marked unavailable here kern_return_t host_info ^ 1 warning and 1 error generated. make[2]: *** [runtime/src/CMakeFiles/omp.dir/z_Linux_util.cpp.o] Error 1 ```
1 parent c5bbdb6 commit 31880df

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,21 +1889,8 @@ static int __kmp_get_xproc(void) {
18891889

18901890
#elif KMP_OS_DARWIN
18911891

1892-
// Bug C77011 High "OpenMP Threads and number of active cores".
1893-
1894-
// Find the number of available CPUs.
1895-
kern_return_t rc;
1896-
host_basic_info_data_t info;
1897-
mach_msg_type_number_t num = HOST_BASIC_INFO_COUNT;
1898-
rc = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&info, &num);
1899-
if (rc == 0 && num == HOST_BASIC_INFO_COUNT) {
1900-
// Cannot use KA_TRACE() here because this code works before trace support
1901-
// is initialized.
1902-
r = info.avail_cpus;
1903-
} else {
1904-
KMP_WARNING(CantGetNumAvailCPU);
1905-
KMP_INFORM(AssumedNumCPU);
1906-
}
1892+
size_t len = sizeof(r);
1893+
sysctlbyname("hw.logicalcpu", &r, &len, NULL, 0);
19071894

19081895
#else
19091896

0 commit comments

Comments
 (0)