martinnovaak / motor

UCI chess engine written in C++
10 stars 2 forks source link

Makefile or Cmakelist? #72

Closed rwbc closed 2 months ago

rwbc commented 2 months ago

Would you mind to provide also either a makefile or a cmakelist for those, who don't use MSVC?

Guenther (RWBC)

martinnovaak commented 2 months ago

Hello, I added a CMakeList to the project with instructions on how to compile the engine using cmake or just using clang.

Let me know if there are any problems with compilation.

Martin

rwbc commented 2 months ago

Thanks, but yes a lot of problems so far. (too much to look into it this night)

Admin@ESPRESSO CLANG64 ~/motor
# cmake -S . -B build
-- Building for: Ninja
-- The C compiler identification is Clang 17.0.6
-- The CXX compiler identification is Clang 17.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/clang64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/clang64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/msys64/home/Admin/motor/build

Admin@ESPRESSO CLANG64 ~/motor
# cd build

Admin@ESPRESSO CLANG64 ~/motor/build
# ninja -j 2
[4/5] Building CXX object CMakeFiles/motor.dir/main.cpp.obj
FAILED: CMakeFiles/motor.dir/main.cpp.obj
C:\msys64\clang64\bin\c++.exe   -march=native -std=gnu++20 -MD -MT CMakeFiles/motor.dir/main.cpp.obj -MF CMakeFiles\motor.dir\main.cpp.obj.d @CMakeFiles\motor.dir\main.cpp.obj.modmap -o CMakeFiles/motor.dir/main.cpp.obj -c C:/msys64/home/Admin/motor/main.cpp
In file included from C:/msys64/home/Admin/motor/main.cpp:1:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:7:
In file included from C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:10:
In file included from C:/msys64/home/Admin/motor/cli/../search/../evaluation/evaluation.hpp:4:
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:127:39: error: unknown type name '__m256i'
  127 |     std::int32_t horizontal_sum(const __m256i input_sum) {
      |                                       ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:114:20: error: use of undeclared identifier '_mm256_setzero_si256'
  114 |         auto sum = _mm256_setzero_si256();
      |                    ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:115:20: error: use of undeclared identifier '_mm256_setzero_si256'
  115 |         auto min = _mm256_setzero_si256();
      |                    ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:116:20: error: use of undeclared identifier '_mm256_set1_epi16'
  116 |         auto max = _mm256_set1_epi16(QA);
      |                    ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:118:72: error: unknown type name '__m256i'
  118 |             auto us_vector = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(accumulator + i * CHUNK));
      |                                                                        ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:118:30: error: use of undeclared identifier '_mm256_loadu_si256'
  118 |             auto us_vector = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(accumulator + i * CHUNK));
      |                              ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:119:74: error: unknown type name '__m256i'
  119 |             auto weights_vec = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(weights + i * CHUNK));
      |                                                                          ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:119:32: error: use of undeclared identifier '_mm256_loadu_si256'
  119 |             auto weights_vec = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(weights + i * CHUNK));
      |                                ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:128:9: error: unknown type name '__m256i'
  128 |         __m256i horizontal_sum_256 = _mm256_hadd_epi32(input_sum, input_sum);
      |         ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:129:9: error: unknown type name '__m128i'
  129 |         __m128i upper_128 = _mm256_extracti128_si256(horizontal_sum_256, 1);
      |         ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:130:9: error: unknown type name '__m128i'
  130 |         __m128i combined_128 = _mm_add_epi32(upper_128, _mm256_castsi256_si128(horizontal_sum_256));
      |         ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:131:9: error: unknown type name '__m128i'
  131 |         __m128i horizontal_sum_128 = _mm_hadd_epi32(combined_128, combined_128);
      |         ^
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:148:60: warning: left operand of comma operator has no effect [-Wunused-value]
  148 |                 network.update_accumulator<Operation::Set>(piece, side, square);
      |                                                            ^~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:148:67: warning: left operand of comma operator has no effect [-Wunused-value]
  148 |                 network.update_accumulator<Operation::Set>(piece, side, square);
      |                                                                   ^~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:159:52: warning: left operand of comma operator has no effect [-Wunused-value]
  159 |         network.update_accumulator<Operation::Set>(piece, our_color, square);
      |                                                    ^~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:159:59: warning: left operand of comma operator has no effect [-Wunused-value]
  159 |         network.update_accumulator<Operation::Set>(piece, our_color, square);
      |                                                           ^~~~~~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:168:54: warning: left operand of comma operator has no effect [-Wunused-value]
  168 |         network.update_accumulator<Operation::Unset>(piece, our_color, square);
      |                                                      ^~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:168:61: warning: left operand of comma operator has no effect [-Wunused-value]
  168 |         network.update_accumulator<Operation::Unset>(piece, our_color, square);
      |                                                             ^~~~~~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:177:52: warning: left operand of comma operator has no effect [-Wunused-value]
  177 |         network.update_accumulator<Operation::Set>(piece, our_color, square);
      |                                                    ^~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:177:59: warning: left operand of comma operator has no effect [-Wunused-value]
  177 |         network.update_accumulator<Operation::Set>(piece, our_color, square);
      |                                                           ^~~~~~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:178:54: warning: left operand of comma operator has no effect [-Wunused-value]
  178 |         network.update_accumulator<Operation::Unset>(captured_piece, their_color, square);
      |                                                      ^~~~~~~~~~~~~~
C:/msys64/home/Admin/motor/cli/../search/../evaluation/nnue.hpp:178:70: warning: left operand of comma operator has no effect [-Wunused-value]
  178 |         network.update_accumulator<Operation::Unset>(captured_piece, their_color, square);
      |                                                                      ^~~~~~~~~~~
In file included from C:/msys64/home/Admin/motor/main.cpp:1:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:7:
In file included from C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:10:
C:/msys64/home/Admin/motor/cli/../search/../evaluation/evaluation.hpp:8:20: error: missing 'template' keyword prior to dependent template name 'evaluate'
    8 |     return network.evaluate<color>();
      |                    ^       ~~~~~~~
In file included from C:/msys64/home/Admin/motor/main.cpp:1:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:7:
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:22:5: error: use of undeclared identifier 'Bound'; did you mean 'round'?
   22 |     Bound flag = Bound::UPPER;
      |     ^~~~~
      |     round
C:/msys64/clang64/include/c++/v1/math.h:1570:1: note: 'round' declared here
 1570 | round(_A1 __x) _NOEXCEPT
      | ^
In file included from C:/msys64/home/Admin/motor/main.cpp:1:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:7:
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:22:10: error: expected ';' after expression
   22 |     Bound flag = Bound::UPPER;
      |          ^
      |          ;
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:22:5: error: reference to overloaded function could not be resolved; did you mean to call it?
   22 |     Bound flag = Bound::UPPER;
      |     ^~~~~
C:/msys64/clang64/include/c++/v1/math.h:1570:1: note: possible target for call
 1570 | round(_A1 __x) _NOEXCEPT
      | ^
In file included from C:/msys64/home/Admin/motor/main.cpp:1:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:7:
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:22:11: error: use of undeclared identifier 'flag'
   22 |     Bound flag = Bound::UPPER;
      |           ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:22:18: error: use of undeclared identifier 'Bound'
   22 |     Bound flag = Bound::UPPER;
      |                  ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:25:11: error: unknown type name 'TT_entry'
   25 |     const TT_entry& tt_entry = tt[zobrist_key];
      |           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
10 warnings and 20 errors generated.
ninja: build stopped: subcommand failed.

Guenther

martinnovaak commented 2 months ago

Does you cpu support AVX2? If so, can you try adding this include to the evaluation/nnue.hpp file? #include <immintrin.h> I see that I forgot to put it there. But I'm not sure if it's causing you errors, because it works fine for me without it.

Martin

rwbc commented 2 months ago

Yes it does. The missing header cured the intrinsic errors part.

Now I am looking for a solution (which might be also other missing includes) for the lots of error: use of undeclared identifier....

Guenther

P.S. including <iostream> and <cmath> headers in search.hpp and quiescence_search.hpp surprisingly did not help.

# ninja -j 2
[4/5] Building CXX object CMakeFiles/motor.dir/main.cpp.obj
FAILED: CMakeFiles/motor.dir/main.cpp.obj
C:\msys64\clang64\bin\c++.exe   -march=native -std=gnu++20 -MD -MT CMakeFiles/motor.dir/main.cpp.obj -MF CMakeFiles\motor.dir\main.cpp.obj.d @CMakeFiles\motor.dir\main.cpp.obj.modmap -o CMakeFiles/motor.dir/main.cpp.obj -c C:/msys64/home/Admin/motor/main.cpp
In file included from C:/msys64/home/Admin/motor/main.cpp:2:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:12:
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:27:5: error: use of undeclared identifier 'Bound'; did you mean 'round'?
   27 |     Bound flag = Bound::UPPER;
      |     ^~~~~
      |     round
C:/msys64/clang64/include/c++/v1/math.h:1570:1: note: 'round' declared here
 1570 | round(_A1 __x) _NOEXCEPT
      | ^
In file included from C:/msys64/home/Admin/motor/main.cpp:2:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:12:
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:27:10: error: expected ';' after expression
   27 |     Bound flag = Bound::UPPER;
      |          ^
      |          ;
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:27:5: error: reference to overloaded function could not be resolved; did you mean to call it?
   27 |     Bound flag = Bound::UPPER;
      |     ^~~~~
C:/msys64/clang64/include/c++/v1/math.h:1570:1: note: possible target for call
 1570 | round(_A1 __x) _NOEXCEPT
      | ^
In file included from C:/msys64/home/Admin/motor/main.cpp:2:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
In file included from C:/msys64/home/Admin/motor/cli/../search/search.hpp:12:
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:27:11: error: use of undeclared identifier 'flag'
   27 |     Bound flag = Bound::UPPER;
      |           ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:27:18: error: use of undeclared identifier 'Bound'
   27 |     Bound flag = Bound::UPPER;
      |                  ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:30:11: error: unknown type name 'TT_entry'
   30 |     const TT_entry& tt_entry = tt[zobrist_key];
      |           ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:30:32: error: use of undeclared identifier 'tt'
   30 |     const TT_entry& tt_entry = tt[zobrist_key];
      |                                ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:35:32: error: use of undeclared identifier 'Bound'
   35 |         if ((tt_entry.bound == Bound::EXACT) ||
      |                                ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:36:32: error: use of undeclared identifier 'Bound'
   36 |             (tt_entry.bound == Bound::LOWER && tt_eval >= beta) ||
      |                                ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:37:32: error: use of undeclared identifier 'Bound'
   37 |             (tt_entry.bound == Bound::UPPER && tt_eval <= alpha)) {
      |                                ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:64:9: error: use of undeclared identifier 'tt'
   64 |         tt.prefetch(chessboard.get_hash_key());
      |         ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:76:13: error: use of undeclared identifier 'flag'
   76 |             flag = Bound::LOWER;
      |             ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:76:20: error: use of undeclared identifier 'Bound'
   76 |             flag = Bound::LOWER;
      |                    ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:82:13: error: use of undeclared identifier 'flag'
   82 |             flag = Bound::EXACT;
      |             ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:82:20: error: use of undeclared identifier 'Bound'
   82 |             flag = Bound::EXACT;
      |                    ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:86:5: error: use of undeclared identifier 'tt'
   86 |     tt[zobrist_key] = { flag, 0, eval, best_move, zobrist_key };
      |     ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:86:25: error: use of undeclared identifier 'flag'
   86 |     tt[zobrist_key] = { flag, 0, eval, best_move, zobrist_key };
      |                         ^
In file included from C:/msys64/home/Admin/motor/main.cpp:2:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
C:/msys64/home/Admin/motor/cli/../search/search.hpp:71:16: error: no matching function for call to 'quiescence_search'
   71 |         return quiescence_search<color>(chessboard, data, alpha, beta);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/home/Admin/motor/cli/../search/search.hpp:141:48: note: in instantiation of function template specialization 'alpha_beta<White, NodeType::Null>' requested here
  141 |                 std::int16_t nullmove_score = -alpha_beta<enemy_color, NodeType::Null>(chessboard, data, -beta, -alpha, depth - R);
      |                                                ^
C:/msys64/home/Admin/motor/cli/../search/search.hpp:237:22: note: in instantiation of function template specialization 'alpha_beta<Black, NodeType::PV>' requested here
  237 |             score = -alpha_beta<enemy_color, NodeType::PV>(chessboard, data, -beta, -alpha, depth - 1 + ext);
      |                      ^
C:/msys64/home/Admin/motor/cli/../search/search.hpp:366:21: note: in instantiation of function template specialization 'alpha_beta<White, NodeType::Root>' requested here
  366 |             score = alpha_beta<color, NodeType::Root>(chessboard, data, -10'000, 10'000, depth);
      |                     ^
C:/msys64/home/Admin/motor/cli/../search/search.hpp:407:9: note: in instantiation of function template specialization 'iterative_deepening<White>' requested here
  407 |         iterative_deepening<White>(chessboard, data, info.max_depth);
      |         ^
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:18:14: note: candidate template ignored: substitution failure [with color = White]
   18 | std::int16_t quiescence_search(board & chessboard, search_data & data, std::int16_t alpha, std::int16_t beta) {
      |              ^
In file included from C:/msys64/home/Admin/motor/main.cpp:2:
In file included from C:/msys64/home/Admin/motor/cli/uci.hpp:13:
C:/msys64/home/Admin/motor/cli/../search/search.hpp:123:43: error: no matching function for call to 'quiescence_search'
  123 |                 std::int16_t razor_eval = quiescence_search<color>(chessboard, data, alpha, beta);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/home/Admin/motor/cli/../search/quiescence_search.hpp:18:14: note: candidate template ignored: substitution failure [with color = White]
   18 | std::int16_t quiescence_search(board & chessboard, search_data & data, std::int16_t alpha, std::int16_t beta) {
      |              ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
ninja: build stopped: subcommand failed.
martinnovaak commented 2 months ago

Thanks for sending compilation errors. I pushed changes that hopefully fix these problems. I was using CMake through Visual Studio and it didn't have any problems with compiling.

I tried to install CMake separately and I started to get the same errors like you. I am still getting multiple warnings that I do not get in Visual Studio ..., but hopefully it might work now.

Can you try to compile new pushed changes and report if it works now?

Martin

rwbc commented 2 months ago

All problems solved Martin! Thanks for the quick change. :)

Guenther

martinnovaak commented 2 months ago

That's great. Thank you for your help, Guenther.

Martin