Is there a way of detecting a M1 mac in MATLAB? MATLAB has ismac
but that presumably won't differentiate between processor types.

- 2,886
- 2
- 29
- 45
-
1Detecting a M1 mac versus what? See the `computer` and `ismac` functions – Luis Mendo Apr 21 '21 at 16:49
-
1Or maybe the `cpuInfoMac` subfunction [here](https://www.mathworks.com/matlabcentral/fileexchange/33155-cpu-info) (I haven't tested it) – Luis Mendo Apr 21 '21 at 16:55
2 Answers
New Answer: Tested on M1 Mac
My impression is that MATLAB is running through Rosetta 2, which means that the result of uname -m
is actually x86_64
, which does not help guard against calls to Intel targeting mex code.
Instead we'll ask for the kernel version and try to find ARM64
if ismac()
[~,result] = system('uname -v');
is_m1_mac = any(strfind(result,'ARM64'));
else
is_m1_mac = false;
end
Note result
above is on my computer : Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
Old Answer: Not correct
To detect the processor one can call to the system command line: Detect Apple Silicon from command line
Note, this has not been tested on a m1 mac ...
if ismac()
[~,result] = system('uname -m');
is_m1_mac = strcmp(strtrim(result),'arm64');
else
is_m1_mac = false;
end
Note, this would help if you are running an older version of MATLAB, as MATLAB doesn't officially support M1 macs until 2020b update 3 ... https://www.mathworks.com/matlabcentral/answers/641925-is-matlab-supported-on-apple-silicon-macs
However, it is not clear to me that this would eventually detect execution of MATLAB natively vs via ROSETTA (when a native option actually exists).

- 2,886
- 2
- 29
- 45
Tested on M2 pro with R2022b (ARM beta):
system('uname -m')
arm64
ans =
0
and
if ismac()
[~,result] = system('uname -m');
is_m1_mac = strcmp(strtrim(result),'arm64');
else
is_m1_mac = false;
end
>> is_m1_mac
is_m1_mac =
logical
1

- 1
- 2