From b6a9f6084ec2e469aebc111565ad8a5314b7ec9e Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Wed, 9 Sep 2020 21:51:17 -0700 Subject: [PATCH] Fix Visual Studio build - Add /permissive- flag to disable MSVC extension. Fixes ternary operator. - Fix usage of %l for size_t - Disable non-wroking FFTW SIMD check - Missing imports - Compiler warning fix --- cmake/FindFFTW.cmake | 100 +++++++++--------- cmake/gmxCFlags.cmake | 1 + cmake/gmxManageFFTLibraries.cmake | 18 ++-- .../hardware/device_management_common.cpp | 9 +- src/gromacs/mdlib/md_support.cpp | 1 + src/gromacs/mdtypes/checkpointdata.h | 2 + src/gromacs/mdtypes/energyhistory.cpp | 4 +- src/gromacs/nbnxm/pairlist.cpp | 2 +- 8 files changed, 76 insertions(+), 61 deletions(-) diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake index f46fe2c21b..b1f5827d34 100644 --- a/cmake/FindFFTW.cmake +++ b/cmake/FindFFTW.cmake @@ -106,56 +106,58 @@ if (${FFTW}_FOUND) message(FATAL_ERROR "Could not find ${${FFTW}_FUNCTION_PREFIX}_plan_many_[r2c|c2r] in ${${FFTW}_LIBRARY}, take a look at the error message in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log to find out what went wrong. If you are using a static lib (.a) make sure you have specified all dependencies of ${${FFTW}_PKG} in ${FFTW}_LIBRARY by hand (e.g. -D${FFTW}_LIBRARY='/path/to/lib${${FFTW}_PKG}.so;/path/to/libm.so') !") endif() - # Check for FFTW3 compiled with --enable-sse - foreach(SSE_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse ${${FFTW}_FUNCTION_PREFIX}_have_sse) - if (FFTW_LIBRARY_CHANGED) - unset(${FFTW}_HAVE_${SSE_FUNCTION} CACHE) - endif() - check_library_exists("${${FFTW}_LIBRARIES}" "${SSE_FUNCTION}" "" ${FFTW}_HAVE_${SSE_FUNCTION}) - if(${FFTW}_HAVE_${SSE_FUNCTION}) - set(${FFTW}_HAVE_SSE TRUE) - set(${FFTW}_HAVE_SIMD TRUE) - break() - endif() - endforeach() - - # Check for FFTW3 compiled with --enable-sse2 - foreach(SSE2_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse2 ${${FFTW}_FUNCTION_PREFIX}_have_sse2) - if (FFTW_LIBRARY_CHANGED) - unset(${FFTW}_HAVE_${SSE2_FUNCTION} CACHE) - endif() - check_library_exists("${${FFTW}_LIBRARIES}" "${SSE2_FUNCTION}" "" ${FFTW}_HAVE_${SSE2_FUNCTION}) - if(${FFTW}_HAVE_${SSE2_FUNCTION}) - set(${FFTW}_HAVE_SSE2 TRUE) - set(${FFTW}_HAVE_SIMD TRUE) - break() + if(NOT WIN32) # *_have_* functions aren't external. Thus aren't visible on Windows. + # Check for FFTW3 compiled with --enable-sse + foreach(SSE_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse ${${FFTW}_FUNCTION_PREFIX}_have_sse) + if (FFTW_LIBRARY_CHANGED) + unset(${FFTW}_HAVE_${SSE_FUNCTION} CACHE) + endif() + check_library_exists("${${FFTW}_LIBRARIES}" "${SSE_FUNCTION}" "" ${FFTW}_HAVE_${SSE_FUNCTION}) + if(${FFTW}_HAVE_${SSE_FUNCTION}) + set(${FFTW}_HAVE_SSE TRUE) + set(${FFTW}_HAVE_SIMD TRUE) + break() + endif() + endforeach() + + # Check for FFTW3 compiled with --enable-sse2 + foreach(SSE2_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse2 ${${FFTW}_FUNCTION_PREFIX}_have_sse2) + if (FFTW_LIBRARY_CHANGED) + unset(${FFTW}_HAVE_${SSE2_FUNCTION} CACHE) + endif() + check_library_exists("${${FFTW}_LIBRARIES}" "${SSE2_FUNCTION}" "" ${FFTW}_HAVE_${SSE2_FUNCTION}) + if(${FFTW}_HAVE_${SSE2_FUNCTION}) + set(${FFTW}_HAVE_SSE2 TRUE) + set(${FFTW}_HAVE_SIMD TRUE) + break() + endif() + endforeach() + + # Check for any other SIMD support in FFTW + if (NOT ${FFTW}_HAVE_SIMD) + foreach(SIMD_FCT + ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx + ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2 + ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2_128 + ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx512 + ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_128_fma + ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_512 + ${${FFTW}_FUNCTION_PREFIX}_have_simd_kcvi + ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec + ${${FFTW}_FUNCTION_PREFIX}_have_simd_neon + ${${FFTW}_FUNCTION_PREFIX}_have_simd_vsx + ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec + ${${FFTW}_FUNCTION_PREFIX}_have_altivec) # Name used before FFTW 3.3 + if (FFTW_LIBRARY_CHANGED) + unset(${FFTW}_HAVE_${SIMD_FCT} CACHE) + endif() + check_library_exists("${${FFTW}_LIBRARIES}" "${SIMD_FCT}" "" ${FFTW}_HAVE_${SIMD_FCT}) + if(${FFTW}_HAVE_${SIMD_FCT}) + set(${FFTW}_HAVE_SIMD TRUE) + break() + endif() + endforeach() endif() - endforeach() - - # Check for any other SIMD support in FFTW - if (NOT ${FFTW}_HAVE_SIMD) - foreach(SIMD_FCT - ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx - ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2 - ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2_128 - ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx512 - ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_128_fma - ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_512 - ${${FFTW}_FUNCTION_PREFIX}_have_simd_kcvi - ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec - ${${FFTW}_FUNCTION_PREFIX}_have_simd_neon - ${${FFTW}_FUNCTION_PREFIX}_have_simd_vsx - ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec - ${${FFTW}_FUNCTION_PREFIX}_have_altivec) # Name used before FFTW 3.3 - if (FFTW_LIBRARY_CHANGED) - unset(${FFTW}_HAVE_${SIMD_FCT} CACHE) - endif() - check_library_exists("${${FFTW}_LIBRARIES}" "${SIMD_FCT}" "" ${FFTW}_HAVE_${SIMD_FCT}) - if(${FFTW}_HAVE_${SIMD_FCT}) - set(${FFTW}_HAVE_SIMD TRUE) - break() - endif() - endforeach() endif() #Verify FFTW is compiled with fPIC (necessary for shared libraries) diff --git a/cmake/gmxCFlags.cmake b/cmake/gmxCFlags.cmake index 7f7e466326..5789f62e51 100644 --- a/cmake/gmxCFlags.cmake +++ b/cmake/gmxCFlags.cmake @@ -407,6 +407,7 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3;/wd161;/wd177;/wd411;/wd593;/wd981;/wd1418;/wd14 else() # MSVC projects only use the C++ flags GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068;" GMXC_CXXFLAGS) endif() + GMX_TEST_CXXFLAG(CXXFLAGS_LANG "/permissive-" GMXC_CXXFLAGS) endif() if (CMAKE_C_COMPILER_ID MATCHES "Clang") diff --git a/cmake/gmxManageFFTLibraries.cmake b/cmake/gmxManageFFTLibraries.cmake index 65434390aa..f59e011ecc 100644 --- a/cmake/gmxManageFFTLibraries.cmake +++ b/cmake/gmxManageFFTLibraries.cmake @@ -96,14 +96,16 @@ if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3") set(PKG_FFT "${${FFTW}_PKG}") include_directories(SYSTEM ${${FFTW}_INCLUDE_DIRS}) - if ((${GMX_SIMD_ACTIVE} MATCHES "SSE" OR ${GMX_SIMD_ACTIVE} MATCHES "AVX") AND NOT ${FFTW}_HAVE_SIMD) - set(FFT_WARNING_MESSAGE "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin") - else() - if(${GMX_SIMD_ACTIVE} MATCHES "AVX" AND NOT (${FFTW}_HAVE_SSE OR ${FFTW}_HAVE_SSE2)) - # If we end up here we have an AVX Gromacs build, and - # FFTW with SIMD. - set(FFT_WARNING_MESSAGE "The FFTW library was compiled with neither --enable-sse nor --enable-sse2; those would have enabled SSE(2) SIMD instructions. This will give suboptimal performance. You should (re)compile the FFTW library with --enable-sse2 and --enable-avx (and --enable-avx2 or --enable-avx512 if supported).") - endif() + if(NOT WIN32) # Detection doesn't work on Windows + if ((${GMX_SIMD_ACTIVE} MATCHES "SSE" OR ${GMX_SIMD_ACTIVE} MATCHES "AVX") AND NOT ${FFTW}_HAVE_SIMD) + set(FFT_WARNING_MESSAGE "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin") + else() + if(${GMX_SIMD_ACTIVE} MATCHES "AVX" AND NOT (${FFTW}_HAVE_SSE OR ${FFTW}_HAVE_SSE2)) + # If we end up here we have an AVX Gromacs build, and + # FFTW with SIMD. + set(FFT_WARNING_MESSAGE "The FFTW library was compiled with neither --enable-sse nor --enable-sse2; those would have enabled SSE(2) SIMD instructions. This will give suboptimal performance. You should (re)compile the FFTW library with --enable-sse2 and --enable-avx (and --enable-avx2 or --enable-avx512 if supported).") + endif() + endif() endif() find_path(ARMPL_INCLUDE_DIR "armpl.h" HINTS ${${FFTW}_INCLUDE_DIRS} diff --git a/src/gromacs/hardware/device_management_common.cpp b/src/gromacs/hardware/device_management_common.cpp index d505833d76..3d04323432 100644 --- a/src/gromacs/hardware/device_management_common.cpp +++ b/src/gromacs/hardware/device_management_common.cpp @@ -60,7 +60,14 @@ bool canPerformDeviceDetection(std::string* errorMessage) bool isDeviceDetectionEnabled() { - return c_binarySupportsGpus && getenv("GMX_DISABLE_GPU_DETECTION") == nullptr; + if (c_binarySupportsGpus) + { + return getenv("GMX_DISABLE_GPU_DETECTION") == nullptr; + } + else + { + return false; + } } bool canComputeOnDevice() diff --git a/src/gromacs/mdlib/md_support.cpp b/src/gromacs/mdlib/md_support.cpp index eab2e1e69a..26c19efa16 100644 --- a/src/gromacs/mdlib/md_support.cpp +++ b/src/gromacs/mdlib/md_support.cpp @@ -48,6 +48,7 @@ #include "gromacs/domdec/domdec.h" #include "gromacs/gmxlib/network.h" #include "gromacs/gmxlib/nrnb.h" +#include "gromacs/math/utilities.h" #include "gromacs/math/vec.h" #include "gromacs/mdlib/coupling.h" #include "gromacs/mdlib/gmx_omp_nthreads.h" diff --git a/src/gromacs/mdtypes/checkpointdata.h b/src/gromacs/mdtypes/checkpointdata.h index b82da7cf1e..e2a2f8829c 100644 --- a/src/gromacs/mdtypes/checkpointdata.h +++ b/src/gromacs/mdtypes/checkpointdata.h @@ -42,6 +42,8 @@ #ifndef GMX_MODULARSIMULATOR_CHECKPOINTDATA_H #define GMX_MODULARSIMULATOR_CHECKPOINTDATA_H +#include + #include "gromacs/math/vectypes.h" #include "gromacs/utility/arrayref.h" #include "gromacs/utility/keyvaluetreebuilder.h" diff --git a/src/gromacs/mdtypes/energyhistory.cpp b/src/gromacs/mdtypes/energyhistory.cpp index a0c09a08e2..5cadd9e4cb 100644 --- a/src/gromacs/mdtypes/energyhistory.cpp +++ b/src/gromacs/mdtypes/energyhistory.cpp @@ -92,8 +92,8 @@ void delta_h_history_t::doCheckpoint(gmx::CheckpointData checkpointDa checkpointData.scalar("start_lambda_set", &start_lambda_set); for (std::size_t idx = 0; idx < dh.size(); ++idx) { - checkpointVectorSize(&checkpointData, gmx::formatString("vecSize %lu", idx), &dh[idx]); - checkpointData.arrayRef(gmx::formatString("vec %lu", idx), + checkpointVectorSize(&checkpointData, gmx::formatString("vecSize %zu", idx), &dh[idx]); + checkpointData.arrayRef(gmx::formatString("vec %zu", idx), gmx::makeCheckpointArrayRef(dh[idx])); } } diff --git a/src/gromacs/nbnxm/pairlist.cpp b/src/gromacs/nbnxm/pairlist.cpp index 95f8243c88..aa29c61cde 100644 --- a/src/gromacs/nbnxm/pairlist.cpp +++ b/src/gromacs/nbnxm/pairlist.cpp @@ -3638,7 +3638,7 @@ static void print_reduction_cost(gmx::ArrayRef flags, int n } const auto numFlags = static_cast(flags.size()); fprintf(debug, - "nbnxn reduction: #flag %lu #list %d elem %4.2f, keep %4.2f copy %4.2f red %4.2f\n", + "nbnxn reduction: #flag %zu #list %d elem %4.2f, keep %4.2f copy %4.2f red %4.2f\n", flags.size(), nout, nelem / numFlags, nkeep / numFlags, ncopy / numFlags, nred / numFlags); } -- 2.22.0