lithander / Leorik

Leorik is a strong, open-source UCI chess engine written in C#
MIT License
25 stars 3 forks source link

Compilation for old hardware possible? #1

Open rwbc opened 2 years ago

rwbc commented 2 years ago

Hi Thomas,

I downloaded Leorik and noticed it misses a dll on my old quadcore with old WIN7. Downloading the dll threw an exception.

Then I remembered how I compiled Minimal once and tried to compile it the same way. It told me I have to use DotNet6.0 (since I was still on 5.x), which I downloaded and I could finally build it successfully from cmd. (I just had to remove the old NuGet.config file after asking 'Dr. Google' for this problem:

C:\Program Files\dotnet\sdk\6.0.200\NuGet.targets(564,5): error :   Data at the root level is invalid. Line 1, position 1. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Leorik.Core.csproj]
C:\Program Files\dotnet\sdk\6.0.200\NuGet.targets(564,5): error : NuGet.Config weist kein gültiges XML-Format auf. Pfad: "C:\Users\Guenther Simon\AppData\Roaming\NuGet\NuGet.Config". [C:\msys64\home\Guenther Simon\Leorik\Leorik.Perft\Leorik
.Perft.csproj]

solution => https://medium.com/@vaishali.fresher/nuget-config-is-not-valid-xml-4967e4d66470)

C:\msys64\home\Guenther Simon\Leorik>dotnet build -c Release
Microsoft (R)-Build-Engine, Version 17.1.0+ae57d105c für .NET
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

  Wiederherzustellende Projekte werden ermittelt...
  "C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Leorik.Core.csproj" wiederhergestellt (in "512 ms").
  "C:\msys64\home\Guenther Simon\Leorik\Leorik.Perft\Leorik.Perft.csproj" wiederhergestellt (in "556 ms").
  "C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Leorik.Test.csproj" wiederhergestellt (in "556 ms").
  "C:\msys64\home\Guenther Simon\Leorik\Leorik.Search\Leorik.Search.csproj" wiederhergestellt (in "556 ms").
  "C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj" wiederhergestellt (in "3 ms").
C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Move.cs(5,28): warning CS0660: "Move" definiert den Operator == oder !=, aber überschreibt Object.Equals(object o) nicht. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Leorik.Core.csproj]

C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Move.cs(5,28): warning CS0661: "Move" definiert den Operator == oder !=, aber überschreibt Object.GetHashCode() nicht. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Leorik.Core.csproj]
  Leorik.Core -> C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\bin\Release\net6.0\Leorik.Core.dll
C:\msys64\home\Guenther Simon\Leorik\Leorik.Search\Transpositions.cs(64,16): warning CS8618: Non-Nullable-Feld "_table" muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie eine Deklaration von "Feld" als Nulla
ble. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Search\Leorik.Search.csproj]
  Leorik.Search -> C:\msys64\home\Guenther Simon\Leorik\Leorik.Search\bin\Release\net6.0\Leorik.Search.dll
  Leorik.Perft -> C:\msys64\home\Guenther Simon\Leorik\Leorik.Perft\bin\Release\net6.0\Leorik.Perft.dll
C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(87,30): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(130,23): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]

C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(8,35): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(9,29): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Program.cs(49,70): warning CS8604: Mögliches Nullverweisargument für den Parameter "epd" in "int Program.ParseEpd(string epd, out BoardState board, out List<Move> bestMoves)". [C:\msys64\home
\Guenther Simon\Leorik\Leorik.Test\Leorik.Test.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Program.cs(132,30): warning CS8600: Das NULL-Literal oder ein möglicher NULL-Wert wird in einen Non-Nullable-Typ konvertiert. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Leorik.Test.csp
roj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Program.cs(133,31): warning CS8602: Dereferenzierung eines möglichen Nullverweises. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Leorik.Test.csproj]
  Leorik.Engine -> C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\bin\Release\net6.0\Leorik.Engine.dll
  Leorik.Test -> C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\bin\Release\net6.0\Leorik.Test.dll

Der Buildvorgang wurde erfolgreich ausgeführt.

C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Move.cs(5,28): warning CS0660: "Move" definiert den Operator == oder !=, aber überschreibt Object.Equals(object o) nicht. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Leorik.Core.csproj]

