Remove cycle suppression
[gromacs.git] / cmake / gmxDetectAvx512FmaUnits.cmake
blob6b21540c64c99837aec437a5ae3a160d9e571a05
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2017, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 include(gmxTestInlineASM)
36 include(gmxSimdFlags)
38 # gmx_detect_avx_512_fma_units()
40 # Try to detect whether the host has one or two AVX-512 FMA units
41 # by executing a small program. This will only work on hosts that
42 # support AVX-512. If successful it sets RESULT to 1 or 2 for the
43 # number of AVX-512 FMA units, and otherwise -1.
45 function(gmx_detect_avx_512_fma_units RESULT)
46     if(CMAKE_CROSSCOMPILING)
47         set(${RESULT} -1 CACHE INTERNAL "Result of test for number of AVX-512 FMA units")
48     else()
49         set(AVX_512_FMA_UNIT_DETECTION_BINARY "${PROJECT_BINARY_DIR}/CMakeFiles/GmxDetectAvx512FmaUnits${CMAKE_EXECUTABLE_SUFFIX}")
50         if(NOT AVX_512_FMA_UNIT_DETECTION_COMPILED)
52             # Find flags required for AVX-512
53             gmx_find_simd_avx_512_flags(SIMD_AVX_512_C_SUPPORTED SIMD_AVX_512_CXX_SUPPORTED
54                                         SIMD_AVX_512_C_FLAGS SIMD_AVX_512_CXX_FLAGS)
55             # Find flag for GCC inline assembly
56             gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
58             if(SIMD_AVX_512_CXX_SUPPORTED AND GMX_X86_GCC_INLINE_ASM)
59                 # Compile the detection program
61                 set(_compile_definitions "-I${PROJECT_SOURCE_DIR}/src -DGMX_IDENTIFY_AVX512_FMA_UNITS_STANDALONE -DSIMD_AVX_512_CXX_SUPPORTED=1 -DGMX_X86_GCC_INLINE_ASM=1 ${SIMD_AVX_512_CXX_FLAGS} ${GMX_STDLIB_CXX_FLAGS}")
62                 try_compile(AVX_512_FMA_UNIT_DETECTION_COMPILED
63                     "${PROJECT_BINARY_DIR}"
64                     "${PROJECT_SOURCE_DIR}/src/gromacs/hardware/identifyavx512fmaunits.cpp"
65                     COMPILE_DEFINITIONS "${_compile_definitions}"
66                     LINK_LIBRARIES "${GMX_STDLIB_LIBRARIES}"
67                     OUTPUT_VARIABLE AVX_512_FMA_UNIT_DETECTION_COMPILED_OUTPUT
68                     COPY_FILE ${AVX_512_FMA_UNIT_DETECTION_BINARY})
69                 if(NOT AVX_512_FMA_UNIT_DETECTION_COMPILED AND NOT RUN_AVX_512_FMA_UNIT_DETECTION_COMPILATION_QUIETLY)
70                   message(STATUS "Could not identify number of AVX-512 units - detection program did not compile")
71                 endif()
72                 set(RUN_AVX_512_FMA_UNIT_DETECTION_COMPILATION_QUIETLY TRUE CACHE INTERNAL "Keep quiet on any future compilation attempts")
73             else()
74                 message(STATUS "Could not identify number of AVX-512 units - detection program missing compilation prerequisites")
75             endif()
77             if(AVX_512_FMA_UNIT_DETECTION_COMPILED)
78                 # Run the program
79                 if(NOT DEFINED ${RESULT})
80                     execute_process(COMMAND ${AVX_512_FMA_UNIT_DETECTION_BINARY}
81                         RESULT_VARIABLE RESULT_VAR
82                         OUTPUT_VARIABLE OUTPUT_VAR_TEMP
83                         ERROR_QUIET)
84                     if (RESULT_VAR EQUAL 0)
85                         string(STRIP "${OUTPUT_VAR_TEMP}" OUTPUT_VAR)
86                         set(${RESULT} ${OUTPUT_VAR_TEMP} CACHE INTERNAL "Result of test for number of AVX-512 FMA units")
87                     else()
88                         message(STATUS "Could not identify number of AVX-512 units - detection program did run successfully")
89                         set(${RESULT} -1 CACHE INTERNAL "Result of test for number of AVX-512 FMA units")
90                     endif()
91                 endif()
92             endif()
93         endif()
94       endif()
95 endfunction()