Skip to content

[OpenMP] get logical core count on modern apple platform #87231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

nihui
Copy link
Contributor

@nihui nihui commented Apr 1, 2024

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

@llvmbot llvmbot added the openmp:libomp OpenMP host runtime label Apr 1, 2024
@nihui nihui changed the title [OpenMP] get logical cpu count on modern apple platform [OpenMP] get logical core count on modern apple platform Apr 1, 2024
@shiltian
Copy link
Contributor

shiltian commented Apr 2, 2024

Did you try on macOS? I doubt it will cause any issue but be better on the safe side.

@shiltian shiltian self-requested a review April 2, 2024 13:40
@nihui
Copy link
Contributor Author

nihui commented Apr 2, 2024

Did you try on macOS? I doubt it will cause any issue but be better on the safe side.

A simple test on github macos x86-64 and M1 machine

https://github.com/nihui/action-protobuf/actions/runs/8524611415/job/23349591784
https://github.com/nihui/action-protobuf/actions/runs/8524611415/job/23349592164

#include <stdio.h>
#include <sys/sysctl.h>
#include <sys/types.h>

int main()
{
    int r = 0;
    size_t len = sizeof(r);
    sysctlbyname("hw.logicalcpu", &r, &len, NULL, 0);
    printf("core count = %d\n", r);
    return 0;
}

@nihui
Copy link
Contributor Author

nihui commented Apr 2, 2024

Hello, I have no commit access, please commit it for me (smile)

@shiltian shiltian merged commit 31880df into llvm:main Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomp OpenMP host runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants