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

[SofaCore] FIX: enable ExtVecXf mappings with double floating type #827

Merged
merged 3 commits into from
Nov 29, 2018

Conversation

marques-bruno
Copy link
Member

Compiling sofa with SOFA_FLOATING_POINT_TYPE=double (no float) leads to a series of compile errors in Mapping and MultiMapping

I believe the bug has been introduced in PR #738

The reason for this crash is that some Mappings double->float are necessary for some applications (usually for visual models, CUDA, etc.).
Thus ExtVecXfTypes are always compiled, even when #ifndef SOFA_FLOAT

This PR fixes the bug, but also raises an important underlying point:
Having ifndefs everywhere in the code is very intrusive, source of errors, and most importantly, prevents having a full code coverage in the CI in a single build. Floats are slower, and much less precise than Doubles. We do not support XBox / PS3 code, thus we have one less reason to keep this code smell in the core of sofa.
If the only reason we still need floats is for Cuda compatibility and other visual rendering stuff, shouldn't the conversions be done in those components / plugins, instead of having this FLOAT things affecting the whole codebase of SOFA?

I dream of a sofa without all these ifdefs lying around polluting the code.
@courtecuisse @fredroy , you worked the most on CUDA stuff and visual rendering respectively, do you have an opinion on the subject?


This PR:

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

Reviewers will merge only if all these checks are true.

@marques-bruno marques-bruno added the issue: bug (major) Critical bug affecting everyone: not working, performances or accuracy degraded label Nov 14, 2018
@marques-bruno marques-bruno self-assigned this Nov 14, 2018
@marques-bruno marques-bruno added the pr: status to review To notify reviewers to review this pull-request label Nov 14, 2018
@jnbrunet
Copy link
Contributor

I agree that maintaining those ifdef are quite cumbersome and there are probably easier ways to manage this.

Just a small remark, while arithmetic operations on double are probably faster than float (well, at least on most of our hardware), using float might minimize cache misses and might, with the help of compiler optimisations, produce faster execution times on memory intensive application (like SOFA) .

I think we should test this before removing floats from everywhere. If we got different results, maybe we could set a default floating type for the entire Sofa, and allow modules to change this default value for their components.

@damienmarchal
Copy link
Contributor

IMO the complexity price we are paying right know in term of maintainability, code uglyness, bugs and weird issues it far bigger than the "un-measure" performance gain we expect. An our engineering time should be more useful in fixing all the crash/segfaul or performance issues because of n^2 algorithm (as in) than trying to get a totally minor (if any) performance increase because of switching from double to float.

So I recommand to only use Vec3Type in sofa instead of having both Vec3dType / Vec3fType, it will save thousand of man-month to invest more intelligent things.

As said by @jnbrunet, using Vec3Type allows to switch from float/double.

@marques-bruno marques-bruno added the pr: fast merge Minor change that can be merged without waiting for the 7 review days label Nov 15, 2018
@marques-bruno
Copy link
Member Author

Thanks for your feedback @jnbrunet @damienmarchal .

Meanwhile, this PR is ready, and I suggest reviewing it as a fast-merge since it's not much and fixes a compile-time issue for quite a few people.

@guparan guparan added pr: fix Fix a bug and removed issue: bug (major) Critical bug affecting everyone: not working, performances or accuracy degraded labels Nov 20, 2018
@guparan guparan changed the title FIX: moving definitions of double mappigs with ExtVecXf outside of SOFA_FLOAT only scope [SofaCore] FIX: enable ExtVecXf mappings with double floating type Nov 20, 2018
@hugtalbot hugtalbot added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Nov 21, 2018
@marques-bruno marques-bruno added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status wip Development in the pull-request is still in progress labels Nov 22, 2018
// this is needed even if SOFA_DOUBLE only is compiled
extern template class SOFA_CORE_API Mapping< sofa::defaulttype::Vec2dTypes, sofa::defaulttype::ExtVec2fTypes >;
extern template class SOFA_CORE_API Mapping< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >;
extern template class SOFA_CORE_API Mapping< sofa::defaulttype::Vec6dTypes, sofa::defaulttype::ExtVec3fTypes >;
Copy link
Contributor

Choose a reason for hiding this comment

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

If SOFA_FLOATING_POINT_TYPE=double, then SOFA_WITH_DOUBLE is defined so line 341 is activated.
Why this block?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this block should be just before the closing #endif //SOFA_WITH_FLOAT line 436 and the similar block line 341 should be deleted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, that was a duplicated bloc that I didn't remove after moving it in SOFA_WITH_DOUBLE:
VecXd -> ExtVecXf are required both when compiling in SOFA_WITH_DOUBLE and in SOFA_WITH_DOUBLE + SOFA_WITH_FLOAT. So technically, they could either be in the SOFA_WITH_DOUBLE bloc or in the combination of both, it would be the same.
Stupid logic. can't wait to see it dissapear...

@guparan guparan added pr: status to review To notify reviewers to review this pull-request and removed pr: status ready Approved a pull-request, ready to be squashed labels Nov 26, 2018
@guparan guparan 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 Nov 28, 2018
@guparan guparan merged commit c2de071 into sofa-framework:master Nov 29, 2018
@marques-bruno marques-bruno deleted the fix_mapping_nofloat branch December 5, 2018 08:31
@guparan guparan added this to the v18.12 milestone Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fast merge Minor change that can be merged without waiting for the 7 review days pr: fix Fix a bug pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants