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

Custom allocators

Tags: None
(comma "," separated)
gregoire
Registered Member
Posts
3
Karma
0

Custom allocators

Fri Jan 28, 2011 4:13 pm
As mentioned here: "custom allocator for sparse and dynamic-sized vecs/matrices?" it would be great to use custom allocators.

Passing an allocator as template parameter of Matrix would be great because one could implement so many great features: track info about who allocated what and when, use a memory pool, etc. But It might be long to implement...

I am wondering if it would be a good and easy thing to slightly modify the following implementations:

ei_matrix_array
ei_conditional_aligned_realloc_new
ei_conditional_aligned_delete

and use an option to select a custom allocation/storage method.

For example the declaration of ei_matrix_array could be:
Code: Select all
template <typename T, int Size, int MatrixOptions,
          int Alignment = (MatrixOptions&DontAlign) ? 0
                        : (((Size*sizeof(T))%16)==0) ? 16
                        : 0,
          int CustomArray = MatrixOptions&UseMatrixArrayPlugin>
ei_matrix_array
{
  T array[Size];
  ei_matrix_array() {}
  ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
}

And somewhere with the Eigen plugin mechanism already used here and there have a specialized template like that:

Code: Select all
templare</* ... */>
struct ei_matrix_array</* ... */>
{
  T array[Size];
  ei_matrix_array() {MyMemoryTracker::add(Size);}
  ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
  ~ei_matrix_array(){MyMemoryTracker::remove(Size);}
}
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Custom allocators

Sat Jan 29, 2011 4:30 am
Just a few remarks as we really dont have much time to spend on that with the impending 3.0 release.

* bugzilla is a better place for discussion of feature development
* dont hesitate to work on proofs of concept, you can use 'forks' on bitbucket.org to share your work
* work off eigen3, not eigen2


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
gregoire
Registered Member
Posts
3
Karma
0

Re: Custom allocators

Sat Jan 29, 2011 11:02 pm
Ok, sorry. Just wanted to check if someone had already done something about that.
I'll switch to bugzilla.
MarkusS
Registered Member
Posts
9
Karma
0
OS

Re: Custom allocators

Sun Jan 30, 2011 1:08 am
I just finished implementing a private allocator for Eigen. The allocator can be activated by defining EIGEN_USE_PRIVATE_ALLOC before including any Eigen headers. It replaces eigen_alinged_malloc / eigen_alinged_free in eigen_aligned_new / eigen_aligned_delete and should be transparent for the user.

I am happy to share the code. It's tested with OSX 10.6 (64bit) and with Linux (x86), but should also work with Linux amd64. There is some code for Windows, but this is not tested yet...

What is the best way to contribute the code to Eigen?

Markus
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Custom allocators

Sun Jan 30, 2011 1:12 am
* if you just want to share code, without necessarily pushing for it to be included in eigen, a fork on bitbucket.org is a good way

* if you want discussing including this into eigen, file a bug @ bugzilla.

* if you want a more general discussion with more people interested in eigen, use the mailing list


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
MarkusS
Registered Member
Posts
9
Karma
0
OS

Re: Custom allocators

Sun Jan 30, 2011 2:20 am
All right,

I created a new fork and tried to add my code. Please check https://bitbucket.org/MarkusS/eigen-private-alloc and see if my code works for you. (Haven't used hg before, so be gentle ;)). So only modification is a few lines in Memory.h and two new files, PrivateAlloc.h and Mutex.h (like Memory.h in src/Core/util).

As I said before, just define EIGEN_USE_PRIVATE_ALLOC before including any Eigen headers and enjoy. Use valgrind to check for the numbers of malloc with and without the define, especially if you use Eigen in long loops.

I'll also add a bug @ bugzilla...

Thanks,

Markus


Bookmarks



Who is online

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