Improve status messages for SIMD checks
authorErik Lindahl <erik@kth.se>
Fri, 24 Nov 2017 19:26:56 +0000 (20:26 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 28 Nov 2017 06:15:43 +0000 (07:15 +0100)
The present SIMD checks always include a blank flag as the last
variable. This will (obviously) always work as a compiler flag,
and then we instead issued a status message saying a compiler
flag was found, but updating binutils might help. This alters
the error message to reflect that no flag was found, and we are
intentionally unspecific and suggest updating the compiler and/or
binutils.

Change-Id: If99aeac391adc709c295e71b94583a8f9e395b0e

cmake/gmxFindFlagsForSource.cmake
cmake/gmxManageSimd.cmake

index 54f45bd083d6e1f72046c87623730374da5ec415..0efa4f4281de141b7ec9cdb124f37574e16242df 100644 (file)
@@ -77,13 +77,20 @@ FUNCTION(GMX_FIND_FLAG_FOR_SOURCE RESULT_VARIABLE SOURCE LANGUAGE TOOLCHAIN_FLAG
     # emulate AVX instructions with SSE4.1 otherwise.
     foreach(_testflag ${ARGN} "")
         # make valid variable names from the flag string: replace all non-alphanumerical chars
-        string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" FLAG_WORKS_VARIABLE "${LANGUAGE}_${_testflag}_FLAG_WORKS")
+        string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" FLAG_ACCEPTED_VARIABLE "${LANGUAGE}_${_testflag}_FLAG_ACCEPTED")
         string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_WORKS_VARIABLE "${LANGUAGE}_${_testflag}_COMPILE_WORKS")
 
-        # Check that the flag itself is fine, and that it does not generate warnings either
-        gmx_check_compiler_flag("${${TOOLCHAIN_FLAGS_VARIABLE}} ${_testflag}" "${LANGUAGE}" ${FLAG_WORKS_VARIABLE})
+        # Check that the flag itself is fine, and that it does not generate warnings either, but don't
+        # confuse the user by saying an empty flag was "accepted"
+        if("${_testflag}" STREQUAL "")
+            set(${FLAG_ACCEPTED_VARIABLE} 1)
+            # Give the empty flag variable a better name since we cannot control the CMake status messages
+            set(COMPILE_WORKS_VARIABLE "${LANGUAGE}_COMPILE_WORKS_WITHOUT_SPECIAL_FLAGS")
+        else()
+            gmx_check_compiler_flag("${${TOOLCHAIN_FLAGS_VARIABLE}} ${_testflag}" "${LANGUAGE}" ${FLAG_ACCEPTED_VARIABLE})
+        endif()
 
-        if(${FLAG_WORKS_VARIABLE})
+        if(${FLAG_ACCEPTED_VARIABLE})
             IF(DEFINED ${COMPILE_WORKS_VARIABLE})
                 # This is a subsequent call to CMake, don't spam the status line
                 set(RUN_QUIETLY TRUE)
@@ -94,11 +101,15 @@ FUNCTION(GMX_FIND_FLAG_FOR_SOURCE RESULT_VARIABLE SOURCE LANGUAGE TOOLCHAIN_FLAG
 
             if(NOT ${COMPILE_WORKS_VARIABLE})
                 if (NOT RUN_QUIETLY)
-                    message(STATUS "Compiler flag was valid, but executable did not build - perhaps update the binutils package")
+                    if("${_testflag}" STREQUAL "")
+                        message(STATUS "Could not find any flag to build test source (this could be due to either the compiler or binutils)")
+                    else()
+                        message(STATUS "Flag was accepted, but it did not build test source (this could be due to either the compiler or binutils)")
+                        set(SUGGEST_BINUTILS_UPDATE 1 PARENT_SCOPE)
+                    endif()
                 endif()
-                set(SUGGEST_BINUTILS_UPDATE 1 PARENT_SCOPE)
             endif()
-            if (${FLAG_WORKS_VARIABLE} AND ${COMPILE_WORKS_VARIABLE})
+            if (${FLAG_ACCEPTED_VARIABLE} AND ${COMPILE_WORKS_VARIABLE})
                 set(${RESULT_VARIABLE} 1 PARENT_SCOPE)
                 set(${NEW_FLAGS_VARIABLE} "${_testflag}" PARENT_SCOPE)
                 break()
index e592197d5c72cf868b96690cb00c1929e3d968c9..12e25a7a6a723c3ba9281840b767256aa90f4e01 100644 (file)
@@ -175,7 +175,7 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "MIC")
 
     # No flags needed. Not testing.
     set(GMX_SIMD_X86_MIC 1)
-    set(SIMD_STATUS_MESSAGE "Enabling MIC (Xeon Phi) SIMD instructions")
+    set(SIMD_STATUS_MESSAGE "Enabling MIC (Xeon Phi) SIMD instructions without special flags.")
 
 elseif(GMX_SIMD_ACTIVE STREQUAL "AVX_512")
 
@@ -244,7 +244,7 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "IBM_QPX")
 
     if (TEST_QPX)
         set(GMX_SIMD_${GMX_SIMD_ACTIVE} 1)
