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

[LinearSystem] Introduce components to map matrices #4490

Merged
merged 9 commits into from
Feb 22, 2024

Conversation

alxbilger
Copy link
Contributor

In some simulations relying on mappings, a computation intensive task is the product J^T * K * J (including the computation of J). To offer the user a choice of strategy regarding the way to compute this product, I introduce a component MatrixMapping. This component is optional in a scene. If not present, it will be created automatically with a generic-purpose strategy, i.e. the one already implemented.

In order to illustrate the options given to the user, I already added a Data to consider the mapping Jacobians to be constant. For example, it is true for ModelOrderReductionMapping. In the future, maybe this property can be defined automatically. I benchmarked the reduced diamond robot over 1000 time steps (the previous benchmark is in #4443):

Before

[INFO]    [BatchGUI] 1000 iterations done in 17.4661 s ( 57.2539 FPS). 
 LEVEL   START    NUM      MIN     MAX   MEAN     DEV    TOTAL  PERCENT ID
   6       1.08    1      11.85   20.52   13       0.85   13      88.39 ......projectMappedMatrices

After (with areJacobiansConstant=True)

[INFO]    [BatchGUI] 1000 iterations done in 12.3888 s ( 80.7183 FPS).
 LEVEL   START    NUM      MIN     MAX   MEAN     DEV    TOTAL  PERCENT ID
   6       1.03    1       7.64   18.39    8.59    0.76    8.59   84.35 ......projectMappedMatrices

Speed up x1.5 on the matrix mapping.

Note that using a ConstantSparsityPatternSystem instead of a MatrixLinearSystem is slightly faster (but it is not in the scope of this PR):

[INFO]    [BatchGUI] 1000 iterations done in 11.7897 s ( 84.82 FPS).

Plans for the future:

  • Write a new MatrixMapping component taking advantage of the constant sparsity pattern to further improve the performances
  • Write a new MatrixMapping component that would use multithreading, and maybe one using the GPU

By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request pr: highlighted in next release Highlight this contribution in the notes of the upcoming release labels Feb 9, 2024
@alxbilger
Copy link
Contributor Author

alxbilger commented Feb 9, 2024

Finally, the optimization in 1b04773 allows the following timing:

[INFO]    [BatchGUI] 1000 iterations done in 9.61064 s ( 104.051 FPS).
 LEVEL   START    NUM      MIN     MAX   MEAN     DEV    TOTAL  PERCENT ID
   6       0.76    1       5.59   15.95    6.37    0.69    6.37   83.21 ......projectMappedMatrices

Speed up x2 compared to before this PR

@alxbilger alxbilger force-pushed the matrixmapping branch 2 times, most recently from 9e03f23 to 6274dae Compare February 12, 2024 08:46
@alxbilger
Copy link
Contributor Author

[ci-build][with-all-tests]

@@ -80,6 +80,10 @@
<MechanicalObject template="Vec3d" name="DOFs"/>
<SubsetMapping input="@../DOFs" output="@DOFs" indices="@box.indices"/>
</Node>
<MatrixProjectionMethod areJacobiansConstant="true" mechanicalStates="@/rigidSections/green/a/DOFs @/rigidSections/green/a/DOFs"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@damienmarchal I was not able to move this component in a header part because of links towards mechanical states that don't exist yet.

@bakpaul bakpaul added this to the v24.06 milestone Feb 20, 2024
@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Feb 21, 2024
@fredroy fredroy merged commit 43f2e77 into sofa-framework:master Feb 22, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement About a possible enhancement pr: highlighted in next release Highlight this contribution in the notes of the upcoming release pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants