Stockfish port to C# Complete

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

diep
Posts: 1822
Joined: Thu Mar 09, 2006 11:54 pm
Location: The Netherlands

Re: Stockfish port to C# Complete

Post by diep »

whittenizer wrote:Yep, we started this just a few months ago. As for testing, I know the 1.5 times slower is not detailed enough. There's much more in depth testng I'll be doing but I need to fix the operators to get the perofrmance up where it needs to be. I mean its pretty darn fast now but I want it better. Also, there are some pre-loading of structures I want to try to get the search to go deeper in less time but that comes later. Not even sure if it will work.

Its going to take me a few weeks to refactor some of this c# as I dont have too much time on my hands. I'll keep you all posted. I will say that Ive made some improvements already simply doing loops using ints instead of the types. Thats why the operators were used. But theres some serious overhead there so Im removing the operators where I think they need to be removed, and going from there.

Thanks
Thanks for the quick answer David!

Against what did you compoare your C# app with?
The C++ app called stockfish, how did it get compiled and by whom and tested at which processor with which size hashtables at both sides?

We see a lot of flawed Fritz benchmarks for example, some use 1MB hashtable others 100MB, and they sometimes get crisscross compared...
whittenizer
Posts: 85
Joined: Sun May 29, 2011 11:56 pm
Location: San Diego

Re: Stockfish port to C# Complete

Post by whittenizer »

Sorry about not fully answering your questions. Well, I'm running an i-7 with 8 processors. I'm using 1024 for the hash, and compiled it using Visual Studio 2010 with the Optimize checkbox check under build settings. Other than that, I'm not much up on the inner working of compilers. Honestly, I'm very new to the chess programming scene so alot of the terms being thrown around, its over my head a bit. Im learning alot though.

I had help getting the C++ ported over the C# so now Im taking over and making some adjustments.

Thanks for the interest.

David
diep
Posts: 1822
Joined: Thu Mar 09, 2006 11:54 pm
Location: The Netherlands

Re: Stockfish port to C# Complete

Post by diep »

whittenizer wrote:Sorry about not fully answering your questions. Well, I'm running an i-7 with 8 processors. I'm using 1024 for the hash, and compiled it using Visual Studio 2010 with the Optimize checkbox check under build settings. Other than that, I'm not much up on the inner working of compilers. Honestly, I'm very new to the chess programming scene so alot of the terms being thrown around, its over my head a bit. Im learning alot though.

I had help getting the C++ ported over the C# so now Im taking over and making some adjustments.

Thanks for the interest.

David
Default it compiles it in 32 bits, which is factor 2 slower.
And intel c++ will give you another 50% speedup or so with PGO,
as just hitting the optimize box without doing a run first ain't gonna help much.

So you're probably still around factor 4 slower than optimized C++ versions of Stockfish as it appears.

It's a huge project to carry out. Who's paying for this?

Kind Regards,
Vincent
whittenizer
Posts: 85
Joined: Sun May 29, 2011 11:56 pm
Location: San Diego

Re: Stockfish port to C# Complete

Post by whittenizer »

I've hired this guy to do it. I mean, as far as our agreement, he's completed the task. Everything is working fine. Book.bin is working, the same exact moves are coming back in C# as it is in C++. It just needs some performance enhancements. I'm planning on doing some search and evaluation enhancements as well as soon as things are more stable performance wise. I've been working with Houdini as well and it seems it can go mich deeper in less time so thats motivating me to relook at how SF is doing the search and eval.

Thanks,
diep
Posts: 1822
Joined: Thu Mar 09, 2006 11:54 pm
Location: The Netherlands

Re: Stockfish port to C# Complete

Post by diep »

whittenizer wrote:I've hired this guy to do it. I mean, as far as our agreement, he's completed the task. Everything is working fine. Book.bin is working, the same exact moves are coming back in C# as it is in C++. It just needs some performance enhancements. I'm planning on doing some search and evaluation enhancements as well as soon as things are more stable performance wise. I've been working with Houdini as well and it seems it can go mich deeper in less time so thats motivating me to relook at how SF is doing the search and eval.

Thanks,
Thanks for your openness in answerring all questions so far, really much appreciated.

The 1 to 1 compare of C++ versus C# is far more interesting than you might guess though. Probably Microsoft will put a full team at your port, just to speedup their C# compiler (managed or compiled for dot net, both) if we have a clear version of SF and a 1 on 1 deterministic version in C#. It's a very interesting comparision to look at.

As for algorithmic improvements, AFAIK stockfish falls under GPL, not LGPL, so means any change you do to it you should make public as well.

Even then would be interesting to see whether you manage algorithmic improvements. So far nothing new was invented that one or more other engines already didn't have and/or had tried, by any SF member other than Tord.

Note that with todays huge nps'es algorithmic improvements are quite possible; in fact a lot more algorithms/algorithmic enhancements can be put to work now than in 90s, when you simply didn't have the system time nor search depth to do something that eats overhead and results in an improvement.

Vincent

p.s. considering your name i interpreted your answer in a different manner than how you wrote it down. I read it as: i'm getting paid to do this.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Stockfish port to C# Complete

Post by mcostalba »

