Optimization for speed in VS 2008

Discussion of chess software programming and technical issues.

Moderator: Ras

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

Re: Optimization for speed in VS 2008

Post by wgarvin »

Milos wrote:
rbarreira wrote:OK good for you. Now how does that give you the right to be an annoying prick who says others are preaching and not helping? :P

Honestly I didn't get the idea that he was asking only for compile flags in the OP.
And your idea about helping someone is to advice him the most banal thing like he's stupid or something.
It would help if you actually read what ppl write instead of only making arrogant assumptions.
I found his original post a little unclear. What I got out of it was:
(1) his NPS was way slower than he wanted it to be, compared to e.g. Crafty,
(2) he doesn't want to give away his source code, and
(3) Jim already suggested PGO to him and he's tried that and he didn't see much improvement from it.

One possibility is that he might have made some mistake when trying the PGO. You have to run your program on representative workloads for a while so the profiler gets good data. But lets assume he did that properly.

There are lots of reasons his engine could be "way slower" than Crafty; if he were compiling in Debug or something, it would be way slower than Crafty. Okay, he's posting long command lines with O2 in them, so we can probably rule that out. What's left? Sure, he could fiddle with a few command line options, but that is not generally a way to make code "way faster". If you've turned off exceptions and RTTI and security checks, allowed it to inline and chosen the SSE2 instruction set, then you're most of the way there already.

Maybe his way of counting NPS is not the same as Crafty and other engines? For example, does he include hash hits as nodes?

Anyway, what other possible causes of slowness remain?

Well, the code might be doing dumb things. Passing structures by value, making unnecessary recursive calls, incurring unnecessary cache misses, etc. That was my first guess when I read the OP because its quite easy for a first engine to be slow.

Fixing that sort of stuff will probably help a lot more than tweaking some command line options. He doesn't want to share his source code, so its hard to offer concrete suggestions about those things, isn't it?
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimization for speed in VS 2008

Post by bob »

Milos wrote:
bob wrote:Been compiling a long time. Never seen a case where you use -O2 + PGO and then can find another 10-15% on top of that, except for cases where you can tell the compiler to use instructions specific to the processor you are using.
I was not saying that, I tried to say that -O2+PGO can be sometimes slower than just -O2 -XX (some other flags) without PGO.
When you add PGO on top of that you get more speedup (however, PGO brings then usually only few %).
Then I am lost, because he already said he tried a basic optimization setting and then tested using PGO. That certainly suggests that looking at the code is going to be _far_ more useful than playing with compiler options.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimization for speed in VS 2008

Post by bob »

wgarvin wrote:
Milos wrote:
rbarreira wrote:OK good for you. Now how does that give you the right to be an annoying prick who says others are preaching and not helping? :P

Honestly I didn't get the idea that he was asking only for compile flags in the OP.
And your idea about helping someone is to advice him the most banal thing like he's stupid or something.
It would help if you actually read what ppl write instead of only making arrogant assumptions.
I found his original post a little unclear. What I got out of it was:
(1) his NPS was way slower than he wanted it to be, compared to e.g. Crafty,
(2) he doesn't want to give away his source code, and
(3) Jim already suggested PGO to him and he's tried that and he didn't see much improvement from it.

One possibility is that he might have made some mistake when trying the PGO. You have to run your program on representative workloads for a while so the profiler gets good data. But lets assume he did that properly.

There are lots of reasons his engine could be "way slower" than Crafty; if he were compiling in Debug or something, it would be way slower than Crafty. Okay, he's posting long command lines with O2 in them, so we can probably rule that out. What's left? Sure, he could fiddle with a few command line options, but that is not generally a way to make code "way faster". If you've turned off exceptions and RTTI and security checks, allowed it to inline and chosen the SSE2 instruction set, then you're most of the way there already.

Maybe his way of counting NPS is not the same as Crafty and other engines? For example, does he include hash hits as nodes?

Anyway, what other possible causes of slowness remain?

Well, the code might be doing dumb things. Passing structures by value, making unnecessary recursive calls, incurring unnecessary cache misses, etc. That was my first guess when I read the OP because its quite easy for a first engine to be slow.

Fixing that sort of stuff will probably help a lot more than tweaking some command line options. He doesn't want to share his source code, so its hard to offer concrete suggestions about those things, isn't it?
The first thing he _should_ have tried was to compile his program and Crafty using the same compiler options. If Crafty is _still_ way faster, then fiddling with compiler options is poingless, there is something wrong with the program from an efficiency perspective.
vladstamate
Posts: 161
Joined: Thu Jan 08, 2009 9:06 pm
Location: San Francisco, USA

Re: Optimization for speed in VS 2008

Post by vladstamate »

he hint me to compile with PGO too , but this is only a small increase of speed i get.
How are you using PGO? I get some good speedups in my chess engine when using it with Visual Studio 2008. What I do is the following:

perft computation upto 6 depth
analyze at 10 sec / position 10 positions in one of the STS tests
analyze at 10 sec /position 10 end game tests (pet.epd)

So this takes about 4-5 minutes of running. Easy for me since I can run plisk with command line parameters to do the above.

Ideally the longer you run your engine with PGO enabled the better. I think Dann Corbit mentioned ones he runs few hundred games or so with PGO before using the data to optimize.

Regards,
Vlad.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimization for speed in VS 2008

Post by bob »

vladstamate wrote:
he hint me to compile with PGO too , but this is only a small increase of speed i get.
How are you using PGO? I get some good speedups in my chess engine when using it with Visual Studio 2008. What I do is the following:

perft computation upto 6 depth
analyze at 10 sec / position 10 positions in one of the STS tests
analyze at 10 sec /position 10 end game tests (pet.epd)

So this takes about 4-5 minutes of running. Easy for me since I can run plisk with command line parameters to do the above.

Ideally the longer you run your engine with PGO enabled the better. I think Dann Corbit mentioned ones he runs few hundred games or so with PGO before using the data to optimize.

Regards,
Vlad.
There is a risk with running too long. Counters overflow and screw up the results...
Dann Corbit
Posts: 12791
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Optimization for speed in VS 2008

Post by Dann Corbit »

vladstamate wrote:
he hint me to compile with PGO too , but this is only a small increase of speed i get.
How are you using PGO? I get some good speedups in my chess engine when using it with Visual Studio 2008. What I do is the following:

perft computation upto 6 depth
analyze at 10 sec / position 10 positions in one of the STS tests
analyze at 10 sec /position 10 end game tests (pet.epd)

So this takes about 4-5 minutes of running. Easy for me since I can run plisk with command line parameters to do the above.

Ideally the longer you run your engine with PGO enabled the better. I think Dann Corbit mentioned ones he runs few hundred games or so with PGO before using the data to optimize.

Regards,
Vlad.
Here is my general PGO procedure:
After the PGO preparatory compile, I do the following {each separate runs}:
1. A ten game match at 2' + 2" engine against self
2. Analyze WAC at 5 seconds (300 pos, general tactics)
3. Analyze pawntest at 5 seconds (75 pos, exercise tablebase)
4. Run perft (if available) at depths 4,5,6 (if perft is fast also 7)
5. Analyze WAC.230 at 30 minutes (deep middle game search)

I have seen improvment up to 35%
I have seen the engine run slower after PGO
I have seen the engine execute illegal instructions after PGO

So it is no panacea, but sometimes it gives a big boost.
Engin
Posts: 1001
Joined: Mon Jan 05, 2009 7:40 pm
Location: Germany
Full name: Engin Üstün

Re: Optimization for speed in VS 2008

Post by Engin »

are you suggest that this option is worse ? Ob2 too ?
Engin
Posts: 1001
Joined: Mon Jan 05, 2009 7:40 pm
Location: Germany
Full name: Engin Üstün

Re: Optimization for speed in VS 2008

Post by Engin »

i done the same way, but i dont running so long time, after the optimization i get some errors, that i dont get if i compiled normal without PGO
Engin
Posts: 1001
Joined: Mon Jan 05, 2009 7:40 pm
Location: Germany
Full name: Engin Üstün

Re: Optimization for speed in VS 2008

Post by Engin »

what i dont understand is that i am using nearly the same way to generate moves with bitboards but after perft 6 is crafty on my pc double faster then my move generator, why ? are my bitboards to slow ? or is the make and unmake moves slower .... ?
Engin
Posts: 1001
Joined: Mon Jan 05, 2009 7:40 pm
Location: Germany
Full name: Engin Üstün

Re: Optimization for speed in VS 2008

Post by Engin »

the other thing what i never undestand is that crafty search nps is very fast about 2500 knps on my pc, and Tornado is only by 500 Knps, that is a speedup of 5x