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

Add option to compile Eigen with alignment enabled #1196

Merged

Conversation

p12tic
Copy link
Contributor

@p12tic p12tic commented Jul 25, 2022

Eigen is most optimal when using SIMD instructions which require overaligned buffers. In C++14 this is a problem because there's no built-in support for correctly aligned allocations, so this Eigen feature is currently disabled in AliceVision. C++17 solves Eigen alignment issues completely because there now exist additional overloads of operator new() which support correct allocation alignment. We can't upgrade to C++17 yet, but certain compilers added support for this feature earlier, such as -faligned-new in GCC 7.1.

Given the above it makes sense to add a configuration option to allow enabling alignment support in Eigen in cases when the compiler is good enough (we enable -faligned-new automatically). This will improve performance for people who can control the set of supported compilers.

Clang also supports -faligned-new, but their documentation is empty and I didn't find which version of clang was the first to support the option, so I didn't add any special cases for clang yet.

@p12tic p12tic force-pushed the option-enable-aligned-eigen branch from 34c9707 to 8c9b081 Compare July 25, 2022 23:19
CMakeLists.txt Outdated Show resolved Hide resolved
@p12tic
Copy link
Contributor Author

p12tic commented Aug 25, 2022

@fabiencastan friendly ping :-) I think this PR is good to go.

@p12tic p12tic force-pushed the option-enable-aligned-eigen branch from 7c5b54e to 613c128 Compare August 26, 2022 22:47
@fabiencastan
Copy link
Member

We should also re-evaluate if we cannot switch to C++17 nowadays.

@p12tic
Copy link
Contributor Author

p12tic commented Aug 29, 2022

@fabiencastan I think just using C++17 is the cleanest solution. While I don't know where exactly AliceVision is used, but full C++17 is already supported in gcc 7.x, which is in e.g. Ubuntu 18.04 LTS already, so more than 4 years old. Similar situation is across other Linux distributions. On Windows it's rather easy to target older versions of Windows, so C++17 support should not be a problem either.

Eigen is most optimal when using SIMD instructions which require
overaligned buffers. In C++14 this is a problem because there's no
built-in support for correctly aligned allocations, so this Eigen
feature is currently disabled in AliceVision. C++17 solves Eigen
alignment issues completely because there now exist additional overloads
of operator new() which support correct allocation alignment. We can't
upgrade to C++17 yet, but certain compilers added support for this
feature earlier, such as -faligned-new in GCC 7.1. Therefore it makes
sense to add a configuration option to allow enabling alignment support
in Eigen in cases when the compiler is good enough.
@p12tic p12tic force-pushed the option-enable-aligned-eigen branch from 613c128 to 4ae2ff6 Compare August 29, 2022 17:15
@p12tic
Copy link
Contributor Author

p12tic commented Sep 8, 2022

@fabiencastan Just a friendly ping :) I think this PR can be merged.

@fabiencastan fabiencastan added this to the 2.5.0 milestone Sep 8, 2022
@fabiencastan fabiencastan merged commit f2e0c95 into alicevision:develop Sep 8, 2022
@fabiencastan
Copy link
Member

@p12tic Thinking again about it, we need to use the same flags for eigen in all dependencies.
Could add a test here in a new PR?

@p12tic
Copy link
Contributor Author

p12tic commented Sep 8, 2022

@p12tic Thinking again about it, we need to use the same flags for eigen in all dependencies. Could add a test here in a new PR?

Done in #1214

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