Portfish - C# port of Stockfish

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Post Reply
bpfliegel
Posts: 71
Joined: Fri Mar 16, 2012 9:16 am

Portfish - C# port of Stockfish

Post by bpfliegel » Fri May 04, 2012 8:30 pm

Dear all,

let me present you Portfish, the .Net port of Stockfish, currently as a first beta.

Github URL and readme:
https://github.com/bpfliegel/Portfish

Latest desktop releases:
https://github.com/downloads/bpfliegel/ ... elease.zip

I would be happy to receive feedback on engine performance and strength (especially on i7 and 8+ core Xeons) and compiling it on Mono.
The fastest/strongest version is 4.5 (which is currently a beta framework) and 4.0, x64.

Thanks a lot, cheers,
Balint

gladius
Posts: 535
Joined: Tue Dec 12, 2006 9:10 am

Re: Portfish - C# port of Stockfish

Post by gladius » Fri May 04, 2012 10:59 pm

Wow, that must have been a huge amount of work! Very impressive :).

User avatar
lucasart
Posts: 2952
Joined: Mon May 31, 2010 11:29 am
Contact:

Re: Portfish - C# port of Stockfish

Post by lucasart » Sat May 05, 2012 1:22 am

bpfliegel wrote:Dear all,

let me present you Portfish, the .Net port of Stockfish, currently as a first beta.

Github URL and readme:
https://github.com/bpfliegel/Portfish

Latest desktop releases:
https://github.com/downloads/bpfliegel/ ... elease.zip

I would be happy to receive feedback on engine performance and strength (especially on i7 and 8+ core Xeons) and compiling it on Mono.
The fastest/strongest version is 4.5 (which is currently a beta framework) and 4.0, x64.

Thanks a lot, cheers,
Balint
Did you verify the node count with a ./stockfish bench ? This is essentialt, if node counts are equal most likely all is good. If not then there is a bug somewhere, as it is not functionally equivalent to the original SF.

User avatar
pocopito
Posts: 228
Joined: Tue Jul 12, 2011 11:31 am
Contact:

Re: Portfish - C# port of Stockfish

Post by pocopito » Sat May 05, 2012 7:28 am

x86 port40 seems to work with mono under ubuntu 12.04. It uses my four cores and makes arround 500 kN/s

~/PortfishLatestRelease/x86$ mono PortfishNet40.exe

Just in case it can be of any interest, this is the output of a few seconds analyzing the initial position.

Code: Select all

1 [+0.72]  1.Nf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5 Nxd3 11.Qxd3  (29.11)
20 [+0.36]  1.e4 e6 2.d4 d5 3.Nc3 Nf6 4.e5 Ne4 5.Nxe4 dxe4 6.Be3 Nc6 7.c3 Qh4 8.g3  (35.43)
20 [+0.16]  1.e4 e6 2.d4 d5 3.exd5 exd5 4.Nf3 Nf6 5.Bd3 Bd6 6.Nc3 Be6 7.O-O O-O 8.Re1 Nc6 9.Nb5 Nb4 10.Nxd6 Qxd6 11.Ne5 Rae8 12.Bf4 Nxd3 13.Nxd3 Qb6  (40.97)
21 [+0.24]  1.e4 e6 2.d4 d5 3.exd5 exd5 4.Nf3 Nf6 5.Bb5+ c6 6.Bd3 Qe7+ 7.Be2 Qc7 8.c4 Bb4+ 9.Nc3 Ne4 10.Qb3 Bxc3+ 11.bxc3 O-O 12.O-O  (46.88)
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.

mcostalba
Posts: 2679
Joined: Sat Jun 14, 2008 7:17 pm

Re: Portfish - C# port of Stockfish

Post by mcostalba » Sat May 05, 2012 7:35 am

gladius wrote:Wow, that must have been a huge amount of work! Very impressive :).
Yes, it has been.

I have been in contact with Balint during these months and I know the effort has been very big. He not only did a perfect porting so that Portish it is 100% functional equivalent to current development version of Stockfish, but he also tried hard to optimize it for .Net platform. I am not talking of micro-optimization, but of big reworks as memory allocation.

I really would like to congratulate with him also publicly (privately I had already done): Balint, you really made something awesome.

Thanks
Marco

bpfliegel
Posts: 71
Joined: Fri Mar 16, 2012 9:16 am

Re: Portfish - C# port of Stockfish

Post by bpfliegel » Sat May 05, 2012 8:13 am

Marco, thanks a lot for your kind words! :)

When reaching up to the Apr 17 version the port was tested with the Arasan 14 (175 positions) against the original version - this allowed to find one issue earlier that the standard benchmark did not enable (just simply not covering that btw very specific case). It should be alright functionally, I will recheck it on the weekend again to be certain.

It was some effort, 4 months overall.

Emilio, thanks for the feedback on Mono, looks good, somewhat slow. What type of CPUs do you use? I get 900-1000 kps on my laptop i5 in 4 CPU mode for the 4.0/4.5 x64.

Cheers, Balint

User avatar
pocopito
Posts: 228
Joined: Tue Jul 12, 2011 11:31 am
Contact:

Re: Portfish - C# port of Stockfish