-        set(SIMD_STATUS_MESSAGE "Enabling IBM QPX SIMD instructions (no special flags)")
+        set(SIMD_STATUS_MESSAGE "Enabling IBM QPX SIMD instructions without special flags.")
     else()
         gmx_give_fatal_error_when_simd_support_not_found("IBM QPX" "or 'cmake .. -DCMAKE_TOOLCHAIN_FILE=Platform/BlueGeneQ-static-bgclang-CXX' to set up the tool chain" "${SUGGEST_BINUTILS_UPDATE}")
     endif()
@@ -287,7 +287,7 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "SPARC64_HPC_ACE")
     # Note that GMX_RELAXED_DOUBLE_PRECISION is enabled by default in the top-level CMakeLists.txt
 
     set(GMX_SIMD_${GMX_SIMD_ACTIVE} 1)
-    set(SIMD_STATUS_MESSAGE "Enabling Sparc64 HPC-ACE SIMD instructions")
+    set(SIMD_STATUS_MESSAGE "Enabling Sparc64 HPC-ACE SIMD instructions without special flags.")
 
 elseif(GMX_SIMD_ACTIVE STREQUAL "REFERENCE")
 
@@ -302,7 +302,7 @@ elseif(GMX_SIMD_ACTIVE STREQUAL "REFERENCE")
     endif()
 
     set(GMX_SIMD_${GMX_SIMD_ACTIVE} 1)
-    set(SIMD_STATUS_MESSAGE "Enabling reference (emulated) SIMD instructions.")
+    set(SIMD_STATUS_MESSAGE "Enabling reference (emulated) SIMD instructions without special flags.")
 
 else()
     gmx_invalid_option_value(GMX_SIMD_ACTIVE)
@@ -328,8 +328,19 @@ mark_as_advanced(GMX_ENABLE_AVX512_TESTS)
 
 if(GMX_ENABLE_AVX512_TESTS AND
     (GMX_SIMD_ACTIVE STREQUAL "AVX_256" OR GMX_SIMD_ACTIVE STREQUAL "AVX2_256" OR GMX_SIMD_ACTIVE STREQUAL "AVX2_128"))
+    if(NOT DEFINED SIMD_AVX_512_CXX_SUPPORTED)
+        message(STATUS "Detecting flags to enable runtime detection of AVX-512 units on newer CPUs")
+        set(SIMD_AVX_512_REPORT_STATUS 1)
+    endif()
     gmx_find_simd_avx_512_flags(SIMD_AVX_512_C_SUPPORTED SIMD_AVX_512_CXX_SUPPORTED
                                 SIMD_AVX_512_C_FLAGS SIMD_AVX_512_CXX_FLAGS)
+    if(SIMD_AVX_512_REPORT_STATUS)
+        if(SIMD_AVX_512_CXX_SUPPORTED)
+            message(STATUS "Detecting flags to enable runtime detection of AVX-512 units on newer CPUs - ${SIMD_AVX_512_CXX_FLAGS}")
+        else()
+            message(STATUS "Detecting flags to enable runtime detection of AVX-512 units on newer CPUs - not supported")
+        endif()
+    endif()
 endif()
 
 # By default, 32-bit windows cannot pass SIMD (SSE/AVX) arguments in registers,