You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Retrieve CPU information in terminal / script / CMake running on Apple M1 (and later models)

I am looking for a possibility to identify the CPU of current and future(!) ARM-based MacBooks. We are developing research codes that can be compiled under macOS/Linux/Windows and use CMake for the build process. The build system tries to identify the CPU type as accurate as possible to activate optimisation flags of the compiler. We support cross-compilation so -mtune=native is not an option.


Under Linux we read out /proc/cpuinfo and parse "vendor_id", "cpu_family", etc. for x86-based CPU and "CPU implementer", "CPU architecture", etc. for ARM-based systems.


Under macOS (x86_64) we use the following command

/usr/sbin/sysctl -n machdep.cpu.vendor machdep.cpu.family machdep.cpu.model machdep.cpu.stepping machdep.cpu.features

to retrieve the relevant information.


I was able to retrieve some information on my ARM-based MacBook Pro using

/usr/sbin/sysctl -a machdep.cpu 
machdep.cpu.cores_per_package: 8
machdep.cpu.core_count: 8
machdep.cpu.logical_per_package: 8
machdep.cpu.thread_count: 8
machdep.cpu.brand_string: Apple M1

I wonder if the brand_string follows/will follow a systematic naming convention. Looking at the CPU types supported by the clang++ compiler I do see such systematic naming convention:

clang++ --print-supported-cpus
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: arm64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Available CPUs for this target:
	apple-a10
	apple-a11
	apple-a12
	apple-a13
	apple-a7
	apple-a8
	apple-a9
	apple-latest
	apple-s4
	apple-s5
	cortex-a35
	cortex-a53
	cortex-a55
    ...


I also wonder which target cpu should be selected to compile code optimised for Apple M1. Any help is appreciated.

MacBook Pro

Posted on Jan 8, 2021 8:10 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 9, 2021 7:39 AM

I would build for arm64, and not get hung up on available CPU names. Apple has demonstrated that they will change anything that you choose for dependency, and they won't be changing arm64 anytime soon.

Similar questions

1 reply

Retrieve CPU information in terminal / script / CMake running on Apple M1 (and later models)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.