Registered Member
|
I'm attempting to (perhaps foolishly) use Eigen on a 32-bit ARM Cortex-M4 microcontroller. Initial results look pretty good, I'm able to build and run with very reasonable execution times. However, the code generated by Eigen for my fairly simple example (4-state Kalman Filter) is ~85 kB.
Now don't laugh, I know 85 kB is a piddly amount to a PC, but I'd like to be able to use Eigen on other versions of this microcontroller that have only 32 kB total flash memory. Currently I've set the following #defines: EIGEN_NO_DEBUG EIGEN_DONT_ALIGN EIGEN_MALLOC_ALREADY_ALIGNED EIGEN_NO_MALLOC Are there any other knobs I can turn to reduce the code size? I'm using fixed-size matrices only. Thanks, Ben |
Moderator
|
Some ideas:
- disable unrolling on Eigen's side with: -DEIGEN_UNROLLING_LIMIT=0 - try with compiler options: -Os, inlining, etc. (looking at the generated ASM with -S might also help figuring out code reduction opportunities) - make sure the general product kernel is never instanciated by using A.lazyProduct(B) instead of A*B - factorize some costly enough piece of codes within non-inlined functions. Sharing the core of your code might also help to propose more relevant suggestions.... |
Registered Member
|
Thanks for replying!
You can find a fairly recent version of my Kalman Filter implementation here: https://github.com/bminerd/Kalman/blob/ ... anFilter.h I'd rather not have to use things like "A.lazyProduct(B)" if possible, as the clean syntax of Eigen is a big draw for me. Unless there's an easy way to override? Ben Edit: Tried limiting unrolling, saved about 4 kB. |
Moderator
|
That's gonna be easy, replace:
JacobiSVD<MatrixXf> sMatrixSvd(sMatrix, ComputeThinU | ComputeThinV); by: JacobiSVD<Matrix<ValueType, nStates, nStates> > sMatrixSvd(sMatrix, ComputeFullU | ComputeFullV); You should get a huge code size reduction, and speedup too. |
Registered Member
|
Ahh yes, didn't think about that. Code size dropped 50 kB!
I'm thinking there might be a simpler inverse than using SVD, too, that could save some space. Thanks for your help! |
Moderator
|
50kB seems to be still a lot, here compiling with "-O3 -DNDEBUG" only, I observed a drop from 82KB to 17KB with such a change.
|
Registered Member
|
Oops, sorry. I meant it dropped by 50 kB down to ~30 kB.
I'm not using GCC, but after enabling high optimizations on my compiler (IAR EWARM) the Eigen code dropped to 14 kB. I can deal with that! Ben |
Moderator
|
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot]