Page 1 of 2

PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 5:50 pm
by Cardoso
Hi,
I'm trying to make a PGO compile of my engine using Visual Studio 2019 but with no success.
I copied the pgort140.dll file from:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.22.27905\bin\Hostx64\x64
to the folder C:\Profound\ wich is the default folder for my engine.
I link with /LTCG and /GENPROFILE
and use Build->Profile Guided Optimization->Instrument
My engine is exactly "engine.exe", I copied it to C:\Profound\
After running it for some time and closing it just doesn't appear the "engine!1.pgc" file.
I had no trouble at all with visual studio 2017, but with version 2019 I'm not getting anything.
What am I doing wrong?

thanks in advance,
Alvaro

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 6:17 pm
by Joost Buijs
Maybe the dll file is too old? VS 2019 is currently at v1.42. I don't understand why you have to use a separate dll anyway, maybe the community edition is not supporting PGO? I use the profession edition, and I don't have issues with PGO at all.

You have the enterprise version with the same version number as I have, so it should work with the dll at the default installation location, no need to copy that dll at all, maybe there is something wrong with your library path.

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 6:54 pm
by Joost Buijs
I use exactly the same options /LTGC /GENPROFILE to instrument and /LTGC and /USEPROFILE to optimize, if you use the PGO options from the build menu I suppose these are automatically set for you.

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 6:57 pm
by Cardoso
Joost Buijs wrote: Sat Aug 24, 2019 6:17 pm Maybe the dll file is too old? VS 2019 is currently at v1.42. I don't understand why you have to use a separate dll anyway, maybe the community edition is not supporting PGO? I use the profession edition, and I don't have issues with PGO at all.

You have the enterprise version with the same version number as I have, so it should work with the dll at the default installation location.
Funny I can't find a version 1.42 in my VS2019 instalation folder.
I also tried to remove the pgort140.dll from my C:\Profound\ folder, but the engine aborted.
I putted it back again and noticed that pgort140.dll is loaded into engine.exe using process explorer.
But it just doesn't save the "engine!1.pgc" file.

Alvaro

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 7:01 pm
by Cardoso
Joost Buijs wrote: Sat Aug 24, 2019 6:54 pm I use exactly the same options /LTGC /GENPROFILE to instrument and /LTGC and /USEPROFILE to optimize, if you use the PGO options from the build menu I suppose these are automatically set for you.
Right, and the engine works very slowly, so it confirms that the instrumented compilation was successful.
But that as far as I can go.

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 7:09 pm
by Joost Buijs
Cardoso wrote: Sat Aug 24, 2019 6:57 pm
Joost Buijs wrote: Sat Aug 24, 2019 6:17 pm Maybe the dll file is too old? VS 2019 is currently at v1.42. I don't understand why you have to use a separate dll anyway, maybe the community edition is not supporting PGO? I use the profession edition, and I don't have issues with PGO at all.

You have the enterprise version with the same version number as I have, so it should work with the dll at the default installation location.
Funny I can't find a version 1.42 in my VS2019 instalation folder.
I also tried to remove the pgort140.dll from my C:\Profound\ folder, but the engine aborted.
I putted it back again and noticed that pgort140.dll is loaded into engine.exe using process explorer.
But it just doesn't save the "engine!1.pgc" file.

Alvaro
I just looked at it, although the MSVC version is at 1.42 the dll is still called pgort1.40.dll, it has a size of 49.016 bytes. I remember in older versions of VS 2017 there was a bug and you had to copy that dll to the location of the executable, but that is not necessary anymore. It can be a bug in MSVC that makes the instrumented version crash, but it can also be a subtile bug in your engine that does not appear normally.

Maybe it is possible run the instrumented executable under the debugger, I never tried so I don't know if this will work.

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 7:25 pm
by Cardoso
I just looked at it, although the MSVC version is at 1.42 the dll is still called pgort1.40.dll, it has a size of 49.016 bytes. I remember in older versions of VS 2017 there was a bug and you had to copy that dll to the location of the executable, but that is not necessary anymore. It can be a bug in MSVC that makes the instrumented version crash, but it can also be a subtile bug in your engine that does not appear normally.

Maybe it is possible run the instrumented executable under the debugger, I never tried so I don't know if this will work.
Thanks Joost for you time and patience.
I just tried that.
I removed the pgort140.dll (confirmed size of 49.016 bytes) from c:\Profound
and introduced a pause in:

Code: Select all

int _tmain(int argc, _TCHAR* argv[])
{
	Sleep(12000)
to give me time to attach engine.exe to the debugger, but still, engine.exe doesn't show up, it crashes instantly without pgort140.dll in the C:\Profound folder.
Maybe I'll try to install the Professional edition of Visual studio 2019.

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 7:31 pm
by Joost Buijs
Another thing I can think of is to make a completely new project file with VS 2019, in the past I had some issues when I used project files from VS2017 converted to VS2019, but maybe you did this already.

Re: PGO compile on VS2019 not working

Posted: Sat Aug 24, 2019 7:33 pm
by Cardoso
Joost Buijs wrote: Sat Aug 24, 2019 7:31 pm Another thing I can think of is to make a completely new project file with VS 2019, in the past I had some issues when I used project files from VS2017 converted to VS2019, but maybe you did this already.
Ok thanks for the tip Joost.

Re: PGO compile on VS2019 not working

Posted: Sun Aug 25, 2019 2:17 pm
by Joost Buijs
Hopefully you can get it to work, I never use PGO while I'm developing, but the latest MSVC compiler really does a good job, especially with PGO.
I tried it with perft for the following 10 positions:

Code: Select all

{"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 6, 119060324},
{"r3k2r/1bp2pP1/5n2/1P1Q4/1pPq4/5N2/1B1P2p1/R3K2R b KQkq c3 0 1", 6, 8419356881},
{"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", 4, 4085603},
{"1Q5Q/8/3p1p2/2RpkpR1/2PpppP1/2QPQPB1/8/4K3 b - - 0 1", 7, 290063345},
{"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", 5, 193690690},
{"8/PPP4k/8/8/8/8/4Kppp/8 w - - 0 1", 6, 34336777},
{"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1", 7, 178633661},
{"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", 6, 8031647685},
{"r3r1k1/1pq2pp1/2p2n2/1PNn4/2QN2b1/6P1/3RPP2/2R3KB b - - 0 1", 6, 15097513050},
{"8/p1p1p3/8/1P1P2k1/1K2p1p1/8/3P1P1P/8 w - - 0 1", 7, 118590233},
With the AVX2 build that I normally use it does:

Total moves: 32486978249
Total time: 175.355 sec.
Average mps: 185264374
Errors: 0

With PGO it does:

Total moves: 32486978249
Total time: 154.644 sec.
Average mps: 210075808
Errors: 0

So this is a whopping 13.5% improvement for the move-generator/do-undo-move logic. A strange thing is that when I specify 'std:c++17' for language instead of the default this gives me about 2% improvement, you would expect that this has influence on the parser only, but it seems to change something in the code-generator/optimizer as well.

With the VS-2017 compiler I get on average 150 mps with the same positions and source code, so the code-generator improved quite a bit.