floating point SSE eval

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
elcabesa
Posts: 815
Joined: Sun May 23, 2010 11:32 am
Contact:

floating point SSE eval

Post by elcabesa » Fri Dec 13, 2013 6:18 pm

Hi,
I'm puzzled about the possibility of using floating point inside the evalutation function of my new engine. I'm now using SSE variable to store 2 32 bit integer in a single variable and I'm trying to implement an evalutation this way.
Up to now my evalutation only consider material and piece-square table and at the end does a tapered evalutation to return a single 32 bit integer.
The search uses the int to do a very standard alpha beta searcher.

what I'm now thinking is to use SSE floating point instructions inside the evalutation and to return at the end an integer (to not break the search, comparison and null windows search). I have noticed that there are more SSE floating point istruction than integer ones and that them are more powerful.
Has anyone tried them in a chess engine evalutation function? have you found faster/slower time execution with SSE floating point ? Any problems?

thank you all

tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 3:57 pm
Location: Germany
Contact:

Re: floating point SSE eval

Post by tpetzke » Fri Dec 13, 2013 7:05 pm

Hi Marco,

in the very early versions of my engine (4 years ago) I used floating point eval scores, I changed it later to integer but there was not much impact on the speed. Probably the engine was spending most of its time elsewhere. At that time I just started with the whole stuff and I did not use a profiler for such decisions.

There might be side effects that you do not think of, like the compiler is not able to optimize as efficiently with floats as it is with ints (e.g. integer addition is commutative, addition of floating points is not so the order of adding the values has influence on the result - limiting the options of the compiler)

So, I would say. Don't guess. Use a profiler and measure.

Thomas...
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine

wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 3:03 pm
Location: British Columbia, Canada

Re: floating point SSE eval

Post by wgarvin » Fri Dec 13, 2013 7:31 pm

elcabesa wrote:Hi,
I'm puzzled about the possibility of using floating point inside the evalutation function of my new engine. I'm now using SSE variable to store 2 32 bit integer in a single variable and I'm trying to implement an evalutation this way.
Up to now my evalutation only consider material and piece-square table and at the end does a tapered evalutation to return a single 32 bit integer.
The search uses the int to do a very standard alpha beta searcher.

what I'm now thinking is to use SSE floating point instructions inside the evalutation and to return at the end an integer (to not break the search, comparison and null windows search). I have noticed that there are more SSE floating point istruction than integer ones and that them are more powerful.
Has anyone tried them in a chess engine evalutation function? have you found faster/slower time execution with SSE floating point ? Any problems?

thank you all
If you want to use the integer ones, the SSE2 set of instructions is supported by all modern x86 chips (everything since Pentium 4 and AMD K8 has supported it), every x64 chip can do SSE2, so don't be afraid to use those.

Daniel Shawul
Posts: 3757
Joined: Tue Mar 14, 2006 10:34 am
Location: Ethiopia
Contact:

Re: floating point SSE eval

Post by Daniel Shawul » Fri Dec 13, 2013 7:50 pm

elcabesa wrote:Hi,
I'm puzzled about the possibility of using floating point inside the evalutation function of my new engine. I'm now using SSE variable to store 2 32 bit integer in a single variable and I'm trying to implement an evalutation this way.
Up to now my evalutation only consider material and piece-square table and at the end does a tapered evalutation to return a single 32 bit integer.
The search uses the int to do a very standard alpha beta searcher.

what I'm now thinking is to use SSE floating point instructions inside the evaluation and to return at the end an integer (to not break the search, comparison and null windows search). I have noticed that there are more SSE floating point istruction than integer ones and that them are more powerful.
Has anyone tried them in a chess engine evaluation function? have you found faster/slower time execution with SSE floating point ? Any problems?

thank you all
The question is why do you want to use floats in evaluation. It will only make you go slower especially if you use double precision. You can use milli-pawns instead of centi-pawns, or a 1pawn=256units as some engines already do. If you are a bitboarder, there maybe some uses of it in chess-wiki or ask Gerd. SSE/AVX are designed for HP scientific computing just like GPU units, so branching code in chess is not gonna benefit from that a lot.

Henk
Posts: 5819
Joined: Mon May 27, 2013 8:31 am

Re: floating point SSE eval

Post by Henk » Fri Dec 13, 2013 9:16 pm

Always watch out for rounding errors. For instance when testing the value of a rational number. If you test A == 0 but A is 0.000000000133333 it will be false.

Sorry if this looks like programming for beginners.

elcabesa
Posts: 815
Joined: Sun May 23, 2010 11:32 am
Contact:

Re: floating point SSE eval

Post by elcabesa » Sat Dec 14, 2013 7:37 am

wgarvin wrote: If you want to use the integer ones, the SSE2 set of instructions is supported by all modern x86 chips (everything since Pentium 4 and AMD K8 has supported it), every x64 chip can do SSE2, so don't be afraid to use those.
I think i'll use sse2 or later integer or float instructions.
Always watch out for rounding errors. For instance when testing the value of a rational number. If you test A == 0 but A is 0.000000000133333 it will be false.

Sorry if this looks like programming for beginners.
I'm writing a floating point eval function so it shouldn't happen. thank you for the warning
The question is why do you want to use floats in evaluation. It will only make you go slower especially if you use double precision. You can use milli-pawns instead of centi-pawns, or a 1pawn=256units as some engines already do. If you are a bitboarder, there maybe some uses of it in chess-wiki or ask Gerd. SSE/AVX are designed for HP scientific computing just like GPU units, so branching code in chess is not gonna benefit from that a lot.
it looks like thah sse floating point instructions are "stonger" than integer ones.
with the library i'm using you can do sqrt nad pow of packed float for example. you can calculate a reciprocal ans so on.

User avatar
lucasart
Posts: 3040
Joined: Mon May 31, 2010 11:29 am
Full name: lucasart
Contact:

Re: floating point SSE eval

Post by lucasart » Sat Dec 14, 2013 8:23 am

Henk wrote:Always watch out for rounding errors. For instance when testing the value of a rational number. If you test A == 0 but A is 0.000000000133333 it will be false.

Sorry if this looks like programming for beginners.
Actually, this is a very good point! Writing a PVS algorithm for use with floating point evaluation is a disastrous. How do you write a zero window with floating point scores?
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.

elcabesa
Posts: 815
Joined: Sun May 23, 2010 11:32 am
Contact:

Re: floating point SSE eval

Post by elcabesa » Sat Dec 14, 2013 8:55 am

lucasart wrote: Actually, this is a very good point! Writing a PVS algorithm for use with floating point evaluation is a disastrous. How do you write a zero window with floating point scores?
sorry lucas for my next few words but .....

why everyone write without reading what I have weritten?? :D


I stated that I want to write a floating point evalutation and at the end convert it to an int to not break the PVS search.

have you found slower/flawed/wrong using float inside evalutation?
has anyon an insight of it?
thank you all

tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 3:57 pm
Location: Germany
Contact:

Re: floating point SSE eval

Post by tpetzke » Sat Dec 14, 2013 9:08 am

Hi Marco,

as I wrote. Floating points worked for me and when I changed to int I had no significant speedup.

At that time I did not have a term that required a division (e.g. scaling king safety depending on the enemy material left or so). If you do a lot of this stuff than ints might be faster.

Thomas...
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine

Gerd Isenberg
Posts: 2127
Joined: Wed Mar 08, 2006 7:47 pm
Location: Hattingen, Germany

Re: floating point SSE eval

Post by Gerd Isenberg » Sat Dec 14, 2013 9:27 am

You may give it a try. See also the papers referred in cpw:

https://chessprogramming.wikispaces.com/Float

and

http://www.talkchess.com/forum/viewtopic.php?t=22817
http://en.wikipedia.org/wiki/FMA_instruction_set

For a null window in PVS one has to pass only one bound anyway, so one may try it even in search...

Post Reply