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

Print warning if incompatible alignment option chosen #6184

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ if(WITH_SYSTEM_CJSON)
endif()
endif()

set(CMAKE_REQUIRED_LIBRARIES Eigen3::Eigen) # so that Eigen/Core is found below
CHECK_CXX_SOURCE_COMPILES("
#include <Eigen/Core>
#if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
#error Eigen will not use handmade_aligned_malloc (which is fine, we just throw an error here to make this compilation fail)
#endif
int main() { return 0; }"
PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC)
if (PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC) # CHECK_CXX_SOURCE_COMPILES does not necessarily set this to 0 or 1
set(PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC 1)
else()
set(PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC 0)
endif()
unset(CMAKE_REQUIRED_LIBRARIES)

### ---[ Create the config.h file
set(pcl_config_h_in "${CMAKE_CURRENT_SOURCE_DIR}/pcl_config.h.in")
set(pcl_config_h "${CMAKE_CURRENT_BINARY_DIR}/include/pcl/pcl_config.h")
Expand Down
23 changes: 23 additions & 0 deletions common/include/pcl/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,36 @@
*/

#include <pcl/type_traits.h> // for has_custom_allocator
#include <pcl/pcl_config.h> // for PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC

#include <Eigen/Core> // for EIGEN_MAKE_ALIGNED_OPERATOR_NEW

#include <memory> // for std::allocate_shared, std::dynamic_pointer_cast, std::make_shared, std::shared_ptr, std::static_pointer_cast, std::weak_ptr
#include <type_traits> // for std::enable_if_t, std::false_type, std::true_type
#include <utility> // for std::forward

#if !defined(PCL_SILENCE_MALLOC_WARNING)
#if PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC
// EIGEN_DEFAULT_ALIGN_BYTES and EIGEN_MALLOC_ALREADY_ALIGNED will be set after including Eigen/Core
// this condition is the same as in the function aligned_malloc in Memory.h in the Eigen code
#if (defined(EIGEN_DEFAULT_ALIGN_BYTES) && EIGEN_DEFAULT_ALIGN_BYTES==0) || (defined(EIGEN_MALLOC_ALREADY_ALIGNED) && EIGEN_MALLOC_ALREADY_ALIGNED)
#if defined(_MSC_VER)
#error "Potential runtime error due to aligned malloc mismatch! You likely have to compile your code with AVX enabled or define EIGEN_MAX_ALIGN_BYTES=32 (to silence this message at your own risk, define PCL_SILENCE_MALLOC_WARNING=1)"
#else // defined(_MSC_VER)
#warning "Potential runtime error due to aligned malloc mismatch! You likely have to compile your code with AVX enabled or define EIGEN_MAX_ALIGN_BYTES=32 (to silence this message at your own risk, define PCL_SILENCE_MALLOC_WARNING=1)"
#endif // defined(_MSC_VER)
#endif
#else // PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC
#if (defined(EIGEN_DEFAULT_ALIGN_BYTES) && EIGEN_DEFAULT_ALIGN_BYTES!=0) && (defined(EIGEN_MALLOC_ALREADY_ALIGNED) && !EIGEN_MALLOC_ALREADY_ALIGNED)
#if defined(_MSC_VER)
#error "Potential runtime error due to aligned malloc mismatch! PCL was likely compiled without AVX support but you enabled AVX for your code (to silence this message at your own risk, define PCL_SILENCE_MALLOC_WARNING=1)"
#else // defined(_MSC_VER)
#warning "Potential runtime error due to aligned malloc mismatch! PCL was likely compiled without AVX support but you enabled AVX for your code (to silence this message at your own risk, define PCL_SILENCE_MALLOC_WARNING=1)"
#endif // defined(_MSC_VER)
#endif
#endif // PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC
#endif // !defined(PCL_SILENCE_MALLOC_WARNING)

/**
* \brief Macro to signal a class requires a custom allocator
*
Expand Down
2 changes: 2 additions & 0 deletions pcl_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#endif //PCL_MINOR_VERSION
#endif

#define PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC ${PCL_USES_EIGEN_HANDMADE_ALIGNED_MALLOC}

#cmakedefine HAVE_OPENNI 1

#cmakedefine HAVE_OPENNI2 1
Expand Down