Skip to content
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 alloc #24

Closed
wants to merge 6 commits into from
Closed

Eigen alloc #24

wants to merge 6 commits into from

Conversation

ahundt
Copy link

@ahundt ahundt commented Feb 19, 2017

#23

Copy link
Collaborator

@haudren haudren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! It actually solved a problem I had today on the robot with the GazeTask. I'll just wait for @gergondet to submit feedback 😈

@@ -1 +1,41 @@
# Clang code formatting file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to add a .gitignore? I'm not sure we really want this in the repo, especially since some of the files are OSX specific...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helps me on both linux and mac... it is almost entirely binaries which shouldn't be committed anyway.

@@ -69,6 +69,8 @@ class TASKS_DLLAPI LSSOLQPSolver : public GenQPSolver
Eigen::VectorXd C_;

int nrALines_;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if it's possible to simply declare EIGEN_MAKE_ALIGNED_OPERATOR_NEW in the parent class? It would prevent a lot of repetition...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just being conservative on this... I assumed no unfortunately but haven't verified.

Copy link
Collaborator

@haudren haudren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR broke the build on Travis, because there is no eigen allocator for dynamic-size objects.

'std::vector<Eigen::VectorXd>', 'vector')
tasks.add_container('std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> >', 'Eigen::Vector3d', 'vector')
tasks.add_container('std::vector<Eigen::Matrix3d, Eigen::aligned_allocator<Eigen::Matrix3d> >', 'Eigen::Matrix3d', 'vector')
tasks.add_container('std::vector<Eigen::VectorXd, Eigen::aligned_allocator<Eigen::VectorXd> >', 'Eigen::VectorXd', 'vector')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, you should not use aligned allocation for dynamic size types... Even for some fixed-size objects, such care is not necessary. See here:
http://eigen.tuxfamily.org/dox-devel/group__TopicFixedSizeVectorizable.html

Long story short: things that have an even number of doubles in them (Vector2d, Vector4d, Matrix2d...).

@ahundt
Copy link
Author

ahundt commented Feb 22, 2017

actually... it does compile for eigen 3.3. I'll change it back anyway for the dynamic objects.

@gergondet
Copy link
Member

Hi,

As Hervé already pointed out, this is indeed an important issue that can be particularly

Thanks for all the work you put into this PR but I think most of it is unnecessary. An important thing to note is that EIGEN_MAKE_ALIGNED_OPERATOR_NEW does not entirely solve alignment issues with Eigen in C++11 (and beyond).

I will leave a comment here but this applies to the similar PRs on SVA and RBDyn.

I will start by citing this part of Eigen documentation:

If you define a structure having members of fixed-size vectorizable Eigen types, you must overload its "operator new" so that it generates 16-bytes-aligned pointers. Fortunately, Eigen provides you with a macro EIGEN_MAKE_ALIGNED_OPERATOR_NEW that does that for you.

Then this page defines what are fixed-size vectorizable Eigen types. According to this page and to the code you changed it would seem most of the EIGEN_MAKE_ALIGNED_OPERATOR_NEW you added are superfluous. In particular, no classes in SpaceVecAlg or RBDyn have fixed-size vectorizable Eigen types as members. I would rather not add superfluous code of such nature.

Similarly, it seems superfluous on most cases for Tasks but there is indeed some places where it should be required (e.g. GazeTask).

Finally, I'd prefer if we could find a better solution than what is suggested by Eigen because it does not work well in a C++11 context, e.g.:

std::shared_ptr<tasks::qp::GazeTask> qt = std::make_shared<tasks::qp::GazeTask>(mbs, 0, bodyName, pt, 1.0, sva::PTransformd::Identity());

can (and does) trigger alignment issues even with EIGEN_MAKE_ALIGNED_OPERATOR_NEW. I haven't look into the issue deeply so I don't have a suggestion yet. In the worst case scenario we could go with EIGEN_MAKE_ALIGNED_OPERATOR_NEW and advice people to avoid make_shared with Tasks.

@gergondet
Copy link
Member

I'm closing this since #29 superseeds it.

@gergondet gergondet closed this Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants