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

45-50% performance improvement in MPPI controller using Eigen library for computation. #4621

Open
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

Ayush1285
Copy link
Contributor

@Ayush1285 Ayush1285 commented Aug 14, 2024

Basic Info

Info Please fill out this column
Ticket(s) this addresses #4237 #3351
Primary OS tested on Ubuntu
Robotic platform tested on NA, Optimizer Benchmark
Does this PR contain AI generated software? No

Description of contribution in a few bullet points

  • Replaced xtensor with Eigen library for computation.
  • Performance increased by 45-50% with footprint and critics enabled.
  • Currently WIP

Description of documentation updates required from your changes


Future work that may be required in bullet points

For Maintainers:

  • Check that any new parameters added are updated in docs.nav2.org
  • Check that any significant change is added to the migration guide
  • Check that any new features OR changes to existing behaviors are reflected in the tuning guide
  • Check that any new functions have Doxygen added
  • Check that any new features have test coverage
  • Check that any new plugins is added to the plugins page
  • If BT Node, Additionally: add to BT's XML index of nodes for groot, BT package's readme table, and BT library lists

Copy link
Contributor

mergify bot commented Aug 14, 2024

This pull request is in conflict. Could you fix it @Ayush1285?

Copy link
Contributor

mergify bot commented Aug 16, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Contributor

mergify bot commented Aug 19, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Contributor

mergify bot commented Aug 19, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

I did a pretty fast review, so far from complete on each detail, but a good starting point!

nav2_mppi_controller/CMakeLists.txt Outdated Show resolved Hide resolved
nav2_mppi_controller/CMakeLists.txt Outdated Show resolved Hide resolved
nav2_mppi_controller/CMakeLists.txt Outdated Show resolved Hide resolved
nav2_mppi_controller/CMakeLists.txt Show resolved Hide resolved
nav2_mppi_controller/CMakeLists.txt Outdated Show resolved Hide resolved
nav2_mppi_controller/src/critics/constraint_critic.cpp Outdated Show resolved Hide resolved
nav2_mppi_controller/src/optimizer.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

mergify bot commented Aug 20, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Contributor

mergify bot commented Aug 23, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

@SteveMacenski
Copy link
Member

Let me know here when you want me to take a look again! I'm quite excited for this work - even if for no reason than to move to Eigen + 10% performance boost, since Eigen's release and support is much more known than xtensor's

@Ayush1285
Copy link
Contributor Author

Let me know here when you want me to take a look again! I'm quite excited for this work - even if for no reason than to move to Eigen + 10% performance boost, since Eigen's release and support is much more known than xtensor's

Sure, I'm trying a few optimizations and will push changes once I'm done.

Signed-off-by: Ayush1285 <[email protected]>
Copy link
Contributor

mergify bot commented Sep 2, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

@Ayush1285
Copy link
Contributor Author

Ayush1285 commented Sep 3, 2024

Let me know here when you want me to take a look again! I'm quite excited for this work - even if for no reason than to move to Eigen + 10% performance boost, since Eigen's release and support is much more known than xtensor's

I've completed the migration to Eigen. But we need to make sure that functionality-wise everything is correct or not. I'll run tests and ensure that all of them are passing. Meanwhile, you can take a look at the latest changes.

Copy link
Contributor

mergify bot commented Sep 3, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

I did a first look through (didn't analyze in detail the math in the critics, but higher level programming items first), but generally looks good to me with some details to answer!

nav2_mppi_controller/CMakeLists.txt Show resolved Hide resolved
nav2_mppi_controller/benchmark/optimizer_benchmark.cpp Outdated Show resolved Hide resolved
nav2_mppi_controller/src/optimizer.cpp Outdated Show resolved Hide resolved
nav2_mppi_controller/src/optimizer.cpp Outdated Show resolved Hide resolved
nav2_mppi_controller/src/optimizer.cpp Outdated Show resolved Hide resolved
vx_last = vx_curr;

float & wz_curr = control_sequence_.wz(i);
wz_curr = std::clamp(wz_curr, wz_last - max_delta_wz, wz_last + max_delta_wz);
Copy link
Member

Choose a reason for hiding this comment

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

Worth having a util for clamp that implements this instead of putting inline for each location? It is prone to copy+paste errors

Copy link
Member

Choose a reason for hiding this comment

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

I think this is still nice-to-have, but I won't block for it

Copy link
Member

Choose a reason for hiding this comment

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

@Ayush1285 thoughts on adding this? it would make things quite a bit more readable and less error prone for future modifiations

Copy link
Contributor Author

@Ayush1285 Ayush1285 Nov 20, 2024

Choose a reason for hiding this comment

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

We can add an util function. What will it implement? Clamping for all x, y, and z values, or just wrapping std::min(..., std::max())?

Copy link
Member

Choose a reason for hiding this comment

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

Just a wrapper around min(max())

nav2_mppi_controller/src/optimizer.cpp Show resolved Hide resolved
Signed-off-by: Ayush1285 <[email protected]>
Copy link
Contributor

mergify bot commented Sep 9, 2024

@Ayush1285, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Contributor

mergify bot commented Sep 10, 2024

This pull request is in conflict. Could you fix it @Ayush1285?

@Ayush1285
Copy link
Contributor Author

@SteveMacenski It seems system tests are passing now after fixing the CostCritic issue but dwb_critics tests failed, Is it a flaky test? On my local system, it is passing.

Copy link

codecov bot commented Oct 20, 2024

Codecov Report

Attention: Patch coverage is 83.49515% with 51 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
..._mppi_controller/src/critics/constraint_critic.cpp 21.05% 15 Missing ⚠️
...ontroller/src/critics/velocity_deadband_critic.cpp 25.00% 12 Missing ⚠️
...2_mppi_controller/src/critics/obstacles_critic.cpp 70.58% 5 Missing ⚠️
..._mppi_controller/src/critics/path_angle_critic.cpp 85.71% 3 Missing ⚠️
...i_controller/src/critics/prefer_forward_critic.cpp 40.00% 3 Missing ⚠️
nav2_mppi_controller/src/optimizer.cpp 96.25% 3 Missing ⚠️
nav2_mppi_controller/src/critics/cost_critic.cpp 80.00% 2 Missing ⚠️
..._mppi_controller/src/critics/goal_angle_critic.cpp 60.00% 2 Missing ⚠️
nav2_mppi_controller/src/critics/goal_critic.cpp 71.42% 2 Missing ⚠️
..._mppi_controller/src/critics/path_align_critic.cpp 81.81% 2 Missing ⚠️
... and 2 more
Files with missing lines Coverage Δ
...er/include/nav2_mppi_controller/critic_manager.hpp 100.00% <ø> (ø)
...e/nav2_mppi_controller/models/control_sequence.hpp 100.00% <100.00%> (ø)
...oller/include/nav2_mppi_controller/models/path.hpp 100.00% <100.00%> (ø)
...ller/include/nav2_mppi_controller/models/state.hpp 100.00% <100.00%> (ø)
...clude/nav2_mppi_controller/models/trajectories.hpp 100.00% <100.00%> (ø)
...ler/include/nav2_mppi_controller/motion_models.hpp 100.00% <100.00%> (ø)
...troller/include/nav2_mppi_controller/optimizer.hpp 100.00% <ø> (ø)
...ude/nav2_mppi_controller/tools/noise_generator.hpp 100.00% <ø> (ø)
...v2_mppi_controller/tools/trajectory_visualizer.hpp 100.00% <ø> (ø)
...oller/include/nav2_mppi_controller/tools/utils.hpp 97.67% <100.00%> (+0.46%) ⬆️
... and 14 more

... and 3 files with indirect coverage changes


🚨 Try these New Features:

Signed-off-by: Ayush1285 <[email protected]>
@SteveMacenski
Copy link
Member

SteveMacenski commented Nov 7, 2024

Back from ROSCon / ROS-I meetings now. Reviewing the software / remaining open items today. I think next steps from there are for me to play with this on my machine as well and:

  • do some sanity testing of the various critics to make sure they're still working as I expect
  • do some functional sanity checking on the math for the (1) optimizer, (2) motion models, and (3) constraint compliance on the output optimal trajectory. These are software changes I want to scrutinize a little more functionally after a code review for my own piece of mind
  • Performance benchmarking :-)
  • Ask another non-me party to review the software changes and the performance on their practically applied platform as a second verification

Then good to merge and very publicly thank you for this amazing work 🎆

Is there anything else you think needs to be done here or is planned that we should factor in?

I'm noticing on the code coverage report that there are a couple of lines that are no longer being tested that the UX is saying were covered before in the Obstacle Critic and possibly Optimizer (?). Its just a few stray lines, but makes my eyebrows raise a little bit since I'm not sure how that's possible if the tests are unchanged and they appear to be things that should be triggering 🤷

Please go through all open comments (you may need to expand some the GitHub UX collapses) as some are open questions I want the 👍 on that you checked on those things. There are 5 above this comment :-)

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

I got to everything except for the main optimizer file, I ran out of time :(

nav2_mppi_controller/test/utils_test.cpp Show resolved Hide resolved
nav2_mppi_controller/test/utils_test.cpp Show resolved Hide resolved
nav2_mppi_controller/test/utils_test.cpp Show resolved Hide resolved
nav2_mppi_controller/test/utils_test.cpp Show resolved Hide resolved
nav2_mppi_controller/src/critics/prefer_forward_critic.cpp Outdated Show resolved Hide resolved
nav2_mppi_controller/src/critics/obstacles_critic.cpp Outdated Show resolved Hide resolved
nav2_mppi_controller/src/critics/obstacles_critic.cpp Outdated Show resolved Hide resolved
Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

Completed the full review

nav2_mppi_controller/src/optimizer.cpp Outdated Show resolved Hide resolved
@Ayush1285 Ayush1285 changed the title 20-25% performance improvement in MPPI controller using Eigen library for computation. 45-50% performance improvement in MPPI controller using Eigen library for computation. Nov 20, 2024
@Ayush1285
Copy link
Contributor Author

Ayush1285 commented Nov 20, 2024

Is there anything else you think needs to be done here or is planned that we should factor in?

@SteveMacenski Verifying the impact of the fast-math compiler flag needs to be done. On my machine, removing fast-math and keeping fma flag resulted in sped up for Eigen.

I'm noticing on the code coverage report that there are a couple of lines that are no longer being tested that the UX is saying were covered before in the Obstacle Critic and possibly Optimizer (?). Its just a few stray lines, but makes my eyebrows raise a little bit since I'm not sure how that's possible if the tests are unchanged and they appear to be things that should be triggering 🤷

I'll take a look at it.

@SteveMacenski
Copy link
Member

SteveMacenski commented Nov 21, 2024

To prevent us from scrolling up through old comments before the last review: the only one left open is the Clamp question where I responded "yes, just min(max()) to make it more ergonomic and help reduce likely issues with later modifications from other users"

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

Otherwise, my only open other things are the clamping util, copy in the util return, stride either mistake or my misunderstanding, and reviewing the test coverage

Everything else is on me to do some functional testing for external validation and this is finally good to be merged! I'm very optimistic we can get this in before the end of the year!

Signed-off-by: Ayush1285 <[email protected]>
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.

2 participants