C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Move.cs(5,28): warning CS0661: "Move" definiert den Operator == oder !=, aber überschreibt Object.GetHashCode() nicht. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Leorik.Core.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Search\Transpositions.cs(64,16): warning CS8618: Non-Nullable-Feld "_table" muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie eine Deklaration von "Feld" als Nulla
ble. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Search\Leorik.Search.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(87,30): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(130,23): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]

C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(8,35): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs(9,29): warning CS8625: Ein NULL-Literal kann nicht in einen Non-Nullable-Verweistyp konvertiert werden. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Leorik.Engine.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Program.cs(49,70): warning CS8604: Mögliches Nullverweisargument für den Parameter "epd" in "int Program.ParseEpd(string epd, out BoardState board, out List<Move> bestMoves)". [C:\msys64\home
\Guenther Simon\Leorik\Leorik.Test\Leorik.Test.csproj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Program.cs(132,30): warning CS8600: Das NULL-Literal oder ein möglicher NULL-Wert wird in einen Non-Nullable-Typ konvertiert. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Leorik.Test.csp
roj]
C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Program.cs(133,31): warning CS8602: Dereferenzierung eines möglichen Nullverweises. [C:\msys64\home\Guenther Simon\Leorik\Leorik.Test\Leorik.Test.csproj]
    10 Warnung(en)
    0 Fehler

The problem is it will still throw an exception which clearly hints 'my platform' is not supported, probably due to missing 'bmi' and/or 'popcnt'.

0.234: < Leorik 1.0
0.296: < Unhandled exception. System.TypeInitializationException: The type initializer for 'Leorik.Engine.Program' threw an exception.
0.296: <  ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
0.296: <    at System.Runtime.Intrinsics.X86.Bmi1.X64.ResetLowestSetBit(UInt64 value)
0.296: <    at Leorik.Core.Evaluation.AddPieces(BoardState& board) in C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Evaluation.cs:line 26
0.296: <    at Leorik.Core.Notation.GetBoardState(String fen) in C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Notation.cs:line 105
0.296: <    at Leorik.Core.Notation.GetStartingPosition() in C:\msys64\home\Guenther Simon\Leorik\Leorik.Core\Notation.cs:line 53
0.296: <    at Leorik.Engine.Engine..ctor() in C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Engine.cs:line 12
0.296: <    at Leorik.Engine.Program..cctor() in C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Program.cs:line 11
0.296: <    --- End of inner exception stack trace ---
0.296: <    at Leorik.Engine.Program.Main() in C:\msys64\home\Guenther Simon\Leorik\Leorik.Engine\Program.cs:line 17
0.296: <    at Leorik.Engine.Program.<Main>()

Is it possible to add a flag to the build process for the C# compiler, or does it require some code change? (I don't care, if it would lose some speed)

lithander commented 2 years ago

Thanks for filing this issue, Günther. The bitboard stuff is new to me and I wasn't sure how to best provide compatibility to older hardware (that I don't have available for testing) but if I can find a way to make it work on older hardware without making the build generally for all slower I'll gladly patch it in!

Let's first see if we can get it to work for you locally.

In Bitboard.cs if you comment out line 135 that uses Bmi1.X64.ResetLowestSetBit and remove the comment from line 136 then this alternative way of clearing the least significant bit from the bitboard should work on your PC, too.

If you still get exceptions then they are likely from a different source and I'd kindly ask you to attach the log to this issue again!

rwbc commented 2 years ago

Fine Thomas :)

Thanks for the quick help!

