Is in this world really no compile of Sf-NNUE for arm-8?

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

Moderators: hgm, Rebel, chrisw

User avatar
Thomas Lagershausen
Posts: 328
Joined: Mon Jun 11, 2007 6:59 pm

Is in this world really no compile of Sf-NNUE for arm-8?

Post by Thomas Lagershausen »

Sorry for asking here.

Yesterday i had asked in discord stockfish-nnue- general and -help and got no answer.

Today the same game.

Really, no one is interested?

Where is the hero who makes a arm-8 compile for the 256x nn.bin?

Please,make the world a better place :!:
TL
supersharp77
Posts: 1242
Joined: Sat Jul 05, 2014 7:54 am
Location: Southwest USA

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by supersharp77 »

Thomas Lagershausen wrote: Mon Jul 20, 2020 7:31 pm Sorry for asking here.

Yesterday i had asked in discord stockfish-nnue- general and -help and got no answer.

Today the same game.

Really, no one is interested?

Where is the hero who makes a arm-8 compile for the 256x nn.bin?

Please,make the world a better place :!:
Skynet "Well, before making android engine i've put the nn.bin file in src/eval folder, here is simple lto arm8 engine (non pgo). First of all, when Droidfish or Chess for Android GUIs loading the engine, they not providing any information about nn.bin if it was loaded or not." "Almost all android devices has the same path / directory to the internal memory,
which is /storage/emulated/0, I created a folder with name "eval" and put the nn.bin file there, whole path
/storage/emulated/0/eval/nn.bin, and i still don't have any idea if engine is using nn.bin. Try by yourself, maybe you find the correct path. "
Btw, using NDK's CLANG i didn't saw a single warning.


http://outskirts.altervista.org/forum/d ... php?id=831

All Thx to Skynet........ :) :wink:
User avatar
Thomas Lagershausen
Posts: 328
Joined: Mon Jun 11, 2007 6:59 pm

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by Thomas Lagershausen »

I am looking for a working compile for arm-8 on android.

Please check sf-nnue with a testposition.

Here is one:

[d]rn1qrnk1/p4pp1/1p1pp3/6P1/2Pp1PN1/2PQ4/P5P1/2KR3R w - - 0 1

22/45 00:04 17.874.055 3.874.713 +1,59 Sg4-h6+ g7xh6 Th1xh6 Sf8-g6 Td1-h1 Kg8-f8 Dd3xg6 Kf8-e7 Th6-h7 Te8-f8 Th1-h6 Dd8-e8 Dg6-e4 De8-c8 f4-f5 Dc8xc4 Th6xe6+ Ke7-d8 Te6xd6+ Kd8-c8 g5-g6 Dc4-f1+ Kc1-b2 Df1-b5+ Kb2-c2 Kc8-c7 Th7xf7+ Tf8xf7 g6xf7 Sb8-d7 Td6xd4

To find Nh6+ so fast shows that sf-nnue loaded net 256halfkp-Gekkehenker.

Thx in advance.
TL
petero2
Posts: 687
Joined: Mon Apr 19, 2010 7:07 pm
Location: Sweden
Full name: Peter Osterlund

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by petero2 »

Here is a version for 64-bit Android that should work at least for Android 7 and later:

https://www.dropbox.com/s/zz6cgi5kxbupd ... api24?dl=1

I needed a small patch to enable ARM NEON vector instructions, which on my Galaxy S10 phone makes the engine about 2.75x faster than without vector instructions. This is still only around 30% of the regular Stockfish speed, so not as good as on Intel hardware.

I don't know how vector instructions affect thermal throttling though. The speedup for longer searches using more cores may be different.

I used the following patch for the nodchip code to enable ARM NEON vector instructions:

Code: Select all

diff --git a/src/Makefile b/src/Makefile
index 2e6c415d..b47aacf0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -312,8 +312,10 @@ endif
 
 ifeq ($(COMP),clang)
 	comp=clang
-	CXX=clang++
-	CXXFLAGS += -pedantic -Wextra -Wshadow
+#	CXX=clang++
+	p=$(ANDROID_BASE)/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin
+	CXX=$(p)/aarch64-linux-android24-clang++
+	CXXFLAGS += -Wall -DIS_ARM
 
 	ifneq ($(KERNEL),Darwin)
 	ifneq ($(KERNEL),OpenBSD)
@@ -388,7 +390,7 @@ ifneq ($(comp),mingw)
 	ifneq ($(OS),Android)
 		# Haiku has pthreads in its libroot, so only link it in on other platforms
 		ifneq ($(KERNEL),Haiku)
