floating point SSE eval

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

floating point SSE eval

Post by elcabesa »

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 4:57 pm
Location: Germany

Re: floating point SSE eval

Post by tpetzke »

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 5:03 pm
Location: British Columbia, Canada

Re: floating point SSE eval

Post by wgarvin »

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: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: floating point SSE eval

Post by Daniel Shawul »

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: 7216
Joined: Mon May 27, 2013 10:31 am

Re: floating point SSE eval

Post by Henk »

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: 855
Joined: Sun May 23, 2010 1:32 pm

Re: floating point SSE eval

Post by elcabesa »

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: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: floating point SSE eval

Post by lucasart »

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: 855
Joined: Sun May 23, 2010 1:32 pm

Re: floating point SSE eval

Post by elcabesa »

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 4:57 pm
Location: Germany

Re: floating point SSE eval

Post by tpetzke »

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: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: floating point SSE eval

Post by Gerd Isenberg »

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...