Leorik 1.0
uci
id name Leorik 1.0
id author Thomas Jahn
option name Hash type spin default 50 min 1 max 2047
uciok
isready
readyok
position startpos
go depth 12
info depth 1 score cp 36 nodes 21 nps 21000 time 0 pv d2d4
info depth 2 score cp 0 nodes 86 nps 4300 time 20 pv d2d4 d7d5
info depth 3 score cp 35 nodes 654 nps 31142 time 21 pv d2d4 d7d5 g1f3
info depth 4 score cp 0 nodes 2324 nps 96833 time 24 pv d2d4 d7d5 g1f3 g8f6
info depth 5 score cp 33 nodes 13691 nps 402676 time 34 pv d2d4 d7d5 g1f3 g8f6 b1c3
info depth 6 score cp 1 nodes 70430 nps 658224 time 107 pv e2e4 b8c6 d2d4 g8f6 b1c3 e7e5
info depth 7 score cp 26 nodes 297216 nps 1134412 time 262 pv e2e4 b8c6 d2d4 e7e5 d4e5 c6e5 g1f3
info depth 8 score cp 10 nodes 1408742 nps 1288876 time 1093 pv e2e4 e7e5 b1c3 g8f6 g1f3 b8c6 d2d4 f8d6
info depth 9 score cp 34 nodes 5229417 nps 2039554 time 2564 pv e2e4 e7e5 b1c3 g8f6 g1f3 f8d6 d2d4 b8c6 c1e3
info depth 10 score cp 8 nodes 23412852 nps 1674739 time 13980 pv e2e4 e7e5 g1f3 b8c6 b1c3 g8f6 d2d4 e5d4 f3d4 f8d6
info depth 11 score cp 33 nodes 185781564 nps 1826796 time 101698 pv d2d4 d7d5 g1f3 g8f6 e2e3 e7e6 b1c3 f8d6 f1d3 e8g8 e1g1

(I guess it should be possible to add an if clause, which detects if the hardware supports the LSB and if not add the alternative line?)

BTW did you measure the speed diff on your own hardware? If you need some numbers for comparing the speed on other programs in line with my hardware I am happy to provide some tests. Below is Minimal 0.6 the official release from your repo.

MinimalChess 0.6
uci
id name MinimalChess 0.6
id author Thomas Jahn
option name Hash type spin default 50 min 1 max 2047
uciok
isready
readyok
position startpos
go depth 15
info string Search scheduled to take 715827862ms!
info depth 1 score cp 54 nodes 21 nps 420 time 50 pv e2e3
info depth 2 score cp 0 nodes 116 nps 1841 time 63 pv e2e3 e7e6
info depth 3 score cp 49 nodes 217 nps 3390 time 64 pv e2e3 e7e6 b1c3
info depth 4 score cp 0 nodes 583 nps 8449 time 69 pv e2e3 e7e6 b1c3 b8c6
info depth 5 score cp 41 nodes 1883 nps 24141 time 78 pv g1f3 g8f6 e2e3 b8c6 b1c3
info depth 6 score cp 0 nodes 3741 nps 41109 time 91 pv g1f3 g8f6 b1c3 d7d5 d2d4 b8c6
info depth 7 score cp 33 nodes 6323 nps 59093 time 107 pv g1f3 g8f6 b1c3 d7d5 d2d4 b8c6 c1g5
info depth 8 score cp -7 nodes 19906 nps 113748 time 175 pv g1f3 g8f6 b1c3 d7d5 d2d4 b8c6 h2h3 e7e6
info depth 9 score cp 26 nodes 48700 nps 151242 time 322 pv g1f3 b8c6 d2d4 d7d5 b1c3 g8f6 h2h3 e7e6 c1g5
info depth 10 score cp 5 nodes 92256 nps 176397 time 523 pv g1f3 b8c6 e2e4 e7e5 b1c3 g8f6 f1b5 c6d4 f3e5 d4b5
info depth 11 score cp 28 nodes 153368 nps 208097 time 737 pv g1f3 b8c6 e2e4 e7e5 b1c3 g8f6 d2d4 e5d4 f3d4 f8b4 d4f5
info depth 12 score cp 3 nodes 344575 nps 263839 time 1306 pv g1f3 b8c6 d2d4 d7d5 e2e3 g8f6 f1e2 c8g4 b1c3 e7e6 e1g1 f8b4
info depth 13 score cp 31 nodes 939307 nps 301059 time 3120 pv d2d4 g8f6 b1c3 d7d5 g1f3 b8c6 e2e3 a7a6 f1d3 c8g4 h2h3 g4f3 d1f3
info depth 14 score cp 6 nodes 2555216 nps 314178 time 8133 pv e2e4 e7e5 b1c3 b8c6 g1f3 g8f6 f1b5 c6d4 f3e5 d4b5 c3b5 f6e4 d1f3 e4g5
info depth 15 score cp 32 nodes 4205086 nps 317556 time 13242 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6 d7c6 d1d8 e8d8 b1c3 f8b4 c1g5
bestmove e2e4
lithander commented 2 years ago

