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.
37 # gmx_detect_avx_512_fma_units()
39 # Try to detect whether the host has one or two AVX-512 FMA units
40 # by executing a small program. This will only work on hosts that
41 # support AVX-512. If successful it sets RESULT to 1 or 2 for the
42 # number of AVX-512 FMA units, and otherwise -1.
44 function(gmx_detect_avx_512_fma_units RESULT)
45 if(CMAKE_CROSSCOMPILING)
46 set(${RESULT} -1 CACHE INTERNAL "Result of test for number of AVX-512 FMA units")
48 set(AVX_512_FMA_UNIT_DETECTION_BINARY "${PROJECT_BINARY_DIR}/CMakeFiles/GmxDetectAvx512FmaUnits${CMAKE_EXECUTABLE_SUFFIX}")
49 if(NOT AVX_512_FMA_UNIT_DETECTION_COMPILED)
51 # Find flags required for AVX-512
52 gmx_find_simd_avx_512_flags(SIMD_AVX_512_C_SUPPORTED SIMD_AVX_512_CXX_SUPPORTED
53 SIMD_AVX_512_C_FLAGS SIMD_AVX_512_CXX_FLAGS)
55 if(${SIMD_AVX_512_CXX_SUPPORTED})
56 # Compile the detection program
58 set(_compile_definitions "-I${PROJECT_SOURCE_DIR}/src -DGMX_IDENTIFY_AVX512_FMA_UNITS_STANDALONE ${SIMD_AVX_512_CXX_FLAGS} ${GMX_STDLIB_CXX_FLAGS}")
59 try_compile(AVX_512_FMA_UNIT_DETECTION_COMPILED
60 "${PROJECT_BINARY_DIR}"
61 "${PROJECT_SOURCE_DIR}/src/gromacs/hardware/identifyavx512fmaunits.cpp"
62 COMPILE_DEFINITIONS "${_compile_definitions}"
63 LINK_LIBRARIES "${GMX_STDLIB_LIBRARIES}"
64 OUTPUT_VARIABLE AVX_512_FMA_UNIT_DETECTION_COMPILED_OUTPUT
65 COPY_FILE ${AVX_512_FMA_UNIT_DETECTION_BINARY})
66 if(NOT AVX_512_FMA_UNIT_DETECTION_COMPILED AND NOT RUN_AVX_512_FMA_UNIT_DETECTION_COMPILATION_QUIETLY)
67 message(STATUS "Could not identify number of AVX-512 units - detection program did not compile")
69 set(RUN_AVX_512_FMA_UNIT_DETECTION_COMPILATION_QUIETLY TRUE CACHE INTERNAL "Keep quiet on any future compilation attempts")
72 if(AVX_512_FMA_UNIT_DETECTION_COMPILED)
74 if(NOT DEFINED ${RESULT})
75 execute_process(COMMAND ${AVX_512_FMA_UNIT_DETECTION_BINARY}
76 RESULT_VARIABLE RESULT_VAR
77 OUTPUT_VARIABLE OUTPUT_VAR_TEMP
79 if (RESULT_VAR EQUAL 0)
80 string(STRIP "${OUTPUT_VAR_TEMP}" OUTPUT_VAR)
81 set(${RESULT} ${OUTPUT_VAR_TEMP} CACHE INTERNAL "Result of test for number of AVX-512 FMA units")
83 message(STATUS "Could not identify number of AVX-512 units - detection program did run successfully")
84 set(${RESULT} -1 CACHE INTERNAL "Result of test for number of AVX-512 FMA units")