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

[cmake] AVX not detected on macos #5120

Closed
themightyoarfish opened this issue Jan 5, 2022 · 5 comments
Closed

[cmake] AVX not detected on macos #5120

themightyoarfish opened this issue Jan 5, 2022 · 5 comments
Labels

Comments

@themightyoarfish
Copy link
Contributor

I am compiling the current master c1835f4.

System is macos 10.15.7. The cmake configuration process does not pick up on the fact that both AVX and AVX2 should be available:

 > cmake ..                 -DBUILD_io=ON                 -DWITH_VTK=ON -DBUILD_kdtree=ON                 -DBUILD_visualization=ON -DBUILD_octree=ON                 -DBUILD_io=ON                 -DBUILD_filters=ON -DBUILD_surface=ON                 -DBUILD_CUDA=OFF                 -DBUILD_GPU=OFF -DBUILD_examples=OFF                 -DBUILD_features=ON -DBUILD_tools=ON                 -DBUILD_keypoints=OFF                 -DBUILD_ml=OFF -DBUILD_outofcore=OFF                 -DBUILD_people=OFF -DBUILD_tracking=OFF                 -DBUILD_registration=ON                 -DBUILD_recognition=OFF                 -DBUILD_stereo=OFF                 -DBUILD_ml=ON  -DBUILD_tools=ON -DBUILD_recognition=ON -DBUILD_keypoints=ON -DBUILD_apps=ON -DBUILD_apps_pointcloud_editor=ON-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/opt/ccache/libexec/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/opt/ccache/libexec/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2") 
-- Found ClangFormat: /usr/local/bin/clang-format (found suitable version "13.0.0", minimum required is "10") 
-- Adding target 'format'
-- Performing Test HAVE_MM_MALLOC
-- Performing Test HAVE_MM_MALLOC - Success
-- Performing Test HAVE_POSIX_MEMALIGN
-- Performing Test HAVE_POSIX_MEMALIGN - Success
-- Performing Test HAVE_SSE4_2_EXTENSIONS
-- Performing Test HAVE_SSE4_2_EXTENSIONS - Failed
-- Performing Test HAVE_SSE4_1_EXTENSIONS
-- Performing Test HAVE_SSE4_1_EXTENSIONS - Success
-- Performing Test HAVE_AVX2
-- Performing Test HAVE_AVX2 - Failed			# <-------- here
-- Performing Test HAVE_AVX
-- Performing Test HAVE_AVX - Failed

My cpu supports both AVX 1.0 and AVX2:

> /usr/sbin/sysctl -n machdep.cpu.features machdep.cpu.leaf7_features
[…] AVX1.0 […] AVX2 […]
@themightyoarfish themightyoarfish added kind: bug Type of issue status: triage Labels incomplete labels Jan 5, 2022
@themightyoarfish
Copy link
Contributor Author

themightyoarfish commented Jan 5, 2022

The first interesting observations is that in cmake/pcl_find_avx.cmake, CMAKE_COMPILER_IS_CLANG is false, no matter if I use ccache or Apple's default compiler.

This leads to CMAKE_REQUIRED_FLAGS not getting set and hence check_cxx_source_runs() tries to compile without -march=native which fails.

@themightyoarfish
Copy link
Contributor Author

Solution:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 63721efc7..84c9f5de4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,7 +47,7 @@ set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
 # Compiler identification
 # Define a variable CMAKE_COMPILER_IS_X where X is the compiler short name.
 # Note: CMake automatically defines one for GNUCXX, nothing to do in this case.
-if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*")
   set(CMAKE_COMPILER_IS_CLANG 1)
 elseif(__COMPILER_PATHSCALE)
   set(CMAKE_COMPILER_IS_PATHSCALE 1)

The check tests for exact compiler name, but on macos, the compiler is not Clang but AppleClang.

@mvieth
Copy link
Member

mvieth commented Jan 5, 2022

Could you take a look at #3131 ? If it looks good to you we could perhaps merge it soon

@themightyoarfish
Copy link
Contributor Author

themightyoarfish commented Jan 6, 2022

Well I can see that using that branch, optimizations are detected

-- Using CPU native flags for SSE optimization: -march=native

Cant's speak to the other changes in that PR.
With my fix here, I'm getting more flags, but that's probably because I'm basing on current master, and #3131 is some time behind.

-- -ftemplate-depth=1024 -Qunused-arguments -Wno-invalid-offsetof -msse4.2 -mfpmath=sse -march=native -mavx2 -Xclang -fopenmp

@mvieth
Copy link
Member

mvieth commented Feb 7, 2022

Fixed by pull request #5153

@mvieth mvieth closed this as completed Feb 7, 2022
@mvieth mvieth added module: cmake and removed status: triage Labels incomplete labels Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants