This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Size of code generated by Eigen

Tags: None
(comma "," separated)
bminerd
Registered Member
Posts
4
Karma
0

Size of code generated by Eigen

Thu Dec 03, 2015 6:46 pm
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
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Size of code generated by Eigen

Thu Dec 03, 2015 8:12 pm
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....
bminerd
Registered Member
Posts
4
Karma
0

Re: Size of code generated by Eigen

Thu Dec 03, 2015 8:21 pm
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.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Size of code generated by Eigen

Thu Dec 03, 2015 9:40 pm
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.
bminerd
Registered Member
Posts
4
Karma
0

Re: Size of code generated by Eigen

Thu Dec 03, 2015 10:24 pm
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!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Size of code generated by Eigen

Fri Dec 04, 2015 9:45 am
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.
bminerd
Registered Member
Posts
4
Karma
0

Re: Size of code generated by Eigen

Tue Dec 08, 2015 2:38 pm
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
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Size of code generated by Eigen

Tue Dec 08, 2015 3:41 pm
great!


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot]