Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cmake/Modules/CheckAVX2Support.cmake fails to detect AVX2 #4967

Closed
rouault opened this issue May 10, 2024 · 1 comment · Fixed by #4969
Closed

cmake/Modules/CheckAVX2Support.cmake fails to detect AVX2 #4967

rouault opened this issue May 10, 2024 · 1 comment · Fixed by #4969

Comments

@rouault
Copy link
Contributor

rouault commented May 10, 2024

On Ubuntu 24.04 with gcc 13.2.0, AVX2 detection fails

Cf build_cmake/CMakeFiles/CMakeConfigureLog.yaml:

  -
    kind: "try_run-v1"
    backtrace:
      - "/usr/share/cmake-3.28/Modules/Internal/CheckSourceRuns.cmake:93 (try_run)"
      - "/usr/share/cmake-3.28/Modules/CheckCXXSourceRuns.cmake:52 (cmake_check_source_runs)"
      - "cmake/Modules/CheckAVX2Support.cmake:57 (check_cxx_source_runs)"
      - "CMakeLists.txt:252 (CheckAVX2Support)"
    checks:
      - "Performing Test COMPILER_SUPPORTS_AVX2"
    directories:
      source: "/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR"
      binary: "/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR"
    cmakeVariables:
      CMAKE_CXX_FLAGS: ""
      CMAKE_CXX_FLAGS_DEBUG: "-g"
      CMAKE_EXE_LINKER_FLAGS: ""
      CMAKE_MODULE_PATH: "/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/cmake;/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/cmake/Modules;/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/cmake/Options"
    buildResult:
      variable: "COMPILER_SUPPORTS_AVX2_COMPILED"
      cached: true
      stdout: |
        Change Dir: '/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR'
        
        Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_49a4d/fast
        /usr/bin/gmake  -f CMakeFiles/cmTC_49a4d.dir/build.make CMakeFiles/cmTC_49a4d.dir/build
        gmake[1]: Entering directory '/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR'
        Building CXX object CMakeFiles/cmTC_49a4d.dir/src.cxx.o
        /usr/bin/c++ -DCOMPILER_SUPPORTS_AVX2  -std=c++20 -o CMakeFiles/cmTC_49a4d.dir/src.cxx.o -c /home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR/src.cxx
        /home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR/src.cxx: In function 'int main()':
        /home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR/src.cxx:4:71: warning: AVX vector return without AVX enabled changes the ABI [-Wpsabi]
            4 |       __m256i packed = _mm256_set_epi32(-1, -2, -3, -4, -5, -6, -7, -8);
              |                                                                       ^
        In file included from /usr/lib/gcc/x86_64-linux-gnu/13/include/immintrin.h:51,
                         from /home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR/src.cxx:2:
        /usr/lib/gcc/x86_64-linux-gnu/13/include/avx2intrin.h:70:1: error: inlining failed in call to 'always_inline' '__m256i _mm256_abs_epi32(__m256i)': target specific option mismatch
           70 | _mm256_abs_epi32 (__m256i __A)
              | ^~~~~~~~~~~~~~~~
        /home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR/src.cxx:5:49: note: called from here
            5 |       __m256i absolute_values = _mm256_abs_epi32(packed);
              |                                 ~~~~~~~~~~~~~~~~^~~~~~~~
        In file included from /usr/lib/gcc/x86_64-linux-gnu/13/include/immintrin.h:43:
        /usr/lib/gcc/x86_64-linux-gnu/13/include/avxintrin.h:1274:1: error: inlining failed in call to 'always_inline' '__m256i _mm256_set_epi32(int, int, int, int, int, int, int, int)': target specific option mismatch
         1274 | _mm256_set_epi32 (int __A, int __B, int __C, int __D,
              | ^~~~~~~~~~~~~~~~
        /home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR/src.cxx:4:40: note: called from here
            4 |       __m256i packed = _mm256_set_epi32(-1, -2, -3, -4, -5, -6, -7, -8);
              |                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        gmake[1]: *** [CMakeFiles/cmTC_49a4d.dir/build.make:78: CMakeFiles/cmTC_49a4d.dir/src.cxx.o] Error 1
        gmake[1]: Leaving directory '/home/even/gdal/gdal/build_2404/tiledb/TileDB-2.23.0/build_cmake/CMakeFiles/CMakeScratch/TryCompile-4PCZFR'
        gmake: *** [Makefile:127: cmTC_49a4d/fast] Error 2
        
      exitCode: 2
    runResult:
      variable: "COMPILER_SUPPORTS_AVX2_EXITCODE"
      cached: true

Note that the gcc compilation line lacks a -mavx2, hence the failure to build the test program

The following patch fixes it:

--- cmake/Modules/CheckAVX2Support.cmake.ori	2024-05-10 22:59:59.525018317 +0200
+++ cmake/Modules/CheckAVX2Support.cmake	2024-05-10 23:00:14.888960496 +0200
@@ -53,7 +53,7 @@
   endif()
 
   cmake_push_check_state()
-  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${COMPILER_AVX2_FLAG}")
   check_cxx_source_runs("
     #include <immintrin.h>
     int main() {
@KiterLuc
Copy link
Contributor

Thanks for reporting this @rouault! @teo-tsirpanis can you make a PR for the change recommended here?

KiterLuc pushed a commit that referenced this issue May 13, 2024
[SC-47213](https://app.shortcut.com/tiledb-inc/story/47213)

A typo in #4449 prevented AVX2 from being detected in GCC. This PR fixes
the typo and adds logging to allow validating whether AVX2 was detected.

Fixes #4967.

---
TYPE: BUILD
DESC: Fix AVX2 support detection.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants