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

Move the init of static variables to library load time #4640

Merged
merged 3 commits into from
Apr 9, 2021

Conversation

kunaltyagi
Copy link
Member

Possibly fixes #1593 (race condition in OMP implementation of SHOT)

@kunaltyagi kunaltyagi requested review from mvieth and larshg March 10, 2021 06:28
@kunaltyagi kunaltyagi added changelog: fix Meta-information for changelog generation module: features needs: testing Specify why not closed/merged yet labels Mar 10, 2021
@kunaltyagi
Copy link
Member Author

Wow, seems like apple-clang doesn't keep the lambdas unique

Copy link

@vseib vseib left a comment

Choose a reason for hiding this comment

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

Dear all,
this looks like a valid solution to #1593, thanks @kunaltyagi
I am not sure if I am allowed to approve a pull request, therefore I just create a review with a general comment.
Best,
Viktor

@kunaltyagi kunaltyagi added the changelog: ABI break Meta-information for changelog generation label Mar 11, 2021
@mvieth
Copy link
Member

mvieth commented Mar 12, 2021

@kunaltyagi What do you think about moving the RGB2LAB functionality to the common module? There is a function in gicp6d that basically does the same (without LUT).

@kunaltyagi
Copy link
Member Author

Sounds like a good idea. I'll take a deeper look either tomorrow or after the weekend.

@kunaltyagi
Copy link
Member Author

@vseib @mvieth PTAL This should still remove the race condition 🤞🏾 (static vars are specially protected by the standard), while allowing code reuse.

Added a bunch of references as well which I hunted down while making sure I wasn't messing up anything major

@kunaltyagi
Copy link
Member Author

@larshg Need help on windows 😄

@larshg
Copy link
Contributor

larshg commented Mar 15, 2021

It seems MSVC has a bug with constexpr and lambda - see here.

Setting them to just static instead of constexpr, then it works - not sure if that is sufficient?

Alternatively, you could add an additional definition of constexpr const std::size_t size = 1 << bits; within the lambda.

@kunaltyagi
Copy link
Member Author

Thanks @larshg. That worked wonders

@larshg
Copy link
Contributor

larshg commented Mar 15, 2021

Thanks @larshg. That worked wonders

Great😅

@kunaltyagi
Copy link
Member Author

I'll have to check this error on Windows before merging:

test\registration\test_registration.cpp(619): error: Expected: (reg.getFitnessScore ()) < (0.003), actual: 0.00387298 vs 0.003

@kunaltyagi
Copy link
Member Author

I'm unable to test why Windows is having such a large error in registration. On linux machines, the error is approx 4e-5, much lower than on Windows (reducing the LUT size used in GICP6D increases error, but going to 1024 increases it to only 4.5e-5)

Any ideas? Is this due to difference in c math lib?

@mvieth
Copy link
Member

mvieth commented Mar 18, 2021

I'm unable to test why Windows is having such a large error in registration. On linux machines, the error is approx 4e-5, much lower than on Windows (reducing the LUT size used in GICP6D increases error, but going to 1024 increases it to only 4.5e-5)

Any ideas? Is this due to difference in c math lib?

Perhaps because the second LUT is of float type, not of double? Not really a good explanation, but something to test out. Else you could try to replace the second LUT with a normal computation as it was before to check if that is the problem.
BTW I originally had something different in mind, maybe something like a simple class that creates the LUTs in the constructor and has a RGB2LAB function. SHOT and GICP6D could each have such an object as a class member, and use the conversion function when needed. I think with the current solution, in RGB2Lab in GICP6D, the LUTs are computed every time the function is called, aren't they? I think that would ultimately be worse than without LUTs.
But if you don't want to implement such a class and only focus on fixing the race condition in this PR, that would be fine, too.

@kunaltyagi
Copy link
Member Author

the LUTs are computed every time the function is called, aren't they?

This shouldn't be the case. The LUT are static variables inside the function. They are created on the first function call, and in a thread-safe manner (guarantee of language). Once init, they are returned safely.

Re: adding a class for easy conversion
IMO, the class for converting between colors should be left for another time, since colors aren't something that PCL specializes in either.

Re: float vs double
I'll push an update with double LUT since it's a plausible explanation. :) Let's see.

registration/src/gicp6d.cpp Show resolved Hide resolved
@mvieth
Copy link
Member

mvieth commented Apr 8, 2021

Ok, from my side, this is good to merge 👍

Added header for `array`, newly added in this PR

Move the LUT for sRGB and XYZ to common,

Also utilize them in gicp6d and SHOT
Not used for XYZ due to windows getting low accuracy with LUT
@kunaltyagi kunaltyagi merged commit 203067d into PointCloudLibrary:master Apr 9, 2021
@kunaltyagi kunaltyagi deleted the shot.static_init branch April 9, 2021 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: ABI break Meta-information for changelog generation changelog: fix Meta-information for changelog generation module: features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible race condition in FPFH feature, OMP implementation
4 participants