-			LDFLAGS += -lpthread
+#			LDFLAGS += -lpthread
 		endif
 	endif
 endif
@@ -532,6 +534,8 @@ ifeq ($(OS), Android)
 	LDFLAGS += -fPIE -pie
 endif
 
+LDFLAGS += -static
+
 ### ==========================================================================
 ### Section 4. Public Targets
 ### ==========================================================================
diff --git a/src/eval/nnue/nnue_common.h b/src/eval/nnue/nnue_common.h
index cffb0098..549e05ca 100644
--- a/src/eval/nnue/nnue_common.h
+++ b/src/eval/nnue/nnue_common.h
@@ -13,6 +13,8 @@
 #include <tmmintrin.h>
 #elif defined(USE_SSE2)
 #include <emmintrin.h>
+#elif defined(IS_ARM)
+#include <arm_neon.h>
 #endif
 
 namespace Eval {
Aleksei
Posts: 25
Joined: Fri Jul 06, 2018 1:14 am
Full name: Aleksei

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by Aleksei »

petero2 wrote: Fri Jul 24, 2020 4:12 pm Here is a version for 64-bit Android that should work at least for Android 7 and later:

https://www.dropbox.com/s/zz6cgi5kxbupd ... api24?dl=1

I needed a small patch to enable ARM NEON vector instructions, which on my Galaxy S10 phone makes the engine about 2.75x faster than without vector instructions. This is still only around 30% of the regular Stockfish speed, so not as good as on Intel hardware.

I don't know how vector instructions affect thermal throttling though. The speedup for longer searches using more cores may be different.

I used the following patch for the nodchip code to enable ARM NEON vector instructions:

Code: Select all

diff --git a/src/Makefile b/src/Makefile
index 2e6c415d..b47aacf0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -312,8 +312,10 @@ endif
 
 ifeq ($(COMP),clang)
 	comp=clang
-	CXX=clang++
-	CXXFLAGS += -pedantic -Wextra -Wshadow
+#	CXX=clang++
+	p=$(ANDROID_BASE)/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin
+	CXX=$(p)/aarch64-linux-android24-clang++
+	CXXFLAGS += -Wall -DIS_ARM
 
 	ifneq ($(KERNEL),Darwin)
 	ifneq ($(KERNEL),OpenBSD)
@@ -388,7 +390,7 @@ ifneq ($(comp),mingw)
 	ifneq ($(OS),Android)
 		# Haiku has pthreads in its libroot, so only link it in on other platforms
 		ifneq ($(KERNEL),Haiku)
-			LDFLAGS += -lpthread
+#			LDFLAGS += -lpthread
 		endif
 	endif
 endif
@@ -532,6 +534,8 @@ ifeq ($(OS), Android)
 	LDFLAGS += -fPIE -pie
 endif
 
+LDFLAGS += -static
+
 ### ==========================================================================
 ### Section 4. Public Targets
 ### ==========================================================================
diff --git a/src/eval/nnue/nnue_common.h b/src/eval/nnue/nnue_common.h
index cffb0098..549e05ca 100644
--- a/src/eval/nnue/nnue_common.h
+++ b/src/eval/nnue/nnue_common.h
@@ -13,6 +13,8 @@
 #include <tmmintrin.h>
 #elif defined(USE_SSE2)
 #include <emmintrin.h>
+#elif defined(IS_ARM)
+#include <arm_neon.h>
 #endif
 
 namespace Eval {
Hi Peter, can you help me with my batch file here? http://talkchess.com/forum3/viewtopic.p ... 09#p853009
User avatar
Thomas Lagershausen
Posts: 328
Joined: Mon Jun 11, 2007 6:59 pm

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by Thomas Lagershausen »

@petero2

You bring the sun back to our live. :P :P :P :P :P :P :P

This is a big step forward in quality of live. :!:

Thx so much ! 8-)
TL
MMarco
Posts: 195
Joined: Sun Apr 12, 2020 1:09 am
Full name: Marc-O Moisan-Plante

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by MMarco »

petero2 wrote: Fri Jul 24, 2020 4:12 pm Here is a version for 64-bit Android that should work at least for Android 7 and later:

https://www.dropbox.com/s/zz6cgi5kxbupd ... api24?dl=1

I needed a small patch to enable ARM NEON vector instructions, which on my Galaxy S10 phone makes the engine about 2.75x faster than without vector instructions. This is still only around 30% of the regular Stockfish speed, so not as good as on Intel hardware.

I don't know how vector instructions affect thermal throttling though. The speedup for longer searches using more cores may be different.

I used the following patch for the nodchip code to enable ARM NEON vector instructions:

Code: Select all

diff --git a/src/Makefile b/src/Makefile
index 2e6c415d..b47aacf0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -312,8 +312,10 @@ endif
 
 ifeq ($(COMP),clang)
 	comp=clang
-	CXX=clang++
-	CXXFLAGS += -pedantic -Wextra -Wshadow
+#	CXX=clang++
+	p=$(ANDROID_BASE)/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin
+	CXX=$(p)/aarch64-linux-android24-clang++
+	CXXFLAGS += -Wall -DIS_ARM
 
 	ifneq ($(KERNEL),Darwin)
 	ifneq ($(KERNEL),OpenBSD)
@@ -388,7 +390,7 @@ ifneq ($(comp),mingw)
 	ifneq ($(OS),Android)
 		# Haiku has pthreads in its libroot, so only link it in on other platforms
 		ifneq ($(KERNEL),Haiku)
-			LDFLAGS += -lpthread
+#			LDFLAGS += -lpthread
 		endif
 	endif
 endif
@@ -532,6 +534,8 @@ ifeq ($(OS), Android)
 	LDFLAGS += -fPIE -pie
 endif
 
+LDFLAGS += -static
+
 ### ==========================================================================
 ### Section 4. Public Targets
 ### ==========================================================================
diff --git a/src/eval/nnue/nnue_common.h b/src/eval/nnue/nnue_common.h
index cffb0098..549e05ca 100644
--- a/src/eval/nnue/nnue_common.h
+++ b/src/eval/nnue/nnue_common.h
@@ -13,6 +13,8 @@
 #include <tmmintrin.h>
 #elif defined(USE_SSE2)
 #include <emmintrin.h>
+#elif defined(IS_ARM)
+#include <arm_neon.h>
 #endif
 
 namespace Eval {
Awesome!! Everything runs fine!! I get 180knps in the startposition on one thread on a Kirin 710. SF 110720 gets 530knps (so I'm at 34%).

Thank you so much.

Would it be possible to built for a net size of 96? Smaller nets are appearing on SF discord and they could be interesting to have on Android as they are faster.
Small 7.5 MB net ,size halfkp_96x32x32 ,Komodo playing level or maybe slightly better,very fast.With binaries.

https://gofile.io/d/1OgCOc
Aleksei
Posts: 25
Joined: Fri Jul 06, 2018 1:14 am
Full name: Aleksei

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by Aleksei »

petero2 wrote: Fri Jul 31, 2020 8:40 pm
Aleksei wrote: Thu Jul 30, 2020 1:53 am I managed to make android version (from nodechip source) using standalone toolchain, and i want to ask you something. Why your compilation is 1.446 KB while mine is 723 KB, also your is faster about 200 nps, did you make it on Linux PC? Or there is another way for engines compiling with NDK's clang?
I used static linking (-static) to make the engine work on more android devices. This makes the compiled file a lot larger though.

The speed difference is probably because I enabled ARM NEON vector instructions (-DIS_ARM). To make this work I had to add an include file to nnue_common.h. For details see:

http://talkchess.com/forum3/viewtopic.p ... 10#p853010
Hi Peter!
So, for use static linking i have to change flag in my batch from -static-libstdc++ to -static, add -DIS_ARM flag, and i need to add in to Makefile, right?

Code: Select all

+#	CXX=clang++
+	p=$(ANDROID_BASE)/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin
+	CXX=$(p)/aarch64-linux-android24-clang++
+	CXXFLAGS += -Wall -DIS_ARM

+#			LDFLAGS += -lpthread

+#elif defined(IS_ARM)
+#include <arm_neon.h>
RogerC
Posts: 41
Joined: Tue Oct 29, 2019 8:33 pm
Location: French Polynesia
Full name: Roger C.

Re: Is in this world really no compile of Sf-NNUE for arm-8?

Post by RogerC »

petero2 wrote: Fri Jul 24, 2020 4:12 pm Here is a version for 64-bit Android that should work at least for Android 7 and later:

https://www.dropbox.com/s/zz6cgi5kxbupd ... api24?dl=1

I needed a small patch to enable ARM NEON vector instructions, which on my Galaxy S10 phone makes the engine about 2.75x faster than without vector instructions. This is still only around 30% of the regular Stockfish speed, so not as good as on Intel hardware.

I don't know how vector instructions affect thermal throttling though. The speedup for longer searches using more cores may be different.
Hi petero2, your Android compilation that enable NEON vector instructions and NNUE nets is great !
Would you please compile the SFdev version of August 8 that is 20-30 elo points added to NNUE nets ? Thank you very much.