2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2017,2019, 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)
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")
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}")
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 OUTPUT_VARIABLE AVX_512_FMA_UNIT_DETECTION_COMPILED_OUTPUT
67 COPY_FILE ${AVX_512_FMA_UNIT_DETECTION_BINARY})
68 if(NOT AVX_512_FMA_UNIT_DETECTION_COMPILED AND NOT RUN_AVX_512_FMA_UNIT_DETECTION_COMPILATION_QUIETLY)
69 message(STATUS "Could not identify number of AVX-512 units - detection program did not compile")
71 set(RUN_AVX_512_FMA_UNIT_DETECTION_COMPILATION_QUIETLY TRUE CACHE INTERNAL "Keep quiet on any future compilation attempts")
73 message(STATUS "Could not identify number of AVX-512 units - detection program missing compilation prerequisites")
76 if(AVX_512_FMA_UNIT_DETECTION_COMPILED)
78 if(NOT DEFINED ${RESULT})
79 execute_process(COMMAND ${AVX_512_FMA_UNIT_DETECTION_BINARY}
80 RESULT_VARIABLE RESULT_VAR
81 OUTPUT_VARIABLE OUTPUT_VAR_TEMP
83 if (RESULT_VAR EQUAL 0)
84 string(STRIP "${OUTPUT_VAR_TEMP}" OUTPUT_VAR)
85 set(${RESULT} ${OUTPUT_VAR_TEMP} CACHE INTERNAL "Result of test for number of AVX-512 FMA units")
87 message(STATUS "Could not identify number of AVX-512 units - detection program did run successfully")
88 set(${RESULT} -1 CACHE INTERNAL "Result of test for number of AVX-512 FMA units")