How to measure FLOPS of a MatLab function?

104 vues (au cours des 30 derniers jours)
Steven Bratt
Steven Bratt le 23 Oct 2012
I'm running MS-OS XP, service pack 3, Pentium 4, CPU 3.4GHz.
Matlab 7.11.0.584, 32 BIT.
BACKGROUND:
I recently installed a FLOPS toolbox called Lightspeed by Tom Minka. http://research.microsoft.com/en-us/um/people/minka/software/lightspeed/
The install went well, and I'm able to access the commands.
I'm running a function I've created that involves addition, subtraction, index searching, if-statements, for-loops, conditional statements, large database structures, etc...
QUESTION:
How do I use the FLOPS commands from the Lightspeed Toolbox to measure the number of flops performed by the function? I only want the total number of flops performed by the function.
And if that doesn't work, what other method exists to measure flops of a function in Matlab and how do I use those?

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Oct 2012
You cannot use the flops() command from that toolbox to measure the number of flops performed by one function: you have to rewrite the code so that every operation you want to be counted is specifically measured, such as by changing multiplication calls to flops_mult() calls.
What are you trying to measure, exactly? "Idealized" floating point operation counts sometimes have only a rough resemblance to actual code execution times.
  2 commentaires
Steven Bratt
Steven Bratt le 24 Oct 2012
I was trying to measure the overall number of flops to run the function. I wanted to measure flops for multiplication, for subtraction, for array index searching, for-loops, things of that nature.
Now by using flops_mult(), do I need to make a separate line of code for that? Or can it be part of my equations? What I mean is, do I choose 1) or 2)?
1)
x = A*b; %A is a matrix, b is an array
addflops(A*b,flops_multi)
2)
x = flops_multi(A*b);
Honestly, I plead ignorance when it comes to this toolbox. I don't know how to use the commands properly.
Alexey
Alexey le 12 Sep 2014
You probably already found the answer, but for the sake of others who might come across this, the answer is more like 2 - you need to add to your code a counting line for every operation you want counted. For example, if you want to do x=A*b:
flops(0) %start global flop count at 0
A=[1 2 3; 4 5 6];
b=[7 8 9]';
x=A*b; %do the operation
addflops(flops_mul(A, b)) %do the counting
flops %display count so far
you will get 10, which makes sense, there are 6 multiplications and 4 additions each costing 1 flop: [1*7+2*8+3*9; 4*7+5*8+6*9]. Note that the arguments to flops_mul should be the same as what you did. I say that for 2 reasons: 1) is obviously you want to count what was computed exactly, but 2) is that flops_mul doesn't seem to do any matrix multiplication checking - eg flops_mul([2 2; 2 2], [5 5 5 5 5]') happily returns 6 even though you can't multiply a 2x2 matrix with a 5x1 vector... Hope this helps

Connectez-vous pour commenter.

Plus de réponses (1)

wided hechkel
wided hechkel le 27 Août 2016
Modifié(e) : wided hechkel le 27 Août 2016
please can you give me the matlab code for calculating the FLOPs of this algorithm:
zf=10
for zj=0:0.01:20
for xf=1:1:64
for xi=0:0.01:10
for xr=1:1:128
ZT=sign(zj-zf)*sqrt((zj-zf)^2+(xf-xi)^2)-abs(zj-zf);
ZD=sqrt(zf^2+(xr-xi)^2)-zf;
somme=sum(zj-ZD-2*ZT);
end
end
end
end
i want to know the method of utilizing the lightspeed matlab toolbox, please can you give me the code not only the results of FLOPs number
  1 commentaire
Walter Roberson
Walter Roberson le 21 Mar 2017
Modifié(e) : Walter Roberson le 19 Juin 2017
The operation sqrt((zj-zf)^2+(xf-xi)^2) can be implemented in some architectures as hypot(zj-sf, xf-xi) where hypot is a built-in instruction. Such instructions can be more accurate than the naive computation done here for the case where the two values are between 0 and sqrt(realmin) as squaring such values would underflow to 0. How do you count FLOPS for a hybrid hardware instruction, one which might take fewer or more cycles than the naive equivalent (due to accuracy issues)? How do you count FLOPS for sqrt(), which is neither a multiply nor an addition?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Manual Performance Optimization dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by