Counting flops for code!

It really takes my time. I could not find an easy way to evaluate FLOPS for the following code (loop), how many FLOPS for one iteration of the loop:

float func(float * atominfo, float energygridItem, int xindex, int yindex) { ... for (atomid=0; atomid<numatoms*4; atomid+=4) { float dy = coory - atominfo[atomid+2]; float dysqpdzsq = (dy * dy) + atominfo[atomid+3]; float dx1 = coorx1 - atominfo[atomid+1]; float s, y, t; s = atominfo[atomid] * (1.0f / sqrtf(dx1*dx1 + dysqpdzsq)); y = s - energycomp1; t = energyvalx1 + y; energycomp1 = (t - energyvalx1) - y; energyvalx1 = t; } ... } 

It looks simple, but I got confused in some other numbers given earlier, so it would be great if someone could specify the exact number.

Thanks.

+4
source share
4 answers

I see (in increasing order of difficulty):

  • 8 additions (incl. Deductions)
  • 3 multiplications
  • 1 inverse square root

How they relate to each other is highly dependent on the processor family.

+4
source

Try either executing the intermediate build code or decompiling exe.

Then count all floating point operations (in x86 build code, they start with the prefix F as FSIN ).

+5
source

I count 12 plus sqrt (which probably uses the Newton method, which is a loop), but it depends on the data types of some variables you didn't specify, and the compilation result (which may add more, or optimize some operations).

I count every +, /, - or *, where the expression contains at least one floating point variable, so the array indices and the loop invariant are not taken into account, and these are whole operations.

+1
source

Try using a performance measurement library such as PAPI, they provide abstractions for hardware counters that would be best for measuring FLOPS. PAPI_FLOPS

0
source

Source: https://habr.com/ru/post/1343990/


All Articles