Profiling a mex-function

后端 未结 3 2442
醉话见心
醉话见心 2021-02-20 13:10

I have just rewritten a Matlab program in c++ as a mex-function to speed things up, with fantastic results. This optimization decision was a very very good idea, with up to a fa

相关标签:
3条回答
  • 2021-02-20 13:50

    Two possible solutions in addition to the fine ones already suggested.

    1. It's possible to write a script which loads the data, runs your mex function, and then exits. You can then let the profiler call the Matlab executable with that script. This worked for me with nVidia's visual profiler when I was profiling my CUDA mex functions.

    2. If you built the mex function in Visual Studio, you should be able to do attach to the Matlab process and then run the function for either debugging or profiling.

    0 讨论(0)
  • 2021-02-20 14:01

    Is there a way to run the whole thing under a VC IDE. Like you could say "debug DLL Foo.dll, using Matlab as the startup app".

    Then, if the function Bar you're using in Foo.dll runs in < 1 sec, make sure Matlab calls it a lot of times, or add a wrapper function in the DLL to call it a lot of times.

    If you can get to that point, you can use the manual call stack sampling technique, that really works in spite of not being popular or requiring installation of a tool.

    0 讨论(0)
  • 2021-02-20 14:04

    the only way i've managed to do this is to separate out the function doing the work and writing a separate wrapper (instead of mexFunction) that loads .mat files with test data and runs as a standalone executable. this can then be profiled using e.g. gprof

    0 讨论(0)
提交回复
热议问题