I just released Version 2.0 and that version should run on old hardware without any further steps necessary. I chose not to use the Bmi Instruction as the benefit was barely measurable. You should be able to just use the binary that I uploaded. Let me know if it does not work as I have no hardware old enough to verify it myself!

rwbc commented 2 years ago

Thomas, it seems I forgot to give another ok here? :) This is your release version 2.0 for win.

I just had to add a missing dll for my old Win7-Ultimate64 from a safe site: api-ms-win-core-winrt-l1-1-0.dll Here is a link to a trustworthy dll site, the one I used, may be other users can use that info too. https://de.dll-files.com/api-ms-win-core-winrt-l1-1-0.dll.html

Leorik 2.0
uci
id name Leorik 2.0
id author Thomas Jahn
option name Hash type spin default 50 min 1 max 2047
uciok
isready
readyok
position startpos
go infinite
info depth 1 score cp 36 nodes 21 nps 21000 time 0 pv d2d4
info depth 2 score cp 0 nodes 88 nps 1955 time 45 pv d2d4 d7d5
info depth 3 score cp 35 nodes 184 nps 3914 time 47 pv d2d4 d7d5 g1f3
info depth 4 score cp 0 nodes 369 nps 7687 time 48 pv d2d4 d7d5 g1f3 g8f6
info depth 5 score cp 33 nodes 666 nps 13875 time 48 pv d2d4 d7d5 g1f3 g8f6 b1c3
info depth 6 score cp 0 nodes 2662 nps 53240 time 50 pv d2d4 d7d5 g1f3 g8f6 b1c3 b8c6
info depth 7 score cp 26 nodes 5353 nps 102942 time 52 pv d2d4 d7d5 g1f3 g8f6 b1c3 b8c6 c1e3
info depth 8 score cp 0 nodes 10168 nps 181571 time 56 pv d2d4 d7d5 g1f3 g8f6 b1c3 b8c6 c1e3 c8f5
info depth 9 score cp 30 nodes 64321 nps 606801 time 106 pv e2e4 g8f6 b1c3 b8c6 g1f3 d7d5 e4d5 f6d5 d2d4
info depth 10 score cp 4 nodes 281066 nps 1060626 time 265 pv e2e4 e7e5 g1f3 g8f6 d2d4 e5d4 e4e5 f8b4 c2c3 d4c3
info depth 11 score cp 23 nodes 470690 nps 1272135 time 370 pv d2d4 d7d5 e2e3 g8f6 f1d3 b8c6 g1f3 c8g4 e1g1 e7e5 c2c3
info depth 12 score cp 7 nodes 808152 nps 1530590 time 528 pv e2e4 e7e5 g1f3 b8c6 f1d3 f8d6 e1g1 g8f6 b1c3 e8g8 c3b5 d6c5
info depth 13 score cp 21 nodes 2621822 nps 2089101 time 1255 pv g1f3 g8f6 g2g3 d7d5 d2d4 e7e6 f1g2 f8d6 e1g1 e8g8 b1c3 b8c6 c1e3
info depth 14 score cp 8 nodes 5329036 nps 2234396 time 2385 pv e2e4 e7e5 g1f3 b8c6 b1c3 g8f6 f1d3 f8d6 e1g1 e8g8 c3b5 f8e8 b5d6 c7d6
info depth 15 score cp 20 nodes 8472919 nps 2337356 time 3625 pv e2e4 e7e5 g1f3 b8c6 b1c3 g8f6 d2d4 e5d4 f3d4 c6d4 d1d4 f8e7 f1c4 e8g8 e1g1
info depth 16 score cp 9 nodes 12196153 nps 2358111 time 5172 pv e2e4 e7e5 g1f3 b8c6 b1c3 g8f6 f1d3 f8d6 e1g1 e8g8 c3b5 d6c5 c2c4 f8e8 f1e1 d7d6
info depth 17 score cp 26 nodes 26835335 nps 2415639 time 11109 pv g1f3 g8f6 d2d4 d7d5 c1f4 e7e6 e2e3 f8d6 b1c3 e8g8 f1d3 b8c6 e1g1 c8d7 a1c1 a8c8 f1e1
lithander commented 2 years ago

Thanks for the feedback! And great to know that Leorik runs fine on Win7 and legacy hardware. 👍