diep wrote: As for algorithmic improvements, AFAIK stockfish falls under GPL, not LGPL, so means any change you do to it you should make public as well.
No this is not correct. In case of a modified GPL software the developer (or the owner as in this case) should make public the modified source only if he makes public the binary. IOW in case he keeps the porting for private use he doesn't need to do anything to comply with GPL.

But this was the easiest part that (almost) everybody understands (you don't now as well you didn't when a similar case arose for our private 'tuning' branch). The tricky part is another: what about a porting from GPL sources ?

In this interesting case there is no a single line of C# that is 'copied' verbatim by the C++ counterpart, so does the GPL license applies also in this case ?
diep
Posts: 1822
Joined: Thu Mar 09, 2006 11:54 pm
Location: The Netherlands

Re: Stockfish port to C# Complete

Post by diep »

mcostalba wrote:
diep wrote: As for algorithmic improvements, AFAIK stockfish falls under GPL, not LGPL, so means any change you do to it you should make public as well.
No this is not correct. In case of a modified GPL software the developer (or the owner as in this case) should make public the modified source only if he makes public the binary. IOW in case he keeps the porting for private use he doesn't need to do anything to comply with GPL.

But this was the easiest part that (almost) everybody understands (you don't now as well you didn't when a similar case arose for our private 'tuning' branch). The tricky part is another: what about a porting from GPL sources ?

In this interesting case there is no a single line of C# that is 'copied' verbatim by the C++ counterpart, so does the GPL license applies also in this case ?
Much depends upon which factual GPL you put on top of the version that David ported. Seems he already was posting about porting around 2011 and referrals to a chessprogram towwards C# i see of him februari 2010. Maybe David wants to shine a light there. So he's been busy quite some months, around a 24+, to port as it seems now.

As for the GPL i would guess, but i'm not a lawyer, that it does apply as it is a literrally port and also promoted as such as he is doing the speed claim of C++ versus C#.

Actually he did make results public of it, legally it might, depending upon which court in which nation, not matter whether he also released the managed code in this case (whether that's a binary is yet another question), claiming it's roughly 50% faster or slower ,w hich has a huge impact, making releasing the code very important to verify that claim.

Lucky David very quickly posted on how he tested things, which of course gives him some credits. Also David wrote about intending to release the entire code, which will make him a hero to some people who toy in C#.

Strictly speaking Marco, the GPL rules are much tougher and restricting than usually gets used; just of course as computerchess is hardly about money, and more about governments injecting money and consultants who try to get paid by government organisations, that such claims seldom get fought out in court.

If i may remind you that within the linux community we had some great x-windows type codebase, then suddenly becasue of some parts falling under a different owner basically all that was lost for linux, putting it back 15 years in time or so, with the current ugly x.org (which eats massive RAM and is duck slow) as a replacement; so if you throw big cash at it, enforcing rules can have far reachign implications, much further than anyone so far has ever interpreted them within the chess community where not too many dogfights about GPL have been fought out so far.

Kind Regards,
Vincent
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Stockfish port to C# Complete

Post by mcostalba »

diep wrote: Strictly speaking Marco, the GPL rules are much tougher and restricting than usually gets used
Neverthless it is critical to spread information instead of mis-information about GPL to reference to the soruces, and not on own opinions/ideas/wishes: From http://www.gnu.org/licenses/gpl-faq.en. ... stedPublic

---------------------------------------------------
Does the GPL require that source code of modified versions be posted to the public?

The GPL does not require you to release your modified version, or any part of it. You are free to make modifications and use them privately, without ever releasing them. This applies to organizations (including companies), too; an organization can make a modified version and use it internally without ever releasing it outside the organization.
---------------------------------------------------
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: Stockfish port to C# Complete

Post by syzygy »

mcostalba wrote:
diep wrote: As for algorithmic improvements, AFAIK stockfish falls under GPL, not LGPL, so means any change you do to it you should make public as well.
No this is not correct. In case of a modified GPL software the developer (or the owner as in this case) should make public the modified source only if he makes public the binary. IOW in case he keeps the porting for private use he doesn't need to do anything to comply with GPL.
I might add that if you modify and distribute LGPL software, you have to provide the modified source as well. So LGPL or GPL makes no difference here.
The tricky part is another: what about a porting from GPL sources ?
Copyright law makes no distinction between modifying and porting. If you distribute ported GPL code, you have to publish the source code of the port.
In this interesting case there is no a single line of C# that is 'copied' verbatim by the C++ counterpart, so does the GPL license applies also in this case ?
Certainly it does.

Btw, compiled object code basically has not a single byte in common with its source code. Still, it is very clear that the object code is protected by the copyright on the source code. It is not different for other types of transformation (unless they filter out all creative elements of the original, such as piping through "wc -l" would do). However, assuming the porter has added "creative elements" of his own, he will also have a copyright on the ported source code.

It might be help to think of foreign language translations of books. The copyright holder on the original text obviously can assert its copyright against translated versions, but the translator will usually have a copyright on the translated text of his own.

(Of course the GPL does not apply if all copyirght holders of Stockfish choose to grant the porter a separate license. It is the copyright holders that decide.)
whittenizer
Posts: 85
Joined: Sun May 29, 2011 11:56 pm
Location: San Diego

Re: Stockfish port to C# Complete

Post by whittenizer »

Hum, I'm getting mixed views here. I've paid to have SF translated. Am I obligated to release my code or not?

I said I would but is it necessary for compliance purposes?