On Thursday 21 April 2011, Julian Seward wrote:
> > Can anyone tell me, is it possible to collect number of fetches and
> > cache misses for a particular array using Callgrind/Cachegrind?
> > For example, I have such fragment:
> > 
> >                  for (j = 0; j < length; j++) {
> >                          for (i = ip[j]; i <= ip[j+1]-1; i++) {
> >                                  b[ia[i]] = b[ia[i]] + a[i]*x[j];
> >                          }
> >                  }
> > 
> > And I want to collect information only about array /b/. How can this be
> > done?
> 
> Short answer is, like this
> 
>       for (j = 0; j < length; j++) {
>               for (i = ip[j]; i <= ip[j+1]-1; i++) {
>                       long ia_i = ia[i];
>                       double tmp = a[i] * x[j];  // or whatever type it is
>                       b[ia_i] += tmp;
>               }
>       }

Good suggestion!

If you can decipher the machine code, that rewriting is not even needed.
Just run callgrind with "--dump-instr=yes" and identify the instructions
accessing array b (in the machine code annotation view of KCachegrind).

> Now the stats for the line b[ia_i] += tmp should show you info only
> for the /b/ access.
> 
> Long answer is, the question is kind-of meaningless.  Cache misses are
> a function of the overall memory behaviour of your program.  So the 
> misses on b[] also depend on how the program accesses a[], x[], ip[],
> etc, and you can't really measure each in isolation.

Just collecting pure counts in isolation is possible. It just does
not make much sense. Of course, the simulator always has to be fed by
all memory accesses. But you always want to see the relation of
separate counters to the total number.

If 90% of misses in the inner loop are because of accesses to array b,
it makes sense to do cache blocking on b.

Josef



> 
> J
> 
> ------------------------------------------------------------------------------
> Benefiting from Server Virtualization: Beyond Initial Workload 
> Consolidation -- Increasing the use of server virtualization is a top
> priority.Virtualization can reduce costs, simplify management, and improve 
> application availability and disaster protection. Learn more about boosting 
> the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
> _______________________________________________
> Valgrind-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
> 



------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to