Skip to content

Commit

Permalink
Merge branch 'Main_SFNNv9.6.3' into 0425_Main_SFNNv9.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim26 authored May 1, 2024
2 parents be14233 + 0f7224e commit 9552176
Show file tree
Hide file tree
Showing 21 changed files with 360 additions and 56 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/SFMnpsNoPGO_ArmWinBinariesUpload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: SFNNv6_avx2Upload
on:
workflow_dispatch:
jobs:
SFnpsArmWinBuilds:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
env:
COMPILER: ${{ matrix.config.compiler }}
COMP: ${{ matrix.config.comp }}
strategy:
matrix:
config:
- name: Windows 2022 Mingw-w64 GCC x86_64
os: windows-2022
compiler: g++
comp: mingw
run_win11_build: true
msys_sys: mingw64
msys_env: x86_64-gcc
shell: msys2 {0}

defaults:
run:
working-directory: src
shell: ${{ matrix.config.shell }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup msys and install required packages
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.config.msys_sys }}
install: mingw-w64-${{ matrix.config.msys_env }} make git

- name: Download both networks from the fishtest framework
run: |
make net
- name: win11 build
if: ${{ matrix.config.run_win11_build }}
run: |
make clean
make -j3 profile-build ARCH=x86-64-avx2 COMP=$COMP
make strip ARCH=x86-64-avx2 COMP=$COMP
cp stockfish.exe ../SFNNv6_avx2.exe
- uses: xresloader/upload-to-github-Release@v1
if: ${{ matrix.config.run_win11_build }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
overwrite: false
file: "SFNNv6_avx2.exe"
update_latest_release: false

- uses: actions/upload-artifact@v4
if: ${{ matrix.config.run_win11_build }}
with:
name: SFNNv6_avx2
path: SFNNv6_avx2.exe
101 changes: 101 additions & 0 deletions .github/workflows/SFnps_ArmWinBinariesUpload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: SFnpsArmWinBinariesUpload
on:
workflow_dispatch:
jobs:
SFnpsArmTest:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
env:
COMPILER: ${{ matrix.config.compiler }}
COMP: ${{ matrix.config.comp }}
strategy:
matrix:
config:
- name: Ubuntu 22.04 NDK armv8
os: ubuntu-22.04
compiler: aarch64-linux-android21-clang++
comp: ndk
run_armv8_tests: true
shell: bash {0}

- name: Windows 2022 Mingw-w64 GCC x86_64
os: windows-2022
compiler: g++
comp: mingw
run_win11_tests: true
msys_sys: mingw64
msys_env: x86_64-gcc
shell: msys2 {0}

defaults:
run:
working-directory: src
shell: ${{ matrix.config.shell }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup msys and install required packages
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.config.msys_sys }}
install: mingw-w64-${{ matrix.config.msys_env }} make git

- name: Download the used network from the fishtest framework
run: make net

- name: Test armv8 build
if: ${{ matrix.config.run_armv8_tests }}
run: |
export PATH=$ANDROID_NDK_HOME:$PATH
export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
cp nn-*.nnue ../jni
cd ../jni
cp Application_v8.mk Application.mk
ndk-build
cd ../libs/arm64-v8a
cp Stockfish ../../SFnps_armv8
- uses: xresloader/[email protected]
if: ${{ matrix.config.run_armv8_tests }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
overwrite: false
file: "SFnps_armv8"
update_latest_release: false

- uses: actions/upload-artifact@v4
if: ${{ matrix.config.run_armv8_tests }}
with:
name: SFnps-armv8
path: SFnps_armv8
#path: /home/runner/work/StockfishNPS/StockfishNPS/SFnps_armv8

- name: win11 build
if: ${{ matrix.config.run_win11_tests }}
run: |
make clean
make -j profile-build ARCH=x86-64-modern COMP=$COMP
make strip ARCH=x86-64-modern COMP=$COMP
cp stockfish.exe ../SFnps_modern.exe
- uses: xresloader/[email protected]
if: ${{ matrix.config.run_win11_tests }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
overwrite: false
file: "SFnps_modern.exe"
update_latest_release: false

- uses: actions/upload-artifact@v4
if: ${{ matrix.config.run_win11_tests }}
with:
name: SFnps-modern
path: SFnps_modern.exe
#path: D:\a\StockfishNPS\StockfishNPS\SFnps_modern.exe

18 changes: 18 additions & 0 deletions jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := Stockfish
LOCAL_C_INCLUDES :=
LOCAL_SRC_FILES := $(wildcard ../src/*.cpp ../src/nnue/*.cpp ../src/nnue/features/*.cpp ../src/syzygy/*.cpp)
LOCAL_CFLAGS += -std=c++17 -O3 -flto -fexperimental-new-pass-manager -Wfatal-errors -Wall -Wextra -Wshadow -DNNUE_EMBEDDING_OFF -DUSE_PTHREADS
LOCAL_CPPFLAGS +=
LOCAL_CPP_FEATURES :=

ifeq ($(TARGET_ARCH_ABI), arm64-v8a)
LOCAL_CFLAGS += -DIS_64BIT -DUSE_NEON=8 -DUSE_POPCNT
endif
ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
LOCAL_CFLAGS += -DUSE_NEON=7 -DUSE_POPCNT
endif

LOCAL_LDFLAGS +=
include $(BUILD_EXECUTABLE)
3 changes: 3 additions & 0 deletions jni/Application_v7.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_ABI := armeabi-v7a
APP_PLATFORM := android-19
APP_STL := c++_static
3 changes: 3 additions & 0 deletions jni/Application_v8.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_ABI := arm64-v8a
APP_PLATFORM := android-21
APP_STL := c++_static
21 changes: 14 additions & 7 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Updated Makefile for StockfishNPS building on Termux
# works for clang, gcc, ndk, armv8, armv7, and pgo.
#
#
#
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
# Copyright (C) 2004-2024 The Stockfish developers (see AUTHORS file)
#
Expand Down Expand Up @@ -387,7 +392,7 @@ ifeq ($(MAKELEVEL),0)
export ENV_LDFLAGS := $(LDFLAGS)
endif

CXXFLAGS = $(ENV_CXXFLAGS) -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
CXXFLAGS = $(ENV_CXXFLAGS) -Wall -Wcast-qual -fno-exceptions -std=c++17 -DNNUE_EMBEDDING_OFF $(EXTRACXXFLAGS)
DEPENDFLAGS = $(ENV_DEPENDFLAGS) -std=c++17
LDFLAGS = $(ENV_LDFLAGS) $(EXTRALDFLAGS)

Expand All @@ -398,12 +403,12 @@ endif
ifeq ($(COMP),gcc)
comp=gcc
CXX=g++
CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations -flax-vector-conversions

ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
ifeq ($(OS),Android)
CXXFLAGS += -m$(bits)
LDFLAGS += -m$(bits)
CXXFLAGS +=
LDFLAGS += -lgcov -static-libstdc++
endif
ifeq ($(ARCH),riscv64)
CXXFLAGS += -latomic
Expand Down Expand Up @@ -475,7 +480,7 @@ ifeq ($(COMP),clang)
ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
ifeq ($(OS),Android)
CXXFLAGS += -m$(bits)
LDFLAGS += -m$(bits)
LDFLAGS += -m$(bits) -static-libstdc++
endif
ifeq ($(ARCH),riscv64)
CXXFLAGS += -latomic
Expand Down Expand Up @@ -595,7 +600,7 @@ ifeq ($(optimize),yes)

ifeq ($(comp),gcc)
ifeq ($(OS), Android)
CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
CXXFLAGS += -fno-gcse -march=native
endif
endif

Expand All @@ -610,7 +615,7 @@ ifeq ($(optimize),yes)
endif
endif
endif

### -mcpu=native
ifeq ($(comp),clang)
clangmajorversion := $(shell $(CXX) -dumpversion 2>/dev/null | cut -f1 -d.)
ifeq ($(shell expr $(clangmajorversion) \< 16),1)
Expand Down Expand Up @@ -968,6 +973,8 @@ endef
net:
$(call netvariables, EvalFileDefaultNameBig)
$(call fetch_network)
$(call netvariables, EvalFileDefaultNameMedium)
$(call fetch_network)
$(call netvariables, EvalFileDefaultNameSmall)
$(call fetch_network)

Expand Down
18 changes: 13 additions & 5 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Engine::Engine(std::string path) :
states(new std::deque<StateInfo>(1)),
networks(NN::Networks(
NN::NetworkBig({EvalFileDefaultNameBig, "None", ""}, NN::EmbeddedNNUEType::BIG),
NN::NetworkMedium({EvalFileDefaultNameMedium, "None", ""}, NN::EmbeddedNNUEType::MEDIUM),
NN::NetworkSmall({EvalFileDefaultNameSmall, "None", ""}, NN::EmbeddedNNUEType::SMALL))) {
pos.set(StartFEN, false, &states->back());
capSq = SQ_NONE;
Expand Down Expand Up @@ -136,24 +137,31 @@ void Engine::set_ponderhit(bool b) { threads.main_manager()->ponder = b; }
// network related

void Engine::verify_networks() const {
networks.big.verify(options["EvalFile"]);
networks.big.verify(options["EvalFileBig"]);
networks.medium.verify(options["EvalFileMedium"]);
networks.small.verify(options["EvalFileSmall"]);
}

void Engine::load_networks() {
networks.big.load(binaryDirectory, options["EvalFile"]);
networks.big.load(binaryDirectory, options["EvalFileBig"]);
networks.medium.load(binaryDirectory, options["EvalFileMedium"]);
networks.small.load(binaryDirectory, options["EvalFileSmall"]);
}

void Engine::load_big_network(const std::string& file) { networks.big.load(binaryDirectory, file); }

void Engine::load_big_network(const std::string& file) {
networks.big.load(binaryDirectory, file);
}
void Engine::load_medium_network(const std::string& file) {
networks.medium.load(binaryDirectory, file);
}
void Engine::load_small_network(const std::string& file) {
networks.small.load(binaryDirectory, file);
}

void Engine::save_network(const std::pair<std::optional<std::string>, std::string> files[2]) {
networks.big.save(files[0].first);
networks.small.save(files[1].first);
networks.medium.save(files[1].first);
//networks.small.save(files[1].first); //comment out .medium. to save small
}

// utility functions
Expand Down
1 change: 1 addition & 0 deletions src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Engine {
void verify_networks() const;
void load_networks();
void load_big_network(const std::string& file);
void load_medium_network(const std::string& file);
void load_small_network(const std::string& file);
void save_network(const std::pair<std::optional<std::string>, std::string> files[2]);

Expand Down
Loading

0 comments on commit 9552176

Please sign in to comment.