Skip to content

Commit

Permalink
Added StackSize UCI option.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpldgr committed Nov 10, 2024
1 parent fbde758 commit 19074ea
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/stacksize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"include": [
{"os_name": "windows", "arch": "x86-64", "run_os": "windows-2022", "COMPCXX": "g++", "COMP": "mingw", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false, "EXT": ".exe"},
{"os_name": "windows", "arch": "x86-64-bmi2", "run_os": "windows-2022", "COMPCXX": "g++", "COMP": "mingw", "build_std": true, "build_lb": true, "build_all": true, "build_lb_all": true, "EXT": ".exe"},
{"os_name": "windows", "arch": "x86-64-modern", "run_os": "windows-2022", "COMPCXX": "g++", "COMP": "mingw", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false, "EXT": ".exe"},
{"os_name": "ubuntu", "arch": "x86-64", "run_os": "ubuntu-20.04", "COMPCXX": "g++", "COMP": "gcc", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false},
{"os_name": "ubuntu", "arch": "x86-64-bmi2", "run_os": "ubuntu-20.04", "COMPCXX": "g++", "COMP": "gcc", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false},
{"os_name": "ubuntu", "arch": "x86-64-modern", "run_os": "ubuntu-20.04", "COMPCXX": "g++", "COMP": "gcc", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false},
{"os_name": "macos", "arch": "x86-64", "run_os": "macos-13", "COMPCXX": "clang++", "COMP": "clang", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false},
{"os_name": "macos", "arch": "x86-64-bmi2", "run_os": "macos-13", "COMPCXX": "clang++", "COMP": "clang", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false},
{"os_name": "macos", "arch": "x86-64-modern", "run_os": "macos-13", "COMPCXX": "clang++", "COMP": "clang", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false},
{"os_name": "macos-m1", "arch": "apple-silicon", "run_os": "macos-14", "COMPCXX": "clang++", "COMP": "clang", "build_std": false, "build_lb": false, "build_all": false, "build_lb_all": false}
]
}
81 changes: 81 additions & 0 deletions .github/workflows/stacksize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: branch(stacksize)

env:
EXE_NAME: fairy-stockfish
EXE_NAME_ALL: fairy-stockfish-all
EXE_NAME_LB: fairy-stockfish-largeboards
EXE_NAME_LB_ALL: fairy-stockfish-largeboards-all

on:
push:
branches: [ stacksize ]
pull_request:
branches: [ stacksize ]
workflow_dispatch:
branches: [ stacksize ]

jobs:
configure:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4

- name: Set matrix data
id: set-matrix
run: |
echo "build matrix:" >> $GITHUB_STEP_SUMMARY
echo "matrix=$(jq -c . < .github/workflows/stacksize.json)" >> $GITHUB_STEP_SUMMARY
echo "matrix=$(jq -c . < .github/workflows/stacksize.json)" >> $GITHUB_OUTPUT
build:
needs: configure
runs-on: ${{matrix.run_os}}
strategy:
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
steps:
- uses: actions/checkout@v4

- name: Check compiler
run: ${{ matrix.compcxx }} -v

- name: make
if: ${{ matrix.build_std == true }}
run: cd src && make clean && make -j build COMP=${{ matrix.comp }} ARCH=${{ matrix.arch }} EXE=${{ env.EXE_NAME }}_${{ matrix.arch }}${{ matrix.ext }} && strip ${{ env.EXE_NAME }}_${{ matrix.arch }}${{ matrix.ext }}

- uses: actions/upload-artifact@v4
if: ${{ matrix.build_std == true }}
with:
name: ${{ matrix.os_name }} ${{ env.EXE_NAME }}_${{ matrix.arch }}
path: src/${{ env.EXE_NAME }}_${{ matrix.arch }}${{ matrix.ext }}

- name: make largeboards
if: ${{ matrix.build_lb == true }}
run: cd src && make clean && make -j build COMP=${{ matrix.comp }} ARCH=${{ matrix.arch }} EXE=${{ env.EXE_NAME_LB }}_${{ matrix.arch }}${{ matrix.ext }} largeboards=yes && strip ${{ env.EXE_NAME_LB }}_${{ matrix.arch }}${{ matrix.ext }}

- uses: actions/upload-artifact@v4
if: ${{ matrix.build_lb == true }}
with:
name: ${{ matrix.os_name }} ${{ env.EXE_NAME_LB }}_${{ matrix.arch }}
path: src/${{ env.EXE_NAME_LB }}_${{ matrix.arch }}${{ matrix.ext }}

- name: make all
if: ${{ matrix.build_all == true }}
run: cd src && make clean && make -j build COMP=${{ matrix.comp }} ARCH=${{ matrix.arch }} EXE=${{ env.EXE_NAME_ALL }}_${{ matrix.arch }}${{ matrix.ext }} all=yes && strip ${{ env.EXE_NAME_ALL }}_${{ matrix.arch }}${{ matrix.ext }}

- uses: actions/upload-artifact@v4
if: ${{ matrix.build_all == true }}
with:
name: ${{ matrix.os_name }} ${{ env.EXE_NAME_ALL }}_${{ matrix.arch }}
path: src/${{ env.EXE_NAME_ALL }}_${{ matrix.arch }}${{ matrix.ext }}

- name: make largeboards all
if: ${{ matrix.build_lb_all == true }}
run: cd src && make clean && make -j build COMP=${{ matrix.comp }} ARCH=${{ matrix.arch }} EXE=${{ env.EXE_NAME_LB_ALL }}_${{ matrix.arch }}${{ matrix.ext }} largeboards=yes all=yes && strip ${{ env.EXE_NAME_LB_ALL }}_${{ matrix.arch }}${{ matrix.ext }}

- uses: actions/upload-artifact@v4
if: ${{ matrix.build_lb_all == true }}
with:
name: ${{ matrix.os_name }} ${{ env.EXE_NAME_LB_ALL }}_${{ matrix.arch }}
path: src/${{ env.EXE_NAME_LB_ALL }}_${{ matrix.arch }}${{ matrix.ext }}
2 changes: 2 additions & 0 deletions src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

namespace Stockfish {

size_t TH_STACK_SIZE = 8 * 1024 * 1024; // Default size.

ThreadPool Threads; // Global object


Expand Down
2 changes: 2 additions & 0 deletions src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

namespace Stockfish {

extern size_t TH_STACK_SIZE;

/// Thread class keeps together all the thread-related stuff. We use
/// per-thread pawn and material hash tables so that once we get a
/// pointer to an entry its life time is unlimited and we don't have
Expand Down
4 changes: 3 additions & 1 deletion src/thread_win32_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
#if defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(USE_PTHREADS)

#include <pthread.h>
#include <iostream>

namespace Stockfish {

static const size_t TH_STACK_SIZE = 8 * 1024 * 1024;
extern size_t TH_STACK_SIZE;

template <class T, class P = std::pair<T*, void(T::*)()>>
void* start_routine(void* ptr)
Expand All @@ -54,6 +55,7 @@ class NativeThread {
pthread_attr_t attr_storage, *attr = &attr_storage;
pthread_attr_init(attr);
pthread_attr_setstacksize(attr, TH_STACK_SIZE);
std::cout << "Stack Size: " << TH_STACK_SIZE << "\n";
pthread_create(&thread, attr, start_routine<T>, new P(obj, fun));
}
void join() { pthread_join(thread, NULL); }
Expand Down
2 changes: 1 addition & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ constexpr int SQUARE_BITS = 6;
#endif

//When defined, move list will be stored in heap. Delete this if you want to use stack to store move list. Using stack can cause overflow (Segmentation Fault) when the search is too deep.
#define USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST
//#define USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST

#ifdef ALLVARS
constexpr int MAX_MOVES = 8192;
Expand Down
6 changes: 6 additions & 0 deletions src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void init_variant(const Variant* v) {
void on_clear_hash(const Option&) { Search::clear(); }
void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
void on_logger(const Option& o) { start_logger(o); }
#if defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(USE_PTHREADS)
void on_stack_size(const Option& o) { TH_STACK_SIZE=size_t(o)*1024*1024; }
#endif
void on_threads(const Option& o) { Threads.set(size_t(o)); }
void on_tb_path(const Option& o) { Tablebases::init(o); }

Expand Down Expand Up @@ -182,6 +185,9 @@ void init(OptionsMap& o) {

o["Debug Log File"] << Option("", on_logger);
o["Threads"] << Option(1, 1, 512, on_threads);
#if defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(USE_PTHREADS)
o["StackSize"] << Option(8, 1, 64, on_stack_size);
#endif
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
o["Clear Hash"] << Option(on_clear_hash);
o["Ponder"] << Option(false);
Expand Down

0 comments on commit 19074ea

Please sign in to comment.