Counting Flops for a code!

陌路散爱 提交于 2019-12-05 09:18:21

I see (in order of increasing complexity):

  • 8 additions (inc. subtractions)
  • 3 multiplications
  • 1 reciprocal-square-root

How these relate to each other depends strongly on the CPU family.

Try to either take intermediate assembly code or decompile exe.

Then count all floating point operations (in x86 assembly code they start with F prefix like FSIN).

I count 12 plus a sqrt (which is likely using Newton's method, which is a loop), but that depends on the data types of some variables that you did not specify, and the result of compilation (which may add more, or optimize out some operations).

I am counting each +, /, -, or * where the expression contains at least one floating point variable, so array indices and the loop invariant do not count, and those are integer operations.

Try using a performance measurement library like PAPI, they give abstractions to hardware counters which would be your best best to measure the FLOPS. PAPI_FLOPS.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!