Re: [eigen] Performance tuning

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]




On Wed, Dec 28, 2011 at 6:50 PM, Tim Holy <holy@xxxxxxxxx> wrote:
Hi,

I'm writing to ask about people's favorite techniques for tuning the
performance of their code, and in particular whether there exists a HOWTO (or
a desire to write one).

Here's one example: for the kinds of problems I'm studying, I've found that
one of the most helpful steps is to avoid the creation of temporaries. Because
temporaries are usually created "silently," I am sometimes surprised by which
lines are triggering temporaries. Once I discovered that this was an issue,
here's how I went about solving the problem at first:
1. Compile the program with debugging symbols and optimization
2. Profile my code in valgrind
3. See how many times posix_memalign gets called.
4. If it's too many, comment out a suspicious-looking block of code.
5. Go back to step 1 until the problem is localized, then fix it.
But after growing tired of this process, I finally realizing that a better way
to discover the problematic line(s) is to set a breakpoint in
Core/Util/Memory.h::aligned_realloc. And, of course, maybe there's even a
better way I haven't yet stumbled across, like setting some compiler flag to
throw an exception upon the creation of a temporary?

The EIGEN_RUNTIME_NO_MALLOC macro might help here. It is especially useful for unit tests. Minimal usage example:

#define EIGEN_RUNTIME_NO_MALLOC // Define this symbol to enable runtime tests for allocations
#include <Eigen/Dense>

int main(int argc, char** argv)
{
  // It's OK to allocate here
  Eigen::MatrixXd A = Eigen::MatrixXd::Random(20, 20);

  Eigen::internal::set_is_malloc_allowed(false);
  // It's NOT OK to allocate here
  // An assertion will be triggered if an Eigen-related heap allocation takes place

  Eigen::internal::set_is_malloc_allowed(true);
  // It's OK to allocate again
}

HTH,

Adolfo.



But there are other issues I don't know how to solve. For example, in
valgrind, I frequently wish that the cost of inlined code could be "folded in"
to the cost computed for the individual lines of my source code. Does anyone
know of a way of doing that? Or is there a different tool that can do this?

A natural gathering place for useful tips might be
http://eigen.tuxfamily.org/index.php?title=Developer's_Corner#Profiling_tips
but currently that section is fairly short.

Best,
--Tim





--
Adolfo Rodríguez Tsouroukdissian
Robotics engineer
adolfo.rodriguez@xxxxxxxxxxxxxxxx
http://www.pal-robotics.com

PAL ROBOTICS S.L
c/ Pujades 77-79, 4º4ª
08005 Barcelona, Spain.
Tel. +34.93.414.53.47
Fax.+34.93.209.11.09

AVISO DE CONFIDENCIALIDAD: Este mensaje y sus documentos adjuntos, pueden contener información privilegiada y/o confidencial que está dirigida exclusivamente a su destinatario. Si usted recibe este mensaje y no es el destinatario indicado, o el empleado encargado de su entrega a dicha persona, por favor, notifíquelo inmediatamente y remita el mensaje original a la dirección de correo electrónico indicada. Cualquier copia, uso o distribución no autorizados de esta comunicación queda estrictamente prohibida.

CONFIDENTIALITY NOTICE: This e-mail and the accompanying document(s) may contain confidential information which is privileged and intended only for the individual or entity to whom they are addressed.  If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of this e-mail and/or accompanying document(s) is strictly prohibited.  If you have received this e-mail in error, please immediately notify the sender at the above e-mail address.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/