Post by pocopito » Sat May 05, 2012 8:49 am

bpfliegel wrote:Marco, thanks a lot for your kind words! :)
Emilio, thanks for the feedback on Mono, looks good, somewhat slow. What type of CPUs do you use? I get 900-1000 kps on my laptop i5 in 4 CPU mode for the 4.0/4.5 x64.
Cheers, Balint
My laptop is an i5 4 cores. I've (re)tested 4.0 and 4.5 on both x86 and x64 (2.0 doesn't seem to work on none of them), with similar results: after the first plies the nps is around 500.000.
It's a bit odd this difference between both computers. I've double checked the 4 threads options is selected, and my cpu graph shows all the 4 cores are being used during the analysis.

I've also tested in "normal" positions (not only the starting one) and the results are quite similar.

If you think of any test I can do just ask for it.

BTW, thanks for the effort and congratulations for the results. I'm none to say anything like this, but even for a mediocre programmer like me, it's evident that it must have been a hell of a work.

Regards

E Diaz
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.

bpfliegel
Posts: 71
Joined: Fri Mar 16, 2012 9:16 am

Re: Portfish - C# port of Stockfish

Post by bpfliegel » Sat May 05, 2012 9:13 am

pocopito wrote:
bpfliegel wrote:Marco, thanks a lot for your kind words! :)
Emilio, thanks for the feedback on Mono, looks good, somewhat slow. What type of CPUs do you use? I get 900-1000 kps on my laptop i5 in 4 CPU mode for the 4.0/4.5 x64.
Cheers, Balint
My laptop is an i5 4 cores. I've (re)tested 4.0 and 4.5 on both x86 and x64 (2.0 doesn't seem to work on none of them), with similar results: after the first plies the nps is around 500.000.
It's a bit odd this difference between both computers. I've double checked the 4 threads options is selected, and my cpu graph shows all the 4 cores are being used during the analysis.

I've also tested in "normal" positions (not only the starting one) and the results are quite similar.

If you think of any test I can do just ask for it.

BTW, thanks for the effort and congratulations for the results. I'm none to say anything like this, but even for a mediocre programmer like me, it's evident that it must have been a hell of a work.

Regards

E Diaz
It needs some time to warm up as usual - in case of .Net this is more true than by C engines, so nps is maxed out usually only around depths 22-23. Do you have a log on what nps is reached at specific depths?

Also wonder why the 2.0 version does not work, what error did you get (if any)?

I'm looking for objective tests on playing strength - as I've seen there are a lot of people testing engine versions here on CCC.

Thanks a lot for your kind help!
Balint

User avatar
pocopito
Posts: 228
Joined: Tue Jul 12, 2011 11:31 am
Contact:

Re: Portfish - C# port of Stockfish

Post by pocopito » Sat May 05, 2012 12:24 pm

I've analysed the starting position deeper and nps are higher:

Code: Select all

[+0.28 ]  Depth: 26/37  Nodes: 446568K (740 kn/s) Time: 603.06 s
NPS: 740500  Hash: ----  Load: ---- TB hits: ---- Current: d4 (1/20) 
It's not the million nps that you reach, but the increase is quite a bit.

By the way, running on just 1 thread, I get these numbers:

Code: Select all

[+0.24 ]  Depth: 23/35  Nodes:  37637K (368 kn/s) Time: 102.15 s
NPS: 368464  Hash: ----  Load: ---- TB hits: ---- Current: Nf3 (2/20) 
I'm running these tests under scid-vs-pc, and AFAIK there's no option to get a log of the nps at each depth.


EDIT- Just forget the next part: I solved this problem installing some extra mono libraries for the 2.0 version.


And these are the errors for the 2.0 versions:
For x64:

Code: Select all

$ mono PortfishNet20.exe 

Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
  at System.Threading.Thread.StartInternal &#40;&#41; &#91;0x00000&#93; in <filename unknown>&#58;0 
&#91;ERROR&#93; FATAL UNHANDLED EXCEPTION&#58; System.TypeLoadException&#58; A type load exception has occurred.
  at System.Threading.Thread.StartInternal &#40;&#41; &#91;0x00000&#93; in <filename unknown>&#58;0 
For x86:

Code: Select all

$ mono PortfishNet20.exe 

Unhandled Exception&#58; System.TypeLoadException&#58; A type load exception has occurred.
  at System.Threading.Thread.StartInternal &#40;&#41; &#91;0x00000&#93; in <filename unknown>&#58;0 
&#91;ERROR&#93; FATAL UNHANDLED EXCEPTION&#58; System.TypeLoadException&#58; A type load exception has occurred.
  at System.Threading.Thread.StartInternal &#40;&#41; &#91;0x00000&#93; in <filename unknown>&#58;0
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.

bpfliegel
Posts: 71
Joined: Fri Mar 16, 2012 9:16 am

Re: Portfish - C# port of Stockfish

Post by bpfliegel » Sun May 06, 2012 8:42 am

Thanks a lot Emilio!

Should be somewhat better based on the latest performance reports I read over Mono, but this is ok. I'm just installing an Ubuntu 12.04 to able to check on it.

Also checked the Arasan test suite against the very latest Stockfish source. Numbers are equal.

Cheers, Balint

Post Reply