-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eigen allocation bug in tasks, rbdyn, sva, etc #23
Comments
Another question, do you think this will have any effect on when data is fed to any of the fortran solver backends? |
All the pull requests referenced above fix the crash in my software. I still need to add the correct allocator to std::vector and std::map instances. A side effect of these pull requests might also include improved performance. :-) |
Thanks for the PR! Just to confirm, you are working on MacOS ? It might explain the differences in behaviour... |
Yes I ran into this on Mac OS, I run on both mac and linux. I believe this can crop up on any OS. I ran into the problem when I updated to eigen 3.3, although this requirement has been present for quite a long time as I've encountered it in other unrelated code as well on both linux and mac. |
Still TODO is adding the allocator to the STL containers... |
Do you think This issue might also apply to types like probably something like this:
|
No, I'm not a fan of adding unnecessary template parameters and I'm not sure it would really help performance. |
The thing is it may cause the same kind of crash... I'm not completely sure of the detail of alignment of a struct/class containing aligned data. Now that I think on it, I'm guessing that most likely needs aligned allocation too to be guaranteed to work properly. |
@gergondet will these fixes be possible to merge? I've been running them for a few days now and they've fixed the relevant crashes for me. |
Continuing Discussion from @gergondet here. This post covers a number of possibilities for the Either way, there is a known bug that these pull requests resolve, so one way or another I don't think the code should be left as-is on master. Are you proposing I go through and remove the allocator lines everywhere there isn't a fixed size eigen type? Also, perhaps the way I specified the aligned allocators for every class is a bit conservative, but a much simpler rule like that makes it easier to avoid the case where somebody isn't aware of, or forgets, the rule and then adds a fixed size element to a class. |
Yes. But again, it should be vectorizable fixed size Eigen types, not just any fixed size Eigen types. In particular, the issue does not affect SpaceVecAlg and RBDyn at all since all fixed size objects used there are non vectorizable (i.e.
I think we don't need to worry about people who write code within the library. First of all, the code will be reviewed before its inclusion by people who should be aware of the issue. We can also probably come up with a test that has a good chance to trigger the alignment issue. On the other hand, what I am more worried about is people who write new libraries based on our work as |
@gergondet : If we want to avoid class contamination, the "best" way is probably to always encapsulate those containers as (const) member pointers i.e. in QPTasks, use a Overall, I agree, as this macro needs to be propagated to every class that has a member that contains the macro, it would be best to keep it as localized as possible. |
I've pushed the topic/FixAlignmentIssue branch that does that on a minimal number of tasks. I've followed @haudren suggestion regarding the const pointer member as this neatly allows to stop the propagation of I've identified the following tasks that should pose a problem:
I've taken care of the first two in my branch as a proof of concept. I have a simple test that fails (on 32 bits systems) when the allocation is not good but I don't think it's useful to add it to the repository atm. |
I've pushed a more complete fix to the topic/FixAlignmentIssue branch. I've also pushed a test that should trigger alignment issues (I can confirm it segfaults on a 32 bits platform before the alignment patches) It should fix the alignment issue we are facing. @ahundt can you test it on your current setup and check whether you face alignment issues or not? |
Sure I will might need a few days before I have the time to confirm. |
@gergondet looks good! Seems like it will make sense to merge now
sorry had lost track of this so my time estimate was way off :-) |
Seems good, @gergondet I think you can merge! This will help with #28 |
It seems there is a small flaw in many of the classes as per the eigen documentation on memory alignment:
They should all be declaring the following:
This problem only crops up sporadically in practice but when it does nothing runs! I might submit a pull request fixing this in quite a few places.
The same applies to all STL containers, their allocator must be set:
Using an aligned allocator
STL containers take an optional template parameter, the allocator type. When using STL containers on fixed-size vectorizable Eigen types, you need tell the container to use an allocator that will always allocate memory at 16-byte-aligned locations. Fortunately, Eigen does provide such an allocator: Eigen::aligned_allocator.
For example, instead of
std::map<int, Eigen::Vector4f>
you need to use
The case of std::vector
The situation with std::vector was even worse (explanation below) so we had to specialize it for the
Eigen::aligned_allocator
type. In practice you must use theEigen::aligned_allocator
(not another aligned allocator), and#include <Eigen/StdVector>
.Here is an example:
The text was updated successfully, but these errors were encountered: