M1 Apple Silicon for Chess?

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: M1 Apple Silicon for Chess?

Post by Ras »

AlexChess wrote: Thu Sep 09, 2021 3:19 pmBoth versions work out-of-the-box.
That's great news! :) Though I'm wondering why the displayed PV data are different - they should be the same on all systems. Then again, that may happen if one of them was interrupted and restarted a second time (without reloading the engine itself) so that the hashtables are still there from the first run.

What about the 32 bit executables, how do they perform?
As expected the ARM64 binary it's almost 2 times faster than the Intel x64 version
Ah, so Microsoft got around to the x86-64 emulation! A factor of two is about what you can expect from a software emulation. I remember the same factor from Intel Android devices (with 86 CPUs) when they ran ARM executables, so the emulation was the other way around. This one from Microsoft seems actually even better.
Rasmus Althoff
https://www.ct800.net
User avatar
AlexChess
Posts: 1502
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: M1 Apple Silicon for Chess?

Post by AlexChess »

Ras wrote: Thu Sep 09, 2021 3:41 pm
AlexChess wrote: Thu Sep 09, 2021 3:19 pmBoth versions work out-of-the-box.
That's great news! :) Though I'm wondering why the displayed PV data are different - they should be the same on all systems. Then again, that may happen if one of them was interrupted and restarted a second time (without reloading the engine itself) so that the hashtables are still there from the first run.

What about the 32 bit executables, how do they perform?
As expected the ARM64 binary it's almost 2 times faster than the Intel x64 version
Ah, so Microsoft got around to the x86-64 emulation! A factor of two is about what you can expect from a software emulation. I remember the same factor from Intel Android devices (with 86 CPUs) when they ran ARM executables, so the emulation was the other way around. This one from Microsoft seems actually even better.
Yes, Windows 11 on ARM is fast and has a good compatibility with almost all x32, x64 and ARM64 chess binaries (popcnt sse3->sse4.1->sse4.2 , no AVX or BM2) and it is perfectly usable under Parallels Desktop M1. Now I update Visual Studio 2019 and try again to compile some few unstable chess engines for ARM64.

Tested also your 32 bit builds, the x32 OK, the a32 hangs.

Image

Have a nice day,
Alex
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: M1 Apple Silicon for Chess?

Post by Ras »

AlexChess wrote: Thu Sep 09, 2021 3:50 pmTested also your 32 bit builds, the x32 OK, the a32 hangs.
I dug around a bit, and the M1 chip does not implement AARCH32, i.e. it cannot run native 32 bit ARM executables. Makes sense because Apple dropped 32 bit support already back in Catalina, probably because they had been planning ahead for the M1. That would be different with an actual Microsoft device because these do have AARCH32. Interestingly, the conclusion is that Microsoft's emulation layer is always using 64 bit ARM behind the scenes because otherwise, the x32 executable wouldn't run.

Could you please make another run of x64, with the exact same procedure as for the others? Because so far, x32 and a64 match as expected (PVs and node counts), but x64 is slightly different. I'm worried that this could be an engine bug.
Rasmus Althoff
https://www.ct800.net
User avatar
AlexChess
Posts: 1502
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: M1 Apple Silicon for Chess?

Post by AlexChess »

Ras wrote: Thu Sep 09, 2021 5:01 pm
AlexChess wrote: Thu Sep 09, 2021 3:50 pmTested also your 32 bit builds, the x32 OK, the a32 hangs.
I dug around a bit, and the M1 chip does not implement AARCH32, i.e. it cannot run native 32 bit ARM executables. Makes sense because Apple dropped 32 bit support already back in Catalina, probably because they had been planning ahead for the M1. That would be different with an actual Microsoft device because these do have AARCH32. Interestingly, the conclusion is that Microsoft's emulation layer is always using 64 bit ARM behind the scenes because otherwise, the x32 executable wouldn't run.

Could you please make another run of x64, with the exact same procedure as for the others? Because so far, x32 and a64 match as expected (PVs and node counts), but x64 is slightly different. I'm worried that this could be an engine bug.
Image

I have restarted Arena :)
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
User avatar
AlexChess
Posts: 1502
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: M1 Apple Silicon for Chess?

Post by AlexChess »

Since you are an ARM expert, do you know that the Raspberry PI 4 can execute Windows 11 ARM64 and his engines are compatibles with Ubuntu ARM64 out-of-the-box? Could be perfect for all ARM chess engines porting experiments :)

https://www.youtube.com/watch?v=UYSytYtyqCk
Technical Data
Here is an overview on the software, the hardware, and also the relevant authors who contributed to this project.

Software
Author of the ARM-port: Rasmus Althoff.
Base program: NG-Play v9.86 (with extensive improvements and bugfixes).
Author of the base program NG-Play v9.86: George Georgopoulos.
Author of the endgame bitbase for king and pawn vs. king: Marcel van Kervinck.
Opening book: 23,500 different plies in 13,300 unique positions. Transpositions are recognised.
Hash tables: 100 kB.
Pondering: none.
Maximum search depth: 22 plies full search plus 10 plies quiescence.
Maximum game length: 250 moves.
Free ROM: The firmware image is 384 kB, out of which 266 kB are used. 113 kB are for the opening book data and 24 kB for the endgame bitbase.
Free RAM: 16 kB.
Strength: around 2200 ELO.
Operating system: none / bare metal.
Other platforms (via UCI): Windows, Linux, Android, and Raspberry Pi.
Programming languages: mostly C (the best portable macro assembler ever!) and some assembly.
Compiler: GCC 7.3 Q2/2018 ARM none-eabi.
Licence: GNU General Public License, Version 3 or later.
Hardware
CPU: ARM Cortex M4 (STM32F405RG in Olimex STM32-H405).
Speed: 168 MHz (100%) while computing, 18 MHz while waiting for user input.
Clocking: the CPU speed during computing can be configured from 10% to 140%.
ROM: 1 MB.
RAM: 192 kB + 4 kB backup-RAM.
Display: text display with 4×20 characters, plus a red LED, a green LED, and a buzzer.
Display backlight: controlled by software.
Input: 4×4 matrix keypad plus one switch for manual backlight activation.
Power input: 5 V DC (USB) from a power bank, wall power adaptor, or computer. Alternatively, 4×AA NiMH or alkaline batteries.
Battery running time: 37 hours at 168 MHz.
Current consumption at 5 V: 18 mA at 18 MHz (user’s turn), 81 mA at 168 MHz. Each plus 28 mA with active display backlight.
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: M1 Apple Silicon for Chess?

Post by Ras »

AlexChess wrote: Thu Sep 09, 2021 6:13 pmI have restarted Arena :)
Oh that's great, now it's all the same node counts and PV as it should be! :) So we can compare the speed directly for depth 20:
ARM64, native: 100%
x86-64, emulated: 64.7%
x86-32, emulated: 63.4%

Interestingly, it's different for depth 21 where ARM64 (native) sees a sudden 15% uplift in NPS (relative to depth 20) while the x86-64 emulation doesn't, so the emulation has only 55.3% speed for that depth. I'm not sure where that 15% uplift comes from - I'd guess it's how Windows runs the M1 hardware. Maybe the Windows scheduler isn't quite prepared for the asymmetric cores and schedules the engine somewhat randomly across the fast and slow cores. That would of course be something to keep in mind for engine tournaments.
AlexChess wrote: Thu Sep 09, 2021 6:29 pmSince you are an ARM expert, do you know that the Raspberry PI 4 can execute Windows 11 ARM64 and his engines are compatibles with Ubuntu ARM64 out-of-the-box?
That should be due to the WSL (Windows Subsystem for Linux) that allows running Linux binaries on Windows. Though my engine can already be built directly under Linux, including Ubuntu ARM64, using the make_ct800_linux.sh script, executed on the Raspi itself.
Technical Data
Note that this does not refer to ARM Linux or Windows such as on the Raspi, it's instead about the ARM Cortex-M4 target. That's a small microcontroller that has no operating system at all. 1MB ROM, 192kB RAM, 168MHz. That's what's inside the physical CT800 build. :)
Rasmus Althoff
https://www.ct800.net
User avatar
AlexChess
Posts: 1502
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: M1 Apple Silicon for Chess?

