Page 1 of 2

floating point SSE eval

Posted: Fri Dec 13, 2013 7:18 pm
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

Re: floating point SSE eval

Posted: Fri Dec 13, 2013 8:05 pm
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...

Re: floating point SSE eval

Posted: Fri Dec 13, 2013 8:31 pm
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.

Re: floating point SSE eval

Posted: Fri Dec 13, 2013 8:50 pm
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.

Re: floating point SSE eval

Posted: Fri Dec 13, 2013 10:16 pm
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.

Re: floating point SSE eval

Posted: Sat Dec 14, 2013 8:37 am
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.

Re: floating point SSE eval

Posted: Sat Dec 14, 2013 9:23 am
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?

Re: floating point SSE eval

Posted: Sat Dec 14, 2013 9:55 am
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

Re: floating point SSE eval

Posted: Sat Dec 14, 2013 10:08 am
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...

Re: floating point SSE eval

Posted: Sat Dec 14, 2013 10:27 am
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...