Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When building Python with profile guided optimization do I have to leave the computer alone?

This may seem or even be a stupid question: When I build something self-tuning like Python with PGO (or ATLAS or I believe FFTW also does it), does the computer have to be otherwise idle (to not interfere with the measurements) or can I pass the time playing Doom?

The linked README from the python source distribution seems to deem this too trivial a matter to mention, but I'm genuinely unsure about this.

like image 230
Paul Panzer Avatar asked Dec 19 '17 21:12

Paul Panzer


People also ask

How do you use PGO?

Using PGO. Using PGO involves the following steps: Build the library/executable with instrumentation by passing -fprofile-generate to the compiler and linker. Collect profiles by running a representative workload on the instrumented binary.

What is PGO in programming?

Profile guided optimization (PGO), also known as profile-directed feedback (PDF), is a compiler optimization technique in computer programming that uses profiling to improve program runtime performance. PGO is supported in IBM® Open XL Fortran for AIX® 17.1. 0, and there are two ways to generate and use profile data.


1 Answers

What you do on your computer while it is performing the PGO measurements should have no impact what so ever on the result of the optimization. What PGO do is to use measurments to find the hot paths in the code for a given data set and use this information to make the program as fast as possible for this data set and which path is hot and which is not is independent of other programs running on the computer.

To explain things a bit, when optimizing code there are trade offs. The improvement will be higher in some parts of the code and lower in others depending on which code transforms are used and where they are applied. To get a better final result you want high improvements in code that is executed a lot (hot code in compiler lingo) while you can live with smaller improvements in code that is executed less frequently (cold code). Normally a set of heuristics are used to identify these hot parts of the program and apply optimizations in a way that makes these parts as fast as possible. The problem with this approach is that the heuristics does not know anything about how the program will be used in practice and may misidentify hot code as cold.

Profile guided optimization (PGO) is a method to help the compiler to locate the hot parts of the code using data from real executions. As a first step you tell the compiler to build an instrumented version of the program to measure how the code is executed in practice, typically by adding counters to count the number of iterations in loops and which branch is chosen in if-statements. The second step is to run the instrumented program on real data. At the end of execution the program will output the values of all the added counters and by matching counters with the code it is possible to see which parts of the program are hot (high numbers) and which are cold (low numbers). Finally the program is compiled but this time agumented with the program profile. This implies that the compiler no longer need to guess which parts should be faster and which could be slower it can look it up in the profile.

like image 61
Johan Avatar answered Nov 15 '22 14:11

Johan