Post by AlexChess »

Note that this does not refer to ARM Linux or Windows such as on the Raspi, it's instead about the ARM Cortex-M4 target. That's a small microcontroller that has no operating system at all. 1MB ROM, 192kB RAM, 168MHz. That's what's inside the physical CT800 build. :)
...Then with Silicon M1 should be stronger than 2200 ELO :D I try to add it in my SuperBlitz of 54 TOP engines

How many nps it calculates with ARM Cortex-M4? On M1 it's like all the others on starting position: +-2 mN/s with 4 CPUs on Win 11!

Kind regards, Alex

PS:

ARM Cortex-M4 would be perfect for a dedicated chess computer and with 2200 ELO it would be one of the best. If you build and sell, let me know, I'll take this HANDCRAFTED masterpiece! :P Actual dedicated computers are very weak. 30 years ago when I was a Saitek-Kasparov / Mephisto reseller it would be a 750€ hardware like Risc 2500 https://www.chessprogramming.org/RISC_2500 and now all is done with a microcontroller :D

https://create.arduino.cc/projecthub/ca ... ard-04440f
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: M1 Apple Silicon for Chess?

Post by Ras »

AlexChess wrote: Fri Sep 10, 2021 6:55 amHow many nps it calculates with ARM Cortex-M4?
That's around 30kNPS, without overclocking. With maximum overclocking, selectable in software, that would be around 43kNPS.
If you build and sell
Unfortunately, the EU Waste Electrical and Electronic Equipment Directive (WEEE) has effectively banned tiny scale production, something also felt in the model railway sector. However, that doesn't apply for things you'd build yourself, and there is a sister project for affordable hardware: https://github.com/d3rvita/ct800-pcb
Actual dedicated computers are very weak.
Millennium Chess (Germany) has an interesting lineup with the Chess Genius, Chess Genius Pro, Chess Genius Exclusive, and The King Performance - the latter one with de Koning's legendary engine. Staff includes Hegener and Weiner, well-known from the old Mephisto era.
Rasmus Althoff
https://www.ct800.net
Werewolf
Posts: 1796
Joined: Thu Sep 18, 2008 10:24 pm

Re: M1 Apple Silicon for Chess?

Post by Werewolf »

sorry if this has been asked before: is there a SF Dev compile for Apple's M1 / M1X ?
User avatar
AlexChess
Posts: 1502
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: M1 Apple Silicon for Chess?

Post by AlexChess »

Werewolf wrote: Fri Sep 10, 2021 4:41 pm sorry if this has been asked before: is there a SF Dev compile for Apple's M1 / M1X ?
The author of this topic @Acepoint that is very skilled, often releases new native builds for M1.
Or luckily you can compile it by yourself using homebrew as explained on SF site: https://stockfishchess.org/download/ from Terminal, but I don't know if it uses the latest dev. It's easy: You install homebrew: https://brew.sh/
then type: brew install stockfish and you find the compiled binary on: /opt/homebrew/Cellar/stockfish/14

Code: Select all

Warning: stockfish 14 is already installed and up-to-date.
To reinstall 14, run:
  brew reinstall stockfish
alex@Mac-mini-M1 ~ % brew reinstall stockfish
==> Downloading https://ghcr.io/v2/homebrew/core/stockfish/manifests/14
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/stockfish/blobs/sha256:81b4c0a9
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Reinstalling stockfish 
==> Pouring stockfish--14.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/stockfish/14: 6 files, 46.2MB
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN