1

I need to measure the FLOPS for analyzing a Python program I did.

Based on what I found on the Internet it seems like there are two main options:

  1. Including counters in the program (which, I understand, it may make sense if the program is very simple and you are able to get access to a very atomized computations).
  2. Using libraries that access the CPU counters to derive the number of FLOPS. Like this one: http://www.bnikolic.co.uk/blog/python/flops/2019/09/27/python-counting-events.html

Sadly, the installation fails and, on top of that, the website clearly states that the Haswell CPUs are not supported because they don't have counters for floating point calculations. It turns out my server has this CPU. Hence I am stuck over there.

Nonetheless, I was thinking about including a system call to use perf (maybe os.system("perf --event event_for_flops "))

The problem is I have no clue about what is the proper event to monitor for the FLOPS information (assuming there is one, which, based on the "python-papi" library seems quite unlikely).

I listed all the possible events, but I am quite lost there. I tried to find some information on the Internet, but it was not helpful.

Any idea on what is the proper event to monitor (if any)? Or how to do this, without manually adding a counter at the very low level of the code, which for my case is directly unfeasible.

Please find here the full list of events:

List of events of Haswell CPU obtained with perf list command

f.gallardo
  • 41
  • 5
  • 1
    When you say FLOPS you mean floating point operations for second, right? – PiRocks Mar 06 '20 at 17:17
  • @PiRocks yes, that is correct – f.gallardo Mar 06 '20 at 17:18
  • 1
    This is likely going to be very much a processor arch. specific thing. `perf list`(may need sudo) on linux can tell you what sort of events you can capture and there name on linux. You can then use `perf stat -e` to get the value of those specific performance counters. – PiRocks Mar 06 '20 at 17:23
  • 1
    You may need to combine many counters to get a good result, for example they may be different counters for float additions and multiplications. – PiRocks Mar 06 '20 at 17:25
  • 1
    Also keep in mind that the code you write in python is high level, and that this could introduce inaccuracies in your results. – PiRocks Mar 06 '20 at 17:26
  • 1
    I don't have a Haswell handy, but the events you are looking for are going to be something like `fp_arith_inst_retired.scalar`. If you are using some sort of vectorized loops(unlikely in regular python), then you may want to look at events for that too. – PiRocks Mar 06 '20 at 17:43
  • 1
    @PiRocks: Yup, you're going to want `fp_arith_inst_retired.scalar_double` and `..._single`, and the 128b and 256b vector counts. If you're counting FLOPs in Python, hopefully you're using NumPy which does use SIMD code. The counters already count FMA as 2 operations, but you do have to multiply by the number of elements per SIMD vector. I found the linked duplicates by searching on `fp_arith_inst_retired.128b_packed_double` – Peter Cordes Mar 06 '20 at 17:58

0 Answers0